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
71class QPaintEvent;
72class QMouseEvent;
73class QPainter;
74
75
76//== NAMESPACES ===============================================================
77
78
79namespace ACG {
80namespace QtWidgets {
81
82
83//== CLASS DEFINITION =========================================================
84
85
101class ACGDLLEXPORT QtWheel : public QFrame
102{
103 Q_OBJECT
104public:
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
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
202signals:
206 void angleChangedTo(double _angle);
217 void angleChangedBy(double _angle);
218
223 void gearUp();
225 void gearDown();
226
228 void hideWheel();
229
230protected:
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
255private slots:
256 void slotCustomContextMenuRequested ( const QPoint & pos );
257
258private:
259
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_;
276
278
279 int ticks_;
280 bool marker_;
281
282 QPoint pos_;
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
void setMarker(bool _b)
enable/disable markers on the wheel
Definition: QtWheel.hh:149
void gearDown()
Like gearUp() but the value of gear() halves.
int ticks_
number of ticks on the wheel
Definition: QtWheel.hh:279
QtWheel & operator=(const QtWheel &)
Assignment operator. Never used!
bool marker_
should ticks be marked by colors?
Definition: QtWheel.hh:280
double angle_
current angle of the wheel
Definition: QtWheel.hh:270
bool marker() const
Are there markers on the wheel?
Definition: QtWheel.hh:147
bool dragging_
currently dragging the slider?
Definition: QtWheel.hh:283
int gearShift_
click-shifted gear by 2^gearShift_
Definition: QtWheel.hh:275
void angleChangedTo(double _angle)
bool draggingWheel() const
Is the user currently dragging the wheel whith the mouse?
Definition: QtWheel.hh:161
void setOrientation(Orientation _orientation)
set orientation
Definition: QtWheel.hh:156
int size_
size of wheel in pixels
Definition: QtWheel.hh:272
double diffAngle() const
Definition: QtWheel.hh:144
double gear() const
How fast does angle() change when the wheel is turned? (see above)
Definition: QtWheel.hh:182
QPalette palette_
color group
Definition: QtWheel.hh:286
double angle() const
get current angle of the wheel (radiants, unbounded, cf. clip())
Definition: QtWheel.hh:134
void setAngle(double _angle)
set current angle of the wheel (radiants, unbounded, cf. clip())
Definition: QtWheel.hh:136
Orientation orientation() const
get orientation
void updateMenu()
updates the ticks of the menu
virtual void drawContents(QPainter *)
reimplemented
Definition: QtWheel.hh:249
bool tracking() const
Is tracking on?
Definition: QtWheel.hh:171
void angleChangedBy(double _angle)
QPixmap pixmap_
pixmap of the wheel
Definition: QtWheel.hh:287
void setTracking(bool _b)
Definition: QtWheel.hh:169
void setTicks(int _number)
set _number of ticks on the wheel (default: 36)
Definition: QtWheel.hh:129
int ticks() const
get number of ticks on the wheel
Definition: QtWheel.hh:127
QtWheel(const QtWheel &)
Copy constructor. Never used!
void setGear(double _g)
Definition: QtWheel.hh:180
void hideWheel()
Emitted when the wheel will be hidden by the context menu.
Orientation
Orientation of the widget.
Definition: QtWheel.hh:107
double lastAngle_
last angle, depends on tracking_
Definition: QtWheel.hh:271
double gear_
speed of revolution
Definition: QtWheel.hh:274
Orientation orientation_
orientation of the widget
Definition: QtWheel.hh:277
bool tracking_
tracking on?
Definition: QtWheel.hh:284
QPoint pos_
recent mouse position
Definition: QtWheel.hh:282
Namespace providing different geometric functions concerning angles.