-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglanimation.cpp
More file actions
359 lines (284 loc) · 10.2 KB
/
glanimation.cpp
File metadata and controls
359 lines (284 loc) · 10.2 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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
#include "glanimation.h"
#include <QDebug>
GlAnimation::GlAnimation(GlObject* parent) : GlObject(parent)
{
xOffset = 0;
timeLine = new QTimeLine(500, this);
timeLine->setLoopCount(1);
timeLine->setFrameRange(0, 100);
timeLine->setCurveShape(QTimeLine::EaseInCurve);
connect(timeLine, SIGNAL(frameChanged(int)), this, SLOT(newPercent(int)));
}
void GlAnimation::done()
{
/*SLOT: wird ausgeführt wenn die timeLine fertig ist.
Das übergeordnete Object soll sich nach der
Animation neu Zeichnen*/
timeLine->setFrameRange(0, 100);
timeLine->setDuration(500);
newChildToDraw(getParent());
}
void GlAnimation::draw(QPainter *p)
{ /*Führt die Funktion in dem Funktionszeiger doAnimation aus*/
(this->*doAnimation)(p);
}
void GlAnimation::coverNext(QPainter *p)
{
QRect rect = geometry();
QImage tmpImg1, tmpImg2;
int imageWidth;
int per = getPercent();
if(per < 0 || per > 100) return;
p->fillRect(rect, Qt::black);
imageWidth = (int)((per/100.) * getImage().width());
tmpImg1 = getImage().copy(0, 0, getImage().width() - imageWidth, getImage().height());
tmpImg2 = image2.copy(image2.width() - imageWidth, 0, imageWidth, image2.height());
p->drawImage(geometry().x() + imageWidth, geometry().y(), tmpImg1);
p->drawImage(geometry().x(), geometry().y(), tmpImg2);
}
void GlAnimation::coverPrev(QPainter *p)
{
QRect rect = geometry();
QImage tmpImg1, tmpImg2;
int imageWidth;
int per = getPercent();
if(per < 0 || per > 100) return;
p->fillRect(rect, Qt::black);
imageWidth = (int)((per/100.) * getImage().width());
tmpImg1 = getImage().copy(imageWidth, 0, getImage().width() - imageWidth, getImage().height());
tmpImg2 = image2.copy(0, 0, imageWidth, image2.height());
p->drawImage(geometry().x(), geometry().y(), tmpImg1);
p->drawImage(geometry().x() + geometry().width() - imageWidth, geometry().y(), tmpImg2);
}
void GlAnimation::jumpDown(QPainter *p)
{
int per = getPercent();
if(per < 0 || per > 100) return;
p->fillRect(geometry(), Qt::black);
QImage tmpImg = getImage();
int t_height = (int)((1. - per/100.) * tmpImg.height());
int t_y = tmpImg.height() - t_height;
tmpImg = tmpImg.copy(0, 0, tmpImg.width(), t_height);
p->drawImage(geometry().x() + xOffset, geometry().y() + t_y, tmpImg);
}
void GlAnimation::jumpUp(QPainter *p)
{
int per = getPercent();
if(per < 0 || per > 100) return;
p->fillRect(geometry(), Qt::black);
QImage tmpImg = getImage();
int t_y = (int)((per/100.) * tmpImg.height());
int t_height = tmpImg.height() -t_y;
tmpImg = tmpImg.copy(0, t_y, tmpImg.width(), t_height);
p->drawImage(geometry().x() + xOffset, geometry().y(), tmpImg);
}
void GlAnimation::newPercent(int per)
{ /*SLOT: wird ausgeführt wenn timeLine ein neues Frame hat.
Percent wird neu gesetzt und ein Neuzeichnen wird gestartet*/
setPercent(per);
newChildToDraw(this);
}
void GlAnimation::rotateIn(QPainter *p)
{
/*Eindrehen des Images. Der Winkel wird anhand der Prozente berechnet.
Dort wo das Image gezeichnet werden soll wird ein schwarzes Rechteck
gezeichnet, dann wird das gedrehte Image gezeichnet*/
int per = getPercent();
int angle = int((per/100.)* 90);
if(per < 0 || per > 100) return;
p->fillRect(geometry(), Qt::black);
drawImageAtY(p, angle, per);
}
void GlAnimation::rotateOut(QPainter *p)
{
/*Siehe rotateIn*/
int per = getPercent();
int angle = int((per/100.)* -90);
if(per < 0 || per > 100) return;
p->fillRect(geometry(), Qt::black);
drawImageAtY(p, angle, per);
}
void GlAnimation::start()
{
/*SLOT: */
timeLine->start();
}
void GlAnimation::scrollDown(QPainter *p)
{
int per = getPercent();
if(per < 0 || per > 100) return;
p->fillRect(geometry(), Qt::black);
QImage tmpImg = getImage();
int t_height = (int)((1. - per/100.) * tmpImg.height());
int t_y = tmpImg.height() - t_height;
tmpImg = tmpImg.copy(0, 0, tmpImg.width(), t_height);
p->drawImage(geometry().x() + xOffset, geometry().y() + t_y, tmpImg);
t_height = (int)((per/100.) * image2.height());
t_y = image2.height() - t_height;
tmpImg = image2.copy(0,t_y,image2.width(), t_height);
p->drawImage(geometry().x() + xOffset, geometry().y(), tmpImg);
}
void GlAnimation::scrollUp(QPainter *p)
{
int per = getPercent();
if(per < 0 || per > 100) return;
p->fillRect(geometry(), Qt::black);
QImage tmpImg = getImage();
int t_y = (int)((per/100.) * tmpImg.height());
int t_height = tmpImg.height() -t_y;
tmpImg = tmpImg.copy(0, t_y, tmpImg.width(), t_height);
p->drawImage(geometry().x() + xOffset, geometry().y(), tmpImg);
t_y = geometry().y() + tmpImg.height();
t_height = (int)((per/100.) * image2.height());
tmpImg = image2.copy(0,0,image2.width(), t_height);
p->drawImage(geometry().x() + xOffset, t_y, tmpImg);
}
void GlAnimation::startCoverNext()
{
timeLine->disconnect();
timeLine->setDirection(QTimeLine::Forward);
connect(timeLine, SIGNAL(finished()), this, SLOT(done()));
connect(timeLine, SIGNAL(frameChanged(int)), this, SLOT(newPercent(int)));
doAnimation = &GlAnimation::coverNext;
timeLine->start();
}
void GlAnimation::startCoverPrev()
{
timeLine->disconnect();
timeLine->setDirection(QTimeLine::Forward);
connect(timeLine, SIGNAL(finished()), this, SLOT(done()));
connect(timeLine, SIGNAL(frameChanged(int)), this, SLOT(newPercent(int)));
doAnimation = &GlAnimation::coverPrev;
timeLine->start();
}
void GlAnimation::startRotation()
{
/*Startet den ersten Teil der Rotation.
- Alle Verbindungen von timeLine beenden;
- aufwärts zählen in timeLine einstellen;
- Signale neu verbinden
- den Funktionszeiger doAnimation setzen
- timeLine starten*/
timeLine->disconnect();
timeLine->setDirection(QTimeLine::Forward);
connect(timeLine, SIGNAL(finished()), this, SLOT(startRotation2()));
connect(timeLine, SIGNAL(frameChanged(int)), this, SLOT(newPercent(int)));
doAnimation = &GlAnimation::rotateOut;
timeLine->start();
}
void GlAnimation::startJumpDown()
{
timeLine->disconnect();
timeLine->setFrameRange(0, 25);
timeLine->setDuration(250);
timeLine->setDirection(QTimeLine::Forward);
connect(timeLine, SIGNAL(finished()), this, SLOT(startJumpDown2()));
connect(timeLine, SIGNAL(frameChanged(int)), this, SLOT(newPercent(int)));
doAnimation = &GlAnimation::jumpDown;
timeLine->start();
}
void GlAnimation::startJumpDown2()
{
timeLine->disconnect();
timeLine->setDirection(QTimeLine::Backward);
connect(timeLine, SIGNAL(finished()), this, SLOT(done()));
connect(timeLine, SIGNAL(frameChanged(int)), this, SLOT(newPercent(int)));
doAnimation = &GlAnimation::jumpDown;
timeLine->start();
}
void GlAnimation::startJumpUp()
{
timeLine->disconnect();
timeLine->setFrameRange(0, 25);
timeLine->setDuration(250);
timeLine->setDirection(QTimeLine::Forward);
connect(timeLine, SIGNAL(finished()), this, SLOT(startJumpUp2()));
connect(timeLine, SIGNAL(frameChanged(int)), this, SLOT(newPercent(int)));
doAnimation = &GlAnimation::jumpUp;
timeLine->start();
}
void GlAnimation::startJumpUp2()
{
timeLine->disconnect();
timeLine->setDirection(QTimeLine::Backward);
connect(timeLine, SIGNAL(finished()), this, SLOT(done()));
connect(timeLine, SIGNAL(frameChanged(int)), this, SLOT(newPercent(int)));
doAnimation = &GlAnimation::jumpUp;
timeLine->start();
}
void GlAnimation::startRotation2()
{
/*Startet den zweiten Teil der Rotation.
- Image von GlObject mit dem zweiten Bild laden.
Es wird immer nur das Image von GlObject gedreht.
- Siehe startRotation();*/
setImage(image2);
timeLine->disconnect();
timeLine->setDirection(QTimeLine::Backward);
connect(timeLine, SIGNAL(finished()), this, SLOT(done()));
connect(timeLine, SIGNAL(frameChanged(int)), this, SLOT(newPercent(int)));
doAnimation = &GlAnimation::rotateIn;
timeLine->start();
}
void GlAnimation::startScrollDown()
{
timeLine->disconnect();
timeLine->setDirection(QTimeLine::Forward);
connect(timeLine, SIGNAL(finished()), this, SLOT(done()));
connect(timeLine, SIGNAL(frameChanged(int)), this, SLOT(newPercent(int)));
doAnimation = &GlAnimation::scrollDown;
timeLine->start();
}
void GlAnimation::startScrollUp()
{
timeLine->disconnect();
timeLine->setDirection(QTimeLine::Forward);
connect(timeLine, SIGNAL(finished()), this, SLOT(done()));
connect(timeLine, SIGNAL(frameChanged(int)), this, SLOT(newPercent(int)));
doAnimation = &GlAnimation::scrollUp;
timeLine->start();
}
void GlAnimation::startZoomIn()
{
timeLine->disconnect();
timeLine->setDirection(QTimeLine::Forward);
connect(timeLine, SIGNAL(finished()), this, SLOT(done()));
connect(timeLine, SIGNAL(frameChanged(int)), this, SLOT(newPercent(int)));
doAnimation = &GlAnimation::zoomIn;
timeLine->start();
}
void GlAnimation::startZoomOut()
{
timeLine->disconnect();
timeLine->setDirection(QTimeLine::Backward);
connect(timeLine, SIGNAL(finished()), this, SIGNAL(animationDone()));
connect(timeLine, SIGNAL(frameChanged(int)), this, SLOT(newPercent(int)));
doAnimation = &GlAnimation::zoomOut;
timeLine->start();
}
void GlAnimation::zoomIn(QPainter *p)
{
QRect rect = geometry();
QImage image;
int imageX, imageWidth;
int per = getPercent();
if(per < 0 || per > 100) return;
p->fillRect(rect, Qt::black);
imageWidth = (int)((per/100.) * getImage().width());
imageX = getImage().width()/2 - imageWidth/2;
image = getImage().copy(imageX, 0, imageWidth, getImage().height());
p->drawImage(geometry().x() + imageX, geometry().y(), image);
}
void GlAnimation::zoomOut(QPainter *p)
{
QRect rect = geometry();
QImage image;
int imageX, imageWidth;
int per = getPercent();
if(per < 0 || per > 100) return;
p->fillRect(rect, Qt::black);
imageWidth = (int)((per/100.) * getImage().width());
imageX = getImage().width()/2 - imageWidth/2;
image = getImage().copy(imageX, 0, imageWidth, getImage().height());
p->drawImage(geometry().x() + imageX, geometry().y(), image);
}