paip.提升用户体验-----c++ 实现360浏览器收藏动作星星动画效果

paip.提升用户体验-----c++ 实现360浏览器收藏动作星星动画效果


 作者Attilax ,  EMAIL:1466519819@qq.com 
来源:attilax的专栏
地址:http://blog.csdn.net/attilax


c++星星动画效果分解。:

主要是4个动画效果,
一个是放大缩变效果:这个前半段起效果.
一个是位移效果,这个这个效果全程进行
 一个旋转效果:这个效果全程进行
 最后一个缩小效果,,,后半段生效.
 






c++动画单个流程分解:代码太复杂,,仅仅以移动效果为例子..

 int fps=24;
 int  millsecs=2000;  //动画执行毫秒数...重要..
 
int time_span=1000/fps;    //这个做为定时器运行时间间隔


//以下代码计算每次位移像素..
 int fps_count=fps*sec/1000;
x_span=(float)(x_max-x_mini)/(float)fps_count;   


//以下代码计算出本次实际位置。
    x_cur=x_cur+x_span;
    y_cur=y_cur+y_span;






c++的实现总结.:
///
 放大缩变效果, 旋转效果,缩小效果, 位移效果分别有一个定时器控制..
 代码量不少。。写了五个类。。
 增加了cli接口,可以供其他程序调用.
  




 


不规则透明窗体的实现方式:



一种是设置窗体的掩码图像;
另一种是设置窗体背景透明,然后重写其绘图函数,将背景图绘制上去。


   //must set falg togethoer.. 这几个参数要一起使用,贝儿走最后一个生效.
    setWindowFlags( Qt::FramelessWindowHint
    | Qt::WindowStaysOnTopHint |Qt::Tool );
 this->setAttribute(Qt::WA_TranslucentBackground);//设置背景透明
  menuBar()->hide();    //隐藏菜单栏.
 ui->mainToolBar->hide();  //隐藏工具栏.
 ui->statusBar->hide();  //隐藏缩放手柄
  QPixmap1.load("C:\\favstar\\star.png");//加载图像
  
  
  
void IrregularForm2::paintEvent(QPaintEvent * event)
{   
    QPainter painter(this);
    //draw in the top(0,0) in the windows
    QPixmap pix2=QPixmap1.scaled(this->size(), Qt::IgnoreAspectRatio,    Qt::SmoothTransformation);
     painter.drawPixmap(0, 0, pix2);//绘制图像
  }


-----------------部分源码(源码太多,放不哈)---------------
int main(int argc, char *argv[])
{


    QApplication a(argc, argv);
    QString  point1=argv[1];
 MainWindow::point_str=point1;
  QProcess *    myprocess;
      myprocess= new QProcess();
    QObject::connect(myprocess, SIGNAL(readyReadStandardOutput()),
    NULL, SLOT(outlog()));
    QString cmd="autohotkey.exe  log.ahk  parm_is@"+point1;
    QDir dir;
   QString path=dir.currentPath();
    myprocess->setWorkingDirectory(path);
    myprocess->start(cmd);
    // For debugging: Wait until the process has finished.
    myprocess->waitForFinished(30000);
    qDebug() << "myprocess error code:" << myprocess->error();
      /*  */


 //   if(paraFirst == "-exportArtidNCateid")
//    MainWindow::point_str=point1;
    MainWindow w;
    w.show();


    return a.exec();
}


---------------主启动类mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h".
#include <QtWidgets>
#include <QtCore>
#define  IrregularForm2  MainWindow
#include "atimov.h"
#include "atieffectsize.h"
#include  "movup.h"
//#include <private/qwidgetresizehandler_p.h>
//ca1
int fps=30;
int sec=200; //ms
int  size_mini=100;
int fps_count=fps*sec/1000;
int time_span=1000/fps;
float size_cur=0;
float size_span;
QTimer* timer=new QTimer();
ca1
///
  AtiMov* mv= new  AtiMov();


MainWindow::MainWindow(QWidget *parent) :       QMainWindow(parent),ui(new Ui::MainWindow)
{
    ui->setupUi(this);


    //窗体置顶..jeig yao feodg front ,beir zeu yeu toolbar l .
    this-> setWindowFlags(  Qt::WindowStaysOnTopHint);


    //工具条模式 隐藏任务栏图标 jeig yao feodg front ,beir zeu yeu toolb
//   this->setWindowFlags(    Qt::Tool);
  this->setWindowFlags(Qt::FramelessWindowHint);//设置窗体无边框
    //ma titlevar


    //must set falg togethoer..
    setWindowFlags( Qt::FramelessWindowHint
    | Qt::WindowStaysOnTopHint |Qt::Tool );
       this->setAttribute(Qt::WA_TranslucentBackground);//设置背景透明




  menuBar()->hide();


  //隐藏工具栏.
 ui->mainToolBar->hide();
 //隐藏缩放手柄
 ui->statusBar->hide();
 // menuBar()->setVisible(false);
  //tool
  QAction* openAction = new QAction(tr("&Open"), this);
          openAction->setShortcut(QKeySequence::Open);
          openAction->setStatusTip(tr("Open a file."));


          QMenu *file = menuBar()->addMenu(tr("&File"));
          file->addAction(openAction);


          QToolBar *toolBar = addToolBar(tr("&File4toolbar"));
          toolBar->addAction(openAction);


     toolBar->hide();


        QPixmap1.load("C:\\favstar\\star.png");//加载图像
  //       setAutoFillBackground(true);   // 这个属性一定要设置
     //   QPixmap1.load("C:\\favstar\\star.png",0,Qt::AvoidDither|        Qt::ThresholdAlphaDither|        Qt::ThresholdDither);//加载图片,并指明避免图片抖动模式


     //   this->resize(QPixmap1.size());
 this->resize(1,1);
//ca1
int size_max=QPixmap1.width();
  size_span=(float)(size_max-size_mini)/(float)fps_count;
size_cur=size_mini;


    connect(timer,SIGNAL(timeout()),this,SLOT(moveWin()));
      timer->start(time_span);


//        //new一个QWidgetResizeHandler 对象,this是你要实现移动功能的主窗口
//        QWidgetResizeHandler *h = new QWidgetResizeHandler(this);


//        //设置可移动,可拖拽
//        h->setMovingEnabled(true);


     mv->mov_start=  QPoint(1,1);
       mv->mov_end=  QPoint(500,600);
   //mv->start(sec);
  //    QSize
 // QSize mov_end=new QSize(500,600);




   //always move up
       //   movUp  up2=  movUp();
   movUp* up=new movUp();


   int cur_mouse_x=600;
   int cur_mouse_y=430;


   QString point_strx= MainWindow:: point_str;
   if( point_strx!=NULL && point_strx.length()>0)
   {
       QStringList  li=point_strx.split(",");


       cur_mouse_x=li.at(0).toInt();
    cur_mouse_y=li.at(1).toInt();
   }   /**/
   up->mov_start=QPoint(cur_mouse_x,cur_mouse_y);//cur mouse
   int mouse_x_end=cur_mouse_x+200;
     int mouse_y_end=cur_mouse_y-300;
     up->mov_end=QPoint(mouse_x_end,mouse_y_end);
 up->win=(QMainWindow*)this;
 up->finish_exit=true;
     up->start(1000);
}


