mouseGrabber.h
1 /****************************************************************************
2 
3  Copyright (C) 2002-2008 Gilles Debunne. All rights reserved.
4 
5  This file is part of the QGLViewer library version 2.3.10.
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 #if QT_VERSION >= 0x040000
29 # include <QEvent>
30 #else
31 # include <qevent.h>
32 #endif
33 
34 class QGLViewer;
35 
36 namespace qglviewer {
37  class Camera;
38 
134  class QGLVIEWER_EXPORT MouseGrabber
135  {
136 #ifndef DOXYGEN
137  friend class ::QGLViewer;
138 #endif
139 
140  public:
141  MouseGrabber();
143 #if QT_VERSION >= 0x040000
144  virtual ~MouseGrabber() { MouseGrabber::MouseGrabberPool_.removeAll(this); };
145 #else
146  virtual ~MouseGrabber() { MouseGrabber::MouseGrabberPool_.removeRef(this); };
147 #endif
148 
151  public:
182  virtual void checkIfGrabsMouse(int x, int y, const Camera* const camera) = 0;
183 
187  bool grabsMouse() const { return grabsMouse_; };
188 
189  protected:
191  void setGrabsMouse(bool grabs) { grabsMouse_ = grabs; };
193 
194 
197  public:
207 #if QT_VERSION >= 0x040000
208  static const QList<MouseGrabber*>& MouseGrabberPool() { return MouseGrabber::MouseGrabberPool_; };
209 #else
210 # if QT_VERSION >= 0x030000
211  static const QPtrList<MouseGrabber>& MouseGrabberPool() { return MouseGrabber::MouseGrabberPool_; };
212 # else
213  static const QList<MouseGrabber>& MouseGrabberPool() { return MouseGrabber::MouseGrabberPool_; };
214 # endif
215 #endif
216 
222 #if QT_VERSION >= 0x040000
223  bool isInMouseGrabberPool() const { return MouseGrabber::MouseGrabberPool_.contains(const_cast<MouseGrabber*>(this)); };
224 #else
225  bool isInMouseGrabberPool() const { return MouseGrabber::MouseGrabberPool_.findRef(this) != -1; };
226 #endif
227  void addInMouseGrabberPool();
228  void removeFromMouseGrabberPool();
229  void clearMouseGrabberPool(bool autoDelete=false);
231 
232 
235  protected:
251  virtual void mousePressEvent(QMouseEvent* const event, Camera* const camera) { Q_UNUSED(event) Q_UNUSED(camera) };
255  virtual void mouseDoubleClickEvent(QMouseEvent* const event, Camera* const camera) { Q_UNUSED(event) Q_UNUSED(camera) };
257  virtual void mouseReleaseEvent(QMouseEvent* const event, Camera* const camera) { Q_UNUSED(event) Q_UNUSED(camera) };
263  virtual void mouseMoveEvent(QMouseEvent* const event, Camera* const camera) { Q_UNUSED(event) Q_UNUSED(camera) };
267  virtual void wheelEvent(QWheelEvent* const event, Camera* const camera) { Q_UNUSED(event) Q_UNUSED(camera) };
269 
270  private:
271  // Copy constructor and opertor= are declared private and undefined
272  // Prevents everyone from trying to use them
273  MouseGrabber(const MouseGrabber&);
274  MouseGrabber& operator=(const MouseGrabber&);
275 
276  bool grabsMouse_;
277 
278  // Q G L V i e w e r p o o l
279 #if QT_VERSION >= 0x040000
280  static QList<MouseGrabber*> MouseGrabberPool_;
281 #else
282  static QPtrList<MouseGrabber> MouseGrabberPool_;
283 #endif
284  };
285 
286 } // namespace qglviewer
287 
288 #endif // QGLVIEWER_MOUSE_GRABBER_H