[8127] | 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 | #ifndef QWT_KNOB_H
|
---|
| 11 | #define QWT_KNOB_H
|
---|
| 12 |
|
---|
| 13 | #include "qwt_global.h"
|
---|
| 14 | #include "qwt_abstract_slider.h"
|
---|
| 15 |
|
---|
| 16 | class QwtRoundScaleDraw;
|
---|
| 17 |
|
---|
| 18 | /*!
|
---|
| 19 | \brief The Knob Widget
|
---|
| 20 |
|
---|
| 21 | The QwtKnob widget imitates look and behavior of a volume knob on a radio.
|
---|
| 22 | It looks similar to QDial - not to QwtDial.
|
---|
| 23 |
|
---|
| 24 | The value range of a knob might be divided into several turns.
|
---|
| 25 |
|
---|
| 26 | The layout of the knob depends on the knobWidth().
|
---|
| 27 |
|
---|
[9383] | 28 | - width > 0
|
---|
[8127] | 29 | The diameter of the knob is fixed and the knob is aligned
|
---|
[9383] | 30 | according to the alignment() flags inside of the contentsRect().
|
---|
[8127] | 31 |
|
---|
| 32 | - width <= 0
|
---|
| 33 | The knob is extended to the minimum of width/height of the contentsRect()
|
---|
| 34 | and aligned in the other direction according to alignment().
|
---|
| 35 |
|
---|
| 36 | Setting a fixed knobWidth() is helpful to align several knobs with different
|
---|
| 37 | scale labels.
|
---|
[9383] | 38 |
|
---|
[8127] | 39 | \image html knob.png
|
---|
| 40 | */
|
---|
| 41 |
|
---|
| 42 | class QWT_EXPORT QwtKnob: public QwtAbstractSlider
|
---|
| 43 | {
|
---|
| 44 | Q_OBJECT
|
---|
| 45 |
|
---|
| 46 | Q_ENUMS ( KnobStyle MarkerStyle )
|
---|
| 47 |
|
---|
| 48 | Q_PROPERTY( KnobStyle knobStyle READ knobStyle WRITE setKnobStyle )
|
---|
| 49 | Q_PROPERTY( int knobWidth READ knobWidth WRITE setKnobWidth )
|
---|
| 50 | Q_PROPERTY( Qt::Alignment alignment READ alignment WRITE setAlignment )
|
---|
| 51 | Q_PROPERTY( double totalAngle READ totalAngle WRITE setTotalAngle )
|
---|
| 52 | Q_PROPERTY( int numTurns READ numTurns WRITE setNumTurns )
|
---|
| 53 | Q_PROPERTY( MarkerStyle markerStyle READ markerStyle WRITE setMarkerStyle )
|
---|
| 54 | Q_PROPERTY( int markerSize READ markerSize WRITE setMarkerSize )
|
---|
| 55 | Q_PROPERTY( int borderWidth READ borderWidth WRITE setBorderWidth )
|
---|
| 56 |
|
---|
| 57 | public:
|
---|
[9383] | 58 | /*!
|
---|
[8127] | 59 | \brief Style of the knob surface
|
---|
| 60 |
|
---|
| 61 | Depending on the KnobStyle the surface of the knob is
|
---|
| 62 | filled from the brushes of the widget palette().
|
---|
| 63 |
|
---|
| 64 | \sa setKnobStyle(), knobStyle()
|
---|
| 65 | */
|
---|
| 66 | enum KnobStyle
|
---|
| 67 | {
|
---|
| 68 | //! Fill the knob with a brush from QPalette::Button.
|
---|
| 69 | Flat,
|
---|
| 70 |
|
---|
| 71 | //! Build a gradient from QPalette::Midlight and QPalette::Button
|
---|
| 72 | Raised,
|
---|
| 73 |
|
---|
[9383] | 74 | /*!
|
---|
[8127] | 75 | Build a gradient from QPalette::Midlight, QPalette::Button
|
---|
| 76 | and QPalette::Midlight
|
---|
| 77 | */
|
---|
| 78 | Sunken,
|
---|
| 79 |
|
---|
[9383] | 80 | /*!
|
---|
[8127] | 81 | Build a radial gradient from QPalette::Button
|
---|
| 82 | like it is used for QDial in various Qt styles.
|
---|
| 83 | */
|
---|
| 84 | Styled
|
---|
| 85 | };
|
---|
| 86 |
|
---|
| 87 | /*!
|
---|
| 88 | \brief Marker type
|
---|
[9383] | 89 |
|
---|
[8127] | 90 | The marker indicates the current value on the knob
|
---|
| 91 | The default setting is a Notch marker.
|
---|
| 92 |
|
---|
| 93 | \sa setMarkerStyle(), setMarkerSize()
|
---|
| 94 | */
|
---|
[9383] | 95 | enum MarkerStyle
|
---|
| 96 | {
|
---|
[8127] | 97 | //! Don't paint any marker
|
---|
| 98 | NoMarker = -1,
|
---|
| 99 |
|
---|
| 100 | //! Paint a single tick in QPalette::ButtonText color
|
---|
[9383] | 101 | Tick,
|
---|
[8127] | 102 |
|
---|
| 103 | //! Paint a triangle in QPalette::ButtonText color
|
---|
[9383] | 104 | Triangle,
|
---|
[8127] | 105 |
|
---|
| 106 | //! Paint a circle in QPalette::ButtonText color
|
---|
[9383] | 107 | Dot,
|
---|
[8127] | 108 |
|
---|
[9383] | 109 | /*!
|
---|
[8127] | 110 | Draw a raised ellipse with a gradient build from
|
---|
| 111 | QPalette::Light and QPalette::Mid
|
---|
[9383] | 112 | */
|
---|
| 113 | Nub,
|
---|
[8127] | 114 |
|
---|
[9383] | 115 | /*!
|
---|
[8127] | 116 | Draw a sunken ellipse with a gradient build from
|
---|
| 117 | QPalette::Light and QPalette::Mid
|
---|
[9383] | 118 | */
|
---|
| 119 | Notch
|
---|
[8127] | 120 | };
|
---|
| 121 |
|
---|
| 122 | explicit QwtKnob( QWidget* parent = NULL );
|
---|
| 123 | virtual ~QwtKnob();
|
---|
| 124 |
|
---|
| 125 | void setAlignment( Qt::Alignment );
|
---|
| 126 | Qt::Alignment alignment() const;
|
---|
| 127 |
|
---|
| 128 | void setKnobWidth( int );
|
---|
| 129 | int knobWidth() const;
|
---|
| 130 |
|
---|
| 131 | void setNumTurns( int );
|
---|
| 132 | int numTurns() const;
|
---|
| 133 |
|
---|
| 134 | void setTotalAngle ( double angle );
|
---|
| 135 | double totalAngle() const;
|
---|
| 136 |
|
---|
| 137 | void setKnobStyle( KnobStyle );
|
---|
| 138 | KnobStyle knobStyle() const;
|
---|
| 139 |
|
---|
[9383] | 140 | void setBorderWidth( int );
|
---|
[8127] | 141 | int borderWidth() const;
|
---|
| 142 |
|
---|
| 143 | void setMarkerStyle( MarkerStyle );
|
---|
| 144 | MarkerStyle markerStyle() const;
|
---|
| 145 |
|
---|
| 146 | void setMarkerSize( int );
|
---|
| 147 | int markerSize() const;
|
---|
| 148 |
|
---|
| 149 | virtual QSize sizeHint() const;
|
---|
| 150 | virtual QSize minimumSizeHint() const;
|
---|
| 151 |
|
---|
| 152 | void setScaleDraw( QwtRoundScaleDraw * );
|
---|
| 153 |
|
---|
| 154 | const QwtRoundScaleDraw *scaleDraw() const;
|
---|
| 155 | QwtRoundScaleDraw *scaleDraw();
|
---|
| 156 |
|
---|
| 157 | QRect knobRect() const;
|
---|
| 158 |
|
---|
| 159 | protected:
|
---|
| 160 | virtual void paintEvent( QPaintEvent * );
|
---|
| 161 | virtual void changeEvent( QEvent * );
|
---|
| 162 |
|
---|
| 163 | virtual void drawKnob( QPainter *, const QRectF & ) const;
|
---|
| 164 |
|
---|
| 165 | virtual void drawFocusIndicator( QPainter * ) const;
|
---|
| 166 |
|
---|
[9383] | 167 | virtual void drawMarker( QPainter *,
|
---|
| 168 | const QRectF &, double angle ) const;
|
---|
[8127] | 169 |
|
---|
| 170 | virtual double scrolledTo( const QPoint & ) const;
|
---|
| 171 | virtual bool isScrollPosition( const QPoint & ) const;
|
---|
| 172 |
|
---|
| 173 | private:
|
---|
| 174 | class PrivateData;
|
---|
| 175 | PrivateData *d_data;
|
---|
| 176 | };
|
---|
| 177 |
|
---|
| 178 | #endif
|
---|