void IrregularForm2::moveWin()   //for float invoke
{
    size_cur=size_span+size_cur;
    int width=size_cur;
     if(width>QPixmap1.width())
     {
         width=QPixmap1.width();
           size_cur=width;
             qDebug()<<" cur size:is all ok";
            timer->stop();




            //swasyao
            AtiEffectSize* eSize=new AtiEffectSize();
            eSize->startSize=(QPixmap1.size());
            eSize->endSize=QSize(0,0);
            eSize->start(500);
            eSize->win=(QMainWindow*)this;
             return;


     }


  //   this->move(mv->x_cur,mv->y_cur);
    this->resize(width,width);


    qDebug()<<" cur size:--"<<width;


}




//重写绘图事件


void IrregularForm2::paintEvent(QPaintEvent * event)


{


    qDebug()<<" paintEvent--" ;


    QPainter painter(this);
    //draw in the top(0,0) in the windows
    QPixmap pix2=QPixmap1.scaled(this->size(), Qt::IgnoreAspectRatio,    Qt::SmoothTransformation);
     painter.drawPixmap(0, 0, pix2);//绘制图像
    //draw in the top(0,0) in the windows
//   painter.drawPixmap(0, 0, QPixmap1);//绘制图像


    //      painter.drawPixmap(50, 100, QPixmap1);//绘制图像
    //painter.rotate();
    /*
    QPalette pal(palette());
    pal.setBrush(QPalette::Window, QBrush(QPixmap1.scaled(event->, Qt::IgnoreAspectRatio,Qt::SmoothTransformation)));


    setPalette(pal);
    */
}


// 随着窗体变化而设置背景
void IrregularForm2::resizeEvent(QResizeEvent *event)
{
     qDebug()<<" resizeEvent--" ;
//QWidget::resizeEvent(event);
//QPalette pal(palette());
//pal.setBrush(QPalette::Window,
//QBrush(QPixmap1.scaled(event->size(), Qt::IgnoreAspectRatio,
//Qt::SmoothTransformation)));
//setPalette(pal);




}






MainWindow::~MainWindow()
{
    delete ui;
}
-----------------------mov 类
#include "atimov.h"
#include <QObject>


//ca1








ca1
AtiMov::AtiMov(QObject *parent) :
QObject(parent)
{
}






void AtiMov::start(int secs)
{
    //ca1
    int sec=secs; //ms
    int x_mini=this->mov_start.x();
    int y_mini=this->mov_start.y();
     x_max=this->mov_end.x();
     y_max=this->mov_end.y();


    int  size_mini=5;
    int fps_count=fps*sec/1000;
    int time_span=1000/fps;
     x_cur=x_mini;
     y_cur=y_mini;


    //float size_cur=0;
   // float size_span;
//    int size_max=QPixmap1.width();
      x_span=(float)(x_max-x_mini)/(float)fps_count;
       y_span=(float)(y_max-y_mini)/(float)fps_count;
  //  size_cur=size_mini;


         connect(timer,SIGNAL(timeout()),this,SLOT(moveWin()));
          timer->start(time_span);


}




void AtiMov::moveWin()   //for float invoke
{
    x_cur=x_cur+x_span;
    y_cur=y_cur+y_span;
    QPoint pt=  QPoint(x_cur,y_cur);
    //   int width=size_cur;
    if(x_cur>x_max || y_cur>y_max)
    {
        x_cur=x_max;
        y_cur=y_max;
        pt=  QPoint(x_cur,y_cur);


        qDebug()<<" cur posit:is all ok";
        timer->stop();
        return;


    }


    //  this->resize(width,width);
    qDebug()<<" cur poston:--"<<x_cur<<","<<y_cur;


}/*
*/












参考:
                                                                       ^
绘制窗体时防止闪烁 – 【人人分享-人人网】
[QT编程]QT实现不规则窗体和透明窗体 - 程序员小涛 - 博客园.htm
qt显示图片并使其随窗体同步缩放.htm




 
posted @ 2013-10-01 23:32  attilaxAti  阅读(38)  评论(0编辑  收藏  举报