comparison Samples/Qt/QStoneOpenGlWidget.h @ 916:a911f5bb48da am-dev

MultiPlatform Basic Scene sample (so far: SDL + Qt)
author Alain Mazy <alain@mazy.be>
date Fri, 19 Jul 2019 15:06:36 +0200
parents 9c2f6d6b9f4a
children
comparison
equal deleted inserted replaced
915:912cc77be3b4 916:a911f5bb48da
1 #pragma once 1 #pragma once
2 #include "../../Framework/OpenGL/OpenGLIncludes.h" 2 #include "../../Framework/OpenGL/OpenGLIncludes.h"
3 #include <QOpenGLWidget> 3 #include <QOpenGLWidget>
4 #include <QOpenGLFunctions> 4 #include <QOpenGLFunctions>
5 #include <QOpenGLContext>
5 6
6 #include <boost/shared_ptr.hpp> 7 #include <boost/shared_ptr.hpp>
7 #include "../../Framework/OpenGL/IOpenGLContext.h" 8 #include "../../Framework/OpenGL/IOpenGLContext.h"
8 #include "../../Framework/Scene2D/OpenGLCompositor.h" 9 #include "../../Framework/Scene2D/OpenGLCompositor.h"
9 #include "../../Framework/Viewport/IViewport.h" 10 #include "../../Framework/Viewport/ViewportBase.h"
10 #include "../../Applications/Generic/Scene2DInteractor.h" 11 #include "../../Applications/Generic/Scene2DInteractor.h"
11 12
12 namespace OrthancStone 13 namespace OrthancStone
13 { 14 {
14 class QStoneOpenGlWidget : public QOpenGLWidget, public OrthancStone::OpenGL::IOpenGLContext 15 class QStoneOpenGlWidget :
16 public QOpenGLWidget,
17 public OpenGL::IOpenGLContext,
18 public ViewportBase
15 { 19 {
16 boost::shared_ptr<IViewport> viewport_; 20 std::unique_ptr<OrthancStone::OpenGLCompositor> compositor_;
17 boost::shared_ptr<OrthancStone::OpenGLCompositor> compositor_;
18 boost::shared_ptr<Scene2DInteractor> sceneInteractor_; 21 boost::shared_ptr<Scene2DInteractor> sceneInteractor_;
22 QOpenGLContext openGlContext_;
19 23
20 public: 24 public:
21 QStoneOpenGlWidget(QWidget *parent) : 25 QStoneOpenGlWidget(QWidget *parent) :
22 QOpenGLWidget(parent) 26 QOpenGLWidget(parent),
27 ViewportBase("QtStoneOpenGlWidget") // TODO: we shall be able to define a name but construction time is too early !
23 { 28 {
24 setFocusPolicy(Qt::StrongFocus); // to enable keyPressEvent 29 setFocusPolicy(Qt::StrongFocus); // to enable keyPressEvent
25 setMouseTracking(true); // to enable mouseMoveEvent event when no button is pressed 30 setMouseTracking(true); // to enable mouseMoveEvent event when no button is pressed
31 }
32
33 void Init()
34 {
35 QSurfaceFormat requestedFormat;
36 requestedFormat.setVersion( 2, 0 );
37 openGlContext_.setFormat( requestedFormat );
38 openGlContext_.create();
39 openGlContext_.makeCurrent(context()->surface());
40
41 compositor_.reset(new OpenGLCompositor(*this, GetScene()));
26 } 42 }
27 43
28 protected: 44 protected:
29 45
30 //**** QWidget overrides 46 //**** QWidget overrides
53 { 69 {
54 return this->height(); 70 return this->height();
55 } 71 }
56 72
57 public: 73 public:
74
58 void SetInteractor(boost::shared_ptr<Scene2DInteractor> sceneInteractor) 75 void SetInteractor(boost::shared_ptr<Scene2DInteractor> sceneInteractor)
59 { 76 {
60 sceneInteractor_ = sceneInteractor; 77 sceneInteractor_ = sceneInteractor;
61 } 78 }
62 79
63 void SetCompositor(boost::shared_ptr<OrthancStone::OpenGLCompositor> compositor) 80 virtual ICompositor& GetCompositor()
64 { 81 {
65 compositor_ = compositor; 82 return *compositor_;
66 } 83 }
67 84
68 protected: 85 protected:
69 void mouseEvent(QMouseEvent* qtEvent, OrthancStone::GuiAdapterHidEventType guiEventType); 86 void mouseEvent(QMouseEvent* qtEvent, OrthancStone::GuiAdapterHidEventType guiEventType);
70 bool keyEvent(QKeyEvent* qtEvent, OrthancStone::GuiAdapterHidEventType guiEventType); 87 bool keyEvent(QKeyEvent* qtEvent, OrthancStone::GuiAdapterHidEventType guiEventType);