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.
This commit is contained in:
Robert Osfield 2010-05-22 15:45:02 +00:00
parent 0165862701
commit e826bfeb3c
8 changed files with 63 additions and 92 deletions

View File

@ -337,6 +337,9 @@ class OSG_EXPORT Image : public BufferData
virtual void operator () (osg::StateAttribute* attr, osg::NodeVisitor* nv); 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. */ /** 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; } virtual bool sendPointerEvent(int /*x*/, int /*y*/, int /*buttonMask*/) { return false; }

View File

@ -14,6 +14,9 @@
#ifndef QWEBVIEWIMAGE #ifndef QWEBVIEWIMAGE
#define 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 <osgWidget/Browser> #include <osgWidget/Browser>
#include <osgQt/QGraphicsViewAdapter> #include <osgQt/QGraphicsViewAdapter>
@ -24,25 +27,62 @@ class OSGQT_EXPORT QWebViewImage : public osgWidget::BrowserImage
{ {
public: 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; } QWebView* getQWebView() { return _webView; }
QWebPage* getQWebPage() { return _webPage; } QWebPage* getQWebPage() { return _webPage; }
QGraphicsViewAdapter* getQGraphicsViewAdapter() { return _adapter; } 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: protected:
@ -53,4 +93,6 @@ class OSGQT_EXPORT QWebViewImage : public osgWidget::BrowserImage
} }
#endif
#endif #endif

View File

@ -29,18 +29,19 @@ class OSGQT_EXPORT QWidgetImage : public osg::Image
QWidget* getQWidget() { return _widget; } QWidget* getQWidget() { return _widget; }
QGraphicsViewAdapter* getQGraphicsViewAdapter() { return _adapter; } QGraphicsViewAdapter* getQGraphicsViewAdapter() { return _adapter; }
void focusWidget(bool focus);
void clearWriteBuffer(); void clearWriteBuffer();
void render(); 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 sendPointerEvent(int x, int y, int buttonMask);
virtual bool sendKeyEvent(int key, bool keyDown); virtual bool sendKeyEvent(int key, bool keyDown);
virtual void setFrameLastRendered(const osg::FrameStamp* frameStamp);
protected: protected:
QPointer<QGraphicsViewAdapter> _adapter; QPointer<QGraphicsViewAdapter> _adapter;

View File

@ -26,7 +26,7 @@ FOREACH( mylibfolder
ENDFOREACH() ENDFOREACH()
IF (QT4_FOUND AND QT_QTWEBKIT_FOUND) IF (QT4_FOUND)
ADD_SUBDIRECTORY(osgQt) ADD_SUBDIRECTORY(osgQt)
ENDIF() ENDIF()

View File

@ -19,17 +19,17 @@ SET(LIB_PUBLIC_HEADERS
${HEADER_PATH}/Export ${HEADER_PATH}/Export
${HEADER_PATH}/QFontImplementation ${HEADER_PATH}/QFontImplementation
${HEADER_PATH}/QGraphicsViewAdapter ${HEADER_PATH}/QGraphicsViewAdapter
${HEADER_PATH}/QWebViewImage
${HEADER_PATH}/QWidgetImage ${HEADER_PATH}/QWidgetImage
${HEADER_PATH}/QWebViewImage
) )
# FIXME: For OS X, need flag for Framework or dylib # FIXME: For OS X, need flag for Framework or dylib
ADD_LIBRARY(${LIB_NAME} ADD_LIBRARY(${LIB_NAME}
${OPENSCENEGRAPH_USER_DEFINED_DYNAMIC_OR_STATIC} ${OPENSCENEGRAPH_USER_DEFINED_DYNAMIC_OR_STATIC}
${LIB_PUBLIC_HEADERS} ${LIB_PUBLIC_HEADERS}
QFontImplementation.cpp QFontImplementation.cpp
QGraphicsViewAdapter.cpp QGraphicsViewAdapter.cpp
QWebViewImage.cpp
QWidgetImage.cpp QWidgetImage.cpp
${SOURCES_H_MOC} ${SOURCES_H_MOC}
${OPENSCENEGRAPH_VERSIONINFO_RC} ${OPENSCENEGRAPH_VERSIONINFO_RC}
@ -48,7 +48,7 @@ IF(CMAKE_COMPILER_IS_GNUCXX)
STRING(REGEX REPLACE "-pedantic" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") STRING(REGEX REPLACE "-pedantic" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
ENDIF() 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}) INCLUDE_DIRECTORIES(${QT_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR})
LINK_CORELIB_DEFAULT(${LIB_NAME}) LINK_CORELIB_DEFAULT(${LIB_NAME})

View File

@ -13,7 +13,6 @@
#include <osgQt/QGraphicsViewAdapter> #include <osgQt/QGraphicsViewAdapter>
#include <osgQt/QWidgetImage> #include <osgQt/QWidgetImage>
#include <osgQt/QWebViewImage>
#include <QtOpenGL/QGLWidget> #include <QtOpenGL/QGLWidget>
@ -310,11 +309,7 @@ bool QGraphicsViewAdapter::handlePointerEvent(int x, int y, int buttonMask)
if (eventType==QEvent::MouseButtonPress) if (eventType==QEvent::MouseButtonPress)
{ {
QWidgetImage* qwidgetImage = dynamic_cast<QWidgetImage*>(_image.get()); _image->sendFocusHint(true);
if (qwidgetImage) qwidgetImage->focusWidget(true);
QWebViewImage* qwebViewImage = dynamic_cast<QWebViewImage*>(_image.get());
if (qwebViewImage) qwebViewImage->focusBrowser(true);
} }
QMouseEvent event(eventType, QPoint(x, y), qtButton, qtMouseButtons, 0); QMouseEvent event(eventType, QPoint(x, y), qtButton, qtMouseButtons, 0);

View File

@ -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 <osgQt/QWebViewImage>
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);
}
}

View File

@ -31,10 +31,11 @@ QWidgetImage::QWidgetImage( QWidget* widget )
_adapter = new QGraphicsViewAdapter(this, _widget.data()); _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); QFocusEvent event(focus ? QEvent::FocusIn : QEvent::FocusOut, Qt::OtherFocusReason);
QCoreApplication::sendEvent(_widget, &event); QCoreApplication::sendEvent(_widget, &event);
return true;
} }
void QWidgetImage::clearWriteBuffer() void QWidgetImage::clearWriteBuffer()