Mercurial > hg > orthanc-stone
changeset 879:12b591d5d63c am-dev
some Qt integration (wip)
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Fri, 05 Jul 2019 14:52:43 +0200 |
parents | 8f7930f589ef |
children | 9953f16c304d |
files | Applications/Generic/GuiAdapter.cpp Applications/Generic/GuiAdapter.h Samples/Qt/BasicScene.cpp Samples/Qt/BasicSceneWindow.ui Samples/Qt/CMakeLists.txt Samples/Qt/QStoneOpenGlWidget.cpp Samples/Qt/QStoneOpenGlWidget.h Samples/Qt/Scene2DInteractor.cpp Samples/Qt/Scene2DInteractor.h |
diffstat | 9 files changed, 208 insertions(+), 68 deletions(-) [+] |
line wrap: on
line diff
--- a/Applications/Generic/GuiAdapter.cpp Wed Jul 03 10:26:51 2019 +0200 +++ b/Applications/Generic/GuiAdapter.cpp Fri Jul 05 14:52:43 2019 +0200 @@ -41,14 +41,14 @@ widgets_.push_back(widget); } - std::ostream& operator<<( - std::ostream& os, const GuiAdapterKeyboardEvent& event) - { - os << "ctrl: " << event.ctrlKey << ", " << - "shift: " << event.shiftKey << ", " << - "alt: " << event.altKey; - return os; - } + std::ostream& operator<<( + std::ostream& os, const GuiAdapterKeyboardEvent& event) + { + os << "ctrl: " << event.ctrlKey << ", " << + "shift: " << event.shiftKey << ", " << + "alt: " << event.altKey; + return os; + } #if ORTHANC_ENABLE_WASM == 1 void GuiAdapter::Run() @@ -434,15 +434,15 @@ switch (source.button.button) { case SDL_BUTTON_MIDDLE: - dest.button = 1; + dest.button = GUIADAPTER_MOUSEBUTTON_MIDDLE; break; case SDL_BUTTON_RIGHT: - dest.button = 2; + dest.button = GUIADAPTER_MOUSEBUTTON_RIGHT; break; case SDL_BUTTON_LEFT: - dest.button = 0; + dest.button = GUIADAPTER_MOUSEBUTTON_LEFT; break; default: @@ -544,14 +544,14 @@ // the SDL window name IS the canvas name ("canvas" is used because this lib // is designed for Wasm - SDL_Window* sdlWindow = SDL_GetWindowFromID(windowID); - ORTHANC_ASSERT(sdlWindow != NULL, "Window ID \"" << windowID << "\" is not a valid SDL window ID!"); + SDL_Window* sdlWindow = SDL_GetWindowFromID(windowID); + ORTHANC_ASSERT(sdlWindow != NULL, "Window ID \"" << windowID << "\" is not a valid SDL window ID!"); const char* windowTitleSz = SDL_GetWindowTitle(sdlWindow); - ORTHANC_ASSERT(windowTitleSz != NULL, "Window ID \"" << windowID << "\" has a NULL window title!"); + ORTHANC_ASSERT(windowTitleSz != NULL, "Window ID \"" << windowID << "\" has a NULL window title!"); std::string windowTitle(windowTitleSz); - ORTHANC_ASSERT(windowTitle != "", "Window ID \"" << windowID << "\" has an empty window title!"); + ORTHANC_ASSERT(windowTitle != "", "Window ID \"" << windowID << "\" has an empty window title!"); switch (event.mouse.type) { @@ -573,14 +573,14 @@ { // the SDL window name IS the canvas name ("canvas" is used because this lib // is designed for Wasm - SDL_Window* sdlWindow = SDL_GetWindowFromID(windowID); - ORTHANC_ASSERT(sdlWindow != NULL, "Window ID \"" << windowID << "\" is not a valid SDL window ID!"); + SDL_Window* sdlWindow = SDL_GetWindowFromID(windowID); + ORTHANC_ASSERT(sdlWindow != NULL, "Window ID \"" << windowID << "\" is not a valid SDL window ID!"); const char* windowTitleSz = SDL_GetWindowTitle(sdlWindow); - ORTHANC_ASSERT(windowTitleSz != NULL, "Window ID \"" << windowID << "\" has a NULL window title!"); + ORTHANC_ASSERT(windowTitleSz != NULL, "Window ID \"" << windowID << "\" has a NULL window title!"); std::string windowTitle(windowTitleSz); - ORTHANC_ASSERT(windowTitle != "", "Window ID \"" << windowID << "\" has an empty window title!"); + ORTHANC_ASSERT(windowTitle != "", "Window ID \"" << windowID << "\" has an empty window title!"); switch (event.type) { @@ -715,8 +715,8 @@ } #endif } - else if (event.type == SDL_MOUSEWHEEL) - { + else if (event.type == SDL_MOUSEWHEEL) + { int scancodeCount = 0; const uint8_t* keyboardState = SDL_GetKeyboardState(&scancodeCount); @@ -737,21 +737,21 @@ GuiAdapterWheelEvent dest; ConvertFromPlatform(dest, ctrlPressed, shiftPressed, altPressed, event); - OnMouseWheelEvent(event.window.windowID, dest); - - //KeyboardModifiers modifiers = GetKeyboardModifiers(keyboardState, scancodeCount); - - //int x, y; - //SDL_GetMouseState(&x, &y); - - //if (event.wheel.y > 0) - //{ - // locker.GetCentralViewport().MouseWheel(MouseWheelDirection_Up, x, y, modifiers); - //} - //else if (event.wheel.y < 0) - //{ - // locker.GetCentralViewport().MouseWheel(MouseWheelDirection_Down, x, y, modifiers); - //} + OnMouseWheelEvent(event.window.windowID, dest); + + //KeyboardModifiers modifiers = GetKeyboardModifiers(keyboardState, scancodeCount); + + //int x, y; + //SDL_GetMouseState(&x, &y); + + //if (event.wheel.y > 0) + //{ + // locker.GetCentralViewport().MouseWheel(MouseWheelDirection_Up, x, y, modifiers); + //} + //else if (event.wheel.y < 0) + //{ + // locker.GetCentralViewport().MouseWheel(MouseWheelDirection_Down, x, y, modifiers); + //} } else if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
--- a/Applications/Generic/GuiAdapter.h Wed Jul 03 10:26:51 2019 +0200 +++ b/Applications/Generic/GuiAdapter.h Fri Jul 05 14:52:43 2019 +0200 @@ -67,6 +67,14 @@ }; + enum GuiAdapterMouseButtonType + { + GUIADAPTER_MOUSEBUTTON_LEFT = 0, + GUIADAPTER_MOUSEBUTTON_MIDDLE = 1, + GUIADAPTER_MOUSEBUTTON_RIGHT = 2 + }; + + enum GuiAdapterMouseEventType { GUIADAPTER_EVENT_MOUSEDOWN = 1973, @@ -137,6 +145,14 @@ //long canvasX; //long canvasY; //long padding; + + public: + GuiAdapterMouseEvent() + : ctrlKey(false), + shiftKey(false), + altKey(false) + { + } }; struct GuiAdapterWheelEvent { @@ -157,7 +173,7 @@ bool altKey; }; - std::ostream& operator<<(std::ostream& os, const GuiAdapterKeyboardEvent& event); + std::ostream& operator<<(std::ostream& os, const GuiAdapterKeyboardEvent& event); /* Mousedown event trigger when either the left or right (or middle) mouse is pressed
--- a/Samples/Qt/BasicScene.cpp Wed Jul 03 10:26:51 2019 +0200 +++ b/Samples/Qt/BasicScene.cpp Fri Jul 05 14:52:43 2019 +0200 @@ -366,6 +366,8 @@ #include <QApplication> #include "BasicSceneWindow.h" +#include "Scene2DInteractor.h" + int main(int argc, char* argv[]) { { @@ -383,12 +385,14 @@ undoStack, boost::ref(broker)); PrepareScene(controller); + boost::shared_ptr<OrthancStone::Scene2DInteractor> interactor(new BasicScene2DInteractor(controller)); + window.GetOpenGlWidget().SetInteractor(interactor); + QOpenGLContext * context = new QOpenGLContext; context->setFormat( requestedFormat ); context->create(); context->makeCurrent(window.GetOpenGlWidget().context()->surface()); - boost::shared_ptr<OpenGLCompositor> compositor = boost::make_shared<OpenGLCompositor>(window.GetOpenGlWidget(), *controller->GetScene()); compositor->SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT, FONT_SIZE, Orthanc::Encoding_Latin1);
--- a/Samples/Qt/BasicSceneWindow.ui Wed Jul 03 10:26:51 2019 +0200 +++ b/Samples/Qt/BasicSceneWindow.ui Fri Jul 05 14:52:43 2019 +0200 @@ -28,7 +28,7 @@ <property name="layoutDirection"> <enum>Qt::LeftToRight</enum> </property> - <widget class="QWidget" name="centralwidget"> + <widget class="QWidget" name="mainWidget"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <horstretch>0</horstretch> @@ -43,7 +43,7 @@ <enum>QLayout::SetDefaultConstraint</enum> </property> <item> - <widget class="QStoneOpenGlWidget" name="centralWidget"> + <widget class="OrthancStone::QStoneOpenGlWidget" name="centralWidget" native="true"> <property name="minimumSize"> <size> <width>0</width> @@ -75,7 +75,7 @@ <customwidgets> <customwidget> <class>QStoneOpenGlWidget</class> - <extends>QStoneOpenGlWidget</extends> + <extends>QWidget</extends> <header location="global">QStoneOpenGlWidget.h</header> </customwidget> </customwidgets>
--- a/Samples/Qt/CMakeLists.txt Wed Jul 03 10:26:51 2019 +0200 +++ b/Samples/Qt/CMakeLists.txt Fri Jul 05 14:52:43 2019 +0200 @@ -74,9 +74,10 @@ add_executable(BasicScene BasicScene.cpp QStoneOpenGlWidget.cpp + Scene2DInteractor.cpp ${BASIC_SCENE_APPLICATIONS_SOURCES} ) -target_include_directories(BasicScene PUBLIC ${CMAKE_SOURCE_DIR}) +target_include_directories(BasicScene PUBLIC ${CMAKE_SOURCE_DIR} ${STONE_SOURCES_DIR}) target_link_libraries(BasicScene OrthancStone)
--- a/Samples/Qt/QStoneOpenGlWidget.cpp Wed Jul 03 10:26:51 2019 +0200 +++ b/Samples/Qt/QStoneOpenGlWidget.cpp Fri Jul 05 14:52:43 2019 +0200 @@ -1,6 +1,10 @@ #include "../../Framework/OpenGL/OpenGLIncludes.h" #include "QStoneOpenGlWidget.h" +#include <QMouseEvent> + +using namespace OrthancStone; + void QStoneOpenGlWidget::initializeGL() { glewInit(); @@ -25,3 +29,53 @@ doneCurrent(); } +void ConvertFromPlatform( + OrthancStone::GuiAdapterMouseEvent& dest, + const QMouseEvent& qtEvent) +{ + dest.targetX = qtEvent.x(); + dest.targetY = qtEvent.y(); + + 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; + default: + dest.button = OrthancStone::GUIADAPTER_MOUSEBUTTON_LEFT; + } + + if (qtEvent.modifiers().testFlag(Qt::ShiftModifier)) + { + dest.shiftKey = true; + } + if (qtEvent.modifiers().testFlag(Qt::ControlModifier)) + { + dest.ctrlKey = true; + } + if (qtEvent.modifiers().testFlag(Qt::AltModifier)) + { + dest.altKey = true; + } + +} + + + +void QStoneOpenGlWidget::mousePressEvent(QMouseEvent* qtEvent) +{ + OrthancStone::GuiAdapterMouseEvent event; + ConvertFromPlatform(event, *qtEvent); + + if (sceneInteractor_.get() != NULL) + { + sceneInteractor_->OnMouseEvent(event); + } + + + // convert +//TODO event-> + +// sceneInteractor_->OnMouseEvent(event); +} +
--- a/Samples/Qt/QStoneOpenGlWidget.h Wed Jul 03 10:26:51 2019 +0200 +++ b/Samples/Qt/QStoneOpenGlWidget.h Fri Jul 05 14:52:43 2019 +0200 @@ -6,40 +6,55 @@ #include <boost/shared_ptr.hpp> #include "../../Framework/OpenGL/IOpenGLContext.h" #include "../../Framework/Scene2D/OpenGLCompositor.h" - +#include "Scene2DInteractor.h" -class QStoneOpenGlWidget : public QOpenGLWidget, public OrthancStone::OpenGL::IOpenGLContext +namespace OrthancStone { - boost::shared_ptr<OrthancStone::OpenGLCompositor> compositor_; - -public: - QStoneOpenGlWidget(QWidget *parent) : QOpenGLWidget(parent) { } + class QStoneOpenGlWidget : public QOpenGLWidget, public OrthancStone::OpenGL::IOpenGLContext + { + boost::shared_ptr<OrthancStone::OpenGLCompositor> compositor_; + boost::shared_ptr<Scene2DInteractor> sceneInteractor_; -protected: - void initializeGL() override; + public: + QStoneOpenGlWidget(QWidget *parent) : + QOpenGLWidget(parent) + { + } + + protected: - void resizeGL(int w, int h) override; + //**** QWidget overrides + void initializeGL() override; + void resizeGL(int w, int h) override; + void paintGL() override; - void paintGL() override; + void mousePressEvent(QMouseEvent* event) override; - virtual void MakeCurrent() override; + //**** IOpenGLContext overrides - virtual void SwapBuffer() override {} + virtual void MakeCurrent() override; + virtual void SwapBuffer() override {} - virtual unsigned int GetCanvasWidth() const override - { - return this->width(); - } + virtual unsigned int GetCanvasWidth() const override + { + return this->width(); + } + + virtual unsigned int GetCanvasHeight() const override + { + return this->height(); + } - virtual unsigned int GetCanvasHeight() const override - { - return this->height(); - } + public: + void SetInteractor(boost::shared_ptr<Scene2DInteractor> sceneInteractor) + { + sceneInteractor_ = sceneInteractor; + } -public: - void SetCompositor(boost::shared_ptr<OrthancStone::OpenGLCompositor> compositor) - { - compositor_ = compositor; - } + void SetCompositor(boost::shared_ptr<OrthancStone::OpenGLCompositor> compositor) + { + compositor_ = compositor; + } -}; + }; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Samples/Qt/Scene2DInteractor.cpp Fri Jul 05 14:52:43 2019 +0200 @@ -0,0 +1,17 @@ +#include "Scene2DInteractor.h" + + +namespace OrthancStone +{ + +} + +using namespace OrthancStone; + + +void BasicScene2DInteractor::OnMouseEvent(const GuiAdapterMouseEvent& event) +{ + +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Samples/Qt/Scene2DInteractor.h Fri Jul 05 14:52:43 2019 +0200 @@ -0,0 +1,33 @@ +#pragma once + +#include "../../Framework/Scene2DViewport/ViewportController.h" +#include "../../Applications/Generic/GuiAdapter.h" + + +namespace OrthancStone +{ + + class Scene2DInteractor + { + protected: + boost::shared_ptr<ViewportController> viewportController_; + + public: + Scene2DInteractor(boost::shared_ptr<ViewportController> viewportController) : + viewportController_(viewportController) + {} + + virtual void OnMouseEvent(const GuiAdapterMouseEvent& event) = 0; + }; +} + +class BasicScene2DInteractor : public OrthancStone::Scene2DInteractor +{ +public: + BasicScene2DInteractor(boost::shared_ptr<OrthancStone::ViewportController> viewportController) : + Scene2DInteractor(viewportController) + {} + + virtual void OnMouseEvent(const OrthancStone::GuiAdapterMouseEvent& event) override; +}; +