OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
QWebViewImage.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 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 #include <osgQt/Version>
30 
31 namespace osgQt
32 {
33 
35 {
36  public:
37 
39  {
40  // make sure we have a valid QApplication before we start creating widgets.
42 
43  _webView = new QWebView;
44 
45  _webPage = new QWebPage;
46  _webPage->settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
47  _webPage->settings()->setAttribute(QWebSettings::PluginsEnabled, true);
48 
49  _webView->setPage(_webPage);
50 
51  _adapter = new QGraphicsViewAdapter(this, _webView.data());
52  }
53 
54  virtual void navigateTo(const std::string& url)
55  {
56  _webView->load(QUrl(url.c_str()));
57  }
58 
59  QWebView* getQWebView() { return _webView; }
60  QWebPage* getQWebPage() { return _webPage; }
62 
64  {
65  _adapter->clearWriteBuffer();
66  }
67 
68  void render()
69  {
70  if (_adapter->requiresRendering()) _adapter->render();
71  }
72 
73  virtual bool requiresUpdateCall() const { return true; }
74  virtual void update( osg::NodeVisitor* nv ) { render(); }
75 
76  virtual bool sendFocusHint(bool focus)
77  {
78  QFocusEvent event(focus ? QEvent::FocusIn : QEvent::FocusOut, Qt::OtherFocusReason);
79  QCoreApplication::sendEvent(_webPage, &event);
80  return true;
81  }
82 
83  virtual bool sendPointerEvent(int x, int y, int buttonMask)
84  {
85  return _adapter->sendPointerEvent(x,y,buttonMask);
86  }
87 
88  virtual bool sendKeyEvent(int key, bool keyDown)
89  {
90  return QWebViewImage::_adapter->sendKeyEvent(key, keyDown);
91  }
92 
93  virtual void setFrameLastRendered(const osg::FrameStamp* frameStamp)
94  {
95  _adapter->setFrameLastRendered(frameStamp);
96  }
97 
98  protected:
99 
100  QPointer<QGraphicsViewAdapter> _adapter;
101  QPointer<QWebView> _webView;
102  QPointer<QWebPage> _webPage;
103 };
104 
105 }
106 
107 #endif
108 
109 #endif
virtual void update(osg::NodeVisitor *nv)
Definition: QWebViewImage.h:74
virtual void navigateTo(const std::string &url)
Definition: QWebViewImage.h:54
QGraphicsViewAdapter * getQGraphicsViewAdapter()
Definition: QWebViewImage.h:61
virtual bool requiresUpdateCall() const
Definition: QWebViewImage.h:73
QWebPage * getQWebPage()
Definition: QWebViewImage.h:60
QWebView * getQWebView()
Definition: QWebViewImage.h:59
QPointer< QWebPage > _webPage
virtual bool sendPointerEvent(int x, int y, int buttonMask)
Definition: QWebViewImage.h:83
virtual bool sendFocusHint(bool focus)
Definition: QWebViewImage.h:76
virtual void setFrameLastRendered(const osg::FrameStamp *frameStamp)
Definition: QWebViewImage.h:93
OSGQT_EXPORT QCoreApplication * getOrCreateQApplication()
QPointer< QGraphicsViewAdapter > _adapter
QPointer< QWebView > _webView
virtual bool sendKeyEvent(int key, bool keyDown)
Definition: QWebViewImage.h:88