2010-03-04 20:15:35 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 Robert Osfield
|
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef QWEBVIEWIMAGE
|
|
|
|
#define QWEBVIEWIMAGE
|
|
|
|
|
2010-05-22 23:45:02 +08:00
|
|
|
// make sure this header isn't built as par of osgQt, leaving it to applications to build
|
|
|
|
#if !defined(OSGQT_LIBRARY) && !defined(OSG_LIBRARY_STATIC)
|
|
|
|
|
2013-06-10 22:34:25 +08:00
|
|
|
#if QT_VERSION >= 0x050000
|
|
|
|
# include <QtWebKitWidgets>
|
|
|
|
#else
|
|
|
|
# include <QtWebKit>
|
|
|
|
#endif
|
|
|
|
|
2010-06-03 02:09:34 +08:00
|
|
|
|
2010-03-04 20:15:35 +08:00
|
|
|
#include <osgWidget/Browser>
|
|
|
|
#include <osgQt/QGraphicsViewAdapter>
|
|
|
|
|
|
|
|
namespace osgQt
|
|
|
|
{
|
|
|
|
|
2010-05-25 23:52:11 +08:00
|
|
|
class QWebViewImage : public osgWidget::BrowserImage
|
2010-03-04 20:15:35 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2010-05-22 23:45:02 +08:00
|
|
|
QWebViewImage()
|
|
|
|
{
|
|
|
|
// make sure we have a valid QApplication before we start creating widgets.
|
|
|
|
getOrCreateQApplication();
|
2010-03-04 20:15:35 +08:00
|
|
|
|
2010-05-22 23:45:02 +08:00
|
|
|
_webView = new QWebView;
|
2010-03-04 20:15:35 +08:00
|
|
|
|
2010-05-22 23:45:02 +08:00
|
|
|
_webPage = new QWebPage;
|
|
|
|
_webPage->settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
|
|
|
|
_webPage->settings()->setAttribute(QWebSettings::PluginsEnabled, true);
|
2010-03-04 20:15:35 +08:00
|
|
|
|
2010-05-22 23:45:02 +08:00
|
|
|
_webView->setPage(_webPage);
|
2010-03-04 20:15:35 +08:00
|
|
|
|
2010-05-22 23:45:02 +08:00
|
|
|
_adapter = new QGraphicsViewAdapter(this, _webView.data());
|
|
|
|
}
|
2010-03-04 20:15:35 +08:00
|
|
|
|
2010-05-22 23:45:02 +08:00
|
|
|
virtual void navigateTo(const std::string& url)
|
|
|
|
{
|
|
|
|
_webView->load(QUrl(url.c_str()));
|
|
|
|
}
|
2010-03-04 20:15:35 +08:00
|
|
|
|
2010-05-22 23:45:02 +08:00
|
|
|
QWebView* getQWebView() { return _webView; }
|
|
|
|
QWebPage* getQWebPage() { return _webPage; }
|
|
|
|
QGraphicsViewAdapter* getQGraphicsViewAdapter() { return _adapter; }
|
2010-03-04 20:15:35 +08:00
|
|
|
|
2010-05-22 23:45:02 +08:00
|
|
|
void clearWriteBuffer()
|
|
|
|
{
|
|
|
|
_adapter->clearWriteBuffer();
|
|
|
|
}
|
|
|
|
|
|
|
|
void render()
|
|
|
|
{
|
2014-11-19 19:30:53 +08:00
|
|
|
if (_adapter->requiresRendering()) _adapter->render();
|
2010-05-22 23:45:02 +08:00
|
|
|
}
|
|
|
|
|
2014-11-19 19:30:53 +08:00
|
|
|
virtual bool requiresUpdateCall() const { return true; }
|
|
|
|
virtual void update( osg::NodeVisitor* nv ) { render(); }
|
|
|
|
|
2010-05-22 23:45:02 +08:00
|
|
|
virtual bool sendFocusHint(bool focus)
|
|
|
|
{
|
|
|
|
QFocusEvent event(focus ? QEvent::FocusIn : QEvent::FocusOut, Qt::OtherFocusReason);
|
|
|
|
QCoreApplication::sendEvent(_webPage, &event);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool sendPointerEvent(int x, int y, int buttonMask)
|
|
|
|
{
|
|
|
|
return _adapter->sendPointerEvent(x,y,buttonMask);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool sendKeyEvent(int key, bool keyDown)
|
|
|
|
{
|
|
|
|
return QWebViewImage::_adapter->sendKeyEvent(key, keyDown);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void setFrameLastRendered(const osg::FrameStamp* frameStamp)
|
|
|
|
{
|
|
|
|
_adapter->setFrameLastRendered(frameStamp);
|
|
|
|
}
|
2010-03-04 20:15:35 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
QPointer<QGraphicsViewAdapter> _adapter;
|
|
|
|
QPointer<QWebView> _webView;
|
|
|
|
QPointer<QWebPage> _webPage;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-05-22 23:45:02 +08:00
|
|
|
#endif
|
|
|
|
|
2010-06-01 21:32:12 +08:00
|
|
|
#endif
|