Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 #ifndef QGLVIEWER_MOUSE_GRABBER_H
00024 #define QGLVIEWER_MOUSE_GRABBER_H
00025 
00026 #include "config.h"
00027 
00028 #if QT_VERSION >= 0x040000
00029 # include <QEvent>
00030 #else
00031 # include <qevent.h>
00032 #endif
00033 
00034 class QGLViewer;
00035 
00036 namespace qglviewer {
00037   class Camera;
00038 
00134   class QGLVIEWER_EXPORT MouseGrabber
00135   {
00136 #ifndef DOXYGEN
00137     friend class ::QGLViewer;
00138 #endif
00139 
00140   public:
00141     MouseGrabber();
00143 #if QT_VERSION >= 0x040000
00144     virtual ~MouseGrabber() { MouseGrabber::MouseGrabberPool_.removeAll(this); };
00145 #else
00146     virtual ~MouseGrabber() { MouseGrabber::MouseGrabberPool_.removeRef(this); };
00147 #endif
00148 
00151   public:
00182     virtual void checkIfGrabsMouse(int x, int y, const Camera* const camera) = 0;
00183 
00187     bool grabsMouse() const { return grabsMouse_; };
00188 
00189   protected:
00191     void setGrabsMouse(bool grabs) { grabsMouse_ = grabs; };
00193 
00194 
00197   public:
00207 #if QT_VERSION >= 0x040000
00208     static const QList<MouseGrabber*>& MouseGrabberPool() { return MouseGrabber::MouseGrabberPool_; };
00209 #else
00210 # if QT_VERSION >= 0x030000
00211     static const QPtrList<MouseGrabber>& MouseGrabberPool() { return MouseGrabber::MouseGrabberPool_; };
00212 # else
00213     static const QList<MouseGrabber>& MouseGrabberPool() { return MouseGrabber::MouseGrabberPool_; };
00214 # endif
00215 #endif
00216 
00222 #if QT_VERSION >= 0x040000
00223     bool isInMouseGrabberPool() const { return MouseGrabber::MouseGrabberPool_.contains(const_cast<MouseGrabber*>(this)); };
00224 #else
00225     bool isInMouseGrabberPool() const { return MouseGrabber::MouseGrabberPool_.findRef(this) != -1; };
00226 #endif
00227     void addInMouseGrabberPool();
00228     void removeFromMouseGrabberPool();
00229     void clearMouseGrabberPool(bool autoDelete=false);
00231 
00232 
00235   protected:
00251     virtual void mousePressEvent(QMouseEvent* const event, Camera* const camera) { Q_UNUSED(event) Q_UNUSED(camera) };
00255     virtual void mouseDoubleClickEvent(QMouseEvent* const event, Camera* const camera) { Q_UNUSED(event) Q_UNUSED(camera) };
00257     virtual void mouseReleaseEvent(QMouseEvent* const event, Camera* const camera) { Q_UNUSED(event) Q_UNUSED(camera) };
00263     virtual void mouseMoveEvent(QMouseEvent* const event, Camera* const camera) { Q_UNUSED(event) Q_UNUSED(camera) };
00267     virtual void wheelEvent(QWheelEvent* const event, Camera* const camera) { Q_UNUSED(event) Q_UNUSED(camera) };
00269 
00270   private:
00271     
00272     
00273     MouseGrabber(const MouseGrabber&);
00274     MouseGrabber& operator=(const MouseGrabber&);
00275 
00276     bool grabsMouse_;
00277 
00278     
00279 #if QT_VERSION >= 0x040000
00280     static QList<MouseGrabber*> MouseGrabberPool_;
00281 #else
00282     static QPtrList<MouseGrabber> MouseGrabberPool_;
00283 #endif
00284   };
00285 
00286 } 
00287 
00288 #endif // QGLVIEWER_MOUSE_GRABBER_H