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) 2025 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 
104  virtual bool processTouchEvent( QTouchEvent* touchEvent );
105 
106  virtual void mouseMoveEvent( QMouseEvent* event );
107 
108  virtual void focusInEvent( QFocusEvent * event );
109  virtual void focusOutEvent( QFocusEvent * event );
110  virtual bool event( QEvent* event );
111 
113  static QGLFormat createFormatFromTraits(
114  const osg::GraphicsContext::Traits* contextTraits);
115 
116  virtual QSize sizeHint() const;
117 
119  virtual void slot_onRightClickTerrainMenuRequest( double mouseX,
120  double mouseY, DtChannel* channel );
121 
123  virtual void slot_onRightClickSelectionMenuRequest( double mouseX,
124  double mouseY, DtChannel* channel );
125 
127  virtual void slot_onWindowConfigurationModified( const DtWindowConfiguration& newWindowConfig );
128 
129  boost::signalslib::signal<void (DtOsgAdapterQtWidget*)> signal_mouseEnter;
130  boost::signalslib::signal<void (DtOsgAdapterQtWidget*)> signal_mouseExit;
131 
132  signals:
134  void devicePixelRatioChanged();
135 
136  protected:
137  void init();
138 
141  virtual bool channelInThisWidget( const DtChannel& channel );
142 
143  // height, width are going to be in 4K coordinates for example, and not
144  // scaled Qt coordinates
145  virtual void resizeGL(int width, int height) override;
146  virtual void paintGL() override;
147  virtual void paintEvent(QPaintEvent* e) override;
148  virtual void resizeEvent(QResizeEvent* resizeEvent) override;
149 
150  virtual void keyPressEvent(QKeyEvent *);
151  virtual void keyReleaseEvent(QKeyEvent *);
152  virtual void mousePressEvent( QMouseEvent* event );
153  virtual void mouseReleaseEvent( QMouseEvent* event );
154  virtual void enterEvent( QEvent* event );
155  virtual void leaveEvent( QEvent* event );
156 
157  int qtButtonToOsgButton( QMouseEvent* event);
158  virtual void mouseDoubleClickEvent(QMouseEvent* event);
159  virtual void wheelEvent(QWheelEvent *);
160  virtual void closeEvent(QCloseEvent*);
161  virtual void slot_ctrlEnterPressed( const DtChannel& channel );
162 
167  virtual void getTouchPointPositions( const QTouchEvent& touchEvent,
168  osg::Vec2& p0, osg::Vec2& p1 );
169  //virtual void getTouchPointPosition( const QTouchEvent& touchEvent, int index,
170  // osg::Vec2& p );
171 
174  virtual void startOsgTouch( const osg::Vec2& p0, const osg::Vec2& p1, int pointCount );
175 
178  virtual void continueOsgTouch( const osg::Vec2& p0, const osg::Vec2& p1 );
179 
182  virtual void endOsgTouch( const osg::Vec2& p0 );
183 
189  virtual void cleanupOpenGlResources(void);
190 
191  protected slots:
193  void emit_signal_pixelRatioChanged();
194 
195  protected:
196 
198 
202 
203  // The VRV single opengl context.
204  QOpenGLContext* myOpenGLContext;
205 
206  // These are here to work around a bug in Qt 4.5 (and other versions??) where
207  // a doubleclick mouse event is followed by a stray release event.
211 
212  // This is used to suppress the stray left-mouse events that windows insists
213  // on generating when using multi-touch effects
215 
216  // int because we get ints from Qt (unless we are using qml for everything)
218 
220  };
221 
226  {
227  public:
228 
230 
232  static DtOsgAdapterQtWidgetCreator& instance(DtDe& de);
233 
235  static void registerInstance(DtDe& de, DtOsgAdapterQtWidgetCreator* creator);
236 
238  virtual DtOsgAdapterQtWidget* create( DtDe& de,
239  osg::GraphicsContext::Traits* contextTraits, const QGLFormat& format,
240  QWidget * parent, Qt::WindowFlags windowFlags);
241 
242  protected:
243 
244  // This context is used to provide a single opengl context for VRV.
245  // Note that other contexts exist in Qt, but this is the context VRV
246  // will use to store opengl state and draw with.
247  QOpenGLContext* myOpenGLContext = nullptr;
248  };
249 }
250 
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:225
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:210
DtDe & myDe
Definition: DtOsgAdapterQtWidget.h:199
Definition: featureContext.h:36
boost::signalslib::signal< void(DtOsgAdapterQtWidget *)> signal_mouseEnter
Definition: DtOsgAdapterQtWidget.h:129
This owns a list of channel configurations.
Definition: DtWindowConfiguration.h:26
#define DT_DLL_VRVOSGQT
Definition: vrvOsgQt.h:22
int myOldDevicePixelRatio
Definition: DtOsgAdapterQtWidget.h:217
DtOsgAdapterQtWidgetLogic * myLogic
Definition: DtOsgAdapterQtWidget.h:201
DtSignalConnectionManager myConnections
Definition: DtOsgAdapterQtWidget.h:219
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
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:200
Base class to provide boost signal/slot management.
osg::ref_ptr< QGLWidgetAsOsgContext > myEmbeddedWindow
Definition: DtOsgAdapterQtWidget.h:197
boost::signalslib::signal< void(DtOsgAdapterQtWidget *)> signal_mouseExit
Definition: DtOsgAdapterQtWidget.h:130
QOpenGLContext * myOpenGLContext
Definition: DtOsgAdapterQtWidget.h:204
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:76
int myPinchingTouchCount
Definition: DtOsgAdapterQtWidget.h:214
bool myMiddlePressed
Definition: DtOsgAdapterQtWidget.h:209
bool myLeftPressed
Definition: DtOsgAdapterQtWidget.h:208

Document ID: Generated on Thu Oct 23 22:29:17 EDT 2025 from SVN revision 280951
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)