MIRA
OgreWindow.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
47 #ifndef _MIRA_QTOGRE_WINDOW_H_
48 #define _MIRA_QTOGRE_WINDOW_H_
49 
50 #include <QDragEnterEvent>
51 #include <QDropEvent>
52 #include <QKeyEvent>
53 #include <QMouseEvent>
54 #include <QWheelEvent>
55 #include <QtGui/QWindow>
56 
57 #include <Ogre.h>
58 
59 #include <utils/UUID.h>
60 
61 /*****************************************************************************
62  * This file contains the class QtOgreWindow, which provides a better Ogre *
63  * integration into Qt without using QOpenGLWidget/QGLWidget. The basic idea *
64  * is taken from the Qgre Wiki and Qt Forum: *
65  * https://wiki.ogre3d.org/Integrating+Ogre+into+QT5 *
66  * https://forum.qt.io/topic/132600/how-to-embed-ogre3d-in-qt5/2 *
67  ****************************************************************************/
68 
69 namespace mira {
70 
72 
80 {
81 public:
84 
85 public:
86  virtual void onDragEnterEvent(QDragEnterEvent* event) {}
87 
88  virtual void onDropEvent(QDropEvent* event) {}
89 
90  virtual void onKeyPressEvent(QKeyEvent* event) {}
91 
92  virtual void onKeyReleaseEvent(QKeyEvent* event) {}
93 
94  virtual void onWheelEvent(QWheelEvent* event) {}
95 
96  virtual void onMousePressEvent(QMouseEvent* event) {}
97 
98  virtual void onMouseReleaseEvent(QMouseEvent* event) {}
99 
100  virtual void onMouseMoveEvent(QMouseEvent* event) {}
101 };
102 
104 
105 // A callback class for initializing your Ogre components
107 {
108 public:
111 
112 public:
113  virtual void initOgre() = 0;
114 };
115 
117 
118 class OgreSingletonHelper : public QObject
119 {
120  Q_OBJECT
121 
122 public:
124 
125 public slots:
126  virtual void onAboutToQuit() = 0;
127 };
128 
130 
132  public QWindow
133 {
134  Q_OBJECT
135 
136 public:
138  QWindow *parent = NULL);
139  virtual ~QtOgreWindow();
140 
141 public:
142  void setAnimating(bool animating);
143 
145  mEventListener = eventListener;
146  }
147 
148  Ogre::RenderWindow* getRenderWindow() {
149  return mRenderWindow;
150  }
151 
152 public:
153  // We declare these methods virtual to allow for further inheritance.
154  virtual void render(QPainter *painter);
155  virtual void render();
156  virtual void initialize();
157 #if OGRE_VERSION >= ((2 << 16) | (0 << 8) | 0)
158  virtual void createCompositor();
159 #endif
160 
161 
162 public slots:
163  virtual void renderLater();
164  virtual void renderNow();
165 
166  // We use an event filter to be able to capture keyboard/mouse events. More on this later.
167  virtual bool eventFilter(QObject *target, QEvent *event);
168 
169 protected:
170  /*
171  The below methods are what is actually fired when they keys on the keyboard are hit.
172  Similar events are fired when the mouse is pressed or other events occur.
173  */
174  virtual void keyPressEvent(QKeyEvent* ev);
175  virtual void keyReleaseEvent(QKeyEvent* ev);
176  virtual void mouseMoveEvent(QMouseEvent* ev);
177  virtual void wheelEvent(QWheelEvent* ev);
178  virtual void mousePressEvent(QMouseEvent* ev);
179  virtual void mouseReleaseEvent(QMouseEvent* ev);
180 
181  virtual void exposeEvent(QExposeEvent* ev);
182  virtual bool event(QEvent *event);
183 
184 protected:
187  Ogre::RenderWindow* mRenderWindow = NULL;
188 
189  bool mUpdatePending = false;
190  bool mAnimating = false;
191 };
192 
194 
195 } // namespace mira
196 
197 #endif // _MIRA_QTOGRE_WINDOW_H_
virtual ~QtOgreWindowEventListener()
Definition: OgreWindow.h:83
QtOgreWindowInitializeCallback * mOgreInitCb
Definition: OgreWindow.h:185
virtual void keyReleaseEvent(QKeyEvent *ev)
virtual void mousePressEvent(QMouseEvent *ev)
~OgreSingletonHelper()
Definition: OgreWindow.h:123
virtual void onMouseMoveEvent(QMouseEvent *event)
Definition: OgreWindow.h:100
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
virtual void mouseMoveEvent(QMouseEvent *ev)
virtual ~QtOgreWindowInitializeCallback()
Definition: OgreWindow.h:110
QtOgreWindowInitializeCallback()
Definition: OgreWindow.h:109
Ogre::RenderWindow * mRenderWindow
Definition: OgreWindow.h:187
virtual void renderNow()
QtOgreWindow(QtOgreWindowInitializeCallback *initCb, QWindow *parent=NULL)
void setAnimating(bool animating)
QtOgreWindowEventListener * mEventListener
Definition: OgreWindow.h:186
virtual void wheelEvent(QWheelEvent *ev)
bool mUpdatePending
Definition: OgreWindow.h:189
Event listener class for forwarding Qt events from the Ogre window to another Qt widget.
Definition: OgreWindow.h:79
void setEventListener(QtOgreWindowEventListener *eventListener)
Definition: OgreWindow.h:144
virtual void onDropEvent(QDropEvent *event)
Definition: OgreWindow.h:88
virtual void onKeyPressEvent(QKeyEvent *event)
Definition: OgreWindow.h:90
virtual bool event(QEvent *event)
virtual void renderLater()
Definition: OgreWindow.h:131
virtual void onMouseReleaseEvent(QMouseEvent *event)
Definition: OgreWindow.h:98
virtual void initialize()
virtual bool eventFilter(QObject *target, QEvent *event)
virtual void mouseReleaseEvent(QMouseEvent *ev)
virtual ~QtOgreWindow()
virtual void onDragEnterEvent(QDragEnterEvent *event)
Definition: OgreWindow.h:86
Definition: OgreWindow.h:118
Ogre::RenderWindow * getRenderWindow()
Definition: OgreWindow.h:148
virtual void onKeyReleaseEvent(QKeyEvent *event)
Definition: OgreWindow.h:92
Typedefs and serialization support for uuids.
virtual void onAboutToQuit()=0
bool mAnimating
Definition: OgreWindow.h:190
virtual void keyPressEvent(QKeyEvent *ev)
virtual void onWheelEvent(QWheelEvent *event)
Definition: OgreWindow.h:94
virtual void render()
virtual void onMousePressEvent(QMouseEvent *event)
Definition: OgreWindow.h:96
QtOgreWindowEventListener()
Definition: OgreWindow.h:82
virtual void exposeEvent(QExposeEvent *ev)
Definition: OgreWindow.h:106