manipulatedFrame.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_MANIPULATED_FRAME_H
24 #define QGLVIEWER_MANIPULATED_FRAME_H
25 
26 #include "frame.h"
27 #include "mouseGrabber.h"
28 
29 #if QT_VERSION >= 0x040000
30 # include <QString>
31 # include <QTimer>
32 # include <QDateTime>
33 #else
34 # include <qstring.h>
35 # include <qtimer.h>
36 # include <qdatetime.h>
37 #endif
38 
39 namespace qglviewer {
100  class QGLVIEWER_EXPORT ManipulatedFrame : public Frame, public MouseGrabber
101  {
102 #ifndef DOXYGEN
103  friend class Camera;
104  friend class ::QGLViewer;
105 #endif
106 
107  Q_OBJECT
108 
109  public:
112  virtual ~ManipulatedFrame() {};
113 
115  ManipulatedFrame& operator=(const ManipulatedFrame& mf);
116 
117  Q_SIGNALS:
129  void manipulated();
130 
141  void spun();
142 
145  public Q_SLOTS:
147  void setRotationSensitivity(float sensitivity) { rotSensitivity_ = sensitivity; };
149  void setTranslationSensitivity(float sensitivity) { transSensitivity_ = sensitivity; };
151  void setSpinningSensitivity(float sensitivity) { spinningSensitivity_ = sensitivity; };
153  void setWheelSensitivity(float sensitivity) { wheelSensitivity_ = sensitivity; };
154  public:
163  float rotationSensitivity() const { return rotSensitivity_; };
182  float translationSensitivity() const { return transSensitivity_; };
194  float spinningSensitivity() const { return spinningSensitivity_; };
202  float wheelSensitivity() const { return wheelSensitivity_; };
204 
205 
208  public:
215  bool isSpinning() const { return isSpinning_; };
224  Quaternion spinningQuaternion() const { return spinningQuaternion_; }
225  public Q_SLOTS:
228  void setSpinningQuaternion(const Quaternion& spinningQuaternion) { spinningQuaternion_ = spinningQuaternion; }
229  virtual void startSpinning(int updateInterval);
232  virtual void stopSpinning() { spinningTimer_.stop(); isSpinning_ = false; };
233  protected Q_SLOTS:
234  virtual void spin();
235  private Q_SLOTS:
236  void spinUpdate();
238 
241  protected:
242  virtual void mousePressEvent (QMouseEvent* const event, Camera* const camera);
243  virtual void mouseMoveEvent (QMouseEvent* const event, Camera* const camera);
244  virtual void mouseReleaseEvent (QMouseEvent* const event, Camera* const camera);
245  virtual void mouseDoubleClickEvent(QMouseEvent* const event, Camera* const camera);
246  virtual void wheelEvent (QWheelEvent* const event, Camera* const camera);
248 
249  public:
252  bool isManipulated() const;
254 
257  public:
258  virtual void checkIfGrabsMouse(int x, int y, const Camera* const camera);
260 
263  public:
264  virtual QDomElement domElement(const QString& name, QDomDocument& document) const;
265  public Q_SLOTS:
266  virtual void initFromDOMElement(const QDomElement& element);
268 
269 #ifndef DOXYGEN
270  protected:
271  Quaternion deformedBallQuaternion(int x, int y, float cx, float cy, const Camera* const camera);
272 
273  int action_; // Should be a QGLViewer::MouseAction, but include loop
274  Constraint* previousConstraint_; // When manipulation is without Contraint.
275 
276  virtual void startAction(int ma, bool withConstraint=true); // int is really a QGLViewer::MouseAction
277  void computeMouseSpeed(const QMouseEvent* const e);
278  int mouseOriginalDirection(const QMouseEvent* const e);
279 
280  // Previous mouse position (used for incremental updates) and mouse press position.
281  QPoint prevPos_, pressPos_;
282 #endif // DOXYGEN
283 
284  private:
285  // Sensitivity
286  float rotSensitivity_;
287  float transSensitivity_;
288  float spinningSensitivity_;
289  float wheelSensitivity_;
290 
291  // Mouse speed and spinning
292  QTime last_move_time;
293  float mouseSpeed_;
294  int delay_;
295  bool isSpinning_;
296  QTimer spinningTimer_;
297  Quaternion spinningQuaternion_;
298 
299  // Whether the SCREEN_TRANS direction (horizontal or vertical) is fixed or not.
300  bool dirIsFixed_;
301 
302  // MouseGrabber
303  bool keepsGrabbingMouse_;
304  };
305 
306 } // namespace qglviewer
307 
308 #endif // QGLVIEWER_MANIPULATED_FRAME_H