From Jan Peciva, I have improved GraphicsWindowQt:
- renamed osgQt::GraphWidget to osgQt::GLWidget as it better fits to Qt naming (osgQt::GLWidget is derived from QGLWidget while recent GraphWidget... it is unclear, maybe QGraphicsView, QGraphicsScene,....) - added the code to properly manage ON_DEMAND rendering scheme (involves osgQt::setViewer() and internal HeartBeat class) - added forward key events functionality. It allows to not eat the key events by GLWidget, but it forwards them to Qt processing as well. - destroying GLWidget before GraphicsWindowQt and vice versa does not crash the application - it is possible to request particular QGLFormat in GLWidget constructor - added QtWindowingSystem class - multithread OSG rendering improvements/fixes -- From Robert Osfield, added back in getGraphWidget() method for backwards compatibility.
This commit is contained in:
@@ -15,26 +15,53 @@
|
||||
#define OSGVIEWER_GRAPHICSWINDOWQT
|
||||
|
||||
#include <osgViewer/GraphicsWindow>
|
||||
|
||||
#include <QtGui/QWidget>
|
||||
#include <QtGui/QInputEvent>
|
||||
#include <QtOpenGL/QGLWidget>
|
||||
|
||||
#include <osgQt/Export>
|
||||
|
||||
class QInputEvent;
|
||||
|
||||
namespace osgViewer {
|
||||
class ViewerBase;
|
||||
}
|
||||
|
||||
namespace osgQt
|
||||
{
|
||||
|
||||
class OSGQT_EXPORT GraphWidget : public QGLWidget
|
||||
{
|
||||
public:
|
||||
GraphWidget( const QGLFormat& format, QWidget* parent=0, const QGLWidget* shareWidget=0, Qt::WindowFlags f=0 );
|
||||
// forward declarations
|
||||
class GraphicsWindowQt;
|
||||
|
||||
inline void setGraphicsWindow( osgViewer::GraphicsWindow* gw ) { _gw = gw; }
|
||||
/// The function sets the WindowingSystem to Qt.
|
||||
void OSGQT_EXPORT initQtWindowingSystem();
|
||||
|
||||
/** The function sets the viewer that will be used after entering
|
||||
* the Qt main loop (QCoreApplication::exec()).
|
||||
*
|
||||
* The function also initializes internal structures required for proper
|
||||
* scene rendering.
|
||||
*
|
||||
* The method must be called from main thread. */
|
||||
void OSGQT_EXPORT setViewer( osgViewer::ViewerBase *viewer );
|
||||
|
||||
|
||||
class OSGQT_EXPORT GLWidget : public QGLWidget
|
||||
{
|
||||
typedef QGLWidget inherited;
|
||||
public:
|
||||
|
||||
GLWidget( QWidget* parent = NULL, const QGLWidget* shareWidget = NULL, Qt::WindowFlags f = 0, bool forwardKeyEvents = false );
|
||||
GLWidget( QGLContext* context, QWidget* parent = NULL, const QGLWidget* shareWidget = NULL, Qt::WindowFlags f = 0, bool forwardKeyEvents = false );
|
||||
GLWidget( const QGLFormat& format, QWidget* parent = NULL, const QGLWidget* shareWidget = NULL, Qt::WindowFlags f = 0, bool forwardKeyEvents = false );
|
||||
virtual ~GLWidget();
|
||||
|
||||
inline void setGraphicsWindow( GraphicsWindowQt* gw ) { _gw = gw; }
|
||||
inline GraphicsWindowQt* getGraphicsWindow() { return _gw; }
|
||||
inline const GraphicsWindowQt* getGraphicsWindow() const { return _gw; }
|
||||
|
||||
inline bool getForwardKeyEvents() const { return _forwardKeyEvents; }
|
||||
virtual void setForwardKeyEvents( bool f ) { _forwardKeyEvents = f; }
|
||||
|
||||
void setKeyboardModifiers( QInputEvent* event );
|
||||
|
||||
virtual void resizeEvent( QResizeEvent* event );
|
||||
virtual void keyPressEvent( QKeyEvent* event );
|
||||
virtual void keyReleaseEvent( QKeyEvent* event );
|
||||
virtual void mousePressEvent( QMouseEvent* event );
|
||||
@@ -44,25 +71,44 @@ public:
|
||||
virtual void wheelEvent( QWheelEvent* event );
|
||||
|
||||
protected:
|
||||
osgViewer::GraphicsWindow* _gw;
|
||||
friend class GraphicsWindowQt;
|
||||
GraphicsWindowQt* _gw;
|
||||
|
||||
bool _forwardKeyEvents;
|
||||
|
||||
virtual void resizeEvent( QResizeEvent* event );
|
||||
virtual void moveEvent( QMoveEvent* event );
|
||||
virtual void glDraw();
|
||||
virtual bool event( QEvent* event );
|
||||
};
|
||||
|
||||
class OSGQT_EXPORT GraphicsWindowQt : public osgViewer::GraphicsWindow
|
||||
{
|
||||
public:
|
||||
GraphicsWindowQt( osg::GraphicsContext::Traits* traits );
|
||||
GraphicsWindowQt( osg::GraphicsContext::Traits* traits, QWidget* parent = NULL, const QGLWidget* shareWidget = NULL, Qt::WindowFlags f = 0 );
|
||||
GraphicsWindowQt( GLWidget* widget );
|
||||
virtual ~GraphicsWindowQt();
|
||||
|
||||
inline GraphWidget* getGraphWidget() { return _widget; }
|
||||
inline const GraphWidget* getGraphWidget() const { return _widget; }
|
||||
inline GLWidget* getGLWidget() { return _widget; }
|
||||
inline const GLWidget* getGLWidget() const { return _widget; }
|
||||
|
||||
struct WindowData : public osg::Referenced
|
||||
/// deprecated
|
||||
inline GLWidget* getGraphWidget() { return _widget; }
|
||||
/// deprecated
|
||||
inline const GLWidget* getGraphWidget() const { return _widget; }
|
||||
|
||||
struct WindowData : public osg::Referenced
|
||||
{
|
||||
WindowData( GraphWidget* widget ): _widget(widget) {}
|
||||
GraphWidget* _widget;
|
||||
WindowData( GLWidget* widget = NULL, GLWidget* parent = NULL ): _widget(widget), _parent(parent) {}
|
||||
GLWidget* _widget;
|
||||
GLWidget* _parent;
|
||||
};
|
||||
|
||||
bool init();
|
||||
bool init( QWidget* parent, const QGLWidget* shareWidget, Qt::WindowFlags f );
|
||||
|
||||
static QGLFormat traits2qglFormat( const osg::GraphicsContext::Traits* traits );
|
||||
static void qglFormat2traits( const QGLFormat& format, osg::GraphicsContext::Traits* traits );
|
||||
static osg::GraphicsContext::Traits* createTraits( const QGLWidget* widget );
|
||||
|
||||
virtual bool setWindowRectangleImplementation( int x, int y, int width, int height );
|
||||
virtual void getWindowRectangle( int& x, int& y, int& width, int& height );
|
||||
@@ -87,13 +133,14 @@ public:
|
||||
virtual void requestWarpPointer( float x, float y );
|
||||
|
||||
protected:
|
||||
GraphWidget* _widget;
|
||||
friend class GLWidget;
|
||||
|
||||
GLWidget* _widget;
|
||||
bool _ownsWidget;
|
||||
QCursor _currentCursor;
|
||||
bool _initialized;
|
||||
bool _realized;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user