/
GameButton.cpp
53 lines (40 loc) · 1.06 KB
/
GameButton.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
#include <QtGui>
#include "GameButton.h"
const QStringList GameButton::backgroundColors = QStringList()
<< "#cdc0b4" // 0 - empty
<< "#eee4da" // 1 - 2
<< "#ede0c8" // 2 - 4
<< "#f2b179" // 3 - 8
<< "#f59563" // 4 - 16
<< "#f67c5f" // 5 - 32
<< "#f65e3b" // 6 - 64
<< "#edcf72" // 7 - 128
<< "#edcc61" // 8 - 256
<< "#edc850" // 9 - 512
<< "#edc53f" // 10 - 1024
<< "#edc22e"; // 11 - 2048 and higher
GameButton::GameButton(QWidget *parent) : QPushButton(parent)
{
setFocusPolicy(Qt::NoFocus);
setEnabled(false);
}
void GameButton::Set(unsigned int power2)
{
if (power2 == 0)
{
setText("");
setStyleSheet("color: #303030; background-color: " + backgroundColors[0]);
}
else
{
setText(QString::number(1 << power2));
setStyleSheet("color: #303030; background-color: " + backgroundColors[qMin((unsigned int)11, power2)]);
}
}
void GameButton::resizeEvent(QResizeEvent *event)
{
int button_margin = style()->pixelMetric(QStyle::PM_ButtonMargin);
QFont f = font();
f.setPixelSize((event->size().height() - button_margin * 2)/2);
setFont(f);
}