Mercurial > hg > orthanc-stone
changeset 881:a8cd3755db21 am-dev
wip
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Tue, 09 Jul 2019 11:41:16 +0200 |
parents | 9953f16c304d |
children | 31319fe867b9 |
files | Samples/Qt/QStoneOpenGlWidget.cpp Samples/Qt/QStoneOpenGlWidget.h Samples/Qt/Scene2DInteractor.cpp Samples/Qt/Scene2DInteractor.h |
diffstat | 4 files changed, 71 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/Samples/Qt/QStoneOpenGlWidget.cpp Fri Jul 05 15:33:02 2019 +0200 +++ b/Samples/Qt/QStoneOpenGlWidget.cpp Tue Jul 09 11:41:16 2019 +0200 @@ -30,52 +30,66 @@ } void ConvertFromPlatform( - OrthancStone::GuiAdapterMouseEvent& dest, - const QMouseEvent& qtEvent) + OrthancStone::GuiAdapterMouseEvent& guiEvent, + PointerEvent& pointerEvent, + const QMouseEvent& qtEvent, + const OrthancStone::OpenGLCompositor& compositor) { - dest.targetX = qtEvent.x(); - dest.targetY = qtEvent.y(); + guiEvent.targetX = qtEvent.x(); + guiEvent.targetY = qtEvent.y(); + pointerEvent.AddPosition(compositor.GetPixelCenterCoordinates(guiEvent.targetX, guiEvent.targetY)); switch (qtEvent.button()) { - case Qt::LeftButton: dest.button = OrthancStone::GUIADAPTER_MOUSEBUTTON_LEFT; break; - case Qt::MiddleButton: dest.button = OrthancStone::GUIADAPTER_MOUSEBUTTON_MIDDLE; break; - case Qt::RightButton: dest.button = OrthancStone::GUIADAPTER_MOUSEBUTTON_RIGHT; break; + case Qt::LeftButton: guiEvent.button = OrthancStone::GUIADAPTER_MOUSEBUTTON_LEFT; break; + case Qt::MiddleButton: guiEvent.button = OrthancStone::GUIADAPTER_MOUSEBUTTON_MIDDLE; break; + case Qt::RightButton: guiEvent.button = OrthancStone::GUIADAPTER_MOUSEBUTTON_RIGHT; break; default: - dest.button = OrthancStone::GUIADAPTER_MOUSEBUTTON_LEFT; + guiEvent.button = OrthancStone::GUIADAPTER_MOUSEBUTTON_LEFT; } if (qtEvent.modifiers().testFlag(Qt::ShiftModifier)) { - dest.shiftKey = true; + guiEvent.shiftKey = true; } if (qtEvent.modifiers().testFlag(Qt::ControlModifier)) { - dest.ctrlKey = true; + guiEvent.ctrlKey = true; } if (qtEvent.modifiers().testFlag(Qt::AltModifier)) { - dest.altKey = true; + guiEvent.altKey = true; } } +void QStoneOpenGlWidget::mouseEvent(QMouseEvent* qtEvent, OrthancStone::GuiAdapterHidEventType guiEventType) +{ + OrthancStone::GuiAdapterMouseEvent guiEvent; + PointerEvent pointerEvent; + ConvertFromPlatform(guiEvent, pointerEvent, *qtEvent, *compositor_); + guiEvent.type = guiEventType; + if (sceneInteractor_.get() != NULL && compositor_.get() != NULL) + { + sceneInteractor_->OnMouseEvent(guiEvent, pointerEvent); + } + + // force redraw of the OpenGL widget + update(); +} void QStoneOpenGlWidget::mousePressEvent(QMouseEvent* qtEvent) { - OrthancStone::GuiAdapterMouseEvent event; - ConvertFromPlatform(event, *qtEvent); - - if (sceneInteractor_.get() != NULL) - { - sceneInteractor_->OnMouseEvent(event); - } - - - // convert -//TODO event-> - -// sceneInteractor_->OnMouseEvent(event); + mouseEvent(qtEvent, GUIADAPTER_EVENT_MOUSEDOWN); } +void QStoneOpenGlWidget::mouseMoveEvent(QMouseEvent* qtEvent) +{ + mouseEvent(qtEvent, GUIADAPTER_EVENT_MOUSEDOWN); +} + +void QStoneOpenGlWidget::mouseReleaseEvent(QMouseEvent* qtEvent) +{ + mouseEvent(qtEvent, GUIADAPTER_EVENT_MOUSEUP); +}
--- a/Samples/Qt/QStoneOpenGlWidget.h Fri Jul 05 15:33:02 2019 +0200 +++ b/Samples/Qt/QStoneOpenGlWidget.h Tue Jul 09 11:41:16 2019 +0200 @@ -29,6 +29,8 @@ void paintGL() override; void mousePressEvent(QMouseEvent* event) override; + void mouseMoveEvent(QMouseEvent* event) override; + void mouseReleaseEvent(QMouseEvent* event) override; //**** IOpenGLContext overrides @@ -56,5 +58,8 @@ compositor_ = compositor; } + protected: + void mouseEvent(QMouseEvent* qtEvent, OrthancStone::GuiAdapterHidEventType guiEventType); + }; }
--- a/Samples/Qt/Scene2DInteractor.cpp Fri Jul 05 15:33:02 2019 +0200 +++ b/Samples/Qt/Scene2DInteractor.cpp Tue Jul 09 11:41:16 2019 +0200 @@ -1,5 +1,8 @@ #include "Scene2DInteractor.h" +#include "../../Framework/Scene2D/PanSceneTracker.h" +#include "../../Framework/Scene2D/ZoomSceneTracker.h" + namespace OrthancStone { @@ -9,8 +12,26 @@ using namespace OrthancStone; -void BasicScene2DInteractor::OnMouseEvent(const GuiAdapterMouseEvent& event) +void BasicScene2DInteractor::OnMouseEvent(const GuiAdapterMouseEvent& event, const PointerEvent& pointerEvent) { + if (currentTracker_.get() != NULL) + { + currentTracker_->PointerMove(pointerEvent); + } + else + { + if (event.button == GUIADAPTER_MOUSEBUTTON_LEFT) + { + } + else if (event.button == GUIADAPTER_MOUSEBUTTON_MIDDLE) + { + currentTracker_.reset(new PanSceneTracker(viewportController_, pointerEvent)); + } + else if (event.button == GUIADAPTER_MOUSEBUTTON_RIGHT) + { + // TODO: need a pointer to compositor currentTracker_.reset(new ZoomSceneTracker(viewportController_, pointerEvent, viewportController_->)); + } + } }
--- a/Samples/Qt/Scene2DInteractor.h Fri Jul 05 15:33:02 2019 +0200 +++ b/Samples/Qt/Scene2DInteractor.h Tue Jul 09 11:41:16 2019 +0200 @@ -1,6 +1,8 @@ #pragma once +#include "../../Framework/Scene2D/PointerEvent.h" #include "../../Framework/Scene2DViewport/ViewportController.h" +#include "../../Framework/Scene2DViewport/IFlexiblePointerTracker.h" #include "../../Applications/Generic/GuiAdapter.h" @@ -11,13 +13,15 @@ { protected: boost::shared_ptr<ViewportController> viewportController_; + boost::shared_ptr<IFlexiblePointerTracker> currentTracker_; public: Scene2DInteractor(boost::shared_ptr<ViewportController> viewportController) : viewportController_(viewportController) {} - virtual void OnMouseEvent(const GuiAdapterMouseEvent& event) = 0; + virtual void OnMouseEvent(const GuiAdapterMouseEvent& guiEvent, const PointerEvent& pointerEvent) = 0; + }; } @@ -28,6 +32,6 @@ Scene2DInteractor(viewportController) {} - virtual void OnMouseEvent(const OrthancStone::GuiAdapterMouseEvent& event) override; + virtual void OnMouseEvent(const OrthancStone::GuiAdapterMouseEvent& event, const OrthancStone::PointerEvent& pointerEvent) override; };