-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathIndicator.cpp
More file actions
48 lines (45 loc) · 1.2 KB
/
Indicator.cpp
File metadata and controls
48 lines (45 loc) · 1.2 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
#include "Indicator.hpp"
Indicator::Indicator(QWidget* parent)
:QWidget(parent)
, mState(State::Off)
{
setFixedSize(28, 28);
setSizePolicy(QSizePolicy::Policy::MinimumExpanding, QSizePolicy::Policy::MinimumExpanding);
}
void Indicator::setState(State state) noexcept
{
if(state != mState)
{
mState = state;
emit stateChanged();
update();
}
}
void Indicator::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event)
QPainter painter(this);
QRect r = rect();
r.setWidth(r.height());
painter.setPen(Qt::darkGray);
painter.setBrush(QBrush(Qt::darkGray, Qt::SolidPattern));
painter.drawRect(r);
painter.setPen(Qt::darkGray);
if(mState == State::On)
{
painter.setBrush(QBrush(Qt::green, Qt::SolidPattern));
}
else if (mState == State::Busy)
{
painter.setBrush(QBrush(Qt::green, Qt::Dense4Pattern));
}
else
{
painter.setBrush(QBrush(Qt::lightGray, Qt::Dense4Pattern));
}
r.setHeight((r.height() - 2));
r.setWidth(r.height());
r.setX(1);
r.setY(1);
painter.drawRect(r);
}