diff --git a/apps/opencs/view/render/scenewidget.cpp b/apps/opencs/view/render/scenewidget.cpp index 2cc9c93b5..ffe867ae5 100644 --- a/apps/opencs/view/render/scenewidget.cpp +++ b/apps/opencs/view/render/scenewidget.cpp @@ -17,7 +17,7 @@ namespace CSVRender , mCamera(NULL) , mSceneMgr(NULL), mNavigationMode (NavigationMode_Free), mUpdate (false) , mKeyForward (false), mKeyBackward (false), mKeyLeft (false), mKeyRight (false) - , mFast (false) + , mFast (false), mDragging (false) { setAttribute(Qt::WA_PaintOnScreen); setAttribute(Qt::WA_NoSystemBackground); @@ -175,6 +175,52 @@ namespace CSVRender } } + void SceneWidget::leaveEvent (QEvent *event) + { + mDragging = false; + } + + void SceneWidget::mouseMoveEvent (QMouseEvent *event) + { + int factor = mFast ? 4 : 1; /// \todo make this configurable + + if (event->buttons() & Qt::LeftButton) + { + if (mDragging) + { + QPoint diff = mOldPos-event->pos(); + mOldPos = event->pos(); + + if (diff.x()) + { + Ogre::Vector3 direction = mCamera->getDerivedRight(); + /// \todo make mouse sensitivity configurable (the factor 2) + mCamera->move ((factor * direction * diff.x())/2); + mUpdate = true; + } + + if (diff.y()) + { + Ogre::Vector3 direction = mCamera->getDerivedUp(); + /// \todo make mouse sensitivity configurable (the factor 2) + mCamera->move ((factor * -direction * diff.y())/2); + mUpdate = true; + } + } + else + { + mDragging = true; + mOldPos = event->pos(); + } + } + } + + void SceneWidget::mouseReleaseEvent (QMouseEvent *event) + { + if (event->buttons() & Qt::LeftButton) + mDragging = false; + } + void SceneWidget::focusOutEvent (QFocusEvent *event) { mKeyForward = false; diff --git a/apps/opencs/view/render/scenewidget.hpp b/apps/opencs/view/render/scenewidget.hpp index 6b6a8486d..1b78346f7 100644 --- a/apps/opencs/view/render/scenewidget.hpp +++ b/apps/opencs/view/render/scenewidget.hpp @@ -41,6 +41,12 @@ namespace CSVRender void wheelEvent (QWheelEvent *event); + void leaveEvent (QEvent *event); + + void mouseMoveEvent (QMouseEvent *event); + + void mouseReleaseEvent (QMouseEvent *event); + void updateOgreWindow(); Ogre::Camera* mCamera; @@ -54,6 +60,8 @@ namespace CSVRender int mKeyLeft; int mKeyRight; bool mFast; + bool mDragging; + QPoint mOldPos; private slots: