diff --git a/src/interface/modeler/quickapp/MainModelerWindow.h b/src/interface/modeler/quickapp/MainModelerWindow.h index 841d230..da676d9 100644 --- a/src/interface/modeler/quickapp/MainModelerWindow.h +++ b/src/interface/modeler/quickapp/MainModelerWindow.h @@ -19,6 +19,7 @@ public: inline Scenery *getScenery() const {return scenery;} inline OpenGLRenderer *getRenderer() const {return renderer;} + inline ModelerCameras *getCamera() const {return cameras;} protected: virtual void keyReleaseEvent(QKeyEvent *event) override; diff --git a/src/interface/modeler/quickapp/ModelerCameras.cpp b/src/interface/modeler/quickapp/ModelerCameras.cpp index 90ecc47..8e4104f 100644 --- a/src/interface/modeler/quickapp/ModelerCameras.cpp +++ b/src/interface/modeler/quickapp/ModelerCameras.cpp @@ -32,11 +32,22 @@ ModelerCameras::~ModelerCameras() delete topdown; } +void ModelerCameras::processZoom(double value) +{ + active->strafeForward(value); +} + +void ModelerCameras::processScroll(double xvalue, double yvalue) +{ + active->strafeRight(xvalue); + active->strafeUp(yvalue); +} + void ModelerCameras::timerEvent(QTimerEvent *) { OpenGLRenderer *renderer = parent->getRenderer(); - current->transitionToAnother(active, 0.1); + current->transitionToAnother(active, 0.3); renderer->setCamera(current); } diff --git a/src/interface/modeler/quickapp/ModelerCameras.h b/src/interface/modeler/quickapp/ModelerCameras.h index dffaf81..5621203 100644 --- a/src/interface/modeler/quickapp/ModelerCameras.h +++ b/src/interface/modeler/quickapp/ModelerCameras.h @@ -19,6 +19,16 @@ public: ModelerCameras(MainModelerWindow *parent); ~ModelerCameras(); + /** + * Process a zoom request. + */ + void processZoom(double value); + + /** + * Process a scroll request. + */ + void processScroll(double xvalue, double yvalue); + protected: void timerEvent(QTimerEvent *event); diff --git a/src/interface/modeler/quickapp/OpenGLView.cpp b/src/interface/modeler/quickapp/OpenGLView.cpp index 6d8c960..ad3a12b 100644 --- a/src/interface/modeler/quickapp/OpenGLView.cpp +++ b/src/interface/modeler/quickapp/OpenGLView.cpp @@ -3,9 +3,8 @@ #include #include #include "MainModelerWindow.h" -#include "CameraDefinition.h" #include "OpenGLRenderer.h" -#include "Scenery.h" +#include "ModelerCameras.h" OpenGLView::OpenGLView(QQuickItem *parent) : QQuickItem(parent) @@ -15,8 +14,8 @@ OpenGLView::OpenGLView(QQuickItem *parent) : renderer = NULL; setAcceptedMouseButtons(Qt::AllButtons); - setAcceptHoverEvents(true); - setKeepMouseGrab(true); + + mouse_button = Qt::NoButton; connect(this, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(handleWindowChanged(QQuickWindow*))); startTimer(50); @@ -42,7 +41,7 @@ void OpenGLView::handleWindowChanged(QQuickWindow *win) void OpenGLView::paint() { - if (not initialized) + if (not initialized or not renderer) { renderer->initialize(); initialized = true; @@ -58,29 +57,30 @@ void OpenGLView::paint() } } -void OpenGLView::hoverMoveEvent(QHoverEvent *event) +void OpenGLView::wheelEvent(QWheelEvent *event) { - if (!renderer) + window->getCamera()->processZoom(0.1 * (double)event->angleDelta().y()); +} + +void OpenGLView::mousePressEvent(QMouseEvent *event) +{ + mouse_button = event->button(); + mouse_pos = event->windowPos(); +} + +void OpenGLView::mouseReleaseEvent(QMouseEvent *) +{ + mouse_button = Qt::NoButton; +} + +void OpenGLView::mouseMoveEvent(QMouseEvent *event) +{ + QPointF diff = event->windowPos() - mouse_pos; + if (mouse_button == Qt::MidButton) { - return; + window->getCamera()->processScroll(-0.1 * diff.x(), 0.1 * diff.y()); } - - /*CameraDefinition camera; - renderer->getScenery()->getCamera(&camera); - - QPointF diff = event->posF() - event->oldPosF(); - camera.strafeRight(diff.x() * 0.1); - camera.strafeUp(diff.y() * 0.1); - camera.validate(); - - camera.copy(renderer->render_camera); - renderer->getScenery()->setCamera(&camera); - renderer->getScenery()->getCamera(&camera); - renderer->cameraChangeEvent(&camera); - if (window) - { - window->update(); - }*/ + mouse_pos = event->windowPos(); } void OpenGLView::timerEvent(QTimerEvent *) diff --git a/src/interface/modeler/quickapp/OpenGLView.h b/src/interface/modeler/quickapp/OpenGLView.h index e59c379..31fcc5c 100644 --- a/src/interface/modeler/quickapp/OpenGLView.h +++ b/src/interface/modeler/quickapp/OpenGLView.h @@ -19,13 +19,19 @@ public slots: void paint(); protected: - virtual void hoverMoveEvent(QHoverEvent *event) override; + virtual void wheelEvent(QWheelEvent *event) override; + virtual void mousePressEvent(QMouseEvent *event) override; + virtual void mouseReleaseEvent(QMouseEvent *event) override; + virtual void mouseMoveEvent(QMouseEvent *event) override; virtual void timerEvent(QTimerEvent *event) override; private: bool initialized; MainModelerWindow *window; OpenGLRenderer *renderer; + + Qt::MouseButton mouse_button; + QPointF mouse_pos; }; }