OpenWalnut  1.5.0dev
WQtGLWidget.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WQTGLWIDGET_H
26 #define WQTGLWIDGET_H
27 
28 #include <memory>
29 #include <string>
30 
31 #include <QMenu>
32 #include <QWidget>
33 #include <QtCore/QTimer>
34 #include <QtOpenGL/QGLFormat>
35 #include <QtOpenGL/QGLWidget>
36 #include <boost/signals2/signal.hpp>
37 
38 #include "WQtGLScreenCapture.h"
39 #include "core/common/WColor.h" // not forwarded due to duplicated typedef
40 #include "core/graphicsEngine/WGECamera.h"
41 #include "core/graphicsEngine/WGEViewer.h"
42 
43 class WSettingAction;
44 
45 typedef QGLWidget WQtGLWidgetParent;
46 
47 /**
48  * A widget containing an open gl display area. This initializes OpenGL context and adds a view to the
49  * engine.
50  * \ingroup ui
51  */
52 // NOTE: to make this work with MOC, the defines must be set before MOC runs (ensured in Build system)
54 {
55  Q_OBJECT
56 
57 public:
58  /**
59  * Default constructor.
60  *
61  * \param nameOfViewer Name of the Viewer
62  * \param parent Parent widget.
63  * \param projectionMode decides whether the widget uses perspective or othographic projection
64  * \param shareWidget this widget will share OpenGL display lists and texture objects with shareWidget
65  */
66  explicit WQtGLWidget( std::string nameOfViewer, QWidget* parent = 0,
67  WGECamera::ProjectionMode projectionMode = WGECamera::ORTHOGRAPHIC, const QWidget * shareWidget = 0 );
68 
69  /**
70  * Destructor.
71  */
72  virtual ~WQtGLWidget();
73 
74  /**
75  * List of currently possible camera manipulators.
76  */
78  {
79  TRACKBALL, TWO_D, NO_OP, ADVANCED
80  };
81 
82  /**
83  * Sets the camera manipulator to use.
84  *
85  * \param manipulator the manipulator.
86  */
87  void setCameraManipulator( CameraManipulators manipulator );
88 
89  /**
90  * Returns the actually set camera manipulator.
91  *
92  * \return the manipulator.
93  */
95 
96  /**
97  * Get the included viewer.
98  *
99  * \return a shared pointer to the viewer
100  */
101  std::shared_ptr< WGEViewer > getViewer() const;
102 
103  /**
104  * Creates and returns a default OpenGL format description with vertical sync enabled.
105  *
106  * \return the format descriptor
107  */
108  static const QGLFormat getDefaultFormat();
109 
110  /**
111  * The presets menu.
112  *
113  * \return the menu
114  */
116 
117  /**
118  * The presets menu including the reset action
119  *
120  * \return the menu
121  */
123 
124  /**
125  * The action to trigger a camera reset.
126  *
127  * \return the action
128  */
130 
131  /**
132  * Called on close. Clean up all OpenGL stuff.
133  */
134  virtual void cleanUp();
135 
136  /**
137  * Pause rendering. This does not free the viewer. It simply pauses rendering.
138  *
139  * \param pause true to pause.
140  */
141  void setPaused( bool pause = true );
142 
143  /**
144  * Query whether the view is paused or not.
145  *
146  * \return true if paused
147  */
148  bool getPaused() const;
149 
150 signals:
151 
152  /**
153  * Signals that the first frame was rendered.
154  */
156 
157 public slots:
158  /**
159  * Resets the contained view using the installed manipulator.
160  */
161  void reset();
162 
163  /**
164  * Sets the left preset view of the main viewer.
165  */
166  void setPresetViewLeft();
167 
168  /**
169  * Sets the right preset view of the main viewer.
170  */
171  void setPresetViewRight();
172 
173  /**
174  * Sets the superior preset view of the main viewer.
175  */
176  void setPresetViewSuperior();
177 
178  /**
179  * Sets the inferior preset view of the main viewer.
180  */
181  void setPresetViewInferior();
182 
183  /**
184  * Sets the anterior preset view of the main viewer.
185  */
186  void setPresetViewAnterior();
187 
188  /**
189  * Sets the posterior preset view of the main viewer.
190  */
191  void setPresetViewPosterior();
192 
193  /**
194  * Zooms and centers the view to fit the viewer.
195  */
196  void setFitScreenPosition();
197 
198 protected:
199  /**
200  * The viewer to the scene.
201  */
202  std::shared_ptr<WGEViewer> m_Viewer;
203 
204  /**
205  * The name of the viewer.
206  */
207  std::string m_nameOfViewer;
208 
209  /**
210  * Event handler for double clicks.
211  *
212  * \param event the event description.
213  */
214  virtual void mouseDoubleClickEvent( QMouseEvent* event );
215 
216  /**
217  * Event handler for resize events.
218  *
219  * \param width the new width.
220  * \param height the new height.
221  */
222  virtual void resizeGL( int width, int height );
223 
224  /**
225  * Event handler for key press.
226  *
227  * \param event the event description.
228  */
229  virtual void keyPressEvent( QKeyEvent* event );
230 
231  /**
232  * Event handler for key release.
233  *
234  * \param event the event description.
235  */
236  virtual void keyReleaseEvent( QKeyEvent* event );
237 
238  /**
239  * Event handler for mouse button press.
240  *
241  * \param event the event description.
242  */
243  virtual void mousePressEvent( QMouseEvent* event );
244 
245  /**
246  * Event handler for mouse button release.
247  *
248  * \param event the event description.
249  */
250  virtual void mouseReleaseEvent( QMouseEvent* event );
251 
252  /**
253  * Event handler for mouse moves.
254  *
255  * \param event the event description.
256  */
257  virtual void mouseMoveEvent( QMouseEvent* event );
258 
259  /**
260  * Event handler for the mouse wheel.
261  *
262  * \param event the event description.
263  */
264  virtual void wheelEvent( QWheelEvent* event );
265 
266  /**
267  * QT Callback for handling repaints.
268  *
269  * \param event event descriptor.
270  */
271  virtual void paintEvent( QPaintEvent* event );
272 
273  /**
274  * QT Callback for handling repaints.
275  */
276  virtual void paintGL();
277 
278  /**
279  * Simply translate the mouse button from an event to an int.
280  *
281  * \param event the QT Event.
282  *
283  * \return the translated button number.
284  */
285  int translateButton( QMouseEvent* event );
286 
287  /**
288  * Stores the current manipulator.
289  */
291 
292  /**
293  * Camera projection mode used to initialize widget. May not be the actual one!
294  */
296 
297  /**
298  * Custom event dispatcher. Gets called by QT's Event system every time an event got sent to this widget. This event handler
299  * processes the notifyrender events. Others get forwarded.
300  *
301  * \note QT Doc says: use event() for custom events.
302  *
303  * \param event the event that got transmitted.
304  *
305  * \return true if the event got handled properly.
306  */
307  virtual bool event( QEvent* event );
308 
309  /**
310  * Called on close. Accept the event to accept the close call.
311  *
312  * \param event the event.
313  */
314  virtual void closeEvent( QCloseEvent* event );
315 
316 private:
317  /**
318  * Timer for periodic repaints.
319  */
320  QTimer m_Timer;
321 
322  /**
323  * This flag is set to true if the first paint call occured. See the paint method for details.
324  */
326 
327  /**
328  * Called by the WGEViewer to notify about the first frame rendered
329  */
331 
332  /**
333  * Camera menu
334  */
336 
337  /**
338  * Camera menu with reset action
339  */
341 
342  /**
343  * Camera reset.
344  */
346 };
347 
348 #endif // WQTGLWIDGET_H
ProjectionMode
List of possible camera modes.
Definition: WGECamera.h:44
A widget containing an open gl display area.
Definition: WQtGLWidget.h:54
QAction * m_cameraResetAction
Camera reset.
Definition: WQtGLWidget.h:345
virtual bool event(QEvent *event)
Custom event dispatcher.
QMenu * getCameraPresetsAndResetMenu()
The presets menu including the reset action.
void setPresetViewPosterior()
Sets the posterior preset view of the main viewer.
void setPresetViewInferior()
Sets the inferior preset view of the main viewer.
void setPresetViewAnterior()
Sets the anterior preset view of the main viewer.
virtual void paintGL()
QT Callback for handling repaints.
CameraManipulators m_CurrentManipulator
Stores the current manipulator.
Definition: WQtGLWidget.h:290
std::shared_ptr< WGEViewer > getViewer() const
Get the included viewer.
QAction * getCameraResetAction()
The action to trigger a camera reset.
WQtGLWidget(std::string nameOfViewer, QWidget *parent=0, WGECamera::ProjectionMode projectionMode=WGECamera::ORTHOGRAPHIC, const QWidget *shareWidget=0)
Default constructor.
Definition: WQtGLWidget.cpp:54
virtual void paintEvent(QPaintEvent *event)
QT Callback for handling repaints.
CameraManipulators getCameraManipulators()
Returns the actually set camera manipulator.
virtual void closeEvent(QCloseEvent *event)
Called on close.
void setPresetViewRight()
Sets the right preset view of the main viewer.
QMenu * m_cameraPresetResetMenu
Camera menu with reset action.
Definition: WQtGLWidget.h:340
WGECamera::ProjectionMode m_initialProjectionMode
Camera projection mode used to initialize widget.
Definition: WQtGLWidget.h:295
virtual void keyReleaseEvent(QKeyEvent *event)
Event handler for key release.
virtual void mouseReleaseEvent(QMouseEvent *event)
Event handler for mouse button release.
void reset()
Resets the contained view using the installed manipulator.
CameraManipulators
List of currently possible camera manipulators.
Definition: WQtGLWidget.h:78
virtual void mouseDoubleClickEvent(QMouseEvent *event)
Event handler for double clicks.
virtual void wheelEvent(QWheelEvent *event)
Event handler for the mouse wheel.
bool m_firstPaint
This flag is set to true if the first paint call occured.
Definition: WQtGLWidget.h:325
virtual void cleanUp()
Called on close.
virtual void mouseMoveEvent(QMouseEvent *event)
Event handler for mouse moves.
static const QGLFormat getDefaultFormat()
Creates and returns a default OpenGL format description with vertical sync enabled.
virtual void mousePressEvent(QMouseEvent *event)
Event handler for mouse button press.
int translateButton(QMouseEvent *event)
Simply translate the mouse button from an event to an int.
bool getPaused() const
Query whether the view is paused or not.
void setFitScreenPosition()
Zooms and centers the view to fit the viewer.
void notifyFirstRenderedFrame()
Called by the WGEViewer to notify about the first frame rendered.
void setPresetViewSuperior()
Sets the superior preset view of the main viewer.
virtual void keyPressEvent(QKeyEvent *event)
Event handler for key press.
virtual void resizeGL(int width, int height)
Event handler for resize events.
std::string m_nameOfViewer
The name of the viewer.
Definition: WQtGLWidget.h:207
void renderedFirstFrame()
Signals that the first frame was rendered.
QMenu * getCameraPresetsMenu()
The presets menu.
void setPresetViewLeft()
Sets the left preset view of the main viewer.
QTimer m_Timer
Timer for periodic repaints.
Definition: WQtGLWidget.h:320
QMenu * m_cameraPresetMenu
Camera menu.
Definition: WQtGLWidget.h:335
void setPaused(bool pause=true)
Pause rendering.
std::shared_ptr< WGEViewer > m_Viewer
The viewer to the scene.
Definition: WQtGLWidget.h:202
virtual ~WQtGLWidget()
Destructor.
void setCameraManipulator(CameraManipulators manipulator)
Sets the camera manipulator to use.
Class to handle a certain setting with an action.