-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtablecell.cpp
148 lines (123 loc) · 2.81 KB
/
tablecell.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "tablecell.h"
TableCell::TableCell(QColor backgroundColor, qreal lineWidth, QColor lineColor, TableCellWalls walls)
{
_lineColor = lineColor;
_lineWidth = lineWidth;
_walls = walls;
_backgroundColor = backgroundColor;
}
TableCell::TableCell(qreal flex, QColor backgroundColor, qreal lineWidth, QColor lineColor, TableCellWalls walls)
{
_lineColor = lineColor;
_lineWidth = lineWidth;
_walls = walls;
_flex = flex;
_autoFlex = false;
_backgroundColor = backgroundColor;
}
void TableCell::addContent(TableCellContent *content)
{
_contents.append(content);
}
void TableCell::removeContent(unsigned int contentIndex)
{
TableCellContent *content = _contents[contentIndex];
_contents.removeAt(contentIndex);
delete content;
}
void TableCell::draw(QPainter *painter)
{
_paintBackground(painter);
_drawWalls(painter);
for (auto content : qAsConst(_contents))
{
content->draw(painter, _rect);
}
}
qreal TableCell::lineWidth() const
{
return _lineWidth;
}
void TableCell::setLineWidth(qreal newLineWidth)
{
_lineWidth = newLineWidth;
}
const QColor &TableCell::lineColor() const
{
return _lineColor;
}
void TableCell::setLineColor(const QColor &newLineColor)
{
_lineColor = newLineColor;
}
TableCellWalls TableCell::walls() const
{
return _walls;
}
void TableCell::setWalls(TableCellWalls newWalls)
{
_walls = newWalls;
}
qreal TableCell::flex() const
{
return _flex;
}
void TableCell::setFlex(qreal newFlex)
{
_flex = newFlex;
}
const QRectF &TableCell::rect() const
{
return _rect;
}
void TableCell::setRect(const QRectF &newRect)
{
_rect = QRectF(newRect);
}
bool TableCell::autoFlex() const
{
return _autoFlex;
}
void TableCell::setAutoFlex(bool newAutoFlex)
{
_autoFlex = newAutoFlex;
}
void TableCell::_drawWalls(QPainter *painter)
{
for (auto i = 0U; i < 4; i++)
{
// if ((_walls >> i) & 0) continue;
int mask = 1;
if (!(_walls & (mask << i))) {
continue;
}
switch (i) {
case 0:
painter->drawLine(_rect.topLeft(), _rect.topRight());
break;
case 1:
painter->drawLine(_rect.topRight(), _rect.bottomRight());
break;
case 2:
painter->drawLine(_rect.bottomRight(), _rect.bottomLeft());
break;
case 3:
painter->drawLine(_rect.bottomLeft(), _rect.topLeft());
break;
default:
break;
}
}
}
void TableCell::_paintBackground(QPainter *painter)
{
painter->fillRect(_rect, QBrush(_backgroundColor));
}
const QColor &TableCell::backgroundColor() const
{
return _backgroundColor;
}
void TableCell::setBackgroundColor(const QColor &newBackgroundColor)
{
_backgroundColor = newBackgroundColor;
}