[89] | 1 | /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
|
---|
| 2 | * Qwt Widget Library
|
---|
| 3 | * Copyright (C) 1997 Josef Wilgen
|
---|
| 4 | * Copyright (C) 2002 Uwe Rathmann
|
---|
| 5 | *
|
---|
| 6 | * This library is free software; you can redistribute it and/or
|
---|
| 7 | * modify it under the terms of the Qwt License, Version 1.0
|
---|
| 8 | *****************************************************************************/
|
---|
| 9 |
|
---|
| 10 | // vim: expandtab
|
---|
| 11 |
|
---|
| 12 | #ifndef QWT_DIAL_H
|
---|
| 13 | #define QWT_DIAL_H 1
|
---|
| 14 |
|
---|
| 15 | #include <qframe.h>
|
---|
| 16 | #include <qpalette.h>
|
---|
| 17 | #include "qwt_global.h"
|
---|
| 18 | #include "qwt_abstract_slider.h"
|
---|
| 19 | #include "qwt_round_scale_draw.h"
|
---|
| 20 |
|
---|
| 21 | class QwtDialNeedle;
|
---|
| 22 | class QwtDial;
|
---|
| 23 |
|
---|
| 24 | /*!
|
---|
| 25 | \brief A special scale draw made for QwtDial
|
---|
| 26 |
|
---|
| 27 | \sa QwtDial, QwtCompass
|
---|
| 28 | */
|
---|
| 29 | class QWT_EXPORT QwtDialScaleDraw: public QwtRoundScaleDraw
|
---|
| 30 | {
|
---|
| 31 | public:
|
---|
| 32 | explicit QwtDialScaleDraw(QwtDial *);
|
---|
| 33 | virtual QwtText label(double value) const;
|
---|
| 34 |
|
---|
| 35 | void setPenWidth(uint);
|
---|
| 36 | uint penWidth() const;
|
---|
| 37 |
|
---|
| 38 | private:
|
---|
| 39 | QwtDial *d_parent;
|
---|
| 40 | int d_penWidth;
|
---|
| 41 | };
|
---|
| 42 |
|
---|
| 43 | /*!
|
---|
| 44 | \brief QwtDial class provides a rounded range control.
|
---|
| 45 |
|
---|
| 46 | QwtDial is intended as base class for dial widgets like
|
---|
| 47 | speedometers, compass widgets, clocks ...
|
---|
| 48 |
|
---|
| 49 | \image html dials2.png
|
---|
| 50 |
|
---|
| 51 | A dial contains a scale and a needle indicating the current value
|
---|
| 52 | of the dial. Depending on Mode one of them is fixed and the
|
---|
| 53 | other is rotating. If not isReadOnly() the
|
---|
| 54 | dial can be rotated by dragging the mouse or using keyboard inputs
|
---|
| 55 | (see keyPressEvent()). A dial might be wrapping, what means
|
---|
| 56 | a rotation below/above one limit continues on the other limit (f.e compass).
|
---|
| 57 | The scale might cover any arc of the dial, its values are related to
|
---|
| 58 | the origin() of the dial.
|
---|
| 59 |
|
---|
| 60 | Qwt is missing a set of good looking needles (QwtDialNeedle).
|
---|
| 61 | Contributions are very welcome.
|
---|
| 62 |
|
---|
| 63 | \sa QwtCompass, QwtAnalogClock, QwtDialNeedle
|
---|
| 64 | \note The examples/dials example shows different types of dials.
|
---|
| 65 | */
|
---|
| 66 |
|
---|
| 67 | class QWT_EXPORT QwtDial: public QwtAbstractSlider
|
---|
| 68 | {
|
---|
| 69 | Q_OBJECT
|
---|
| 70 |
|
---|
| 71 | Q_ENUMS(Shadow)
|
---|
| 72 | Q_ENUMS(Mode)
|
---|
| 73 | Q_ENUMS(Direction)
|
---|
| 74 |
|
---|
| 75 | Q_PROPERTY(bool visibleBackground READ hasVisibleBackground WRITE showBackground)
|
---|
| 76 | Q_PROPERTY(int lineWidth READ lineWidth WRITE setLineWidth)
|
---|
| 77 | Q_PROPERTY(Shadow frameShadow READ frameShadow WRITE setFrameShadow)
|
---|
| 78 | Q_PROPERTY(Mode mode READ mode WRITE setMode)
|
---|
| 79 | Q_PROPERTY(double origin READ origin WRITE setOrigin)
|
---|
| 80 | Q_PROPERTY(bool wrapping READ wrapping WRITE setWrapping)
|
---|
| 81 | Q_PROPERTY(Direction direction READ direction WRITE setDirection)
|
---|
| 82 |
|
---|
| 83 | friend class QwtDialScaleDraw;
|
---|
| 84 | public:
|
---|
| 85 |
|
---|
| 86 | /*!
|
---|
| 87 | \brief Frame shadow
|
---|
| 88 |
|
---|
| 89 | Unfortunately it is not possible to use QFrame::Shadow
|
---|
| 90 | as a property of a widget that is not derived from QFrame.
|
---|
| 91 | The following enum is made for the designer only. It is safe
|
---|
| 92 | to use QFrame::Shadow instead.
|
---|
| 93 | */
|
---|
| 94 | enum Shadow
|
---|
| 95 | {
|
---|
| 96 | Plain = QFrame::Plain,
|
---|
| 97 | Raised = QFrame::Raised,
|
---|
| 98 | Sunken = QFrame::Sunken
|
---|
| 99 | };
|
---|
| 100 |
|
---|
| 101 | //! see QwtDial::setScaleOptions
|
---|
| 102 | enum ScaleOptions
|
---|
| 103 | {
|
---|
| 104 | ScaleBackbone = 1,
|
---|
| 105 | ScaleTicks = 2,
|
---|
| 106 | ScaleLabel = 4
|
---|
| 107 | };
|
---|
| 108 |
|
---|
| 109 | /*!
|
---|
| 110 | In case of RotateNeedle the needle is rotating, in case of
|
---|
| 111 | RotateScale, the needle points to origin()
|
---|
| 112 | and the scale is rotating.
|
---|
| 113 | */
|
---|
| 114 | enum Mode
|
---|
| 115 | {
|
---|
| 116 | RotateNeedle,
|
---|
| 117 | RotateScale
|
---|
| 118 | };
|
---|
| 119 |
|
---|
| 120 | /*!
|
---|
| 121 | Direction of the dial
|
---|
| 122 | */
|
---|
| 123 | enum Direction
|
---|
| 124 | {
|
---|
| 125 | Clockwise,
|
---|
| 126 | CounterClockwise
|
---|
| 127 | };
|
---|
| 128 |
|
---|
| 129 | explicit QwtDial( QWidget *parent = NULL);
|
---|
| 130 | #if QT_VERSION < 0x040000
|
---|
| 131 | explicit QwtDial( QWidget *parent, const char *name);
|
---|
| 132 | #endif
|
---|
| 133 |
|
---|
| 134 | virtual ~QwtDial();
|
---|
| 135 |
|
---|
| 136 | void setFrameShadow(Shadow);
|
---|
| 137 | Shadow frameShadow() const;
|
---|
| 138 |
|
---|
| 139 | bool hasVisibleBackground() const;
|
---|
| 140 | void showBackground(bool);
|
---|
| 141 |
|
---|
| 142 | void setLineWidth(int);
|
---|
| 143 | int lineWidth() const;
|
---|
| 144 |
|
---|
| 145 | void setMode(Mode);
|
---|
| 146 | Mode mode() const;
|
---|
| 147 |
|
---|
| 148 | virtual void setWrapping(bool);
|
---|
| 149 | bool wrapping() const;
|
---|
| 150 |
|
---|
| 151 | virtual void setScale(int maxMajIntv, int maxMinIntv, double step = 0.0);
|
---|
| 152 |
|
---|
| 153 | void setScaleArc(double min, double max);
|
---|
| 154 | void setScaleOptions(int);
|
---|
| 155 | void setScaleTicks(int minLen, int medLen, int majLen, int penWidth = 1);
|
---|
| 156 |
|
---|
| 157 | double minScaleArc() const;
|
---|
| 158 | double maxScaleArc() const;
|
---|
| 159 |
|
---|
| 160 | virtual void setOrigin(double);
|
---|
| 161 | double origin() const;
|
---|
| 162 |
|
---|
| 163 | void setDirection(Direction);
|
---|
| 164 | Direction direction() const;
|
---|
| 165 |
|
---|
| 166 | virtual void setNeedle(QwtDialNeedle *);
|
---|
| 167 | const QwtDialNeedle *needle() const;
|
---|
| 168 | QwtDialNeedle *needle();
|
---|
| 169 |
|
---|
| 170 | QRect boundingRect() const;
|
---|
| 171 | QRect contentsRect() const;
|
---|
| 172 | virtual QRect scaleContentsRect() const;
|
---|
| 173 |
|
---|
| 174 | virtual QSize sizeHint() const;
|
---|
| 175 | virtual QSize minimumSizeHint() const;
|
---|
| 176 |
|
---|
| 177 | virtual void setScaleDraw(QwtDialScaleDraw *);
|
---|
| 178 |
|
---|
| 179 | QwtDialScaleDraw *scaleDraw();
|
---|
| 180 | const QwtDialScaleDraw *scaleDraw() const;
|
---|
| 181 |
|
---|
| 182 | protected:
|
---|
| 183 | virtual void paintEvent(QPaintEvent *);
|
---|
| 184 | virtual void resizeEvent(QResizeEvent *);
|
---|
| 185 | virtual void keyPressEvent(QKeyEvent *);
|
---|
| 186 |
|
---|
| 187 | virtual void updateMask();
|
---|
| 188 |
|
---|
| 189 | virtual void drawFrame(QPainter *p);
|
---|
| 190 | virtual void drawContents(QPainter *) const;
|
---|
| 191 | virtual void drawFocusIndicator(QPainter *) const;
|
---|
| 192 |
|
---|
| 193 | virtual void drawScale(QPainter *, const QPoint ¢er,
|
---|
| 194 | int radius, double origin, double arcMin, double arcMax) const;
|
---|
| 195 |
|
---|
| 196 | /*!
|
---|
| 197 | Draw the contents inside the scale
|
---|
| 198 |
|
---|
| 199 | Paints nothing.
|
---|
| 200 |
|
---|
| 201 | \param painter Painter
|
---|
| 202 | \param center Center of the contents circle
|
---|
| 203 | \param radius Radius of the contents circle
|
---|
| 204 | */
|
---|
| 205 | virtual void drawScaleContents(QPainter *painter, const QPoint ¢er,
|
---|
| 206 | int radius) const;
|
---|
| 207 |
|
---|
| 208 | virtual void drawNeedle(QPainter *, const QPoint &,
|
---|
| 209 | int radius, double direction, QPalette::ColorGroup) const;
|
---|
| 210 |
|
---|
| 211 | virtual QwtText scaleLabel(double) const;
|
---|
| 212 | void updateScale();
|
---|
| 213 |
|
---|
| 214 | virtual void rangeChange();
|
---|
| 215 | virtual void valueChange();
|
---|
| 216 |
|
---|
| 217 | virtual double getValue(const QPoint &);
|
---|
| 218 | virtual void getScrollMode(const QPoint &,
|
---|
| 219 | int &scrollMode, int &direction);
|
---|
| 220 |
|
---|
| 221 | private:
|
---|
| 222 | void initDial();
|
---|
| 223 |
|
---|
| 224 | class PrivateData;
|
---|
| 225 | PrivateData *d_data;
|
---|
| 226 | };
|
---|
| 227 |
|
---|
| 228 | #endif
|
---|