注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

沙漠里de烟雨

原创分享,禁止转载

 
 
 

日志

 
 

Qt---实现仿360桌面加速球效果  

2014-04-17 20:31:57|  分类: QT5.x与QML |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
先看效果图:

 
Qt---实现仿360桌面加速球效果 - 漠雨 - 沙漠里de烟雨__原创人生
 
Qt---实现仿360桌面加速球效果 - 漠雨 - 沙漠里de烟雨__原创人生
 
Qt---实现仿360桌面加速球效果 - 漠雨 - 沙漠里de烟雨__原创人生

关键代码:
QMovie::setCacheMode(QMovie::CacheAll);
QMovie::start();
QMovie::setPaused(true);
QMovie::jumpToFrame(int);
qApp->processEvents();
三张图片位于同一位置(Z轴方向,最先new的在z轴最内,最后new的在z轴最外)

代码:
//main.cpp ==》

#include "update.h"
#include <QtWidgets/QApplication>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Update w;
w.show();
return a.exec();
}


//update.h ==》

#ifndef UPDATE_H
#define UPDATE_H

#include <QtWidgets/QDialog>

class QMovie;
class QLabel;

class Update : public QDialog
{
Q_OBJECT

public:
Update(QWidget *parent = 0);
~Update();
//overwrite:
protected:
void mousePressEvent(QMouseEvent * event);
void mouseMoveEvent(QMouseEvent * event);

public slots:
void UpdateSlot(int);
void UpdateSlot(const QString&);

private:
QPoint m_LastPoint;
QMovie* m_ProcessMovie;
QString m_NoteText;
QLabel* m_UpdatingTextLabel;
private:
int m_UpdateFileCount;
int m_UpdateingFileNumber;

};

#endif // UPDATE_H


//update.cpp ==》

#include "update.h"

#include <QLabel>
#include <QMovie>
#include <QLayout>
#include <QMouseEvent>
#include <QCoreApplication>

#include "UpdateThread.h"


Update::Update(QWidget *parent) : QDialog(parent)
{
int pixmapWidth = QPixmap("Images/roating_1.png").width(); //239;
int pixmapHeight = QPixmap("Images/roating_1.png").height(); //237;
int textLabelWidth = 120;

QLabel* roatingLabel_1 = new QLabel(this);
roatingLabel_1->setPixmap(QPixmap("Images/roating_1.png"));
roatingLabel_1->setAttribute(Qt::WA_TranslucentBackground,true);

QLabel* roatingLabel_2 = new QLabel(this); 
roatingLabel_2->setFixedSize(pixmapWidth,pixmapHeight);
roatingLabel_2->setAttribute(Qt::WA_TranslucentBackground,true);
m_ProcessMovie = new QMovie("Images/roating_2.gif");
m_ProcessMovie->setCacheMode(QMovie::CacheAll);
roatingLabel_2->setMovie(m_ProcessMovie);

QLabel* roatingLabel_3 = new QLabel(this); 
roatingLabel_3->setFixedSize(pixmapWidth,pixmapHeight);
roatingLabel_3->setAttribute(Qt::WA_TranslucentBackground,true);
QMovie* roatingMovie = new QMovie("Images/roating_3.gif");
roatingLabel_3->setMovie(roatingMovie);
roatingMovie->start();

m_NoteText = QString::fromLocal8Bit("正在更新,请稍后...\n已更新文件:\n");
m_UpdatingTextLabel = new QLabel(m_NoteText,this);
m_UpdatingTextLabel->setFixedWidth(textLabelWidth);
m_UpdatingTextLabel->setAttribute(Qt::WA_TranslucentBackground,true);
m_UpdatingTextLabel->setAlignment(Qt::AlignCenter);

QGridLayout* mainLayout = new QGridLayout;
mainLayout->addWidget(roatingLabel_1,0,0,Qt::AlignCenter);
mainLayout->addWidget(roatingLabel_2,0,0,Qt::AlignCenter);
mainLayout->addWidget(roatingLabel_3,0,0,Qt::AlignCenter);
mainLayout->addWidget(m_UpdatingTextLabel,0,0,Qt::AlignCenter);
this->setLayout(mainLayout);

this->setWindowFlags(Qt::FramelessWindowHint|Qt::Window);
this->setAttribute(Qt::WA_TranslucentBackground,true);

m_UpdateFileCount = 0;
m_UpdateingFileNumber = 0;

UpdateThread* thread = new UpdateThread(this);
thread->start();
}

