File: speedo_meter.cpp

package info (click to toggle)
qwt5 5.2.2-3
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 13,340 kB
  • sloc: cpp: 32,645; makefile: 23; sh: 4
file content (52 lines) | stat: -rw-r--r-- 1,153 bytes parent folder | download | duplicates (6)
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
#include <qpainter.h>
#include <qwt_dial_needle.h>
#include "speedo_meter.h"

SpeedoMeter::SpeedoMeter(QWidget *parent):
    QwtDial(parent),
    d_label("km/h")
{
    setWrapping(false);
    setReadOnly(true);

    setOrigin(135.0);
    setScaleArc(0.0, 270.0);
    scaleDraw()->setSpacing(8);

    QwtDialSimpleNeedle *needle = new QwtDialSimpleNeedle(
            QwtDialSimpleNeedle::Arrow, true, Qt::red, 
            QColor(Qt::gray).light(130));
    setNeedle(needle);

    setScaleOptions(ScaleTicks | ScaleLabel);
    setScaleTicks(0, 4, 8);
}

void SpeedoMeter::setLabel(const QString &label)
{
    d_label = label;
    update();
}

QString SpeedoMeter::label() const
{
    return d_label;
}

void SpeedoMeter::drawScaleContents(QPainter *painter,
    const QPoint &center, int radius) const
{
    QRect rect(0, 0, 2 * radius, 2 * radius - 10);
    rect.moveCenter(center);

    const QColor color =
#if QT_VERSION < 0x040000
        colorGroup().text();
#else
        palette().color(QPalette::Text);
#endif
    painter->setPen(color);

    const int flags = Qt::AlignBottom | Qt::AlignHCenter;
    painter->drawText(rect, flags, d_label);
}