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

Revision 12139, 2.8 kB (checked in by robert, 4 years ago)

Ran:

svn propset svn:eol-style native include/*/*
svn propset svn:keywords "Author Date Id Revision" include/*/*

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