annotate Samples/Qt/QStoneOpenGlWidget.h @ 1115:f00deb2b4733

Added tag toa2019110401 for changeset 33b0a762e98a
author Benjamin Golinvaux <bgo@osimis.io>
date Mon, 04 Nov 2019 15:11:44 +0100
parents a911f5bb48da
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
849
8a8cf2991538 Qt sample (work in progress)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
1 #pragma once
8a8cf2991538 Qt sample (work in progress)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
2 #include "../../Framework/OpenGL/OpenGLIncludes.h"
8a8cf2991538 Qt sample (work in progress)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
3 #include <QOpenGLWidget>
8a8cf2991538 Qt sample (work in progress)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
4 #include <QOpenGLFunctions>
916
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents: 897
diff changeset
5 #include <QOpenGLContext>
849
8a8cf2991538 Qt sample (work in progress)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
6
8a8cf2991538 Qt sample (work in progress)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
7 #include <boost/shared_ptr.hpp>
8a8cf2991538 Qt sample (work in progress)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
8 #include "../../Framework/OpenGL/IOpenGLContext.h"
8a8cf2991538 Qt sample (work in progress)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
9 #include "../../Framework/Scene2D/OpenGLCompositor.h"
916
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents: 897
diff changeset
10 #include "../../Framework/Viewport/ViewportBase.h"
885
56e4e9281076 sharing code between Qt/SDL BasiceScene sample
Alain Mazy <alain@mazy.be>
parents: 883
diff changeset
11 #include "../../Applications/Generic/Scene2DInteractor.h"
849
8a8cf2991538 Qt sample (work in progress)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
12
879
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
13 namespace OrthancStone
849
8a8cf2991538 Qt sample (work in progress)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
14 {
916
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents: 897
diff changeset
15 class QStoneOpenGlWidget :
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents: 897
diff changeset
16 public QOpenGLWidget,
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents: 897
diff changeset
17 public OpenGL::IOpenGLContext,
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents: 897
diff changeset
18 public ViewportBase
879
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
19 {
916
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents: 897
diff changeset
20 std::unique_ptr<OrthancStone::OpenGLCompositor> compositor_;
879
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
21 boost::shared_ptr<Scene2DInteractor> sceneInteractor_;
916
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents: 897
diff changeset
22 QOpenGLContext openGlContext_;
849
8a8cf2991538 Qt sample (work in progress)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
23
879
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
24 public:
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
25 QStoneOpenGlWidget(QWidget *parent) :
916
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents: 897
diff changeset
26 QOpenGLWidget(parent),
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents: 897
diff changeset
27 ViewportBase("QtStoneOpenGlWidget") // TODO: we shall be able to define a name but construction time is too early !
879
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
28 {
885
56e4e9281076 sharing code between Qt/SDL BasiceScene sample
Alain Mazy <alain@mazy.be>
parents: 883
diff changeset
29 setFocusPolicy(Qt::StrongFocus); // to enable keyPressEvent
56e4e9281076 sharing code between Qt/SDL BasiceScene sample
Alain Mazy <alain@mazy.be>
parents: 883
diff changeset
30 setMouseTracking(true); // to enable mouseMoveEvent event when no button is pressed
879
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
31 }
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
32
916
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents: 897
diff changeset
33 void Init()
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents: 897
diff changeset
34 {
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents: 897
diff changeset
35 QSurfaceFormat requestedFormat;
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents: 897
diff changeset
36 requestedFormat.setVersion( 2, 0 );
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents: 897
diff changeset
37 openGlContext_.setFormat( requestedFormat );
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents: 897
diff changeset
38 openGlContext_.create();
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents: 897
diff changeset
39 openGlContext_.makeCurrent(context()->surface());
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents: 897
diff changeset
40
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents: 897
diff changeset
41 compositor_.reset(new OpenGLCompositor(*this, GetScene()));
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents: 897
diff changeset
42 }
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents: 897
diff changeset
43
879
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
44 protected:
849
8a8cf2991538 Qt sample (work in progress)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
45
879
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
46 //**** QWidget overrides
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
47 void initializeGL() override;
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
48 void resizeGL(int w, int h) override;
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
49 void paintGL() override;
849
8a8cf2991538 Qt sample (work in progress)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
50
879
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
51 void mousePressEvent(QMouseEvent* event) override;
881
Alain Mazy <alain@mazy.be>
parents: 879
diff changeset
52 void mouseMoveEvent(QMouseEvent* event) override;
Alain Mazy <alain@mazy.be>
parents: 879
diff changeset
53 void mouseReleaseEvent(QMouseEvent* event) override;
883
30268a0cafca basic scene Qt sample working
Alain Mazy <alain@mazy.be>
parents: 881
diff changeset
54 void keyPressEvent(QKeyEvent* event) override;
30268a0cafca basic scene Qt sample working
Alain Mazy <alain@mazy.be>
parents: 881
diff changeset
55 void keyReleaseEvent(QKeyEvent *event) override;
30268a0cafca basic scene Qt sample working
Alain Mazy <alain@mazy.be>
parents: 881
diff changeset
56 void wheelEvent(QWheelEvent* event) override;
849
8a8cf2991538 Qt sample (work in progress)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
57
879
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
58 //**** IOpenGLContext overrides
849
8a8cf2991538 Qt sample (work in progress)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
59
879
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
60 virtual void MakeCurrent() override;
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
61 virtual void SwapBuffer() override {}
849
8a8cf2991538 Qt sample (work in progress)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
62
879
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
63 virtual unsigned int GetCanvasWidth() const override
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
64 {
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
65 return this->width();
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
66 }
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
67
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
68 virtual unsigned int GetCanvasHeight() const override
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
69 {
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
70 return this->height();
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
71 }
849
8a8cf2991538 Qt sample (work in progress)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
72
879
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
73 public:
916
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents: 897
diff changeset
74
879
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
75 void SetInteractor(boost::shared_ptr<Scene2DInteractor> sceneInteractor)
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
76 {
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
77 sceneInteractor_ = sceneInteractor;
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
78 }
849
8a8cf2991538 Qt sample (work in progress)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
79
916
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents: 897
diff changeset
80 virtual ICompositor& GetCompositor()
879
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
81 {
916
a911f5bb48da MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents: 897
diff changeset
82 return *compositor_;
879
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
83 }
849
8a8cf2991538 Qt sample (work in progress)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
84
881
Alain Mazy <alain@mazy.be>
parents: 879
diff changeset
85 protected:
Alain Mazy <alain@mazy.be>
parents: 879
diff changeset
86 void mouseEvent(QMouseEvent* qtEvent, OrthancStone::GuiAdapterHidEventType guiEventType);
883
30268a0cafca basic scene Qt sample working
Alain Mazy <alain@mazy.be>
parents: 881
diff changeset
87 bool keyEvent(QKeyEvent* qtEvent, OrthancStone::GuiAdapterHidEventType guiEventType);
881
Alain Mazy <alain@mazy.be>
parents: 879
diff changeset
88
879
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
89 };
12b591d5d63c some Qt integration (wip)
Alain Mazy <alain@mazy.be>
parents: 863
diff changeset
90 }