Update::~Update()
{

}

void Update::mousePressEvent(QMouseEvent * event)
{
if(event->button()==Qt::LeftButton)
m_LastPoint = event->globalPos();

QDialog::mousePressEvent(event);
}

void Update::mouseMoveEvent(QMouseEvent * event)
{
int dx = event->globalX() - m_LastPoint.x();
int dy = event->globalY() - m_LastPoint.y();
m_LastPoint = event->globalPos();
move(x()+dx, y()+dy);

QDialog::mouseMoveEvent(event);
}

void Update::UpdateSlot(int fileCount)
{
if(fileCount>0)
{
m_UpdateFileCount = fileCount;
m_ProcessMovie->start();
m_ProcessMovie->setPaused(true);
}
}

void Update::UpdateSlot(const QString& fileName)
{
m_UpdateingFileNumber++;
int percent = m_UpdateingFileNumber*m_ProcessMovie->frameCount()/m_UpdateFileCount;
if(percent>=m_ProcessMovie->frameCount())
{
m_ProcessMovie->jumpToFrame(m_ProcessMovie->frameCount()-1);
m_UpdatingTextLabel->setText(m_NoteText+fileName);
qApp->processEvents();
m_UpdatingTextLabel->setText(QString::fromLocal8Bit("更新成功!"));
qApp->processEvents();
QThread::msleep(1000);
this->close();
return ;
}
else
{
m_ProcessMovie->jumpToFrame(percent);
m_UpdatingTextLabel->setText(m_NoteText+fileName);
}
}


//updatethread.h ==》

#ifndef UPDATETHREAD_H
#define UPDATETHREAD_H

#include <QThread>
#include <QStringList>
class Update;

class UpdateThread : public QThread
{
Q_OBJECT

public:
UpdateThread(Update* ui,QObject *parent=0);
~UpdateThread();

signals:
void UpdateSignal(int);
void UpdateSignal(const QString&);

public:
void run();

private slots:
void UpdateSlot();

private:
QStringList m_FileNameList;
};

#endif // UPDATETHREAD_H


//updatethread.cpp ==》

#include "updatethread.h"

#include <QTimer>

#include "Update.h"

UpdateThread::UpdateThread(Update* ui,QObject *parent) : QThread(parent)
{
m_FileNameList  << "Name1.txt"
<< "format.bat"
<< "earth.jpg"
<< "tree1.bat"
<< "lock1.sh"
<< "china1.png" ;

connect(this,SIGNAL(UpdateSignal(int)),ui,SLOT(UpdateSlot(int)));
connect(this,SIGNAL(UpdateSignal(const QString&)),ui,SLOT(UpdateSlot(const QString&)));
emit UpdateSignal(m_FileNameList.count());
}

UpdateThread::~UpdateThread()
{

}

void UpdateThread::run()
{
static bool bStart = false;
if(!bStart)
{
QTimer* timer = new QTimer;
connect(timer,SIGNAL(timeout()),SLOT(UpdateSlot()));
timer->start(500);
bStart = true;
}
this->exec();
}

void UpdateThread::UpdateSlot()
{
if(m_FileNameList.count()>0)
{
emit UpdateSignal(m_FileNameList[0]);
m_FileNameList.pop_front();
}
}
  评论这张
 
阅读(1147)| 评论(0)
推荐

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017