-
Notifications
You must be signed in to change notification settings - Fork 0
/
view_cell.cpp
115 lines (107 loc) · 2.86 KB
/
view_cell.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "view_cell.h"
Cell::Cell(int color)
{
CellColor = color;
setFixedSize(CellSize, CellSize);
}
Cell::Cell(int color, int checkerType, int x, int y)
: CellColor(color), CheckerType(checkerType), X(x), Y(y)
{
setFixedSize(CellSize, CellSize);
}
void Cell::setSelect(bool s)
{
isSelect = s;
}
bool Cell::setCheckerType(int type)
{
if(CellColor == BLACK && type >= C_BLACK && type <= C_NONE) {
CheckerType = type;
return true;
}
return false;
}
void Cell::paintEvent(QPaintEvent *)
{
if(isSelect) {
QPainter painter(this);
painter.setBrush(QColor(120,65,15));
painter.drawRect(0, 0, width(), height());
drawChecker();
}
else {
drawCell();
}
update();
}
void Cell::mousePressEvent(QMouseEvent *me)
{
if(me->buttons() && Qt::LeftButton) {
if(CellColor == BLACK){
emit SelectedCell(X, Y);
}
}
}
void Cell::drawCell()
{
QPainter painter(this);
if(CellColor == BLACK) {
painter.setBrush(QColor(0xbc,0x5c,0xc));
}
else if(CellColor == WHITE) {
painter.setBrush(Qt::white);
}
else {
return;
}
painter.drawRect(0, 0, width(), height());
drawChecker();
update();
}
void Cell::drawChecker()
{
QPainter painter(this);
switch (CheckerType) {
case C_BLACK: {
painter.setBrush(QColor(210,70,65));
QPen pen(QColor(150,40,35));
pen.setWidth(3);
painter.setPen(pen);
painter.drawEllipse(QPoint(width()/2,height()/2),CheckerSize,CheckerSize);
painter.drawEllipse(QPoint(width()/2,height()/2),CheckerSize/2,CheckerSize/2);
break;
}
case C_WHITE: {
painter.setBrush(QColor(220,220,220));
QPen pen(QColor(110,110,110));
pen.setWidth(3);
painter.setPen(pen);
painter.drawEllipse(QPoint(width()/2,height()/2),CheckerSize,CheckerSize);
painter.drawEllipse(QPoint(width()/2,height()/2),CheckerSize/2,CheckerSize/2);
break;
}
case С_BLACK_KING: {
painter.setBrush(QColor(210,70,65));
QPen pen(QColor(150,40,35));
pen.setWidth(3);
painter.setPen(pen);
painter.drawEllipse(QPoint(width()/2,height()/2),CheckerSize,CheckerSize);
painter.setBrush(QColor(220, 200, 90));
painter.drawEllipse(QPoint(width()/2,height()/2),CheckerSize/2,CheckerSize/2);
break;
}
case C_WHITE_KING: {
painter.setBrush(QColor(220,220,220));
QPen pen(QColor(110,110,110));
pen.setWidth(3);
painter.setPen(pen);
painter.drawEllipse(QPoint(width()/2,height()/2),CheckerSize,CheckerSize);
painter.setBrush(QColor(220, 200, 90));
painter.drawEllipse(QPoint(width()/2,height()/2),CheckerSize/2,CheckerSize/2);
break;
}
default:
return;
}
update();
}