# HG changeset patch # User Alain Mazy # Date 1562331163 -7200 # Node ID 12b591d5d63cf45e086d7f1fba16f9488ce2a127 # Parent 8f7930f589ef0bc9618f3a7593a7682649db5cf4 some Qt integration (wip) diff -r 8f7930f589ef -r 12b591d5d63c Applications/Generic/GuiAdapter.cpp --- 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) { diff -r 8f7930f589ef -r 12b591d5d63c Applications/Generic/GuiAdapter.h --- 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 diff -r 8f7930f589ef -r 12b591d5d63c Samples/Qt/BasicScene.cpp --- 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 #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 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 compositor = boost::make_shared(window.GetOpenGlWidget(), *controller->GetScene()); compositor->SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT, FONT_SIZE, Orthanc::Encoding_Latin1); diff -r 8f7930f589ef -r 12b591d5d63c Samples/Qt/BasicSceneWindow.ui --- 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 @@ Qt::LeftToRight - + 0 @@ -43,7 +43,7 @@ QLayout::SetDefaultConstraint - + 0 @@ -75,7 +75,7 @@ QStoneOpenGlWidget - QStoneOpenGlWidget + QWidget
QStoneOpenGlWidget.h
diff -r 8f7930f589ef -r 12b591d5d63c Samples/Qt/CMakeLists.txt --- 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) diff -r 8f7930f589ef -r 12b591d5d63c Samples/Qt/QStoneOpenGlWidget.cpp --- 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 + +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); +} + diff -r 8f7930f589ef -r 12b591d5d63c Samples/Qt/QStoneOpenGlWidget.h --- 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 #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 compositor_; - -public: - QStoneOpenGlWidget(QWidget *parent) : QOpenGLWidget(parent) { } + class QStoneOpenGlWidget : public QOpenGLWidget, public OrthancStone::OpenGL::IOpenGLContext + { + boost::shared_ptr compositor_; + boost::shared_ptr 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 sceneInteractor) + { + sceneInteractor_ = sceneInteractor; + } -public: - void SetCompositor(boost::shared_ptr compositor) - { - compositor_ = compositor; - } + void SetCompositor(boost::shared_ptr compositor) + { + compositor_ = compositor; + } -}; + }; +} diff -r 8f7930f589ef -r 12b591d5d63c Samples/Qt/Scene2DInteractor.cpp --- /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) +{ + +} + + diff -r 8f7930f589ef -r 12b591d5d63c Samples/Qt/Scene2DInteractor.h --- /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_; + + public: + Scene2DInteractor(boost::shared_ptr viewportController) : + viewportController_(viewportController) + {} + + virtual void OnMouseEvent(const GuiAdapterMouseEvent& event) = 0; + }; +} + +class BasicScene2DInteractor : public OrthancStone::Scene2DInteractor +{ +public: + BasicScene2DInteractor(boost::shared_ptr viewportController) : + Scene2DInteractor(viewportController) + {} + + virtual void OnMouseEvent(const OrthancStone::GuiAdapterMouseEvent& event) override; +}; +