mouseGrabber.h
1 /****************************************************************************
2 
3  Copyright (C) 2002-2013 Gilles Debunne. All rights reserved.
4 
5  This file is part of the QGLViewer library version 2.5.2.
6 
7  http://www.libqglviewer.com - contact@libqglviewer.com
8 
9  This file may be used under the terms of the GNU General Public License
10  versions 2.0 or 3.0 as published by the Free Software Foundation and
11  appearing in the LICENSE file included in the packaging of this file.
12  In addition, as a special exception, Gilles Debunne gives you certain
13  additional rights, described in the file GPL_EXCEPTION in this package.
14 
15  libQGLViewer uses dual licensing. Commercial/proprietary software must
16  purchase a libQGLViewer Commercial License.
17 
18  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
19  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 
21 *****************************************************************************/
22 
23 #ifndef QGLVIEWER_MOUSE_GRABBER_H
24 #define QGLVIEWER_MOUSE_GRABBER_H
25 
26 #include "config.h"
27 
28 #include <QEvent>
29 
30 class QGLViewer;
31 
32 namespace qglviewer {
33 class Camera;
34 
130 class QGLVIEWER_EXPORT MouseGrabber
131 {
132 #ifndef DOXYGEN
133  friend class ::QGLViewer;
134 #endif
135 
136 public:
137  MouseGrabber();
139  virtual ~MouseGrabber() { MouseGrabber::MouseGrabberPool_.removeAll(this); }
140 
143 public:
174  virtual void checkIfGrabsMouse(int x, int y, const Camera* const camera) = 0;
175 
179  bool grabsMouse() const { return grabsMouse_; }
180 
181 protected:
183  void setGrabsMouse(bool grabs) { grabsMouse_ = grabs; }
185 
186 
189 public:
199  static const QList<MouseGrabber*>& MouseGrabberPool() { return MouseGrabber::MouseGrabberPool_; }
200 
206  bool isInMouseGrabberPool() const { return MouseGrabber::MouseGrabberPool_.contains(const_cast<MouseGrabber*>(this)); }
207  void addInMouseGrabberPool();
208  void removeFromMouseGrabberPool();
209  void clearMouseGrabberPool(bool autoDelete=false);
211 
212 
215 protected:
231  virtual void mousePressEvent(QMouseEvent* const event, Camera* const camera) { Q_UNUSED(event); Q_UNUSED(camera); }
235  virtual void mouseDoubleClickEvent(QMouseEvent* const event, Camera* const camera) { Q_UNUSED(event); Q_UNUSED(camera); }
237  virtual void mouseReleaseEvent(QMouseEvent* const event, Camera* const camera) { Q_UNUSED(event); Q_UNUSED(camera); }
243  virtual void mouseMoveEvent(QMouseEvent* const event, Camera* const camera) { Q_UNUSED(event); Q_UNUSED(camera); }
247  virtual void wheelEvent(QWheelEvent* const event, Camera* const camera) { Q_UNUSED(event); Q_UNUSED(camera); }
249 
250 private:
251  // Copy constructor and opertor= are declared private and undefined
252  // Prevents everyone from trying to use them
253  MouseGrabber(const MouseGrabber&);
254  MouseGrabber& operator=(const MouseGrabber&);
255 
256  bool grabsMouse_;
257 
258  // Q G L V i e w e r p o o l
259  static QList<MouseGrabber*> MouseGrabberPool_;
260 };
261 
262 } // namespace qglviewer
263 
264 #endif // QGLVIEWER_MOUSE_GRABBER_H
virtual ~MouseGrabber()
Virtual destructor.
Definition: mouseGrabber.h:139
virtual void mouseDoubleClickEvent(QMouseEvent *const event, Camera *const camera)
Callback method called when the MouseGrabber grabsMouse() and a mouse button is double clicked...
Definition: mouseGrabber.h:235
Abstract class for objects that grab mouse focus in a QGLViewer.
Definition: mouseGrabber.h:130
bool isInMouseGrabberPool() const
Returns true if the MouseGrabber is currently in the MouseGrabberPool() list.
Definition: mouseGrabber.h:206
virtual void wheelEvent(QWheelEvent *const event, Camera *const camera)
Callback method called when the MouseGrabber grabsMouse() and the mouse wheel is used.
Definition: mouseGrabber.h:247
A versatile 3D OpenGL viewer based on QGLWidget.
Definition: qglviewer.h:62
A perspective or orthographic camera.
Definition: camera.h:84
void setGrabsMouse(bool grabs)
Sets the grabsMouse() flag.
Definition: mouseGrabber.h:183
bool grabsMouse() const
Returns true when the MouseGrabber grabs the QGLViewer's mouse events.
Definition: mouseGrabber.h:179
virtual void mouseReleaseEvent(QMouseEvent *const event, Camera *const camera)
Mouse release event callback method.
Definition: mouseGrabber.h:237
static const QList< MouseGrabber * > & MouseGrabberPool()
Returns a list containing pointers to all the active MouseGrabbers.
Definition: mouseGrabber.h:199
virtual void mouseMoveEvent(QMouseEvent *const event, Camera *const camera)
Callback method called when the MouseGrabber grabsMouse() and the mouse is moved while a button is pr...
Definition: mouseGrabber.h:243
virtual void mousePressEvent(QMouseEvent *const event, Camera *const camera)
Callback method called when the MouseGrabber grabsMouse() and a mouse button is pressed.
Definition: mouseGrabber.h:231