From e826bfeb3cd7e8b9f76f7f3919ce8bd0a262f1b4 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 22 May 2010 15:45:02 +0000 Subject: [PATCH] Refactored osgQt so that QWebViewImage is now entirely implementated in the header, and osgQt itself no longer compiles it, leaving it to only applications that require it to include the header and it's implementation and with ith the QWebKit dependency. --- include/osg/Image | 3 ++ include/osgQt/QWebViewImage | 58 ++++++++++++++++++++---- include/osgQt/QWidgetImage | 5 ++- src/CMakeLists.txt | 2 +- src/osgQt/CMakeLists.txt | 6 +-- src/osgQt/QGraphicsViewAdapter.cpp | 7 +-- src/osgQt/QWebViewImage.cpp | 71 ------------------------------ src/osgQt/QWidgetImage.cpp | 3 +- 8 files changed, 63 insertions(+), 92 deletions(-) delete mode 100644 src/osgQt/QWebViewImage.cpp diff --git a/include/osg/Image b/include/osg/Image index 21bad3ae1..488e7361b 100644 --- a/include/osg/Image +++ b/include/osg/Image @@ -337,6 +337,9 @@ class OSG_EXPORT Image : public BufferData virtual void operator () (osg::StateAttribute* attr, osg::NodeVisitor* nv); }; + /** method for hinting whether to enable or disable focus to images acting as front ends to interactive surfaces such as a vnc or browser window. Return true if handled. */ + virtual bool sendFocusHint(bool focus) { return false; } + /** method for sending pointer events to images that are acting as front ends to interactive surfaces such as a vnc or browser window. Return true if handled. */ virtual bool sendPointerEvent(int /*x*/, int /*y*/, int /*buttonMask*/) { return false; } diff --git a/include/osgQt/QWebViewImage b/include/osgQt/QWebViewImage index 7149b750d..c8d31d3ab 100644 --- a/include/osgQt/QWebViewImage +++ b/include/osgQt/QWebViewImage @@ -14,6 +14,9 @@ #ifndef QWEBVIEWIMAGE #define QWEBVIEWIMAGE +// 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) + #include #include @@ -24,25 +27,62 @@ class OSGQT_EXPORT QWebViewImage : public osgWidget::BrowserImage { public: - QWebViewImage(); + QWebViewImage() + { + // make sure we have a valid QApplication before we start creating widgets. + getOrCreateQApplication(); - virtual void navigateTo(const std::string& url); + _webView = new QWebView; + + _webPage = new QWebPage; + _webPage->settings()->setAttribute(QWebSettings::JavascriptEnabled, true); + _webPage->settings()->setAttribute(QWebSettings::PluginsEnabled, true); + + _webView->setPage(_webPage); + + _adapter = new QGraphicsViewAdapter(this, _webView.data()); + } + + virtual void navigateTo(const std::string& url) + { + _webView->load(QUrl(url.c_str())); + } QWebView* getQWebView() { return _webView; } QWebPage* getQWebPage() { return _webPage; } QGraphicsViewAdapter* getQGraphicsViewAdapter() { return _adapter; } - void focusBrowser(bool focus); + void clearWriteBuffer() + { + _adapter->clearWriteBuffer(); + } - void clearWriteBuffer(); + void render() + { + _adapter->render(); + } - void render(); + virtual bool sendFocusHint(bool focus) + { + QFocusEvent event(focus ? QEvent::FocusIn : QEvent::FocusOut, Qt::OtherFocusReason); + QCoreApplication::sendEvent(_webPage, &event); + return true; + } - virtual void setFrameLastRendered(const osg::FrameStamp* frameStamp); + virtual bool sendPointerEvent(int x, int y, int buttonMask) + { + return _adapter->sendPointerEvent(x,y,buttonMask); + } - virtual bool sendPointerEvent(int x, int y, int buttonMask); + virtual bool sendKeyEvent(int key, bool keyDown) + { + return QWebViewImage::_adapter->sendKeyEvent(key, keyDown); + } - virtual bool sendKeyEvent(int key, bool keyDown); + virtual void setFrameLastRendered(const osg::FrameStamp* frameStamp) + { + _adapter->setFrameLastRendered(frameStamp); + } protected: @@ -53,4 +93,6 @@ class OSGQT_EXPORT QWebViewImage : public osgWidget::BrowserImage } +#endif + #endif \ No newline at end of file diff --git a/include/osgQt/QWidgetImage b/include/osgQt/QWidgetImage index 79ba0867a..cca59e86c 100644 --- a/include/osgQt/QWidgetImage +++ b/include/osgQt/QWidgetImage @@ -29,18 +29,19 @@ class OSGQT_EXPORT QWidgetImage : public osg::Image QWidget* getQWidget() { return _widget; } QGraphicsViewAdapter* getQGraphicsViewAdapter() { return _adapter; } - void focusWidget(bool focus); void clearWriteBuffer(); void render(); - virtual void setFrameLastRendered(const osg::FrameStamp* frameStamp); + virtual bool sendFocusHint(bool focus); virtual bool sendPointerEvent(int x, int y, int buttonMask); virtual bool sendKeyEvent(int key, bool keyDown); + virtual void setFrameLastRendered(const osg::FrameStamp* frameStamp); + protected: QPointer _adapter; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7c87a4992..ba600a381 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -26,7 +26,7 @@ FOREACH( mylibfolder ENDFOREACH() -IF (QT4_FOUND AND QT_QTWEBKIT_FOUND) +IF (QT4_FOUND) ADD_SUBDIRECTORY(osgQt) ENDIF() diff --git a/src/osgQt/CMakeLists.txt b/src/osgQt/CMakeLists.txt index a9fd068e4..69cc12f11 100644 --- a/src/osgQt/CMakeLists.txt +++ b/src/osgQt/CMakeLists.txt @@ -19,17 +19,17 @@ SET(LIB_PUBLIC_HEADERS ${HEADER_PATH}/Export ${HEADER_PATH}/QFontImplementation ${HEADER_PATH}/QGraphicsViewAdapter - ${HEADER_PATH}/QWebViewImage ${HEADER_PATH}/QWidgetImage + ${HEADER_PATH}/QWebViewImage ) + # FIXME: For OS X, need flag for Framework or dylib ADD_LIBRARY(${LIB_NAME} ${OPENSCENEGRAPH_USER_DEFINED_DYNAMIC_OR_STATIC} ${LIB_PUBLIC_HEADERS} QFontImplementation.cpp QGraphicsViewAdapter.cpp - QWebViewImage.cpp QWidgetImage.cpp ${SOURCES_H_MOC} ${OPENSCENEGRAPH_VERSIONINFO_RC} @@ -48,7 +48,7 @@ IF(CMAKE_COMPILER_IS_GNUCXX) STRING(REGEX REPLACE "-pedantic" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") ENDIF() -TARGET_LINK_LIBRARIES(${LIB_NAME} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTOPENGL_LIBRARY} ${QT_QTWEBKIT_LIBRARY}) +TARGET_LINK_LIBRARIES(${LIB_NAME} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTOPENGL_LIBRARY}) INCLUDE_DIRECTORIES(${QT_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR}) LINK_CORELIB_DEFAULT(${LIB_NAME}) diff --git a/src/osgQt/QGraphicsViewAdapter.cpp b/src/osgQt/QGraphicsViewAdapter.cpp index e152137fb..2aac4ebe8 100644 --- a/src/osgQt/QGraphicsViewAdapter.cpp +++ b/src/osgQt/QGraphicsViewAdapter.cpp @@ -13,7 +13,6 @@ #include #include -#include #include @@ -310,11 +309,7 @@ bool QGraphicsViewAdapter::handlePointerEvent(int x, int y, int buttonMask) if (eventType==QEvent::MouseButtonPress) { - QWidgetImage* qwidgetImage = dynamic_cast(_image.get()); - if (qwidgetImage) qwidgetImage->focusWidget(true); - - QWebViewImage* qwebViewImage = dynamic_cast(_image.get()); - if (qwebViewImage) qwebViewImage->focusBrowser(true); + _image->sendFocusHint(true); } QMouseEvent event(eventType, QPoint(x, y), qtButton, qtMouseButtons, 0); diff --git a/src/osgQt/QWebViewImage.cpp b/src/osgQt/QWebViewImage.cpp deleted file mode 100644 index c973db6e4..000000000 --- a/src/osgQt/QWebViewImage.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* -*-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. -*/ - -#include - -namespace osgQt -{ - -QWebViewImage::QWebViewImage() -{ - // make sure we have a valid QApplication before we start creating widgets. - getOrCreateQApplication(); - - _webView = new QWebView; - - _webPage = new QWebPage; - _webPage->settings()->setAttribute(QWebSettings::JavascriptEnabled, true); - _webPage->settings()->setAttribute(QWebSettings::PluginsEnabled, true); - - _webView->setPage(_webPage); - - _adapter = new QGraphicsViewAdapter(this, _webView.data()); -} - -void QWebViewImage::navigateTo(const std::string& url) -{ - _webView->load(QUrl(url.c_str())); -} - -void QWebViewImage::focusBrowser(bool focus) -{ - QFocusEvent event(focus ? QEvent::FocusIn : QEvent::FocusOut, Qt::OtherFocusReason); - QCoreApplication::sendEvent(_webPage, &event); -} - -void QWebViewImage::clearWriteBuffer() -{ - _adapter->clearWriteBuffer(); -} - -void QWebViewImage::render() -{ - _adapter->render(); -} - -void QWebViewImage::setFrameLastRendered(const osg::FrameStamp* frameStamp) -{ - _adapter->setFrameLastRendered(frameStamp); -} - -bool QWebViewImage::sendPointerEvent(int x, int y, int buttonMask) -{ - return _adapter->sendPointerEvent(x,y,buttonMask); -} - -bool QWebViewImage::sendKeyEvent(int key, bool keyDown) -{ - return QWebViewImage::_adapter->sendKeyEvent(key, keyDown); -} - -} diff --git a/src/osgQt/QWidgetImage.cpp b/src/osgQt/QWidgetImage.cpp index 95743da97..9a72b183c 100644 --- a/src/osgQt/QWidgetImage.cpp +++ b/src/osgQt/QWidgetImage.cpp @@ -31,10 +31,11 @@ QWidgetImage::QWidgetImage( QWidget* widget ) _adapter = new QGraphicsViewAdapter(this, _widget.data()); } -void QWidgetImage::focusWidget(bool focus) +bool QWidgetImage::sendFocusHint(bool focus) { QFocusEvent event(focus ? QEvent::FocusIn : QEvent::FocusOut, Qt::OtherFocusReason); QCoreApplication::sendEvent(_widget, &event); + return true; } void QWidgetImage::clearWriteBuffer()