Developer Documentation

QtWheel.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41
42
43
44
45
46 //=============================================================================
47 //
48 // CLASS QWheel
49 //
50 //=============================================================================
51
52 #ifndef ACG_QT_WHEEL_HH
53 #define ACG_QT_WHEEL_HH
54
55
56 //== INCLUDES =================================================================
57
58 #include <QPalette>
59 #include <QFrame>
60 #include <QMouseEvent>
61 #include <QPixmap>
62 #include <QKeyEvent>
63 #include <QResizeEvent>
64 #include <QPaintEvent>
65
66 #include "../Config/ACGDefines.hh"
67
68
69 //== FORWARDDECLARATIONS ======================================================
70
71 class QPaintEvent;
72 class QMouseEvent;
73 class QPainter;
74
75
76 //== NAMESPACES ===============================================================
77
78
79 namespace ACG {
80 namespace QtWidgets {
81
82
83 //== CLASS DEFINITION =========================================================
84
85
101 class ACGDLLEXPORT QtWheel : public QFrame
102 {
103 Q_OBJECT
104 public:
105
107 enum Orientation { Horizontal, Vertical };
108
109 //
110 // CONSTRUCTORS
111 //
112
114 QtWheel(QWidget* _parent=0,
115 const char* _name=0,
116 Orientation _orientation = Horizontal);
117
119 virtual ~QtWheel();
120
121
122 //
123 // METHODS
124 //
125
127 int ticks() const { return ticks_; }
129 void setTicks(int _number) {
130 ticks_=_number; redrawPixmap(); repaint();
131 }
132
134 double angle() const { return angle_; }
136 void setAngle(double _angle) {
137 angle_=_angle; lastAngle_=0.0; redrawPixmap(); repaint();
138 }
144 double diffAngle() const { return angle_-lastAngle_; }
145
147 bool marker() const { return marker_; }
149 void setMarker(bool _b) {
150 marker_=_b; redrawPixmap(); repaint();
151 }
152
154 Orientation orientation() const;
156 void setOrientation(Orientation _orientation) {
157 orientation_=_orientation; redrawPixmap(); repaint();
158 }
159
161 bool draggingWheel() const { return dragging_; }
162
169 void setTracking(bool _b) { tracking_=_b; }
171 bool tracking() const { return tracking_; }
172
180 void setGear(double _g) { gear_=_g; }
182 double gear() const { return gear_; }
183
185 virtual QSizePolicy sizePolicy() const;
187 virtual QSize sizeHint() const;
188
197 static double clip(double _angle);
198
200 static double deg(double _angle);
201
202 signals:
206 void angleChangedTo(double _angle);
217 void angleChangedBy(double _angle);
218
223 void gearUp();
225 void gearDown();
226
228 void hideWheel();
229
230 protected:
232 virtual void mousePressEvent(QMouseEvent*);
234 virtual void mouseReleaseEvent(QMouseEvent*);
236 virtual void mouseMoveEvent(QMouseEvent*);
238 virtual void mouseDoubleClickEvent(QMouseEvent*);
240 virtual void keyPressEvent(QKeyEvent*);
242 virtual void keyReleaseEvent(QKeyEvent*);
243
245 virtual void resizeEvent(QResizeEvent*);
247 virtual void paintEvent(QPaintEvent*);
249 virtual void drawContents(QPainter*) {};
250
251
253 virtual void redrawPixmap();
254
255 private slots:
256 void slotCustomContextMenuRequested ( const QPoint & pos );
257
258 private:
259
261 QtWheel(const QtWheel&);
263 QtWheel& operator=(const QtWheel&);
264
266 double turn(const QPoint& _pos);
267 void updateMenu();
268 void shrinkRect(QRect&, int, int);
269
270 double angle_;
271 double lastAngle_;
272 int size_;
273
274 double gear_;
275 int gearShift_;
276
277 Orientation orientation_;
278
279 int ticks_;
280 bool marker_;
281
282 QPoint pos_;
283 bool dragging_;
284 bool tracking_;
285
286 QPalette palette_;
287 QPixmap pixmap_;
288 };
289
290 //=============================================================================
291 } // namespace QtWidgets
292 } // namespace ACG
293 //=============================================================================
294 #endif // ACG_QWHEEL_HH defined
295 //=============================================================================
296
ACG
Namespace providing different geometric functions concerning angles.
Definition: BaseObjectData.hh:68
ACG::QtWidgets::QtWheel::gearShift_
int gearShift_
click-shifted gear by 2^gearShift_
Definition: QtWheel.hh:275
ACG::QtWidgets::QtWheel::draggingWheel
bool draggingWheel() const
Is the user currently dragging the wheel whith the mouse?
Definition: QtWheel.hh:161
ACG::QtWidgets::QtWheel::diffAngle
double diffAngle() const
Definition: QtWheel.hh:144
ACG::QtWidgets::QtWheel::ticks_
int ticks_
number of ticks on the wheel
Definition: QtWheel.hh:279
ACG::QtWidgets::QtWheel::setTicks
void setTicks(int _number)
set _number of ticks on the wheel (default: 36)
Definition: QtWheel.hh:129
ACG::QtWidgets::QtWheel::drawContents
virtual void drawContents(QPainter *)
reimplemented
Definition: QtWheel.hh:249
ACG::QtWidgets::QtWheel::pos_
QPoint pos_
recent mouse position
Definition: QtWheel.hh:282
ACG::QtWidgets::QtWheel
Definition: QtWheel.hh:101
ACG::QtWidgets::QtWheel::angle_
double angle_
current angle of the wheel
Definition: QtWheel.hh:270
ACG::QtWidgets::QtWheel::setMarker
void setMarker(bool _b)
enable/disable markers on the wheel
Definition: QtWheel.hh:149
ACG::QtWidgets::QtWheel::gear
double gear() const
How fast does angle() change when the wheel is turned? (see above)
Definition: QtWheel.hh:182
ACG::QtWidgets::QtWheel::orientation_
Orientation orientation_
orientation of the widget
Definition: QtWheel.hh:277
ACG::QtWidgets::QtWheel::tracking_
bool tracking_
tracking on?
Definition: QtWheel.hh:284
ACG::QtWidgets::QtWheel::setTracking
void setTracking(bool _b)
Definition: QtWheel.hh:169
ACG::QtWidgets::QtWheel::dragging_
bool dragging_
currently dragging the slider?
Definition: QtWheel.hh:283
ACG::QtWidgets::QtWheel::marker_
bool marker_
should ticks be marked by colors?
Definition: QtWheel.hh:280
ACG::QtWidgets::QtWheel::setOrientation
void setOrientation(Orientation _orientation)
set orientation
Definition: QtWheel.hh:156
ACG::QtWidgets::QtWheel::pixmap_
QPixmap pixmap_
pixmap of the wheel
Definition: QtWheel.hh:287
ACG::QtWidgets::QtWheel::setAngle
void setAngle(double _angle)
set current angle of the wheel (radiants, unbounded, cf. clip())
Definition: QtWheel.hh:136
ACG::QtWidgets::QtWheel::ticks
int ticks() const
get number of ticks on the wheel
Definition: QtWheel.hh:127
ACG::QtWidgets::QtWheel::gear_
double gear_
speed of revolution
Definition: QtWheel.hh:274
ACG::QtWidgets::QtWheel::tracking
bool tracking() const
Is tracking on?
Definition: QtWheel.hh:171
ACG::QtWidgets::QtWheel::lastAngle_
double lastAngle_
last angle, depends on tracking_
Definition: QtWheel.hh:271
ACG::QtWidgets::QtWheel::Orientation
Orientation
Orientation of the widget.
Definition: QtWheel.hh:107
ACG::QtWidgets::QtWheel::marker
bool marker() const
Are there markers on the wheel?
Definition: QtWheel.hh:147
ACG::QtWidgets::QtWheel::palette_
QPalette palette_
color group
Definition: QtWheel.hh:286
ACG::QtWidgets::QtWheel::setGear
void setGear(double _g)
Definition: QtWheel.hh:180
ACG::QtWidgets::QtWheel::size_
int size_
size of wheel in pixels
Definition: QtWheel.hh:272
ACG::QtWidgets::QtWheel::angle
double angle() const
get current angle of the wheel (radiants, unbounded, cf. clip())
Definition: QtWheel.hh:134