OpendTect  6.6
odgraphicswindow.h
Go to the documentation of this file.
1 #pragma once
2 /* -*-c++-*- OpenSceneGraph - Copyright (C) 2009 Wang Rui
3  *
4  * This library is open source and may be redistributed and/or modified under
5  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
6  * (at your option) any later version. The full license is in LICENSE file
7  * included with this distribution, and on the openscenegraph.org website.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * OpenSceneGraph Public License for more details.
13 */
14 
15 
16 #include "uiosgmod.h"
17 #include "commondefs.h"
18 #include <osgViewer/GraphicsWindow>
19 
20 #include <QMutex>
21 #include <QEvent>
22 #include <QQueue>
23 #include <QSet>
24 #include <QGLWidget>
25 #include <osg/Version>
26 
27 class QInputEvent;
28 class QGestureEvent;
29 
30 namespace osgViewer
31 {
32  class ViewerBase;
33 }
34 
35 class ODGraphicsWindow;
36 
37 #if OSG_VERSION_LESS_THAN(3, 5, 6)
38 void mGlobal(uiOSG) initQtWindowingSystem();
40 #endif
41 
49 void mGlobal(uiOSG) setViewer( osgViewer::ViewerBase *viewer );
50 
51 
52 mExpClass(uiOSG) ODGLWidget : public QGLWidget
53 {
54  typedef QGLWidget inherited;
55 
56 public:
57 
58  ODGLWidget(QWidget* parent=nullptr,
59  const QGLWidget* shareWidget=nullptr,
60  Qt::WindowFlags f=Qt::WindowFlags(),
61  bool forwardKeyEvents=false);
62  ODGLWidget(QGLContext* context,
63  QWidget* parent=nullptr,
64  const QGLWidget* shareWidget=nullptr,
65  Qt::WindowFlags f=Qt::WindowFlags(),
66  bool forwardKeyEvents=false);
67  ODGLWidget(const QGLFormat& format,
68  QWidget* parent=nullptr,
69  const QGLWidget* shareWidget=nullptr,
70  Qt::WindowFlags f=Qt::WindowFlags(),
71  bool forwardKeyEvents=false);
72  virtual ~ODGLWidget();
73 
75  { _gw = gw; }
76  inline ODGraphicsWindow* getGraphicsWindow() { return _gw; }
77  inline const ODGraphicsWindow* getGraphicsWindow() const { return _gw; }
78 
79  inline bool getForwardKeyEvents() const
80  { return _forwardKeyEvents; }
81  virtual void setForwardKeyEvents( bool yn )
82  { _forwardKeyEvents = yn; }
83 
84  inline bool getTouchEventsEnabled() const
85  { return _touchEventsEnabled; }
86  void setTouchEventsEnabled(bool yn);
87 
88  void setKeyboardModifiers(QInputEvent*);
89 
90  virtual void keyPressEvent(QKeyEvent*);
91  virtual void keyReleaseEvent(QKeyEvent*);
92  virtual void mousePressEvent(QMouseEvent*);
93  virtual void mouseReleaseEvent(QMouseEvent*);
94  virtual void mouseDoubleClickEvent(QMouseEvent*);
95  virtual void mouseMoveEvent(QMouseEvent*);
96  virtual void wheelEvent(QWheelEvent*);
97  virtual bool gestureEvent(QGestureEvent*);
98 
99 protected:
100 
102  {
103  QMutexLocker lock(&_deferredEventQueueMutex);
104  return _deferredEventQueue.count();
105  }
107  QEvent::Type removeEventType = QEvent::None )
108  {
109  QMutexLocker lock(&_deferredEventQueueMutex);
110 
111  if (removeEventType != QEvent::None)
112  {
113  if (_deferredEventQueue.removeOne(removeEventType))
114  _eventCompressor.remove(eventType);
115  }
116 
117  if (_eventCompressor.find(eventType) == _eventCompressor.end())
118  {
119  _deferredEventQueue.enqueue(eventType);
120  _eventCompressor.insert(eventType);
121  }
122  }
124 
125  friend class ODGraphicsWindow;
127 
129  QQueue<QEvent::Type> _deferredEventQueue;
130  QSet<QEvent::Type> _eventCompressor;
131 
133 
136 
137  virtual void resizeEvent(QResizeEvent*);
138  virtual void moveEvent(QMoveEvent*);
139  virtual void glDraw();
140  virtual bool event(QEvent*);
141 };
142 
143 
144 mExpClass(uiOSG) ODGraphicsWindow : public osgViewer::GraphicsWindow
145 {
146 public:
147  ODGraphicsWindow(osg::GraphicsContext::Traits*,
148  QWidget* parent=nullptr,
149  const QGLWidget* shareWidget=0,
150  Qt::WindowFlags f=Qt::WindowFlags());
152  virtual ~ODGraphicsWindow();
153 
154  inline ODGLWidget* getGLWidget() { return _widget; }
155  inline const ODGLWidget* getGLWidget() const { return _widget; }
156 
157  struct WindowData : public osg::Referenced
158  {
159  WindowData( ODGLWidget* widget = nullptr, QWidget* parent = nullptr )
160  : _widget(widget), _parent(parent) {}
161 
163  QWidget* _parent;
164  };
165 
166  bool init(QWidget* parent,
167  const QGLWidget* shareWidget,
168  Qt::WindowFlags f );
169 
170  static QGLFormat traits2qglFormat(
171  const osg::GraphicsContext::Traits*);
172  static void qglFormat2traits(const QGLFormat& format,
173  osg::GraphicsContext::Traits*);
174  static osg::GraphicsContext::Traits* createTraits(const QGLWidget* widget);
175 
176  virtual bool setWindowRectangleImplementation(int x,int y,
177  int width,int height);
178  virtual void getWindowRectangle(int& x,int& y,int& width,
179  int& height);
180  virtual bool setWindowDecorationImplementation(bool yn);
181  virtual bool getWindowDecoration() const;
182  virtual void grabFocus();
184  virtual void raiseWindow();
185  virtual void setWindowName(const std::string&);
186  virtual std::string getWindowName();
187  virtual void useCursor(bool cursoron);
188  virtual void setCursor(MouseCursor);
189  inline bool getTouchEventsEnabled() const
190  { return _widget->getTouchEventsEnabled(); }
191  virtual void setTouchEventsEnabled( bool yn )
192  { _widget->setTouchEventsEnabled(yn); }
193 
194  virtual bool valid() const;
195  virtual bool realizeImplementation();
196  virtual bool isRealizedImplementation() const;
197  virtual void closeImplementation();
201  virtual void runOperations();
202 
203  virtual void requestWarpPointer(float x,float y);
204 
205 protected:
206 
207  friend class ODGLWidget;
210  QCursor _currentCursor;
211  bool _realized;
212 };
ODGraphicsWindow::ODGraphicsWindow
ODGraphicsWindow(ODGLWidget *widget)
ODGLWidget::setTouchEventsEnabled
void setTouchEventsEnabled(bool yn)
ODGLWidget::_touchEventsEnabled
bool _touchEventsEnabled
Definition: odgraphicswindow.h:132
ODGLWidget::keyReleaseEvent
virtual void keyReleaseEvent(QKeyEvent *)
setViewer
void setViewer(osgViewer::ViewerBase *viewer)
ODGraphicsWindow::getGLWidget
ODGLWidget * getGLWidget()
Definition: odgraphicswindow.h:154
ODGraphicsWindow::useCursor
virtual void useCursor(bool cursoron)
ODGraphicsWindow::setTouchEventsEnabled
virtual void setTouchEventsEnabled(bool yn)
Definition: odgraphicswindow.h:191
ODGraphicsWindow::setWindowRectangleImplementation
virtual bool setWindowRectangleImplementation(int x, int y, int width, int height)
ODGraphicsWindow::requestWarpPointer
virtual void requestWarpPointer(float x, float y)
ODGLWidget::processDeferredEvents
void processDeferredEvents()
ODGLWidget::resizeEvent
virtual void resizeEvent(QResizeEvent *)
mGlobal
#define mGlobal(module)
Definition: commondefs.h:180
ODGLWidget::wheelEvent
virtual void wheelEvent(QWheelEvent *)
ODGLWidget
Definition: odgraphicswindow.h:53
ODGraphicsWindow::getWindowRectangle
virtual void getWindowRectangle(int &x, int &y, int &width, int &height)
commondefs.h
ODGLWidget::getNumDeferredEvents
int getNumDeferredEvents()
Definition: odgraphicswindow.h:101
ODGLWidget::_gw
ODGraphicsWindow * _gw
Definition: odgraphicswindow.h:126
ODGLWidget::enqueueDeferredEvent
void enqueueDeferredEvent(QEvent::Type eventType, QEvent::Type removeEventType=QEvent::None)
Definition: odgraphicswindow.h:106
mExpClass
#define mExpClass(module)
Definition: commondefs.h:177
ODGraphicsWindow::closeImplementation
virtual void closeImplementation()
ODGLWidget::ODGLWidget
ODGLWidget(QWidget *parent=nullptr, const QGLWidget *shareWidget=nullptr, Qt::WindowFlags f=Qt::WindowFlags(), bool forwardKeyEvents=false)
ODGraphicsWindow::traits2qglFormat
static QGLFormat traits2qglFormat(const osg::GraphicsContext::Traits *)
ODGraphicsWindow::_widget
ODGLWidget * _widget
Definition: odgraphicswindow.h:208
ODGLWidget::_deferredEventQueueMutex
QMutex _deferredEventQueueMutex
Definition: odgraphicswindow.h:128
ODGLWidget::glDraw
virtual void glDraw()
ODGLWidget::_deferredEventQueue
QQueue< QEvent::Type > _deferredEventQueue
Definition: odgraphicswindow.h:129
ODGraphicsWindow::valid
virtual bool valid() const
ODGLWidget::getGraphicsWindow
ODGraphicsWindow * getGraphicsWindow()
Definition: odgraphicswindow.h:76
ODGraphicsWindow::realizeImplementation
virtual bool realizeImplementation()
ODGraphicsWindow::_ownsWidget
bool _ownsWidget
Definition: odgraphicswindow.h:209
ODGraphicsWindow::makeCurrentImplementation
virtual bool makeCurrentImplementation()
ODGraphicsWindow::getWindowDecoration
virtual bool getWindowDecoration() const
ODGraphicsWindow::WindowData::_parent
QWidget * _parent
Definition: odgraphicswindow.h:163
ODGraphicsWindow::WindowData
Definition: odgraphicswindow.h:158
ODGLWidget::_eventCompressor
QSet< QEvent::Type > _eventCompressor
Definition: odgraphicswindow.h:130
ODGLWidget::mouseMoveEvent
virtual void mouseMoveEvent(QMouseEvent *)
ODGLWidget::mousePressEvent
virtual void mousePressEvent(QMouseEvent *)
ODGLWidget::keyPressEvent
virtual void keyPressEvent(QKeyEvent *)
Angle::Type
Type
Definition: angles.h:26
ODGraphicsWindow::swapBuffersImplementation
virtual void swapBuffersImplementation()
ODGraphicsWindow::setWindowDecorationImplementation
virtual bool setWindowDecorationImplementation(bool yn)
ODGLWidget::mouseReleaseEvent
virtual void mouseReleaseEvent(QMouseEvent *)
ODGLWidget::setKeyboardModifiers
void setKeyboardModifiers(QInputEvent *)
ODGraphicsWindow::runOperations
virtual void runOperations()
ODGraphicsWindow::qglFormat2traits
static void qglFormat2traits(const QGLFormat &format, osg::GraphicsContext::Traits *)
ODGraphicsWindow::init
bool init(QWidget *parent, const QGLWidget *shareWidget, Qt::WindowFlags f)
ODGraphicsWindow::WindowData::WindowData
WindowData(ODGLWidget *widget=nullptr, QWidget *parent=nullptr)
Definition: odgraphicswindow.h:159
ODGraphicsWindow::WindowData::_widget
ODGLWidget * _widget
Definition: odgraphicswindow.h:162
ODGraphicsWindow::releaseContextImplementation
virtual bool releaseContextImplementation()
ODGraphicsWindow::~ODGraphicsWindow
virtual ~ODGraphicsWindow()
ODGLWidget::ODGLWidget
ODGLWidget(const QGLFormat &format, QWidget *parent=nullptr, const QGLWidget *shareWidget=nullptr, Qt::WindowFlags f=Qt::WindowFlags(), bool forwardKeyEvents=false)
ODGraphicsWindow::_currentCursor
QCursor _currentCursor
Definition: odgraphicswindow.h:210
ODGraphicsWindow::setWindowName
virtual void setWindowName(const std::string &)
ODGLWidget::ODGLWidget
ODGLWidget(QGLContext *context, QWidget *parent=nullptr, const QGLWidget *shareWidget=nullptr, Qt::WindowFlags f=Qt::WindowFlags(), bool forwardKeyEvents=false)
ODGraphicsWindow::setCursor
virtual void setCursor(MouseCursor)
ODGLWidget::getForwardKeyEvents
bool getForwardKeyEvents() const
Definition: odgraphicswindow.h:79
ODGLWidget::_devicePixelRatio
qreal _devicePixelRatio
Definition: odgraphicswindow.h:135
ODGLWidget::setForwardKeyEvents
virtual void setForwardKeyEvents(bool yn)
Definition: odgraphicswindow.h:81
ODGraphicsWindow::ODGraphicsWindow
ODGraphicsWindow(osg::GraphicsContext::Traits *, QWidget *parent=nullptr, const QGLWidget *shareWidget=0, Qt::WindowFlags f=Qt::WindowFlags())
ODGLWidget::moveEvent
virtual void moveEvent(QMoveEvent *)
Network::None
@ None
Definition: networkcommon.h:33
ODGraphicsWindow::raiseWindow
virtual void raiseWindow()
ODGraphicsWindow::getGLWidget
const ODGLWidget * getGLWidget() const
Definition: odgraphicswindow.h:155
ODGraphicsWindow::createTraits
static osg::GraphicsContext::Traits * createTraits(const QGLWidget *widget)
ODGLWidget::setGraphicsWindow
void setGraphicsWindow(ODGraphicsWindow *gw)
Definition: odgraphicswindow.h:74
ODGLWidget::~ODGLWidget
virtual ~ODGLWidget()
MouseCursor
Definition of a mouse cursor, can be either a predefined shape (from the enum, or a file....
Definition: mousecursor.h:26
ODGraphicsWindow
Definition: odgraphicswindow.h:145
ODGLWidget::_forwardKeyEvents
bool _forwardKeyEvents
Definition: odgraphicswindow.h:134
ODGraphicsWindow::getWindowName
virtual std::string getWindowName()
ODGraphicsWindow::grabFocus
virtual void grabFocus()
ODGLWidget::getTouchEventsEnabled
bool getTouchEventsEnabled() const
Definition: odgraphicswindow.h:84
ODGraphicsWindow::ODGLWidget
friend class ODGLWidget
Definition: odgraphicswindow.h:207
ODGraphicsWindow::getTouchEventsEnabled
bool getTouchEventsEnabled() const
Definition: odgraphicswindow.h:189
ODGLWidget::mouseDoubleClickEvent
virtual void mouseDoubleClickEvent(QMouseEvent *)
ODGLWidget::gestureEvent
virtual bool gestureEvent(QGestureEvent *)
ODGraphicsWindow::grabFocusIfPointerInWindow
virtual void grabFocusIfPointerInWindow()
ODGraphicsWindow::isRealizedImplementation
virtual bool isRealizedImplementation() const
ODGLWidget::inherited
QGLWidget inherited
Definition: odgraphicswindow.h:54
ODGLWidget::getGraphicsWindow
const ODGraphicsWindow * getGraphicsWindow() const
Definition: odgraphicswindow.h:77
osgViewer
Definition: visdata.h:25
ODGLWidget::event
virtual bool event(QEvent *)
ODGraphicsWindow::_realized
bool _realized
Definition: odgraphicswindow.h:211

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B.V. 1995-2021