comparison Resources/Graveyard/Deprecated/Samples/Qt/QStoneOpenGlWidget.h @ 1503:553084468225

moving /Deprecated/ to /Resources/Graveyard/Deprecated/
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 30 Jun 2020 11:38:13 +0200
parents Deprecated/Samples/Qt/QStoneOpenGlWidget.h@182bf3106ee2
children
comparison
equal deleted inserted replaced
1502:e5729dab3f67 1503:553084468225
1 /**
2 * Stone of Orthanc
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Affero General Public License
9 * as published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20
21
22 #pragma once
23 #include "../../Framework/OpenGL/OpenGLIncludes.h"
24 #include <QOpenGLWidget>
25 #include <QOpenGLFunctions>
26 #include <QOpenGLContext>
27
28 #include <boost/shared_ptr.hpp>
29 #include "../../Framework/OpenGL/IOpenGLContext.h"
30 #include "../../Framework/Scene2D/OpenGLCompositor.h"
31 #include "../../Framework/Viewport/ViewportBase.h"
32 #include "../../Applications/Generic/Scene2DInteractor.h"
33
34 namespace OrthancStone
35 {
36 class QStoneOpenGlWidget :
37 public QOpenGLWidget,
38 public OpenGL::IOpenGLContext,
39 public ViewportBase
40 {
41 std::unique_ptr<OrthancStone::OpenGLCompositor> compositor_;
42 boost::shared_ptr<Scene2DInteractor> sceneInteractor_;
43 QOpenGLContext openGlContext_;
44
45 public:
46 QStoneOpenGlWidget(QWidget *parent) :
47 QOpenGLWidget(parent),
48 ViewportBase("QtStoneOpenGlWidget") // TODO: we shall be able to define a name but construction time is too early !
49 {
50 setFocusPolicy(Qt::StrongFocus); // to enable keyPressEvent
51 setMouseTracking(true); // to enable mouseMoveEvent event when no button is pressed
52 }
53
54 void Init()
55 {
56 QSurfaceFormat requestedFormat;
57 requestedFormat.setVersion( 2, 0 );
58 openGlContext_.setFormat( requestedFormat );
59 openGlContext_.create();
60 openGlContext_.makeCurrent(context()->surface());
61
62 compositor_.reset(new OpenGLCompositor(*this, GetScene()));
63 }
64
65 protected:
66
67 //**** QWidget overrides
68 void initializeGL() override;
69 void resizeGL(int w, int h) override;
70 void paintGL() override;
71
72 void mousePressEvent(QMouseEvent* event) override;
73 void mouseMoveEvent(QMouseEvent* event) override;
74 void mouseReleaseEvent(QMouseEvent* event) override;
75 void keyPressEvent(QKeyEvent* event) override;
76 void keyReleaseEvent(QKeyEvent *event) override;
77 void wheelEvent(QWheelEvent* event) override;
78
79 //**** IOpenGLContext overrides
80
81 virtual void MakeCurrent() override;
82 virtual void SwapBuffer() override {}
83
84 virtual unsigned int GetCanvasWidth() const override
85 {
86 return this->width();
87 }
88
89 virtual unsigned int GetCanvasHeight() const override
90 {
91 return this->height();
92 }
93
94 public:
95
96 void SetInteractor(boost::shared_ptr<Scene2DInteractor> sceneInteractor)
97 {
98 sceneInteractor_ = sceneInteractor;
99 }
100
101 virtual ICompositor& GetCompositor()
102 {
103 return *compositor_;
104 }
105
106 protected:
107 void mouseEvent(QMouseEvent* qtEvent, OrthancStone::GuiAdapterHidEventType guiEventType);
108 bool keyEvent(QKeyEvent* qtEvent, OrthancStone::GuiAdapterHidEventType guiEventType);
109
110 };
111 }