-
Notifications
You must be signed in to change notification settings - Fork 2
/
draw_helper.cpp
96 lines (89 loc) · 3.29 KB
/
draw_helper.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
#include "draw_helper.h"
#include <QPainter>
void DrawCharacter::DrawX(QPainter* painter,
const QRect& target_rect,
const QColor& text_color,
const QSize& text_size,
const int pen_width) {
painter->save();
painter->setRenderHints(QPainter::Antialiasing, true);
QRect x_rect = {0, 0, text_size.width(), text_size.height()};
x_rect.moveCenter(target_rect.center());
QPen pen;
pen.setBrush(QBrush(text_color, Qt::SolidPattern));
pen.setStyle(Qt::SolidLine);
pen.setWidth(pen_width);
painter->setPen(pen);
painter->drawLine(x_rect.topLeft(), x_rect.bottomRight());
painter->drawLine(x_rect.bottomLeft(), x_rect.topRight());
painter->restore();
}
void DrawCharacter::DrawPlus(QPainter* painter,
const QRect& target_rect,
const QColor& text_color,
const QSize& text_size,
const int pen_width) {
painter->save();
painter->setRenderHints(QPainter::Antialiasing, true);
QRect rect = {0, 0, text_size.width(), text_size.height()};
rect.moveCenter(target_rect.center());
QPen pen;
pen.setBrush(QBrush(text_color, Qt::SolidPattern));
pen.setStyle(Qt::SolidLine);
pen.setWidth(pen_width);
painter->setPen(pen);
// 画 +
painter->drawLine(
QPoint(rect.left() + rect.width() / 2, rect.top()),
QPoint(rect.left() + rect.width() / 2, rect.top() + rect.height()));
// 画 -
painter->drawLine(
QPoint(rect.left(), rect.top() + rect.height() / 2),
QPoint(rect.left() + rect.width(), rect.top() + rect.height() / 2));
painter->restore();
}
void DrawCircle::Draw(QPainter* painter,
const QRect& target_rect,
const QColor& bg_color) {
painter->save();
painter->setRenderHints(QPainter::Antialiasing, true);
painter->setPen(Qt::NoPen);
painter->setBrush(QBrush(bg_color));
painter->drawEllipse(target_rect);
painter->restore();
}
void DrawRoundRect::Draw(QPainter* painter,
const QRect& target_rect,
const QColor& bg_color,
const int round_size) {
painter->save();
painter->setRenderHints(QPainter::Antialiasing, true);
painter->setPen(Qt::NoPen);
painter->setBrush(QBrush(bg_color));
painter->drawRoundedRect(target_rect, round_size, round_size);
painter->restore();
}
void DrawCircleArror::Draw(QPainter* painter,
const QRect& target_rect,
const QColor& bg_color) {
painter->save();
painter->setRenderHints(QPainter::Antialiasing, true);
QRect rect = {0, 0, 15, 15};
rect.moveCenter(target_rect.center());
QPen pen;
pen.setWidth(2);
pen.setBrush(QBrush(QColor(95, 99, 104)));
painter->setPen(pen);
painter->drawArc(rect, 30 * 16, 310 * 16);
painter->setPen(Qt::NoPen);
painter->setBrush(QColor(Qt::green));
// static const QPointF points[3] = {
// QPointF(0.0, 0.0),
// QPointF(0.0, 20.0),
// QPointF(20.0, 00.0),
// };
// painter->drawPolygon(points, 3);
QRect rect2 = {0, 0, 5, 5};
painter->drawRect(rect2);
painter->restore();
}