-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanimation.cpp
More file actions
97 lines (86 loc) · 1.74 KB
/
Copy pathanimation.cpp
File metadata and controls
97 lines (86 loc) · 1.74 KB
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
#include "animation.h"
//#define qDebug(...)
Animation::Animation(const int msec, const int max, QObject *parent) : QObject(parent)
{
progress = 0;
changeMaxProgress(max);
timer = new QTimer(this);
changeInterval(msec);
widgets.setAutoDelete(false);
positions.setAutoDelete(true);
news.setAutoDelete(false);
deletes.setAutoDelete(true);
refresh.setAutoDelete(false);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
}
void Animation::add(QWidget *w, QPoint to)
{
widgets.append(w);
pos *p = new pos;
p->from = w->pos();
p->d = to - p->from;
positions.append(p);
}
void Animation::remove(QWidget *w)
{
int i = find(w);
if (i < 0)
return;
widgets.remove(i);
positions.remove(i);
}
void Animation::clear(void)
{
widgets.clear();
positions.clear();
news.clear();
deletes.clear();
refresh.clear();
}
void Animation::start(void)
{
if (widgets.count() != 0)
timer->start(interval);
}
void Animation::stop(void)
{
timer->stop();
for (uint i = 0; i < widgets.count(); i++)
widgets.at(i)->move(positions.at(i)->from + positions.at(i)->d);
for (uint i = 0; i < news.count(); i++)
news.at(i)->show();
for (uint i = 0; i < refresh.count(); i++)
refresh.at(i)->refresh();
progress = 0;
clear();
}
void Animation::update(void)
{
if (progress == maxProgress) {
stop();
return;
}
progress++;
QPoint from, to;
for (uint i = 0; i < widgets.count(); i++) {
from = positions.at(i)->from;
to = from + positions.at(i)->d * progress / maxProgress;
widgets.at(i)->move(to);
}
}
void Animation::addNew(QWidget *w)
{
if (!timer->isActive())
return;
w->hide();
news.append(w);
}
void Animation::addDelete(QWidget *w)
{
if (deletes.find(w) == -1)
deletes.append(w);
}
void Animation::addRefresh(Cell *w)
{
refresh.append(w);
}