QQ背景层界面,最复杂的要数Flash播放了。
Qt自带有播放Flash的插件:QAxWidget,正常播放flash没有问题,当被响应层覆盖后,不刷新,会变成黑色。如下:
目前使用定时器播放图片模拟动画[PseudoFlashWidget],效果如下[每组40张照片,目前播放过快或有卡顿,可通过改变图片序列和定时器时间间隔来改进], 该方法不成熟,顾目前未加到资源文件中,通过目录读取,效果:
因此,之前的类图变更为:
期待Qt正统的Flash播放方法,现附上这两个类的实现:
FlashWidget:
#include "flashwidget.h"
#include <QPainter>
#include <QLabel>
#include <QMovie>
FlashWidget::FlashWidget(QString flashPath, QWidget *parent) :
BackgroundWidget(parent)
{
if(parent)
this->setFixedSize(parent->size());
this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
flash = new QAxWidget(parent);
flash->setFixedSize(this->size());
flash->show();
flash->setControl(QString::fromUtf8("{d27cdb6e-ae6d-11cf-96b8-444553540000}"));
flash->dynamicCall("LoadMovie(long,string)",0, flashPath);
// flash->dynamicCall("WMode", "transparent");
timer = new QTimer;
connect(timer, &QTimer::timeout, this, &FlashWidget::update);
timer->start(1000);
}
void FlashWidget::update()
{
flash->update();
}
void FlashWidget::paintEvent(QPaintEvent *)
{
}
PseudoFlashWidget:
#include "pseudoflashwidget.h"
#include <Qpainter>
#include <QDir>
#include <iostream>
using namespace std;
PseudoFlashWidget::PseudoFlashWidget(const QString &dirPath, QWidget *parent) :
BackgroundWidget(parent)
{
QDir dir(dirPath);
if(!dir.exists())
{
cout << dirPath.toStdString() << " not exist."<<endl;
}
dir.setFilter(QDir::Files);
dir.setSorting(QDir::Name);
QFileInfoList list = dir.entryInfoList();
for (int i = 0; i < list.size(); ++i) {
QFileInfo fileInfo = list.at(i);
//cout << fileInfo.filePath().toStdString()<<endl;
pixmaps.push_back(QPixmap(fileInfo.filePath()));
}
if(parent)
this->setFixedSize(parent->size());
else
{
if(pixmaps.size() > 0)
this->setFixedSize(pixmaps[0].size());
}
texturePixmap = QPixmap(":/background/texture").copy(10, 5, 25, this->height());
index = 0;
timer = new QTimer();
connect(timer, &QTimer::timeout, this, &PseudoFlashWidget::setNext);
timer->start(200);
}
void PseudoFlashWidget::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.drawPixmap(this->rect(), pixmaps[index]);
painter.drawPixmap(this->rect(), texturePixmap);
}
void PseudoFlashWidget::setNext()
{
index++;
if(index >= pixmaps.size())
index = 0;
this->update();
}