root/OpenSceneGraph/trunk/include/osgQt/QGraphicsViewAdapter @ 13482

Revision 13482, 3.4 kB (checked in by robert, 10 hours ago)

From Jason Beverage, "It looks like the Callback header got accidentally removed from the CMakeLists.txt in the submission yesterday for the geometry instancing example."

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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 <osg/Image>
18#include <osg/observer_ptr>
19#include <osgQt/Export>
20
21#include <QPointer>
22#include <QGraphicsScene>
23#include <QGraphicsView>
24#include <QApplication>
25#include <QPainter>
26#include <QtEvents>
27
28namespace osgQt
29{
30
31extern OSGQT_EXPORT QCoreApplication* getOrCreateQApplication();
32
33class OSGQT_EXPORT QGraphicsViewAdapter : public QObject
34{
35    Q_OBJECT
36
37    public:
38
39        QGraphicsViewAdapter(osg::Image* image, QWidget* widget);
40
41        void setUpKeyMap();
42
43        bool sendPointerEvent(int x, int y, int buttonMask);
44
45
46        bool sendKeyEvent(int key, bool keyDown);
47
48
49        void setFrameLastRendered(const osg::FrameStamp* frameStamp);
50
51        void clearWriteBuffer();
52
53        void render();
54
55        void assignImage(unsigned int i);
56
57        void resize(int width, int height);
58
59        void setBackgroundColor(QColor color) { _backgroundColor = color; }
60        QColor getBackgroundColor() const     { return _backgroundColor; }
61
62        QGraphicsView* getQGraphicsView() { return _graphicsView; }
63        QGraphicsScene* getQGraphicsScene() { return _graphicsScene; }
64
65    protected:
66
67        bool handlePointerEvent(int x, int y, int buttonMask);
68        bool handleKeyEvent(int key, bool keyDown);
69        QWidget* getWidgetAt(const QPoint& pos);
70
71        osg::observer_ptr<osg::Image>   _image;
72
73        int                             _previousButtonMask;
74        int                             _previousMouseX;
75        int                             _previousMouseY;
76        int                             _previousQtMouseX;
77        int                             _previousQtMouseY;
78        bool                            _previousSentEvent;
79
80        int _width;
81        int _height;
82
83        typedef std::map<int, Qt::Key> KeyMap;
84        KeyMap                          _keyMap;
85        Qt::KeyboardModifiers           _qtKeyModifiers;
86
87        QColor                          _backgroundColor;
88        QPointer<QGraphicsView>         _graphicsView;
89        QPointer<QGraphicsScene>        _graphicsScene;
90        QPointer<QWidget>               _widget;
91
92        OpenThreads::Mutex              _qimagesMutex;
93        OpenThreads::Mutex              _qresizeMutex;
94        unsigned int                    _previousFrameNumber;
95        bool                            _newImageAvailable;
96        unsigned int                    _currentRead;
97        unsigned int                    _currentWrite;
98        unsigned int                    _previousWrite;
99        QImage                          _qimages[3];
100
101        virtual void customEvent ( QEvent * event ) ;
102
103    private slots:
104
105        void repaintRequestedSlot(const QList<QRectF> &regions);
106        void repaintRequestedSlot(const QRectF &region);
107
108};
109
110}
111
112#endif
Note: See TracBrowser for help on using the browser.