Skip to content
Snippets Groups Projects
Commit 6214141e authored by Marco Biasini's avatar Marco Biasini
Browse files

added support for scene rotation by pinching

parent f7d0f0d8
No related branches found
No related tags found
No related merge requests found
...@@ -39,6 +39,10 @@ ...@@ -39,6 +39,10 @@
#include <QApplication> #include <QApplication>
#include <QClipboard> #include <QClipboard>
#include <QMenu> #include <QMenu>
#if QT_VERSION >= 0x040600
# include <QGesture>
#endif
#include "tools/tool_manager.hh" #include "tools/tool_manager.hh"
namespace ost { namespace gui { namespace ost { namespace gui {
...@@ -54,7 +58,8 @@ GLCanvas::GLCanvas(GLWin* gl_win, QWidget* parent, const QGLFormat& f): ...@@ -54,7 +58,8 @@ GLCanvas::GLCanvas(GLWin* gl_win, QWidget* parent, const QGLFormat& f):
bench_flag_(false), bench_flag_(false),
last_pos_(), last_pos_(),
scene_menu_(NULL), scene_menu_(NULL),
show_beacon_(false) show_beacon_(false),
angular_speed_(0.0)
{ {
if(!isValid()) return; if(!isValid()) return;
master_timer_.start(10,this); master_timer_.start(10,this);
...@@ -64,8 +69,52 @@ GLCanvas::GLCanvas(GLWin* gl_win, QWidget* parent, const QGLFormat& f): ...@@ -64,8 +69,52 @@ GLCanvas::GLCanvas(GLWin* gl_win, QWidget* parent, const QGLFormat& f):
this->setContextMenuPolicy(Qt::CustomContextMenu); this->setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this,
SLOT(RequestContextMenu(const QPoint&))); SLOT(RequestContextMenu(const QPoint&)));
#if QT_VERSION >= 0x040600
this->grabGesture(Qt::PinchGesture);
#endif
}
bool GLCanvas::event(QEvent* event)
{
#if QT_VERSION >= 0x040600
if (event->type()==QEvent::Gesture) {
return this->GestureEvent(static_cast<QGestureEvent*>(event));
}
#endif
return QGLWidget::event(event);
} }
#if QT_VERSION >= 0x040600
bool GLCanvas::GestureEvent(QGestureEvent* event)
{
if (QGesture* pinch=event->gesture(Qt::PinchGesture)) {
QPinchGesture* pinch_gesture=static_cast<QPinchGesture*>(pinch);
QPinchGesture::ChangeFlags changeFlags = pinch_gesture->changeFlags();
if (changeFlags & QPinchGesture::RotationAngleChanged) {
qreal value=pinch_gesture->rotationAngle();
qreal lastValue=pinch_gesture->lastRotationAngle();
this->OnTransform(gfx::INPUT_COMMAND_ROTZ, 0, gfx::TRANSFORM_VIEW,
static_cast<Real>(value - lastValue));
this->update();
event->accept();
if (pinch_gesture->state()==Qt::GestureFinished) {
angular_speed_=value-lastValue;
if (!gesture_timer_.isActive())
gesture_timer_.start(10, this);
}
return true;
}
}
return false;
}
#endif
void GLCanvas::MakeActive() void GLCanvas::MakeActive()
{ {
makeCurrent(); makeCurrent();
...@@ -425,6 +474,22 @@ Real delta_time(const timeval& t1, const timeval& t2) ...@@ -425,6 +474,22 @@ Real delta_time(const timeval& t1, const timeval& t2)
void GLCanvas::timerEvent(QTimerEvent * event) void GLCanvas::timerEvent(QTimerEvent * event)
{ {
#if QT_VERSION>= 0x040600
// gesture support
if (gesture_timer_.timerId()==event->timerId()) {
if (angular_speed_!=0.0) {
angular_speed_*=0.95;
this->OnTransform(gfx::INPUT_COMMAND_ROTZ, 0, gfx::TRANSFORM_VIEW,
static_cast<Real>(angular_speed_));
if (std::abs(angular_speed_)<0.001) {
angular_speed_=0.0;
gesture_timer_.stop();
}
this->update();
}
return;
}
#endif
#ifndef _MSC_VER #ifndef _MSC_VER
static struct timeval time0,time1; static struct timeval time0,time1;
static int count=0; static int count=0;
......
...@@ -83,11 +83,14 @@ protected: ...@@ -83,11 +83,14 @@ protected:
virtual void keyReleaseEvent(QKeyEvent* event); virtual void keyReleaseEvent(QKeyEvent* event);
virtual void timerEvent(QTimerEvent * event); virtual void timerEvent(QTimerEvent * event);
virtual void wheelEvent(QWheelEvent* event); virtual void wheelEvent(QWheelEvent* event);
virtual bool event(QEvent* event);
private slots: private slots:
virtual void RequestContextMenu(const QPoint& pos); virtual void RequestContextMenu(const QPoint& pos);
private: private:
#if QT_VERSION >= 0x040600
bool GestureEvent(QGestureEvent* event);
#endif
bool IsToolEvent(QInputEvent* event) const; bool IsToolEvent(QInputEvent* event) const;
MouseEvent::Buttons TranslateButtons(Qt::MouseButtons buttons) const; MouseEvent::Buttons TranslateButtons(Qt::MouseButtons buttons) const;
void HandleMousePressEvent(QMouseEvent* event); void HandleMousePressEvent(QMouseEvent* event);
...@@ -103,6 +106,10 @@ private: ...@@ -103,6 +106,10 @@ private:
QPoint last_pos_; QPoint last_pos_;
SceneMenu* scene_menu_; SceneMenu* scene_menu_;
bool show_beacon_; bool show_beacon_;
float angular_speed_;
#if QT_VERSION>=0x04600
QBasicTimer gesture_timer_;
#endif
}; };
}} // ns }} // ns
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment