-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTile.cpp
More file actions
48 lines (38 loc) · 961 Bytes
/
Tile.cpp
File metadata and controls
48 lines (38 loc) · 961 Bytes
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
#include "Tile.hpp"
namespace view
{
Tile::Tile(QString title, QWidget* parent, int x, int y) :
QPushButton(title, parent),
timer_(this),
x_(x),
y_(y)
{
setGeometry(caseWidth * x_, caseHeight * y_, caseWidth, caseHeight);
setDefaultColor();
timer_.setSingleShot(true);
QObject::connect(&timer_, &QTimer::timeout,
this, &view::Tile::setDefaultColor);
}
void Tile::setImage(QIcon icon)
{
setIcon(icon);
setIconSize(QSize(iconHeight, iconWidth));
}
void Tile::setDefaultColor()
{
const bool isPairColumn = (x_ % 2 == 0);
const bool isPairRow = (y_ % 2 == 0);
const bool isBlackTileCase1 = (isPairColumn && !isPairRow);
const bool isBlackTileCase2 = (!isPairColumn && isPairRow);
const bool isBlackTile = isBlackTileCase1 || isBlackTileCase2;
if (isBlackTile)
setStyleSheet(grey);
else
setStyleSheet(white);
}
void Tile::setInvalid()
{
setStyleSheet(red);
timer_.start(invalidMoveColorTime);
}
}