赞
踩
简单粗暴,直接上代码:
#include “Cbaseanimation.h”
#ifndef CBASEANIMATION_H #define CBASEANIMATION_H #include <QObject> #include <QPropertyAnimation> #include <QParallelAnimationGroup> #include <QtWidgets/QWidget> #include <QtWidgets/QLabel> #include <QTimer> // 界面动画基类 class CBaseAnimation : public QObject { Q_OBJECT public: CBaseAnimation(); ~CBaseAnimation(); void SetAnimation(QWidget *curwidget, QWidget *destwidget,bool directon); // void SetAnimation(QWidget *widget,int Duration,bool directon); // void SetTimeOutReturn(bool enable,uint mse = 0); // bool GetTimeOutReturnEnable(); private: QParallelAnimationGroup *group; QLabel * pixmapLabel; bool isAnimationFinish; // QWidgetList widgetlist; // QTimer * m_timer; // bool isTimeOutReturnEnable; signals: void EM_AnimationFinish(); private slots: // void Slot_timeout(); public slots: void Slot_AnimationFinish(); }; extern CBaseAnimation * pBaseAnimation; #endif // CBASEANIMATION_H
#include “Cbaseanimation.cpp”
#include "Cbaseanimation.h" #include "DispManager.hpp" #include <qDebug> #include <QThread> CBaseAnimation * pBaseAnimation = NULL; CBaseAnimation::CBaseAnimation(): isAnimationFinish(true) { group = new QParallelAnimationGroup(this); connect(group,SIGNAL(finished()),this,SLOT(Slot_AnimationFinish())); // pixmapLabel = new QLabel; // m_timer = new QTimer(this); // connect(m_timer,SIGNAL(timeout()),this,SLOT(Slot_timeout())); } CBaseAnimation::~CBaseAnimation() { } void CBaseAnimation::SetAnimation(QWidget *curwidget, QWidget *destwidget,bool directon) { // QLabel *label = new QLabel(); // label->resize(this->size()); // QPixmap pic; // label->setPixmap(pic.grabWidget(this,this->rect())); label->setBuddy(this); label->setPixmap(*this->backgroundPixmap()); label->setPalette(this->palette()); label->setPixmap(this->backgroundRole(); // label->show(); // widgetlist.clear(); // widgetlist.append(curwidget); // widgetlist.append(destwidget); // // 界面倒计时 // if(timeoutReturnEnable) // { // m_timer->start(mse*1000); // } // else // { // m_timer->stop(); // } // SetTimeOutReturn(timeoutReturnEnable,mse);//need if(!isAnimationFinish) { return; } destwidget->show(); QPropertyAnimation *animation= new QPropertyAnimation(curwidget,"pos"); animation->setDuration(300); // animation->setEasingCurve(QEasingCurve::OutBounce); QPropertyAnimation *animation1= new QPropertyAnimation(destwidget,"pos"); animation1->setDuration(200); // animation1->setEasingCurve(QEasingCurve::OutBounce); if(directon) { animation->setStartValue(QPoint(0,0));//(0,0,curwidget->width(),curwidget->height())); animation->setEndValue(QPoint(-curwidget->width(),0)); //(-curwidget->width(), 0, curwidget->width(), curwidget->height())); animation1->setStartValue(QPoint(destwidget->width()/3,0));//(destwidget->width()/2, 0, destwidget->width(), destwidget->height())); animation1->setEndValue(QPoint(0,0));//(0,0,destwidget->width(), destwidget->height())); // animation->setStartValue(QRect(0,0,curwidget->width(),curwidget->height())); // animation->setEndValue(QRect(-curwidget->width(), 0, curwidget->width(), curwidget->height())); // animation1->setStartValue(QRect(destwidget->width()/2, 0, destwidget->width(), destwidget->height())); // animation1->setEndValue(QRect(0,0,destwidget->width(), destwidget->height())); } else { animation->setStartValue(QPoint(0,0));//(0,0,curwidget->width(),curwidget->height())); animation->setEndValue(QPoint(curwidget->width(),0));//(-curwidget->width(), 0, curwidget->width(), curwidget->height())); animation1->setStartValue(QPoint(-destwidget->width()/3,0));//(destwidget->width()/2, 0, destwidget->width(), destwidget->height())); animation1->setEndValue(QPoint(0,0));//(0,0,destwidget->width(), destwidget->height())); // animation->setStartValue(QRect(0,0,curwidget->width(),curwidget->height())); // animation->setEndValue(QRect(curwidget->width(), 0, curwidget->width(), curwidget->height())); // animation1->setStartValue(QRect(-destwidget->width()/2, 0, destwidget->width(), destwidget->height())); // animation1->setEndValue(QRect(0,0,destwidget->width(), destwidget->height())); } // if(directon) // { // animation->setStartValue(QPoint(0,0));//(0,0,curwidget->width(),curwidget->height())); // animation->setEndValue(QPoint(-curwidget->width(),0)); // //(-curwidget->width(), 0, curwidget->width(), curwidget->height())); // animation1->setStartValue(QPoint(destwidget->width()/2,0));//(destwidget->width()/2, 0, destwidget->width(), destwidget->height())); // animation1->setEndValue(QPoint(0,0));//(0,0,destwidget->width(), destwidget->height())); animation->setStartValue(QRect(0,0,curwidget->width(),curwidget->height())); animation->setEndValue(QRect(-curwidget->width(), 0, curwidget->width(), curwidget->height())); animation1->setStartValue(QRect(destwidget->width()/2, 0, destwidget->width(), destwidget->height())); animation1->setEndValue(QRect(0,0,destwidget->width(), destwidget->height())); // } // else // { // animation->setStartValue(QPoint(0,0));//(0,0,curwidget->width(),curwidget->height())); // animation->setEndValue(QPoint(curwidget->width(),0));//(-curwidget->width(), 0, curwidget->width(), curwidget->height())); // animation1->setStartValue(QPoint(-destwidget->width()/2,0));//(destwidget->width()/2, 0, destwidget->width(), destwidget->height())); // animation1->setEndValue(QPoint(0,0));//(0,0,destwidget->width(), destwidget->height())); animation->setStartValue(QRect(0,0,curwidget->width(),curwidget->height())); animation->setEndValue(QRect(curwidget->width(), 0, curwidget->width(), curwidget->height())); animation1->setStartValue(QRect(-destwidget->width()/2, 0, destwidget->width(), destwidget->height())); animation1->setEndValue(QRect(0,0,destwidget->width(), destwidget->height())); // } // QPropertyAnimation *animation2 = new QPropertyAnimation(destwidget,"windowOpacity"); // animation2->setTargetObject(destwidget); // animation2->setDuration(Duration); // animation2->setStartValue(0); // animation2->setEndValue(1); group->clear(); group->addAnimation(animation); group->addAnimation(animation1); // group->addAnimation(animation2); group->start(); isAnimationFinish = false; } //void CBaseAnimation::SetAnimation(QWidget *widget,int Duration,bool directon) //{ QLabel *label = new QLabel(); label->resize(this->size()); QPixmap pic; label->setPixmap(pic.grabWidget(this,this->rect())); // label->setBuddy(this); // label->setPixmap(*this->backgroundPixmap()); // label->setPalette(this->palette()); // label->setPixmap(this->backgroundRole(); label->show(); // widget->move(0,0); pixmapLabel->setWindowFlags(Qt::FramelessWindowHint | Qt::W1indowStaysOnTopHint| Qt::Tool);// // pixmapLabel->setFixedSize(widget->width(),widget->height()); // pixmapLabel->show(); // QPropertyAnimation *animation= new QPropertyAnimation(pixmapLabel,"geometry"); // animation->setDuration(600); // QPropertyAnimation *animation1= new QPropertyAnimation(widget,"geometry"); // animation1->setDuration(400); // if(directon) // { // animation->setStartValue(QRect(0,0,pixmapLabel->width(), pixmapLabel->height())); // animation->setEndValue(QRect(-pixmapLabel->width(), 0, pixmapLabel->width(), pixmapLabel->height())); // animation1->setStartValue(QRect(widget->width()/2, 0, widget->width(), widget->height())); // animation1->setEndValue(QRect(0,0,widget->width(), widget->height())); // } // else // { // animation->setStartValue(QRect(0,0,pixmapLabel->width(), pixmapLabel->height())); // animation->setEndValue(QRect(pixmapLabel->width(), 0, pixmapLabel->width(), pixmapLabel->height())); // animation1->setStartValue(QRect(-widget->width(), 0, widget->width(), widget->height())); // animation1->setEndValue(QRect(0,0,widget->width(), widget->height())); // } // QParallelAnimationGroup *group = new QParallelAnimationGroup; // group->addAnimation(animation1); // group->addAnimation(animation); // group->start(QParallelAnimationGroup::DeleteWhenStopped); // connect(group,SIGNAL(finished()),this,SLOT(Slot_AnimationFinish())); //} void CBaseAnimation::Slot_AnimationFinish() { // widgetlist.at(0)->hide(); isAnimationFinish = true; emit EM_AnimationFinish(); // pixmapLabel->hide(); } //void CBaseAnimation::Slot_timeout() //{ // m_timer->stop(); // if(widgetlist.count() > 0) // { // SetAnimation(widgetlist.at(1),CDispManager::pUIDisplay,400,false,false); // } //} //void CBaseAnimation::SetTimeOutReturn(bool enable,uint mse) //{ // isTimeOutReturnEnable = enable; // if(isTimeOutReturnEnable) // { // m_timer->start(mse*1000); // } // else // { // m_timer->stop(); // } //} //bool CBaseAnimation::GetTimeOutReturnEnable() //{ // return this->isTimeOutReturnEnable; //}
里面很多注释的可以忽略或者增加扩展也是可以的~
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。