This repository was archived by the owner on May 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHitoriRect.cpp
More file actions
114 lines (92 loc) · 1.84 KB
/
HitoriRect.cpp
File metadata and controls
114 lines (92 loc) · 1.84 KB
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
#include <QRectF>
#include <QPainter>
#include <QDebug>
#include <iostream>
#include <QTextOption>
#include "HitoriRect.h"
HitoriRect::HitoriRect(QGraphicsItem* item) : QGraphicsItem(item)
{
}
void HitoriRect::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
QRectF rect(boundingRect());
QString text = QString::number(_value);
const QColor black(Qt::black);
const QColor white(Qt::white);
painter->setPen(black);
painter->setBrush(!is_checked ? white : black);
painter->drawRect(rect);
painter->drawText(rect, text, QTextOption(Qt::AlignHCenter | Qt::AlignVCenter));
}
QRectF HitoriRect::boundingRect() const
{
return QRectF(_x, _y, _width, _height);
}
void HitoriRect::setIndex(const int& row_index, const int& column_index)
{
_row_index = row_index;
_column_index = column_index;
}
int HitoriRect::rowIndex() const
{
return _row_index;
}
int HitoriRect::columnIndex() const
{
return _column_index;
}
void HitoriRect::setValue(const int& value)
{
_value = value;
}
void HitoriRect::setChecked(const bool state)
{
is_checked = state;
update();
}
bool HitoriRect::isChecked() const
{
return is_checked;
}
int HitoriRect::value() const
{
return _value;
}
void HitoriRect::setX(const int& x)
{
_x = x;
}
void HitoriRect::setY(const int& y)
{
_y = y;
}
int HitoriRect::x() const
{
return _x;
}
int HitoriRect::y() const
{
return _y;
}
void HitoriRect::setWidth(const int& width)
{
_width = width;
}
void HitoriRect::setHeight(const int& height)
{
_height = height;
}
int HitoriRect::width() const
{
return _width;
}
int HitoriRect::height() const
{
return _height;
}
void HitoriRect::mousePressEvent(QGraphicsSceneMouseEvent* e)
{
is_checked = !is_checked;
update();
emit stateChanged(_row_index, _column_index);
}