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

Revision 13482, 2.9 kB (checked in by robert, 79 minutes ago)

Moved widgets from VolumeEditorWidget? to TransferFunctionWidget?, and widget utilities into WidgetUtils?.

  • 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 QWEBVIEWIMAGE
15#define QWEBVIEWIMAGE
16
17// make sure this header isn't built as par of osgQt, leaving it to applications to build
18#if !defined(OSGQT_LIBRARY) && !defined(OSG_LIBRARY_STATIC)
19
20#if QT_VERSION >= 0x050000
21# include <QtWebKitWidgets>
22#else
23# include <QtWebKit>
24#endif
25
26
27#include <osgWidget/Browser>
28#include <osgQt/QGraphicsViewAdapter>
29
30namespace osgQt
31{
32
33class QWebViewImage : public osgWidget::BrowserImage
34{
35    public:
36
37        QWebViewImage()
38        {
39            // make sure we have a valid QApplication before we start creating widgets.
40            getOrCreateQApplication();
41
42            _webView = new QWebView;
43
44            _webPage = new QWebPage;
45            _webPage->settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
46            _webPage->settings()->setAttribute(QWebSettings::PluginsEnabled, true);
47
48            _webView->setPage(_webPage);
49
50            _adapter = new QGraphicsViewAdapter(this, _webView.data());
51        }
52
53        virtual void navigateTo(const std::string& url)
54        {
55            _webView->load(QUrl(url.c_str()));
56        }
57
58        QWebView* getQWebView() { return _webView; }
59        QWebPage* getQWebPage() { return _webPage; }
60        QGraphicsViewAdapter* getQGraphicsViewAdapter() { return _adapter; }
61
62        void clearWriteBuffer()
63        {
64            _adapter->clearWriteBuffer();
65        }
66
67        void render()
68        {
69            _adapter->render();
70        }
71
72        virtual bool sendFocusHint(bool focus)
73        {
74            QFocusEvent event(focus ? QEvent::FocusIn : QEvent::FocusOut, Qt::OtherFocusReason);
75            QCoreApplication::sendEvent(_webPage, &event);
76            return true;
77        }
78
79        virtual bool sendPointerEvent(int x, int y, int buttonMask)
80        {
81            return _adapter->sendPointerEvent(x,y,buttonMask);
82        }
83
84        virtual bool sendKeyEvent(int key, bool keyDown)
85        {
86            return QWebViewImage::_adapter->sendKeyEvent(key, keyDown);
87        }
88
89        virtual void setFrameLastRendered(const osg::FrameStamp* frameStamp)
90        {
91            _adapter->setFrameLastRendered(frameStamp);
92        }
93
94    protected:
95
96        QPointer<QGraphicsViewAdapter>  _adapter;
97        QPointer<QWebView>              _webView;
98        QPointer<QWebPage>              _webPage;
99};
100
101}
102
103#endif
104
105#endif
Note: See TracBrowser for help on using the browser.