Mercurial > hg > orthanc-stone
annotate Samples/Qt/QStoneOpenGlWidget.cpp @ 984:35ed6812d639 toa2019090602
Build fix
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Fri, 06 Sep 2019 11:46:51 +0200 |
parents | a911f5bb48da |
children |
rev | line source |
---|---|
849 | 1 #include "../../Framework/OpenGL/OpenGLIncludes.h" |
2 #include "QStoneOpenGlWidget.h" | |
3 | |
879 | 4 #include <QMouseEvent> |
5 | |
6 using namespace OrthancStone; | |
7 | |
849 | 8 void QStoneOpenGlWidget::initializeGL() |
9 { | |
863
23701fbf228e
first rendering of a 2DScene in Qt widget
Alain Mazy <alain@mazy.be>
parents:
849
diff
changeset
|
10 glewInit(); |
23701fbf228e
first rendering of a 2DScene in Qt widget
Alain Mazy <alain@mazy.be>
parents:
849
diff
changeset
|
11 } |
23701fbf228e
first rendering of a 2DScene in Qt widget
Alain Mazy <alain@mazy.be>
parents:
849
diff
changeset
|
12 |
23701fbf228e
first rendering of a 2DScene in Qt widget
Alain Mazy <alain@mazy.be>
parents:
849
diff
changeset
|
13 void QStoneOpenGlWidget::MakeCurrent() |
23701fbf228e
first rendering of a 2DScene in Qt widget
Alain Mazy <alain@mazy.be>
parents:
849
diff
changeset
|
14 { |
23701fbf228e
first rendering of a 2DScene in Qt widget
Alain Mazy <alain@mazy.be>
parents:
849
diff
changeset
|
15 this->makeCurrent(); |
849 | 16 } |
17 | |
18 void QStoneOpenGlWidget::resizeGL(int w, int h) | |
19 { | |
20 | |
21 } | |
22 | |
23 void QStoneOpenGlWidget::paintGL() | |
24 { | |
25 if (compositor_) | |
26 { | |
27 compositor_->Refresh(); | |
28 } | |
29 doneCurrent(); | |
30 } | |
31 | |
879 | 32 void ConvertFromPlatform( |
881 | 33 OrthancStone::GuiAdapterMouseEvent& guiEvent, |
34 PointerEvent& pointerEvent, | |
35 const QMouseEvent& qtEvent, | |
897 | 36 const IViewport& viewport) |
879 | 37 { |
881 | 38 guiEvent.targetX = qtEvent.x(); |
39 guiEvent.targetY = qtEvent.y(); | |
897 | 40 pointerEvent.AddPosition(viewport.GetPixelCenterCoordinates(guiEvent.targetX, guiEvent.targetY)); |
879 | 41 |
42 switch (qtEvent.button()) | |
43 { | |
881 | 44 case Qt::LeftButton: guiEvent.button = OrthancStone::GUIADAPTER_MOUSEBUTTON_LEFT; break; |
45 case Qt::MiddleButton: guiEvent.button = OrthancStone::GUIADAPTER_MOUSEBUTTON_MIDDLE; break; | |
46 case Qt::RightButton: guiEvent.button = OrthancStone::GUIADAPTER_MOUSEBUTTON_RIGHT; break; | |
879 | 47 default: |
881 | 48 guiEvent.button = OrthancStone::GUIADAPTER_MOUSEBUTTON_LEFT; |
879 | 49 } |
50 | |
51 if (qtEvent.modifiers().testFlag(Qt::ShiftModifier)) | |
52 { | |
881 | 53 guiEvent.shiftKey = true; |
879 | 54 } |
55 if (qtEvent.modifiers().testFlag(Qt::ControlModifier)) | |
56 { | |
881 | 57 guiEvent.ctrlKey = true; |
879 | 58 } |
59 if (qtEvent.modifiers().testFlag(Qt::AltModifier)) | |
60 { | |
881 | 61 guiEvent.altKey = true; |
879 | 62 } |
63 } | |
64 | |
881 | 65 void QStoneOpenGlWidget::mouseEvent(QMouseEvent* qtEvent, OrthancStone::GuiAdapterHidEventType guiEventType) |
66 { | |
67 OrthancStone::GuiAdapterMouseEvent guiEvent; | |
68 PointerEvent pointerEvent; | |
916
a911f5bb48da
MultiPlatform Basic Scene sample (so far: SDL + Qt)
Alain Mazy <alain@mazy.be>
parents:
897
diff
changeset
|
69 ConvertFromPlatform(guiEvent, pointerEvent, *qtEvent, *this); |
881 | 70 guiEvent.type = guiEventType; |
879 | 71 |
881 | 72 if (sceneInteractor_.get() != NULL && compositor_.get() != NULL) |
73 { | |
74 sceneInteractor_->OnMouseEvent(guiEvent, pointerEvent); | |
75 } | |
76 | |
77 // force redraw of the OpenGL widget | |
78 update(); | |
79 } | |
879 | 80 |
81 void QStoneOpenGlWidget::mousePressEvent(QMouseEvent* qtEvent) | |
82 { | |
881 | 83 mouseEvent(qtEvent, GUIADAPTER_EVENT_MOUSEDOWN); |
879 | 84 } |
85 | |
881 | 86 void QStoneOpenGlWidget::mouseMoveEvent(QMouseEvent* qtEvent) |
87 { | |
883 | 88 mouseEvent(qtEvent, GUIADAPTER_EVENT_MOUSEMOVE); |
881 | 89 } |
90 | |
91 void QStoneOpenGlWidget::mouseReleaseEvent(QMouseEvent* qtEvent) | |
92 { | |
93 mouseEvent(qtEvent, GUIADAPTER_EVENT_MOUSEUP); | |
94 } | |
883 | 95 |
96 void ConvertFromPlatform( | |
97 OrthancStone::GuiAdapterKeyboardEvent& guiEvent, | |
98 const QKeyEvent& qtEvent) | |
99 { | |
100 if (qtEvent.text().length() > 0) | |
101 { | |
102 guiEvent.sym[0] = qtEvent.text()[0].cell(); | |
103 } | |
104 else | |
105 { | |
106 guiEvent.sym[0] = 0; | |
107 } | |
108 guiEvent.sym[1] = 0; | |
109 | |
110 if (qtEvent.modifiers().testFlag(Qt::ShiftModifier)) | |
111 { | |
112 guiEvent.shiftKey = true; | |
113 } | |
114 if (qtEvent.modifiers().testFlag(Qt::ControlModifier)) | |
115 { | |
116 guiEvent.ctrlKey = true; | |
117 } | |
118 if (qtEvent.modifiers().testFlag(Qt::AltModifier)) | |
119 { | |
120 guiEvent.altKey = true; | |
121 } | |
122 | |
123 } | |
124 | |
125 | |
126 bool QStoneOpenGlWidget::keyEvent(QKeyEvent* qtEvent, OrthancStone::GuiAdapterHidEventType guiEventType) | |
127 { | |
128 bool handled = false; | |
129 OrthancStone::GuiAdapterKeyboardEvent guiEvent; | |
130 ConvertFromPlatform(guiEvent, *qtEvent); | |
131 guiEvent.type = guiEventType; | |
132 | |
133 if (sceneInteractor_.get() != NULL && compositor_.get() != NULL) | |
134 { | |
135 handled = sceneInteractor_->OnKeyboardEvent(guiEvent); | |
136 | |
137 if (handled) | |
138 { | |
139 // force redraw of the OpenGL widget | |
140 update(); | |
141 } | |
142 } | |
143 return handled; | |
144 } | |
145 | |
146 void QStoneOpenGlWidget::keyPressEvent(QKeyEvent *qtEvent) | |
147 { | |
148 bool handled = keyEvent(qtEvent, GUIADAPTER_EVENT_KEYDOWN); | |
149 if (!handled) | |
150 { | |
151 QOpenGLWidget::keyPressEvent(qtEvent); | |
152 } | |
153 } | |
154 | |
155 void QStoneOpenGlWidget::keyReleaseEvent(QKeyEvent *qtEvent) | |
156 { | |
157 bool handled = keyEvent(qtEvent, GUIADAPTER_EVENT_KEYUP); | |
158 if (!handled) | |
159 { | |
160 QOpenGLWidget::keyPressEvent(qtEvent); | |
161 } | |
162 } | |
163 | |
164 void QStoneOpenGlWidget::wheelEvent(QWheelEvent *qtEvent) | |
165 { | |
166 OrthancStone::GuiAdapterWheelEvent guiEvent; | |
167 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
884 | 168 |
169 // force redraw of the OpenGL widget | |
170 update(); | |
883 | 171 } |