forked from aamirglb/GCSWidgets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
widget.cpp
113 lines (86 loc) · 2.43 KB
/
widget.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
#include "widget.h"
#include "ui_widget.h"
#include <utility>
#include <QGridLayout>
#include <QPair>
#include <QTimer>
#include "dial.h"
#include "flapindicator.h"
#include "fuelindicator.h"
#include "speedfan.h"
#include "battery.h"
#include "winddirdial.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
// set background color
QPalette pal = palette();
pal.setColor(QPalette::Window, QColor(25, 35, 45));
this->setAutoFillBackground(true);
this->setPalette(pal);
m_grid = new QGridLayout;
// RPM
m_rpmDial = new Dial;
m_rpmDial->setRange(0, 1000);
m_rpmDial->setCaution1Range(0, 100);
m_rpmDial->setNormalRange(101, 800);
m_rpmDial->setCautionRange(801, 900);
m_rpmDial->setWarningRange(901, 1000);
// Flap
m_flap = new FlapIndicator;
// Fuel
m_fuel = new FuelIndicator;
auto fullRange = std::make_pair(0, 100);
m_fuel->setMaxFuel(fullRange.second);
m_fuel->setNormalRange({0, 70});
m_fuel->setCautionRange({71, 90});
m_fuel->setWarningRange({91, 100});
// SpeedFan
m_fan = new SpeedFan;
// Battery
m_battery = new Battery;
// Wind direction
m_windDir = new WindDirDial;
m_grid->addWidget(m_rpmDial, 0, 0);
m_grid->addWidget(m_flap, 0, 1);
m_grid->addWidget(m_fuel, 0, 2);
m_grid->addWidget(m_fan, 1, 0);
m_grid->addWidget(m_battery, 1, 1);
m_grid->addWidget(m_windDir, 1, 2);
this->setLayout(m_grid);
QTimer *timer = new QTimer;
timer->setInterval(10);
QObject::connect(timer, &QTimer::timeout, [&, tick=0, delta=1, flapDelta = 1]() mutable {
++tick;
// rpm
if(m_rpm >= 1000) {
delta = -1;
} else if(m_rpm == 0) {
delta = 1;
}
m_rpm += delta;
m_rpmDial->setValue(m_rpm);
// fuel
m_fuel->setFuel(m_rpm * .1);
// fan
m_fan->setSpeed(static_cast<int32_t>(m_rpm * .1));
// battery
m_battery->setValue(static_cast<int32_t>(m_rpm * .1));
m_windDir->setWindDirection(m_rpm * .4);
if( tick % 10 == 0 ) {
if(m_flapValue > 20)
flapDelta = -1;
if(m_flapValue < -20)
flapDelta = 1;
m_flapValue += flapDelta;
m_flap->setFlapAngle(m_flapValue);
}
});
timer->start();
}
Widget::~Widget()
{
delete ui;
}