QtWheel.hh

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper is free software: you can redistribute it and/or modify      *
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenFlipper is distributed in the hope that it will be useful,           *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 6743 $                                                       *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2009-08-05 11:03:10 +0200 (Mi, 05. Aug 2009) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 
00045 //=============================================================================
00046 //
00047 //  CLASS QWheel
00048 //
00049 //=============================================================================
00050 
00051 #ifndef ACG_QT_WHEEL_HH
00052 #define ACG_QT_WHEEL_HH
00053 
00054 
00055 //== INCLUDES =================================================================
00056 
00057 #include <QPalette>
00058 #include <QFrame>
00059 #include <QMouseEvent>
00060 #include <QPixmap>
00061 #include <QKeyEvent>
00062 #include <QResizeEvent>
00063 #include <QPaintEvent>
00064 
00065 #include "../Config/ACGDefines.hh"
00066 
00067 
00068 //== FORWARDDECLARATIONS ======================================================
00069 
00070 class QPaintEvent;
00071 class QMouseEvent;
00072 class QPainter;
00073 
00074 
00075 //== NAMESPACES ===============================================================
00076 
00077 
00078 namespace ACG {
00079 namespace QtWidgets {
00080 
00081 
00082 //== CLASS DEFINITION =========================================================
00083 
00084 
00100 class ACGDLLEXPORT QtWheel : public QFrame
00101 {
00102   Q_OBJECT
00103 public:
00104 
00106   enum Orientation { Horizontal, Vertical };
00107 
00108   //
00109   // CONSTRUCTORS
00110   //
00111 
00113   QtWheel(QWidget* _parent=0,
00114          const char* _name=0,
00115          Orientation _orientation = Horizontal);
00116 
00118   virtual ~QtWheel();
00119 
00120 
00121   //
00122   // METHODS
00123   //
00124 
00126   int ticks() const { return ticks_; }
00128   void setTicks(int _number) {
00129     ticks_=_number; redrawPixmap(); repaint();
00130   }
00131 
00133   double angle() const { return angle_; }
00135   void setAngle(double _angle) {
00136     angle_=_angle; lastAngle_=0.0; redrawPixmap(); repaint();
00137   }
00143   double diffAngle() const { return angle_-lastAngle_; }
00144 
00146   bool marker() const { return marker_; }
00148   void setMarker(bool _b) {
00149     marker_=_b; redrawPixmap(); repaint();
00150   }
00151 
00153   Orientation orientation() const;
00155   void setOrientation(Orientation _orientation) {
00156     orientation_=_orientation; redrawPixmap(); repaint();
00157   }
00158 
00160   bool draggingWheel() const { return dragging_; }
00161 
00168   void setTracking(bool _b) { tracking_=_b; }
00170   bool tracking() const { return tracking_; }
00171 
00179   void setGear(double _g) { gear_=_g; }
00181   double gear() const { return gear_; }
00182 
00184   virtual QSizePolicy sizePolicy() const;
00186   virtual QSize sizeHint() const;
00187 
00196   static double clip(double _angle);
00197 
00199   static double deg(double _angle);
00200 
00201 signals:
00205   void angleChangedTo(double _angle);
00216   void angleChangedBy(double _angle);
00217 
00222   void gearUp();
00224   void gearDown();
00225 
00227   void hideWheel();
00228 
00229 protected:
00231   virtual void mousePressEvent(QMouseEvent*);
00233   virtual void mouseReleaseEvent(QMouseEvent*);
00235   virtual void mouseMoveEvent(QMouseEvent*);
00237   virtual void mouseDoubleClickEvent(QMouseEvent*);
00239   virtual void keyPressEvent(QKeyEvent*);
00241   virtual void keyReleaseEvent(QKeyEvent*);
00242 
00244   virtual void resizeEvent(QResizeEvent*);
00246   virtual void paintEvent(QPaintEvent*);
00248   virtual void drawContents(QPainter*) {};
00249 
00250 
00252   virtual void redrawPixmap();
00253 
00254 private slots:
00255   void slotCustomContextMenuRequested ( const QPoint & pos );
00256 
00257 private:
00258 
00260   QtWheel(const QtWheel&);
00262   QtWheel& operator=(const QtWheel&);
00263 
00265   double turn(const QPoint& _pos);
00266   void updateMenu();                  
00267   void shrinkRect(QRect&, int, int);  
00268 
00269   double       angle_;                
00270   double       lastAngle_;            
00271   int          size_;                 
00272 
00273   double       gear_;                 
00274   int          gearShift_;            
00275 
00276   Orientation  orientation_;          
00277 
00278   int          ticks_;                
00279   bool         marker_;               
00280 
00281   QPoint       pos_;                  
00282   bool         dragging_;             
00283   bool         tracking_;             
00284 
00285   QPalette     palette_;              
00286   QPixmap      pixmap_;               
00287 };
00288 
00289 //=============================================================================
00290 } // namespace QtWidgets
00291 } // namespace ACG
00292 //=============================================================================
00293 #endif // ACG_QWHEEL_HH defined
00294 //=============================================================================
00295 

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .