VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtOsgAdapterQtWidget.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2023 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvOsgQt/vrvOsgQt.h>
13 
15 
17 
18 //We use winsock2, but QGLWidget includes windows.h so we have to get ws2 in first
19 #ifdef _WIN32
20 #include <WinSock2.h>
21 #endif
22 
23 #include <QtOpenGL/QGLWidget>
24 #include <osgViewer/Viewer>
25 #include <QtCore/QTimer>
26 
27 #include <vrvUtil/signalslib.h>
28 
29 class QTouchEvent;
30 
31 QT_BEGIN_NAMESPACE
32 class QOpenGLContext;
33 QT_END_NAMESPACE
34 
35 namespace osg
36 {
37  class GraphicsContext;
38 }
39 
40 namespace makVrv
41 {
42  class DtWindow;
43 
44  class DtChannel;
45  class DtWindowConfiguration;
46  class DtOsgAdapterQtWidgetLogic;
47  class QGLWidgetAsOsgContext;
48 
53  {
54  Q_OBJECT;
55  public:
56 
58  DtOsgAdapterQtWidget( DtDe& de, osg::GraphicsContext::Traits* contextTraits
59  , const QGLFormat& format
60  , QOpenGLContext* openGLContext
61  , QWidget * parent
62  , Qt::WindowFlags windowFlags);
63 
65  virtual ~DtOsgAdapterQtWidget();
66 
68  osgViewer::GraphicsWindow* graphicsWindow();
69 
71  void setView(DtWindow* window);
72  DtWindow* view() const;
73 
78  int widgetToNativeCoordinate(int widgetValue);
79 
84  int nativeToWidgetCoordinate(int nativeValue);
85 
87  virtual osgGA::GUIEventAdapter::KeySymbol osgKeyFromQtKeyEvent( QKeyEvent* event );
88 
91  virtual void processKeyPressEvent( QKeyEvent* keyEvent );
92 
95  virtual void processKeyReleaseEvent( QKeyEvent* keyEvent );
96 
97 
103  virtual bool processTouchEvent( QTouchEvent* touchEvent );
104 
105  virtual void mouseMoveEvent( QMouseEvent* event );
106 
107  virtual void focusInEvent( QFocusEvent * event );
108  virtual void focusOutEvent( QFocusEvent * event );
109  virtual bool event( QEvent* event );
110 
112  static QGLFormat createFormatFromTraits(
113  const osg::GraphicsContext::Traits* contextTraits);
114 
115  virtual QSize sizeHint() const;
116 
118  virtual void slot_onRightClickTerrainMenuRequest( double mouseX,
119  double mouseY, DtChannel* channel );
120 
122  virtual void slot_onRightClickSelectionMenuRequest( double mouseX,
123  double mouseY, DtChannel* channel );
124 
126  virtual void slot_onWindowConfigurationModified( const DtWindowConfiguration& newWindowConfig );
127 
128  boost::signalslib::signal<void (DtOsgAdapterQtWidget*)> signal_mouseEnter;
129  boost::signalslib::signal<void (DtOsgAdapterQtWidget*)> signal_mouseExit;
130 
131  signals:
133  void devicePixelRatioChanged();
134 
135  protected:
136  void init();
137 
140  virtual bool channelInThisWidget( const DtChannel& channel );
141 
142  // height, width are going to be in 4K coordinates for example, and not
143  // scaled Qt coordinates
144  virtual void resizeGL(int width, int height) override;
145  virtual void paintGL() override;
146  virtual void paintEvent(QPaintEvent* e) override;
147  virtual void resizeEvent(QResizeEvent* resizeEvent) override;
148 
149  virtual void keyPressEvent(QKeyEvent *);
150  virtual void keyReleaseEvent(QKeyEvent *);
151  virtual void mousePressEvent( QMouseEvent* event );
152  virtual void mouseReleaseEvent( QMouseEvent* event );
153  virtual void enterEvent( QEvent* event );
154  virtual void leaveEvent( QEvent* event );
155 
156  int qtButtonToOsgButton( QMouseEvent* event);
157  virtual void mouseDoubleClickEvent(QMouseEvent* event);
158  virtual void wheelEvent(QWheelEvent *);
159  virtual void closeEvent(QCloseEvent*);
160  virtual void slot_ctrlEnterPressed( const DtChannel& channel );
161 
166  virtual void getTouchPointPositions( const QTouchEvent& touchEvent,
167  osg::Vec2& p0, osg::Vec2& p1 );
168  //virtual void getTouchPointPosition( const QTouchEvent& touchEvent, int index,
169  // osg::Vec2& p );
170 
173  virtual void startOsgTouch( const osg::Vec2& p0, const osg::Vec2& p1 );
174 
177  virtual void continueOsgTouch( const osg::Vec2& p0, const osg::Vec2& p1 );
178 
181  virtual void endOsgTouch( const osg::Vec2& p0 );
182 
188  virtual void cleanupOpenGlResources(void);
189 
190  protected slots:
192  void emit_signal_pixelRatioChanged();
193 
194  protected:
195 
197 
201 
202  // The VRV single opengl context.
203  QOpenGLContext* myOpenGLContext;
204 
205  // These are here to work around a bug in Qt 4.5 (and other versions??) where
206  // a doubleclick mouse event is followed by a stray release event.
210 
211  // This is used to suppress the stray left-mouse events that windows insists
212  // on generating when using multi-touch effects
214 
215  // int because we get ints from Qt (unless we are using qml for everything)
217 
219  };
220 
225  {
226  public:
227 
229 
231  static DtOsgAdapterQtWidgetCreator& instance(DtDe& de);
232 
234  static void registerInstance(DtDe& de, DtOsgAdapterQtWidgetCreator* creator);
235 
237  virtual DtOsgAdapterQtWidget* create( DtDe& de,
238  osg::GraphicsContext::Traits* contextTraits, const QGLFormat& format,
239  QWidget * parent, Qt::WindowFlags windowFlags);
240 
241  protected:
242 
243  // This context is used to provide a single opengl context for VRV.
244  // Note that other contexts exist in Qt, but this is the context VRV
245  // will use to store opengl state and draw with.
246  QOpenGLContext* myOpenGLContext = nullptr;
247  };
248 }
249 
DT_DLL_EXAMPLESCENEROOTPLUGIN void init(DtDe &anIG)
Abstract Base class.
Definition: DtWindow.h:25
DtOsgAdapterQtWidgetCreator provides the mechanism for creating an extended DtOsgAdapterQtWidget.
Definition: DtOsgAdapterQtWidget.h:224
Virtual base class. Allows for RTTI and proper virtual destruction. Used by Creators, Factories, Providers, Assemblers and User Interfaces.
Definition: DtVirtualBaseClass.h:19
DtOsgAdapterQtWidget provides the mechanism for embedding an OSG context into a Qt widget...
Definition: DtOsgAdapterQtWidget.h:52
bool myRightPressed
Definition: DtOsgAdapterQtWidget.h:209
DtDe & myDe
Definition: DtOsgAdapterQtWidget.h:198
Definition: featureContext.h:37
boost::signalslib::signal< void(DtOsgAdapterQtWidget *)> signal_mouseEnter
Definition: DtOsgAdapterQtWidget.h:128
This owns a list of channel configurations.
Definition: DtWindowConfiguration.h:26
#define DT_DLL_VRVOSGQT
Definition: vrvOsgQt.h:22
int myOldDevicePixelRatio
Definition: DtOsgAdapterQtWidget.h:216
DtOsgAdapterQtWidgetLogic * myLogic
Definition: DtOsgAdapterQtWidget.h:200
DtSignalConnectionManager myConnections
Definition: DtOsgAdapterQtWidget.h:218
Contains DLL export macros.
The abstract Channel Class.
Definition: DtChannel.h:35
Contains makVrv::DtVirtualBaseClass class.
Class to manage disconnection of boost connections on deletion.
Definition: DtSignalConnectionManager.h:20
bool myIsPinching
Definition: DtOsgAdapterQtWidget.h:213
brief The Qt main window. There will be only one of these per DtDe instance. Note, this window will be destroyed by Qt when the QApp is destroyed.
Definition: DtOsgAdapterQtWidgetLogic.h:29
DtWindow * myWindow
Definition: DtOsgAdapterQtWidget.h:199
Base class to provide boost signal/slot management.
osg::ref_ptr< QGLWidgetAsOsgContext > myEmbeddedWindow
Definition: DtOsgAdapterQtWidget.h:196
boost::signalslib::signal< void(DtOsgAdapterQtWidget *)> signal_mouseExit
Definition: DtOsgAdapterQtWidget.h:129
QOpenGLContext * myOpenGLContext
Definition: DtOsgAdapterQtWidget.h:203
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer, DtDeCommunicator, as well as a DtDisplay and other things.
Definition: DtDe.h:72
bool myMiddlePressed
Definition: DtOsgAdapterQtWidget.h:208
bool myLeftPressed
Definition: DtOsgAdapterQtWidget.h:207

Document ID: Generated on Tue Sep 24 19:28:17 EDT 2024 from SVN revision 269799
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)