-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSchemeSensors.cpp
More file actions
180 lines (146 loc) · 5.86 KB
/
SchemeSensors.cpp
File metadata and controls
180 lines (146 loc) · 5.86 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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#include "SchemeSensors.h"
#ifdef _DEBUG
#include <QDebug>
#endif
#include <QPainter>
#include <QToolTip>
#include <QMouseEvent>
#include <QPixmap>
#include <qmath.h>
SchemeSensors::SchemeSensors(QWidget *parent)
: QWidget(parent)
{
retranslateUi();
qDrawSensors = false;
settingsWidget();
}
void SchemeSensors::paintEvent(QPaintEvent *)
{
QPainter schemePainter(this);
schemePainter.setRenderHint(QPainter::Antialiasing, true);
schemePainter.setBrush(QBrush(Qt::gray, Qt::DiagCrossPattern));
schemePainter.setPen(QPen(QColor(0, 153, 204), 2));
/* Draw Rects */
schemePainter.drawRect(QRect(30, 5, width() - 60, height() / 8));
schemePainter.drawRect(QRect(100, 5 + height() / 8, width() - 200, (height() / 4) + (height() / 8)));
/* Draw Polygon */
QPolygonF polygon;
polygon << QPointF(10, (5 + height() / 8) + (height() / 4) + (height() / 8));
polygon << QPointF(width() - 20, (5 + height() / 8) + (height() / 4) + (height() / 8));
polygon << QPointF(width() - 20, 105 + (height() / 2));
polygon << QPointF(width() / 2, 205 + (height() / 2));
polygon << QPointF(10, 105 + (height() / 2));
polygon << QPointF(10, (5 + height() / 8) + (height() / 4) + (height() / 8));
schemePainter.drawPolygon(polygon);
/* Draw Text */
QPainter textPainter(this);
drawRotateText(&textPainter, 270, 25, (height() / 8) - 5, blockA);
drawRotateText(&textPainter, 270, 95, ((height() / 4) + (height() / 8)) - 5, blockB);
drawRotateText(&textPainter, 90, width() - 15, (30 + height() / 8) + (height() / 4) + (height() / 8), blockC);
if (qDrawSensors)
{
drawSensors();
}
}
void SchemeSensors::drawRotateText(QPainter *painter,
float degrees,
int x, int y,
const QString &text)
{
painter->save();
painter->translate(x, y);
painter->rotate(degrees);
painter->drawText(0, 0, text);
painter->restore();
}
void SchemeSensors::drawSensors()
{
/* Draw Sensors */
QPixmap sensors[16];
for (size_t i = 0; i < 16; ++i)
{
sensors[i].convertFromImage(QImage(QString("://gfx/Sensors/Sensor-%1.png").arg(i+1)));
}
QPainter sensorPainter(this);
sensorPainter.drawPixmap(25, 10, sensors[0]);
sensorPainter.drawPixmap(width() - 35, 10, sensors[8]);
sensorPainter.drawPixmap(55, 0, sensors[1]);
sensorPainter.drawPixmap(55, height() / 8, sensors[9]);
sensorPainter.drawPixmap(width() - 70, 0, sensors[2]);
sensorPainter.drawPixmap(width() - 70, height() / 8, sensors[10]);
sensorPainter.drawPixmap(95, 10 + height() / 8, sensors[3]);
sensorPainter.drawPixmap(width() - 105, 10 + height() / 8, sensors[11]);
sensorPainter.drawPixmap(95, 50 + height() / 8, sensors[4]);
sensorPainter.drawPixmap(width() - 105, 50 + height() / 8, sensors[12]);
sensorPainter.drawPixmap(95, ((height() / 8) + (height() / 4) + (height() / 8)) - 15, sensors[5]);
sensorPainter.drawPixmap(width() - 105, ((height() / 8) + (height() / 4) + (height() / 8)) - 15, sensors[13]);
sensorPainter.drawPixmap(50, ((height() / 8) + (height() / 4) + (height() / 8)), sensors[6]);
sensorPainter.drawPixmap(50, (130 + height() / 8) + (height() / 4) + (height() / 8), sensors[14]);
sensorPainter.drawPixmap(width() - 65, (height() / 8) + (height() / 4) + (height() / 8), sensors[7]);
sensorPainter.drawPixmap(width() - 65, (130 + height() / 8) + (height() / 4) + (height() / 8), sensors[15]);
}
void SchemeSensors::settingsWidget()
{
setMinimumWidth(250);
setMouseTracking(true);
}
void SchemeSensors::retranslateUi()
{
blockA = tr("Block \"A\"");
blockB = tr("Block \"B\"");
blockC = tr("Block \"C\"");
}
void SchemeSensors::mouseMoveEvent(QMouseEvent *event)
{
bool qPolALimits =
event->x() >= 30 &&
event->x() <= width() - 60 &&
event->y() >= 5 &&
event->y() <= height() / 8;
bool qPolBLimits =
event->x() >= 80 &&
event->x() <= width() - 160 &&
event->y() >= 5 + height() / 8 &&
event->y() <= (height() / 4) + (height() / 8);
bool qPolCLimits =
event->x() >= 10 &&
event->x() <= width() - 20 &&
event->y() >= (5 + height() / 8) + (height() / 4) + (height() / 8) &&
event->y() <= 105 + (height() / 2);
bool qPolCLimitsTriangle =
area(width() - 20, 105 + (height() / 2), width() / 2, 205 + (height() / 2), 10, 105 + (height() / 2)) ==
area(width() - 20, 105 + (height() / 2), width() / 2, 205 + (height() / 2), event->x(), event->y()) +
area(width() - 20, 105 + (height() / 2), event->x(), event->y(), 10, 105 + (height() / 2)) +
area(width() / 2, 205 + (height() / 2), event->x(), event->y(), 10, 105 + (height() / 2));
if (qPolALimits)
{
QToolTip::showText((QPoint(event->globalX(), event->globalY())),
blockA, this);
}
else if (qPolBLimits)
{
QToolTip::showText((QPoint(event->globalX(), event->globalY())),
blockB, this);
}
else if (qPolCLimits || qPolCLimitsTriangle)
{
QToolTip::showText((QPoint(event->globalX(), event->globalY())),
blockC, this);
}
}
void SchemeSensors::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
qDrawSensors = (qDrawSensors) ? false : true;
repaint();
}
}
int SchemeSensors::area(int ax, int ay, int bx, int by, int cx, int cy)
{
return qAbs((ax - cx) * (by - cy) + (bx - cx) * (cy - ay));
}
SchemeSensors::~SchemeSensors()
{
/* Empty Destructor */
}