-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanimationview_1.cpp
127 lines (101 loc) · 3.62 KB
/
animationview_1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "animationview.h"
#include "ui_animationview.h"
#include "GlobalVariables.h"
#include <QTimer>
#include <QPropertyAnimation>
#include <QParallelAnimationGroup>
#include <QDebug>
animationView::animationView(QWidget *parent) :
QWidget(parent),
ui(new Ui::animationView)
{
ui->setupUi(this);
// setUpCircle();
}
animationView::~animationView()
{
delete ui;
}
void animationView::start() {
if(timer!=nullptr) { return; }
// hideCircle();
t = 0;
timer = new QTimer;
timer->setInterval(800);
connect(timer,&QTimer::timeout,this,&animationView::updateView);
timer->start();
}
void animationView::updateView() {
// 不会自动停止
// t++;
// if(t==6) {
// timer->stop();
// timer->deleteLater();
// showCircle();
// return;
// }
int width = this->geometry().width();
QLabel *la = new QLabel(this);
la->setPixmap(QPixmap(GlobalVs::circle_red_png));
la->setScaledContents(true);
la->setGeometry(width*0.25,width*0.25,width*0.5,width*0.5);
la->raise();
la->show();
QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect();
effect->setOpacity(1);
la->setGraphicsEffect(effect);
QPropertyAnimation *animation1 = new QPropertyAnimation(effect,"opacity");
animation1->setDuration(2500);
animation1->setEasingCurve(QEasingCurve::Linear);
animation1->setStartValue(1);
animation1->setEndValue(0);
QPropertyAnimation *animation2 = new QPropertyAnimation(la,"geometry");
animation2->setDuration(2500);
animation2->setEasingCurve(QEasingCurve::Linear);
animation2->setStartValue(QRect(width*0.25,width*0.25,width*0.5,width*0.5));
animation2->setEndValue(QRect(0,0,width,width));
QParallelAnimationGroup *group = new QParallelAnimationGroup;
group->addAnimation(animation1);
group->addAnimation(animation2);
connect(group,&QParallelAnimationGroup::finished,[=] {
effect->deleteLater();
animation1->deleteLater();
animation2->deleteLater();
group->deleteLater();
la->deleteLater();
});
group->start();
}
void animationView::setUpCircle() {
int width = this->geometry().width();
circle = new QLabel(this);
circle->setGeometry(width*0.1,width*0.1,width*0.8,width*0.8);
circle->setPixmap(QPixmap(GlobalINFO::FilePath=="" ? GlobalVs::circle_red_png : GlobalVs::circle_blue_png));
circle->setScaledContents(true);
circle->raise();
circle->show();
circle_effect = new QGraphicsOpacityEffect();
circle_effect->setOpacity(0.5);
circle->setGraphicsEffect(circle_effect);
}
void animationView::showCircle() {
int width = this->geometry().width();
circle->setGeometry(width*0.1,width*0.1,width*0.8,width*0.8);
circle->setPixmap(QPixmap(GlobalINFO::FilePath=="" ? GlobalVs::circle_red_png : GlobalVs::circle_blue_png));
QPropertyAnimation *animation1 = new QPropertyAnimation(circle_effect,"opacity");
animation1->setDuration(1600);
animation1->setEasingCurve(QEasingCurve::Linear);
animation1->setStartValue(0);
animation1->setEndValue(0.5);
connect(animation1,&QParallelAnimationGroup::finished,animation1,&QParallelAnimationGroup::deleteLater);
animation1->start();
}
void animationView::hideCircle() {
QPropertyAnimation *animation1 = new QPropertyAnimation(circle_effect,"opacity");
animation1->setDuration(800);
animation1->setEasingCurve(QEasingCurve::Linear);
animation1->setStartValue(0.5);
animation1->setEndValue(0);
connect(animation1,&QParallelAnimationGroup::finished,animation1,&QParallelAnimationGroup::deleteLater);
animation1->start();
}