Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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  * $Revision$ *
45  * $Author$ *
46  * $Date$ *
47  * *
48 \*===========================================================================*/
49 
50 
51 
52 //=============================================================================
53 //
54 // CLASS QWheel
55 //
56 //=============================================================================
57 
58 #ifndef ACG_QT_WHEEL_HH
59 #define ACG_QT_WHEEL_HH
60 
61 
62 //== INCLUDES =================================================================
63 
64 #include <QPalette>
65 #include <QFrame>
66 #include <QMouseEvent>
67 #include <QPixmap>
68 #include <QKeyEvent>
69 #include <QResizeEvent>
70 #include <QPaintEvent>
71 
72 #include "../Config/ACGDefines.hh"
73 
74 
75 //== FORWARDDECLARATIONS ======================================================
76 
77 class QPaintEvent;
78 class QMouseEvent;
79 class QPainter;
80 
81 
82 //== NAMESPACES ===============================================================
83 
84 
85 namespace ACG {
86 namespace QtWidgets {
87 
88 
89 //== CLASS DEFINITION =========================================================
90 
91 
107 class ACGDLLEXPORT QtWheel : public QFrame
108 {
109  Q_OBJECT
110 public:
111 
113  enum Orientation { Horizontal, Vertical };
114 
115  //
116  // CONSTRUCTORS
117  //
118 
120  QtWheel(QWidget* _parent=0,
121  const char* _name=0,
122  Orientation _orientation = Horizontal);
123 
125  virtual ~QtWheel();
126 
127 
128  //
129  // METHODS
130  //
131 
133  int ticks() const { return ticks_; }
135  void setTicks(int _number) {
136  ticks_=_number; redrawPixmap(); repaint();
137  }
138 
140  double angle() const { return angle_; }
142  void setAngle(double _angle) {
143  angle_=_angle; lastAngle_=0.0; redrawPixmap(); repaint();
144  }
150  double diffAngle() const { return angle_-lastAngle_; }
151 
153  bool marker() const { return marker_; }
155  void setMarker(bool _b) {
156  marker_=_b; redrawPixmap(); repaint();
157  }
158 
160  Orientation orientation() const;
162  void setOrientation(Orientation _orientation) {
163  orientation_=_orientation; redrawPixmap(); repaint();
164  }
165 
167  bool draggingWheel() const { return dragging_; }
168 
175  void setTracking(bool _b) { tracking_=_b; }
177  bool tracking() const { return tracking_; }
178 
186  void setGear(double _g) { gear_=_g; }
188  double gear() const { return gear_; }
189 
191  virtual QSizePolicy sizePolicy() const;
193  virtual QSize sizeHint() const;
194 
203  static double clip(double _angle);
204 
206  static double deg(double _angle);
207 
208 signals:
212  void angleChangedTo(double _angle);
223  void angleChangedBy(double _angle);
224 
229  void gearUp();
231  void gearDown();
232 
234  void hideWheel();
235 
236 protected:
238  virtual void mousePressEvent(QMouseEvent*);
240  virtual void mouseReleaseEvent(QMouseEvent*);
242  virtual void mouseMoveEvent(QMouseEvent*);
244  virtual void mouseDoubleClickEvent(QMouseEvent*);
246  virtual void keyPressEvent(QKeyEvent*);
248  virtual void keyReleaseEvent(QKeyEvent*);
249 
251  virtual void resizeEvent(QResizeEvent*);
253  virtual void paintEvent(QPaintEvent*);
255  virtual void drawContents(QPainter*) {};
256 
257 
259  virtual void redrawPixmap();
260 
261 private slots:
262  void slotCustomContextMenuRequested ( const QPoint & pos );
263 
264 private:
265 
267  QtWheel(const QtWheel&);
269  QtWheel& operator=(const QtWheel&);
270 
272  double turn(const QPoint& _pos);
273  void updateMenu();
274  void shrinkRect(QRect&, int, int);
275 
276  double angle_;
277  double lastAngle_;
278  int size_;
279 
280  double gear_;
282 
284 
285  int ticks_;
286  bool marker_;
287 
288  QPoint pos_;
289  bool dragging_;
290  bool tracking_;
291 
292  QPalette palette_;
293  QPixmap pixmap_;
294 };
295 
296 //=============================================================================
297 } // namespace QtWidgets
298 } // namespace ACG
299 //=============================================================================
300 #endif // ACG_QWHEEL_HH defined
301 //=============================================================================
302 
int ticks() const
get number of ticks on the wheel
Definition: QtWheel.hh:133
void setGear(double _g)
Definition: QtWheel.hh:186
double gear() const
How fast does angle() change when the wheel is turned? (see above)
Definition: QtWheel.hh:188
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
void setAngle(double _angle)
set current angle of the wheel (radiants, unbounded, cf. clip())
Definition: QtWheel.hh:142
bool tracking() const
Is tracking on?
Definition: QtWheel.hh:177
bool marker() const
Are there markers on the wheel?
Definition: QtWheel.hh:153
double angle_
current angle of the wheel
Definition: QtWheel.hh:276
QPixmap pixmap_
pixmap of the wheel
Definition: QtWheel.hh:293
int ticks_
number of ticks on the wheel
Definition: QtWheel.hh:285
int gearShift_
click-shifted gear by 2^gearShift_
Definition: QtWheel.hh:281
bool draggingWheel() const
Is the user currently dragging the wheel whith the mouse?
Definition: QtWheel.hh:167
double gear_
speed of revolution
Definition: QtWheel.hh:280
int size_
size of wheel in pixels
Definition: QtWheel.hh:278
double angle() const
get current angle of the wheel (radiants, unbounded, cf. clip())
Definition: QtWheel.hh:140
void setTicks(int _number)
set _number of ticks on the wheel (default: 36)
Definition: QtWheel.hh:135
void setMarker(bool _b)
enable/disable markers on the wheel
Definition: QtWheel.hh:155
bool dragging_
currently dragging the slider?
Definition: QtWheel.hh:289
QPalette palette_
color group
Definition: QtWheel.hh:292
Orientation orientation_
orientation of the widget
Definition: QtWheel.hh:283
bool marker_
should ticks be marked by colors?
Definition: QtWheel.hh:286
double diffAngle() const
Definition: QtWheel.hh:150
void setOrientation(Orientation _orientation)
set orientation
Definition: QtWheel.hh:162
virtual void drawContents(QPainter *)
reimplemented
Definition: QtWheel.hh:255
bool tracking_
tracking on?
Definition: QtWheel.hh:290
QPoint pos_
recent mouse position
Definition: QtWheel.hh:288
double lastAngle_
last angle, depends on tracking_
Definition: QtWheel.hh:277
void setTracking(bool _b)
Definition: QtWheel.hh:175
Orientation
Orientation of the widget.
Definition: QtWheel.hh:113