Mercurial > hg > orthanc-stone
comparison Resources/Graveyard/Deprecated/Samples/Qt/QStoneOpenGlWidget.cpp @ 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.cpp@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 #include "../../Framework/OpenGL/OpenGLIncludes.h" | |
23 #include "QStoneOpenGlWidget.h" | |
24 | |
25 #include <QMouseEvent> | |
26 | |
27 using namespace OrthancStone; | |
28 | |
29 void QStoneOpenGlWidget::initializeGL() | |
30 { | |
31 glewInit(); | |
32 } | |
33 | |
34 void QStoneOpenGlWidget::MakeCurrent() | |
35 { | |
36 this->makeCurrent(); | |
37 } | |
38 | |
39 void QStoneOpenGlWidget::resizeGL(int w, int h) | |
40 { | |
41 | |
42 } | |
43 | |
44 void QStoneOpenGlWidget::paintGL() | |
45 { | |
46 if (compositor_) | |
47 { | |
48 compositor_->Refresh(); | |
49 } | |
50 doneCurrent(); | |
51 } | |
52 | |
53 void ConvertFromPlatform( | |
54 OrthancStone::GuiAdapterMouseEvent& guiEvent, | |
55 PointerEvent& pointerEvent, | |
56 const QMouseEvent& qtEvent, | |
57 const IViewport& viewport) | |
58 { | |
59 guiEvent.targetX = qtEvent.x(); | |
60 guiEvent.targetY = qtEvent.y(); | |
61 pointerEvent.AddPosition(viewport.GetPixelCenterCoordinates(guiEvent.targetX, guiEvent.targetY)); | |
62 | |
63 switch (qtEvent.button()) | |
64 { | |
65 case Qt::LeftButton: guiEvent.button = OrthancStone::GUIADAPTER_MOUSEBUTTON_LEFT; break; | |
66 case Qt::MiddleButton: guiEvent.button = OrthancStone::GUIADAPTER_MOUSEBUTTON_MIDDLE; break; | |
67 case Qt::RightButton: guiEvent.button = OrthancStone::GUIADAPTER_MOUSEBUTTON_RIGHT; break; | |
68 default: | |
69 guiEvent.button = OrthancStone::GUIADAPTER_MOUSEBUTTON_LEFT; | |
70 } | |
71 | |
72 if (qtEvent.modifiers().testFlag(Qt::ShiftModifier)) | |
73 { | |
74 guiEvent.shiftKey = true; | |
75 } | |
76 if (qtEvent.modifiers().testFlag(Qt::ControlModifier)) | |
77 { | |
78 guiEvent.ctrlKey = true; | |
79 } | |
80 if (qtEvent.modifiers().testFlag(Qt::AltModifier)) | |
81 { | |
82 guiEvent.altKey = true; | |
83 } | |
84 } | |
85 | |
86 void QStoneOpenGlWidget::mouseEvent(QMouseEvent* qtEvent, OrthancStone::GuiAdapterHidEventType guiEventType) | |
87 { | |
88 OrthancStone::GuiAdapterMouseEvent guiEvent; | |
89 PointerEvent pointerEvent; | |
90 ConvertFromPlatform(guiEvent, pointerEvent, *qtEvent, *this); | |
91 guiEvent.type = guiEventType; | |
92 | |
93 if (sceneInteractor_.get() != NULL && compositor_.get() != NULL) | |
94 { | |
95 sceneInteractor_->OnMouseEvent(guiEvent, pointerEvent); | |
96 } | |
97 | |
98 // force redraw of the OpenGL widget | |
99 update(); | |
100 } | |
101 | |
102 void QStoneOpenGlWidget::mousePressEvent(QMouseEvent* qtEvent) | |
103 { | |
104 mouseEvent(qtEvent, GUIADAPTER_EVENT_MOUSEDOWN); | |
105 } | |
106 | |
107 void QStoneOpenGlWidget::mouseMoveEvent(QMouseEvent* qtEvent) | |
108 { | |
109 mouseEvent(qtEvent, GUIADAPTER_EVENT_MOUSEMOVE); | |
110 } | |
111 | |
112 void QStoneOpenGlWidget::mouseReleaseEvent(QMouseEvent* qtEvent) | |
113 { | |
114 mouseEvent(qtEvent, GUIADAPTER_EVENT_MOUSEUP); | |
115 } | |
116 | |
117 void ConvertFromPlatform( | |
118 OrthancStone::GuiAdapterKeyboardEvent& guiEvent, | |
119 const QKeyEvent& qtEvent) | |
120 { | |
121 if (qtEvent.text().length() > 0) | |
122 { | |
123 guiEvent.sym[0] = qtEvent.text()[0].cell(); | |
124 } | |
125 else | |
126 { | |
127 guiEvent.sym[0] = 0; | |
128 } | |
129 guiEvent.sym[1] = 0; | |
130 | |
131 if (qtEvent.modifiers().testFlag(Qt::ShiftModifier)) | |
132 { | |
133 guiEvent.shiftKey = true; | |
134 } | |
135 if (qtEvent.modifiers().testFlag(Qt::ControlModifier)) | |
136 { | |
137 guiEvent.ctrlKey = true; | |
138 } | |
139 if (qtEvent.modifiers().testFlag(Qt::AltModifier)) | |
140 { | |
141 guiEvent.altKey = true; | |
142 } | |
143 | |
144 } | |
145 | |
146 | |
147 bool QStoneOpenGlWidget::keyEvent(QKeyEvent* qtEvent, OrthancStone::GuiAdapterHidEventType guiEventType) | |
148 { | |
149 bool handled = false; | |
150 OrthancStone::GuiAdapterKeyboardEvent guiEvent; | |
151 ConvertFromPlatform(guiEvent, *qtEvent); | |
152 guiEvent.type = guiEventType; | |
153 | |
154 if (sceneInteractor_.get() != NULL && compositor_.get() != NULL) | |
155 { | |
156 handled = sceneInteractor_->OnKeyboardEvent(guiEvent); | |
157 | |
158 if (handled) | |
159 { | |
160 // force redraw of the OpenGL widget | |
161 update(); | |
162 } | |
163 } | |
164 return handled; | |
165 } | |
166 | |
167 void QStoneOpenGlWidget::keyPressEvent(QKeyEvent *qtEvent) | |
168 { | |
169 bool handled = keyEvent(qtEvent, GUIADAPTER_EVENT_KEYDOWN); | |
170 if (!handled) | |
171 { | |
172 QOpenGLWidget::keyPressEvent(qtEvent); | |
173 } | |
174 } | |
175 | |
176 void QStoneOpenGlWidget::keyReleaseEvent(QKeyEvent *qtEvent) | |
177 { | |
178 bool handled = keyEvent(qtEvent, GUIADAPTER_EVENT_KEYUP); | |
179 if (!handled) | |
180 { | |
181 QOpenGLWidget::keyPressEvent(qtEvent); | |
182 } | |
183 } | |
184 | |
185 void QStoneOpenGlWidget::wheelEvent(QWheelEvent *qtEvent) | |
186 { | |
187 OrthancStone::GuiAdapterWheelEvent guiEvent; | |
188 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
189 | |
190 // force redraw of the OpenGL widget | |
191 update(); | |
192 } |