-
Notifications
You must be signed in to change notification settings - Fork 1
/
baseitem.cpp
81 lines (63 loc) · 1.53 KB
/
baseitem.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
#include "baseitem.h"
BaseItem::BaseItem(qreal opacity, int steps) :
myOpacity(opacity),
myStep(steps)
{
op_step = myOpacity/(double)steps;
}
////////////////////////////////////////////////////////////////////////////////
PixmapItem::PixmapItem(int x, int y, int dx, int dy, const QPixmap &pm, int steps) : BaseItem(1, steps),
myX(x), myY(y),
myDx(dx), myDy(dy),
myPixmap(pm)
{
}
bool PixmapItem::advance()
{
if (myStep-- <= 0)
return false;
myX += myDx;
myY += myDy;
myOpacity -= op_step;
return true;
}
void PixmapItem::paint(QPainter &painter)
{
painter.setOpacity(myOpacity);
painter.drawPixmap(myX, myY, myPixmap);
}
////////////////////////////////////////////////////////////////////////////////
TextItem::TextItem(QRect rect, const QString &text, int textFlags, const QFont &font, QColor color,
qreal opacity, int staysteps, int steps, int dx, int dy) :
BaseItem(opacity, steps),
myRect(rect),
myText(text),
myFlags(textFlags),
myFont(font),
myColor(color),
myStaySteps(staysteps),
myDx(dx), myDy(dy)
{
op_step = myOpacity/(double)steps;
}
bool TextItem::advance()
{
if (myStaySteps)
{
myStaySteps--;
return true;
}
if (myStep-- <= 0)
return false;
myRect.moveLeft(myRect.left() + myDx);
myRect.moveTop(myRect.top() + myDy);
myOpacity -= op_step;
return true;
}
void TextItem::paint(QPainter &painter)
{
painter.setOpacity(myOpacity);
painter.setFont(myFont);
painter.setPen(QPen(myColor));
painter.drawText(myRect, myFlags, myText);
}