3
#include <qwt_analog_clock.h>
4
#include "attitude_indicator.h"
5
#include "speedo_meter.h"
6
#include "cockpit_grid.h"
8
#if QT_VERSION < 0x040000
9
typedef QColorGroup Palette;
11
typedef QPalette Palette;
14
CockpitGrid::CockpitGrid(QWidget *parent):
17
#if QT_VERSION >= 0x040100
18
setAutoFillBackground(true);
21
setPalette(colorTheme(QColor(Qt::darkGray).dark(150)));
23
QGridLayout *layout = new QGridLayout(this);
24
layout->setSpacing(5);
28
for ( i = 0; i < 3; i++ )
30
QwtDial *dial = createDial(i);
31
layout->addWidget(dial, 0, i);
34
#if QT_VERSION < 0x040000
35
for ( i = 0; i < layout->numCols(); i++ )
36
layout->setColStretch(i, 1);
38
for ( i = 0; i < layout->columnCount(); i++ )
39
layout->setColumnStretch(i, 1);
43
QwtDial *CockpitGrid::createDial(int pos)
50
d_clock = new QwtAnalogClock(this);
52
const QColor knobColor = QColor(Qt::gray).light(130);
54
for ( int i = 0; i < QwtAnalogClock::NHands; i++)
56
QColor handColor = QColor(Qt::gray).light(150);
59
if ( i == QwtAnalogClock::SecondHand )
65
QwtDialSimpleNeedle *hand = new QwtDialSimpleNeedle(
66
QwtDialSimpleNeedle::Arrow, true, handColor, knobColor);
67
hand->setWidth(width);
69
d_clock->setHand((QwtAnalogClock::Hand)i, hand);
72
QTimer *timer = new QTimer(d_clock);
73
timer->connect(timer, SIGNAL(timeout()),
74
d_clock, SLOT(setCurrentTime()));
82
d_speedo = new SpeedoMeter(this);
83
d_speedo->setRange(0.0, 240.0);
84
d_speedo->setScale(-1, 2, 20);
86
QTimer *timer = new QTimer(d_speedo);
87
timer->connect(timer, SIGNAL(timeout()),
88
this, SLOT(changeSpeed()));
96
d_ai = new AttitudeIndicator(this);
98
QTimer *gradientTimer = new QTimer(d_ai);
99
gradientTimer->connect(gradientTimer, SIGNAL(timeout()),
100
this, SLOT(changeGradient()));
101
gradientTimer->start(100);
103
QTimer *angleTimer = new QTimer(d_ai);
104
angleTimer->connect(angleTimer, SIGNAL(timeout()),
105
this, SLOT(changeAngle()));
106
angleTimer->start(100);
116
dial->setReadOnly(true);
117
dial->scaleDraw()->setPenWidth(3);
118
dial->setLineWidth(4);
119
dial->setFrameShadow(QwtDial::Sunken);
124
QPalette CockpitGrid::colorTheme(const QColor &base) const
126
const QColor background = base.dark(150);
127
const QColor foreground = base.dark(200);
129
const QColor mid = base.dark(110);
130
const QColor dark = base.dark(170);
131
const QColor light = base.light(170);
132
const QColor text = foreground.light(800);
135
for ( int i = 0; i < QPalette::NColorGroups; i++ )
137
QPalette::ColorGroup cg = (QPalette::ColorGroup)i;
139
palette.setColor(cg, Palette::Base, base);
140
palette.setColor(cg, Palette::Background, background);
141
palette.setColor(cg, Palette::Mid, mid);
142
palette.setColor(cg, Palette::Light, light);
143
palette.setColor(cg, Palette::Dark, dark);
144
palette.setColor(cg, Palette::Text, text);
145
palette.setColor(cg, Palette::Foreground, foreground);
151
void CockpitGrid::changeSpeed()
153
static double offset = 0.8;
155
double speed = d_speedo->value();
157
if ( (speed < 40.0 && offset < 0.0 ) ||
158
(speed > 160.0 && offset > 0.0) )
163
static int counter = 0;
164
switch(counter++ % 12 )
172
d_speedo->setValue(speed + offset);
176
void CockpitGrid::changeAngle()
178
static double offset = 0.05;
180
double angle = d_ai->angle();
184
if ( (angle < -5.0 && offset < 0.0 ) ||
185
(angle > 5.0 && offset > 0.0) )
190
d_ai->setAngle(angle + offset);
193
void CockpitGrid::changeGradient()
195
static double offset = 0.005;
197
double gradient = d_ai->gradient();
199
if ( (gradient < -0.05 && offset < 0.0 ) ||
200
(gradient > 0.05 && offset > 0.0) )
205
d_ai->setGradient(gradient + offset);