| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | #ifndef QGRAPHICSVIEWADAPTER |
|---|
| 15 | #define QGRAPHICSVIEWADAPTER |
|---|
| 16 | |
|---|
| 17 | #include <osg/Image> |
|---|
| 18 | #include <osg/observer_ptr> |
|---|
| 19 | |
|---|
| 20 | #include <QtWebKit/QWebSettings> |
|---|
| 21 | #include <QtWebKit/QtWebKit> |
|---|
| 22 | #include <QtGui/QGraphicsScene> |
|---|
| 23 | #include <QtGui/QGraphicsView> |
|---|
| 24 | #include <QtGui/QApplication> |
|---|
| 25 | #include <QtGui/QPainter> |
|---|
| 26 | #include <QtGui/QtEvents> |
|---|
| 27 | |
|---|
| 28 | extern QCoreApplication* getOrCreateQApplication(); |
|---|
| 29 | |
|---|
| 30 | class QGraphicsViewAdapter : public QObject |
|---|
| 31 | { |
|---|
| 32 | Q_OBJECT |
|---|
| 33 | |
|---|
| 34 | public: |
|---|
| 35 | |
|---|
| 36 | QGraphicsViewAdapter(osg::Image* image, QWidget* widget); |
|---|
| 37 | |
|---|
| 38 | void setUpKeyMap(); |
|---|
| 39 | |
|---|
| 40 | bool sendPointerEvent(int x, int y, int buttonMask); |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | bool sendKeyEvent(int key, bool keyDown); |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | void setFrameLastRendered(const osg::FrameStamp* frameStamp); |
|---|
| 47 | |
|---|
| 48 | void clearWriteBuffer(); |
|---|
| 49 | |
|---|
| 50 | void render(); |
|---|
| 51 | |
|---|
| 52 | void assignImage(unsigned int i); |
|---|
| 53 | |
|---|
| 54 | protected: |
|---|
| 55 | |
|---|
| 56 | bool handlePointerEvent(int x, int y, int buttonMask); |
|---|
| 57 | bool handleKeyEvent(int key, bool keyDown); |
|---|
| 58 | |
|---|
| 59 | osg::observer_ptr<osg::Image> _image; |
|---|
| 60 | |
|---|
| 61 | int _previousButtonMask; |
|---|
| 62 | int _previousMouseX; |
|---|
| 63 | int _previousMouseY; |
|---|
| 64 | |
|---|
| 65 | typedef std::map<int, Qt::Key> KeyMap; |
|---|
| 66 | KeyMap _keyMap; |
|---|
| 67 | Qt::KeyboardModifiers _qtKeyModifiers; |
|---|
| 68 | |
|---|
| 69 | QColor _backgroundColor; |
|---|
| 70 | QPointer<QGraphicsView> _graphicsView; |
|---|
| 71 | QPointer<QGraphicsScene> _graphicsScene; |
|---|
| 72 | |
|---|
| 73 | OpenThreads::Mutex _qimagesMutex; |
|---|
| 74 | int _previousFrameNumber; |
|---|
| 75 | bool _newImageAvailable; |
|---|
| 76 | unsigned int _currentRead; |
|---|
| 77 | unsigned int _currentWrite; |
|---|
| 78 | unsigned int _previousWrite; |
|---|
| 79 | QImage _qimages[3]; |
|---|
| 80 | |
|---|
| 81 | virtual void customEvent ( QEvent * event ) ; |
|---|
| 82 | |
|---|
| 83 | private slots: |
|---|
| 84 | |
|---|
| 85 | void repaintRequestedSlot(const QList<QRectF> ®ions); |
|---|
| 86 | |
|---|
| 87 | }; |
|---|
| 88 | |
|---|
| 89 | #endif |
|---|