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_ABSTRACT_SLIDER_H
|
---|
11 | #define QWT_ABSTRACT_SLIDER_H
|
---|
12 |
|
---|
13 | #include <qwidget.h>
|
---|
14 | #include "qwt_global.h"
|
---|
15 | #include "qwt_double_range.h"
|
---|
16 |
|
---|
17 | /*!
|
---|
18 | \brief An abstract base class for slider widgets
|
---|
19 |
|
---|
20 | QwtAbstractSlider is a base class for
|
---|
21 | slider widgets. It handles mouse events
|
---|
22 | and updates the slider's value accordingly. Derived classes
|
---|
23 | only have to implement the getValue() and
|
---|
24 | getScrollMode() members, and should react to a
|
---|
25 | valueChange(), which normally requires repainting.
|
---|
26 | */
|
---|
27 |
|
---|
28 | class QWT_EXPORT QwtAbstractSlider : public QWidget, public QwtDoubleRange
|
---|
29 | {
|
---|
30 | Q_OBJECT
|
---|
31 | Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly )
|
---|
32 | Q_PROPERTY( bool valid READ isValid WRITE setValid )
|
---|
33 | Q_PROPERTY( double mass READ mass WRITE setMass )
|
---|
34 | #ifndef Q_MOC_RUN // Qt3 moc
|
---|
35 | #define QWT_PROPERTY Q_PROPERTY
|
---|
36 | Q_PROPERTY( Orientation orientation
|
---|
37 | READ orientation WRITE setOrientation )
|
---|
38 | #else // Qt4 moc
|
---|
39 | // MOC_SKIP_BEGIN
|
---|
40 | Q_PROPERTY( Qt::Orientation orientation
|
---|
41 | READ orientation WRITE setOrientation )
|
---|
42 | // MOC_SKIP_END
|
---|
43 | #endif
|
---|
44 |
|
---|
45 | public:
|
---|
46 | /*!
|
---|
47 | Scroll mode
|
---|
48 | \sa getScrollMode()
|
---|
49 | */
|
---|
50 | enum ScrollMode
|
---|
51 | {
|
---|
52 | ScrNone,
|
---|
53 | ScrMouse,
|
---|
54 | ScrTimer,
|
---|
55 | ScrDirect,
|
---|
56 | ScrPage
|
---|
57 | };
|
---|
58 |
|
---|
59 | explicit QwtAbstractSlider(Qt::Orientation, QWidget *parent = NULL);
|
---|
60 | virtual ~QwtAbstractSlider();
|
---|
61 |
|
---|
62 | void setUpdateTime(int t);
|
---|
63 | void stopMoving();
|
---|
64 | void setTracking(bool enable);
|
---|
65 |
|
---|
66 | virtual void setMass(double val);
|
---|
67 | virtual double mass() const;
|
---|
68 |
|
---|
69 | #if QT_VERSION >= 0x040000
|
---|
70 | virtual void setOrientation(Qt::Orientation o);
|
---|
71 | Qt::Orientation orientation() const;
|
---|
72 | #else
|
---|
73 | virtual void setOrientation(Orientation o);
|
---|
74 | Orientation orientation() const;
|
---|
75 | #endif
|
---|
76 |
|
---|
77 | bool isReadOnly() const;
|
---|
78 |
|
---|
79 | /*
|
---|
80 | Wrappers for QwtDblRange::isValid/QwtDblRange::setValid made
|
---|
81 | to be available as Q_PROPERTY in the designer.
|
---|
82 | */
|
---|
83 |
|
---|
84 | /*!
|
---|
85 | \sa QwtDblRange::isValid()
|
---|
86 | */
|
---|
87 | bool isValid() const { return QwtDoubleRange::isValid(); }
|
---|
88 |
|
---|
89 | /*!
|
---|
90 | \param valid true/false
|
---|
91 | \sa QwtDblRange::isValid()
|
---|
92 | */
|
---|
93 | void setValid(bool valid) { QwtDoubleRange::setValid(valid); }
|
---|
94 |
|
---|
95 | public slots:
|
---|
96 | virtual void setValue(double val);
|
---|
97 | virtual void fitValue(double val);
|
---|
98 | virtual void incValue(int steps);
|
---|
99 |
|
---|
100 | virtual void setReadOnly(bool);
|
---|
101 |
|
---|
102 | signals:
|
---|
103 |
|
---|
104 | /*!
|
---|
105 | \brief Notify a change of value.
|
---|
106 |
|
---|
107 | In the default setting
|
---|
108 | (tracking enabled), this signal will be emitted every
|
---|
109 | time the value changes ( see setTracking() ).
|
---|
110 | \param value new value
|
---|
111 | */
|
---|
112 | void valueChanged(double value);
|
---|
113 |
|
---|
114 | /*!
|
---|
115 | This signal is emitted when the user presses the
|
---|
116 | movable part of the slider (start ScrMouse Mode).
|
---|
117 | */
|
---|
118 | void sliderPressed();
|
---|
119 |
|
---|
120 | /*!
|
---|
121 | This signal is emitted when the user releases the
|
---|
122 | movable part of the slider.
|
---|
123 | */
|
---|
124 |
|
---|
125 | void sliderReleased();
|
---|
126 | /*!
|
---|
127 | This signal is emitted when the user moves the
|
---|
128 | slider with the mouse.
|
---|
129 | \param value new value
|
---|
130 | */
|
---|
131 | void sliderMoved(double value);
|
---|
132 |
|
---|
133 | protected:
|
---|
134 | virtual void setPosition(const QPoint &);
|
---|
135 | virtual void valueChange();
|
---|
136 |
|
---|
137 | virtual void timerEvent(QTimerEvent *e);
|
---|
138 | virtual void mousePressEvent(QMouseEvent *e);
|
---|
139 | virtual void mouseReleaseEvent(QMouseEvent *e);
|
---|
140 | virtual void mouseMoveEvent(QMouseEvent *e);
|
---|
141 | virtual void keyPressEvent(QKeyEvent *e);
|
---|
142 | virtual void wheelEvent(QWheelEvent *e);
|
---|
143 |
|
---|
144 | /*!
|
---|
145 | \brief Determine the value corresponding to a specified poind
|
---|
146 |
|
---|
147 | This is an abstract virtual function which is called when
|
---|
148 | the user presses or releases a mouse button or moves the
|
---|
149 | mouse. It has to be implemented by the derived class.
|
---|
150 | \param p point
|
---|
151 | */
|
---|
152 | virtual double getValue(const QPoint & p) = 0;
|
---|
153 | /*!
|
---|
154 | \brief Determine what to do when the user presses a mouse button.
|
---|
155 |
|
---|
156 | This function is abstract and has to be implemented by derived classes.
|
---|
157 | It is called on a mousePress event. The derived class can determine
|
---|
158 | what should happen next in dependence of the position where the mouse
|
---|
159 | was pressed by returning scrolling mode and direction. QwtAbstractSlider
|
---|
160 | knows the following modes:<dl>
|
---|
161 | <dt>QwtAbstractSlider::ScrNone
|
---|
162 | <dd>Scrolling switched off. Don't change the value.
|
---|
163 | <dt>QwtAbstractSlider::ScrMouse
|
---|
164 | <dd>Change the value while the user keeps the
|
---|
165 | button pressed and moves the mouse.
|
---|
166 | <dt>QwtAbstractSlider::ScrTimer
|
---|
167 | <dd>Automatic scrolling. Increment the value
|
---|
168 | in the specified direction as long as
|
---|
169 | the user keeps the button pressed.
|
---|
170 | <dt>QwtAbstractSlider::ScrPage
|
---|
171 | <dd>Automatic scrolling. Same as ScrTimer, but
|
---|
172 | increment by page size.</dl>
|
---|
173 |
|
---|
174 | \param p point where the mouse was pressed
|
---|
175 | \retval scrollMode The scrolling mode
|
---|
176 | \retval direction direction: 1, 0, or -1.
|
---|
177 | */
|
---|
178 | virtual void getScrollMode( const QPoint &p,
|
---|
179 | int &scrollMode, int &direction) = 0;
|
---|
180 |
|
---|
181 | void setMouseOffset(double);
|
---|
182 | double mouseOffset() const;
|
---|
183 |
|
---|
184 | int scrollMode() const;
|
---|
185 |
|
---|
186 | private:
|
---|
187 | void buttonReleased();
|
---|
188 |
|
---|
189 | class PrivateData;
|
---|
190 | PrivateData *d_data;
|
---|
191 | };
|
---|
192 |
|
---|
193 | #endif
|
---|