OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
QGraphicsViewAdapter.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version. The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * OpenSceneGraph Public License for more details.
12 */
13 
14 #ifndef QGRAPHICSVIEWADAPTER
15 #define QGRAPHICSVIEWADAPTER
16 
17 #include <QGLWidget>
18 
19 #include <osg/Image>
20 #include <osg/observer_ptr>
21 #include <osgQt/Export>
22 #include <osgQt/Version>
23 
24 #include <QPointer>
25 #include <QGraphicsScene>
26 #include <QGraphicsView>
27 #include <QApplication>
28 #include <QPainter>
29 #include <QtEvents>
30 
31 namespace osgQt
32 {
33 
34 extern OSGQT_EXPORT QCoreApplication* getOrCreateQApplication();
35 
36 class OSGQT_EXPORT QGraphicsViewAdapter : public QObject
37 {
38  Q_OBJECT
39 
40  public:
41 
42  QGraphicsViewAdapter(osg::Image* image, QWidget* widget);
43 
44  void setUpKeyMap();
45 
46  bool sendPointerEvent(int x, int y, int buttonMask);
47 
48 
49  bool sendKeyEvent(int key, bool keyDown);
50 
51 
52  void setFrameLastRendered(const osg::FrameStamp* frameStamp);
53 
54  void clearWriteBuffer();
55 
56  bool requiresRendering() const { return _requiresRendering; }
57  void render();
58 
59  void assignImage(unsigned int i);
60 
61  void resize(int width, int height);
62 
63  void setBackgroundColor(QColor color) { _backgroundColor = color; }
64  QColor getBackgroundColor() const { return _backgroundColor; }
65 
69  void setBackgroundWidget(QWidget* w) { _backgroundWidget = w; }
70  QWidget* getBackgroundWidget() { return _backgroundWidget; }
71 
72  QGraphicsView* getQGraphicsView() { return _graphicsView; }
73  QGraphicsScene* getQGraphicsScene() { return _graphicsScene; }
74 
75  protected:
76 
77  bool handlePointerEvent(int x, int y, int buttonMask);
78  bool handleKeyEvent(int key, bool keyDown);
79  QWidget* getWidgetAt(const QPoint& pos);
80 
83 
91 
92  int _width;
93  int _height;
94 
95  typedef std::map<int, Qt::Key> KeyMap;
96  KeyMap _keyMap;
97  Qt::KeyboardModifiers _qtKeyModifiers;
98 
100  QPointer<QGraphicsView> _graphicsView;
101  QPointer<QGraphicsScene> _graphicsScene;
102  QPointer<QWidget> _widget;
103 
106  unsigned int _previousFrameNumber;
108  unsigned int _currentRead;
109  unsigned int _currentWrite;
110  unsigned int _previousWrite;
111  QImage _qimages[3];
112 
113  virtual void customEvent ( QEvent * event ) ;
114 
115  private slots:
116 
117  void repaintRequestedSlot(const QList<QRectF> &regions);
118  void repaintRequestedSlot(const QRectF &region);
119 
120 };
121 
122 }
123 
124 #endif
std::map< int, Qt::Key > KeyMap
QPointer< QGraphicsView > _graphicsView
This class provides an object-oriented thread mutex interface.
Definition: Mutex.h:31
#define OSGQT_EXPORT
Definition: Export.h:40
QGraphicsScene * getQGraphicsScene()
osg::observer_ptr< osg::Image > _image
void setBackgroundColor(QColor color)
QPointer< QGraphicsScene > _graphicsScene
GLint GLenum GLsizei width
Definition: GLU.h:71
OSGQT_EXPORT QCoreApplication * getOrCreateQApplication()
GLint GLenum GLsizei GLsizei height
Definition: GLU.h:71
Qt::KeyboardModifiers _qtKeyModifiers