/
scorepanelitem.cpp
98 lines (73 loc) · 1.97 KB
/
scorepanelitem.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
#include "scorepanelitem.h"
#include <QGraphicsLinearLayout>
#include <QPainter>
#include <QGraphicsProxyWidget>
#include <QLabel>
#include <QGraphicsTextItem>
#include <QPropertyAnimation>
ScorePanelItem::ScorePanelItem(QString player_name, QImage icon, Align align, QGraphicsItem *parent):
QGraphicsWidget(parent), m_coord(align)
{
words_layout = new QGraphicsLinearLayout(Qt::Vertical );
words_layout->setSpacing(0);
setLayout(words_layout);
}
void ScorePanelItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QRectF frame(QPointF(0, 0), geometry().size());
painter->setOpacity(0.7);
painter->drawRect(0,0, size().width(), size().height());
}
//leader
void ScorePanelItem::SetLeader(bool is_leader)
{
m_leader = is_leader;
update();
}
bool ScorePanelItem::IsLeader()
{
return m_leader;
}
//player_name
QString ScorePanelItem::PlayerName()
{
return m_player_name;
}
void ScorePanelItem::Clear()
{
m_words.clear();
update();
}
void ScorePanelItem::AddWord(QList<CellItem*> word)
{
QParallelAnimationGroup *anim_group = new QParallelAnimationGroup(this);
QList<QPixmap*> pixmaps;
foreach (CellItem* item, word)
{
Pixmap* p_item = new Pixmap(item->snapshot().scaledToHeight(30, Qt::SmoothTransformation), this);
pixmaps << p_item;
}
QMap<Pixmap*, QPointF> coord = m_coord.getNextWordCoord(word);
CellItem *item;
foreach(Pixmap* p_item, pixmaps)
{
item
QPropertyAnimation *anim = new QPropertyAnimation(p_item, "pos");
anim->setDuration(800);
anim->setStartValue( mapFromItem(item, 0, 0) );
anim->setEndValue( coord[item] );
QEasingCurve c(QEasingCurve::InOutBack);
anim->setEasingCurve(c);
anim_group->addAnimation(anim);
}
anim_group->start();
}
QImage ScorePanelItem::getIcon()
{
return m_icon;
}
void ScorePanelItem::setIcon(QImage icon)
{
m_icon = icon;
update();
}