Newer
Older
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
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#include <math.h>
#include <qpainter.h>
#if QT_VERSION >= 0x040000
#include <qbitmap.h>
#include <qpalette.h>
#endif
#include <qpixmap.h>
#include <qevent.h>
#include "qwt_math.h"
#include "qwt_scale_engine.h"
#include "qwt_scale_map.h"
#include "qwt_paint_buffer.h"
#include "qwt_painter.h"
#include "qwt_dial_needle.h"
#include "qwt_dial.h"
class QwtDial::PrivateData
{
public:
PrivateData():
visibleBackground(true),
frameShadow(Sunken),
lineWidth(0),
mode(RotateNeedle),
origin(90.0),
minScaleArc(0.0),
maxScaleArc(0.0),
scaleDraw(0),
maxMajIntv(36),
maxMinIntv(10),
scaleStep(0.0),
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
delete scaleDraw;
delete needle;
}
bool visibleBackground;
Shadow frameShadow;
int lineWidth;
QwtDial::Mode mode;
double origin;
double minScaleArc;
double maxScaleArc;
QwtDialScaleDraw *scaleDraw;
int maxMajIntv;
int maxMinIntv;
double scaleStep;
QwtDialNeedle *needle;
static double previousDir;
};
double QwtDial::PrivateData::previousDir = -1.0;
/*!
Constructor
\param parent Parent dial widget
*/
QwtDialScaleDraw::QwtDialScaleDraw(QwtDial *parent):
d_parent(parent),
d_penWidth(1)
{
}
/*!
Set the pen width used for painting the scale
\param penWidth Pen width
\sa penWidth(), QwtDial::drawScale()
*/
void QwtDialScaleDraw::setPenWidth(uint penWidth)
{
d_penWidth = penWidth;
}
/*!
\return Pen width used for painting the scale
\sa setPenWidth, QwtDial::drawScale()
*/
uint QwtDialScaleDraw::penWidth() const
{
return d_penWidth;
}
Call QwtDial::scaleLabel of the parent dial widget.
\param value Value to display
QwtText QwtDialScaleDraw::label(double value) const
{
if ( d_parent == NULL )
return QwtRoundScaleDraw::label(value);
return d_parent->scaleLabel(value);
}
/*!
\brief Constructor
\param parent Parent widget
Create a dial widget with no scale and no needle.
The default origin is 90.0 with no valid value. It accepts
mouse and keyboard inputs and has no step size. The default mode
is QwtDial::RotateNeedle.
QwtDial::QwtDial(QWidget* parent):
QwtAbstractSlider(Qt::Horizontal, parent)
{
initDial();
}
#if QT_VERSION < 0x040000
/*!
\brief Constructor
\param parent Parent widget
\param name Object name
Create a dial widget with no scale and no needle.
The default origin is 90.0 with no valid value. It accepts
mouse and keyboard inputs and has no step size. The default mode
is QwtDial::RotateNeedle.
QwtDial::QwtDial(QWidget* parent, const char *name):
QwtAbstractSlider(Qt::Horizontal, parent)
{
setName(name);
initDial();
}
#endif
void QwtDial::initDial()
{
d_data = new PrivateData;
#if QT_VERSION < 0x040000
setWFlags(Qt::WNoAutoErase);
#if QT_VERSION >= 0x040000
using namespace Qt;
#endif
setFocusPolicy(TabFocus);
QPalette p = palette();
for ( int i = 0; i < QPalette::NColorGroups; i++ ) {
const QPalette::ColorGroup cg = (QPalette::ColorGroup)i;
// Base: background color of the circle inside the frame.
// Foreground: background color of the circle inside the scale
#if QT_VERSION < 0x040000
p.setColor(cg, QColorGroup::Foreground,
p.color(cg, QColorGroup::Base));
p.setColor(cg, QPalette::Foreground,
p.color(cg, QPalette::Base));
#endif
}
setPalette(p);
d_data->scaleDraw = new QwtDialScaleDraw(this);
d_data->scaleDraw->setRadius(0);
setScaleArc(0.0, 360.0); // scale as a full circle
setRange(0.0, 360.0, 1.0, 10); // degrees as deafult
}
//! Destructor
Loading
Loading full blame...