diff --git a/CMakeLists.txt b/CMakeLists.txt index d4d2bf0f8..8b863de29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,12 +28,6 @@ if(COMMAND cmake_policy) cmake_policy(SET CMP0008 OLD) endif() - # disable autolinking to qtmain as we have our own main() functions (new in Qt 5.1) - if(${CMAKE_MAJOR_VERSION} GREATER 2 OR - (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} GREATER 8) OR - (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 8 AND ${CMAKE_PATCH_VERSION} GREATER 10)) - cmake_policy(SET CMP0020 OLD) - endif() # nicer version check - but needs at least CMake 2.6.2? Worth upgrading the requirements? #if("${CMAKE_VERSION}" VERSION_GREATER 2.8.10) # or even easier (available in cmake-2.6) @@ -769,61 +763,6 @@ ENDIF() # Include macro utilities here INCLUDE(OsgMacroUtils) -OPTION(OSG_USE_QT "Enable to use Qt (build Qt-dependent libraries, plugins and examples)" ON) - -IF(OSG_USE_QT AND NOT ANDROID) -# To select a specific version of QT define DESIRED_QT_VERSION -# via cmake -DDESIRED_QT_VERSION=5 -# QUIET option disables messages if the package cannot be found. - - IF (DESIRED_QT_VERSION) - IF (DESIRED_QT_VERSION MATCHES 5) - FIND_PACKAGE(Qt5Widgets) - ELSEIF (DESIRED_QT_VERSION MATCHES 4) - FIND_PACKAGE(Qt4) - ELSE() - FIND_PACKAGE(Qt3) - ENDIF() - - ELSE() - - FIND_PACKAGE(Qt5Widgets QUIET) - - IF ( Qt5Widgets_FOUND ) - # CMake 2.8.8 or greater required - BUILDER_VERSION_GREATER(2 8 7) - IF(NOT VALID_BUILDER_VERSION) - MESSAGE( - SEND_ERROR - "Qt5 requires CMake version 2.8.8 or greater!\n" - "Update CMake or set DESIRED_QT_VERSION to less than 5 - or disable OSG_USE_QT." - ) - ENDIF( ) - ENDIF( ) - - IF ( NOT Qt5Widgets_FOUND ) - FIND_PACKAGE(Qt4) - - IF (NOT QT4_FOUND) - FIND_PACKAGE(Qt3) - ENDIF() - ENDIF() - ENDIF() - - #If we have found Qt5, let's try to top off by getting the webkit as well - IF ( Qt5Widgets_FOUND ) - FIND_PACKAGE(Qt5WebKitWidgets QUIET) - - IF(COMMAND cmake_policy) - IF(${CMAKE_MAJOR_VERSION} GREATER 2) - # Qt5 qt5_use_modules usage was causing "Policy CMP0043 is not set: Ignore COMPILE_DEFINITIONS_ properties." warnings - cmake_policy(SET CMP0043 NEW) - ENDIF() - ENDIF() - ENDIF() - -ENDIF() #optional example related dependencies IF (BUILD_OSG_EXAMPLES AND NOT ANDROID) @@ -1327,10 +1266,6 @@ SET(PKGCONFIG_FILES openscenegraph-osgVolume ) -IF(QT4_FOUND OR Qt5Widgets_FOUND ) - SET(PKGCONFIG_FILES ${PKGCONFIG_FILES} openscenegraph-osgQt) -ENDIF() - FOREACH(PKGCONFIG_FILE ${PKGCONFIG_FILES}) CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/packaging/pkgconfig/${PKGCONFIG_FILE}.pc.in ${PROJECT_BINARY_DIR}/packaging/pkgconfig/${PKGCONFIG_FILE}.pc diff --git a/CMakeModules/FindOSG.cmake b/CMakeModules/FindOSG.cmake index 3493a613d..5d8f783c0 100644 --- a/CMakeModules/FindOSG.cmake +++ b/CMakeModules/FindOSG.cmake @@ -116,7 +116,6 @@ FIND_OSG_LIBRARY(OSGUTIL_LIBRARY osgUtil) FIND_OSG_LIBRARY(OSGDB_LIBRARY osgDB) FIND_OSG_LIBRARY(OSGTEXT_LIBRARY osgText) FIND_OSG_LIBRARY(OSGWIDGET_LIBRARY osgWidget) -FIND_OSG_LIBRARY(OSGQT_LIBRARY osgQt) FIND_OSG_LIBRARY(OSGTERRAIN_LIBRARY osgTerrain) FIND_OSG_LIBRARY(OSGFX_LIBRARY osgFX) FIND_OSG_LIBRARY(OSGVIEWER_LIBRARY osgViewer) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 18e49a13d..2a0935cef 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -208,20 +208,6 @@ IF(DYNAMIC_OPENSCENEGRAPH) ENDIF() ENDIF() - IF ( (QT4_FOUND OR Qt5Widgets_FOUND) AND NOT OSG_GLES1_AVAILABLE AND NOT OSG_GLES2_AVAILABLE AND NOT OSG_GL3_AVAILABLE) - - IF ( QT4_FOUND OR Qt5Widgets_FOUND) - ADD_SUBDIRECTORY(osgviewerQt) - ADD_SUBDIRECTORY(osgqfont) - ENDIF() - - IF ( (QT4_FOUND AND QT_QTWEBKIT_FOUND) OR Qt5WebKitWidgets_FOUND ) - ADD_SUBDIRECTORY(osgQtWidgets) - ADD_SUBDIRECTORY(osgQtBrowser) - ENDIF() - - ENDIF() - IF (FLTK_FOUND AND FLTK_GL_LIBRARY) ADD_SUBDIRECTORY(osgviewerFLTK) ENDIF() diff --git a/examples/osgQtBrowser/CMakeLists.txt b/examples/osgQtBrowser/CMakeLists.txt deleted file mode 100644 index d8e5e6d16..000000000 --- a/examples/osgQtBrowser/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -SET(TARGET_SRC - osgQtBrowser.cpp -) - -IF(CMAKE_COMPILER_IS_GNUCXX) - # Remove -pedantic flag as it barfs on Qt headers - STRING(REGEX REPLACE "-pedantic" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") -ENDIF() - -if ( QT4_FOUND ) - SET(TARGET_EXTERNAL_LIBRARIES ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTOPENGL_LIBRARY} ${QT_QTWEBKIT_LIBRARY}) - INCLUDE_DIRECTORIES(${QT_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR} ${QT_QTOPENGL_INCLUDE_DIR} ${QT_QTGUI_INCLUDE_DIR} ${QT_QTWEBKIT_INCLUDE_DIR} ) -endif( QT4_FOUND ) - -SET(TARGET_ADDED_LIBRARIES osgWidget osgQt) - -#### end var setup ### -SET ( EXAMPLE_NAME osgQtBrowser ) -SETUP_EXAMPLE(${EXAMPLE_NAME}) - -IF ( Qt5Widgets_FOUND ) - qt5_use_modules( example_${EXAMPLE_NAME} Widgets OpenGL WebKitWidgets ) -ENDIF( Qt5Widgets_FOUND ) - - diff --git a/examples/osgQtBrowser/osgQtBrowser.cpp b/examples/osgQtBrowser/osgQtBrowser.cpp deleted file mode 100644 index 73028f8f7..000000000 --- a/examples/osgQtBrowser/osgQtBrowser.cpp +++ /dev/null @@ -1,145 +0,0 @@ -/* OpenSceneGraph example, osgcompositeviewer. -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -*/ - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#if QT_VERSION >= 0x050000 -# include -#else -# include -#endif - -#include - -#include -#include -#include -#include -#include - -#include -#include - - -// Thread that runs the viewer's frame loop as we can't run Qt in the background... -class ViewerFrameThread : public OpenThreads::Thread -{ - public: - - ViewerFrameThread(osgViewer::ViewerBase* viewerBase, bool doQApplicationExit): - _viewerBase(viewerBase), - _doQApplicationExit(doQApplicationExit) {} - - ~ViewerFrameThread() - { - if (isRunning()) - { - cancel(); - join(); - } - } - - int cancel() - { - _viewerBase->setDone(true); - return 0; - } - - void run() - { - int result = _viewerBase->run(); - - if (_doQApplicationExit) QApplication::exit(result); - } - - osg::ref_ptr _viewerBase; - bool _doQApplicationExit; -}; - - -int main(int argc, char **argv) -{ - // Qt requires that we construct the global QApplication before creating any widgets. - QApplication app(argc, argv); - - // use an ArgumentParser object to manage the program arguments. - osg::ArgumentParser arguments(&argc,argv); - - bool useFrameLoopThread = false; - if (arguments.read("--no-frame-thread")) useFrameLoopThread = false; - if (arguments.read("--frame-thread")) useFrameLoopThread = true; - - osg::ref_ptr image = new osgQt::QWebViewImage; - - if (arguments.argc()>1) image->navigateTo((arguments[1])); - else image->navigateTo("http://www.youtube.com/"); - - osgWidget::GeometryHints hints(osg::Vec3(0.0f,0.0f,0.0f), - osg::Vec3(1.0f,0.0f,0.0f), - osg::Vec3(0.0f,0.0f,1.0f), - osg::Vec4(1.0f,1.0f,1.0f,1.0f), - osgWidget::GeometryHints::RESIZE_HEIGHT_TO_MAINTAINCE_ASPECT_RATIO); - - - osg::ref_ptr browser = new osgWidget::Browser; - browser->assign(image.get(), hints); - - // image->focusBrowser(true); - - osg::ref_ptr viewer = new osgViewer::Viewer(arguments); - viewer->setSceneData(browser.get()); - viewer->setCameraManipulator(new osgGA::TrackballManipulator()); - viewer->addEventHandler(new osgViewer::StatsHandler); - viewer->addEventHandler(new osgViewer::WindowSizeHandler); - - if (useFrameLoopThread) - { - // create a thread to run the viewer's frame loop - ViewerFrameThread viewerThread(viewer.get(), true); - viewerThread.startThread(); - - // now start the standard Qt event loop, then exists when the viewerThead sends the QApplication::exit() signal. - return QApplication::exec(); - - } - else - { - // run the frame loop, interleaving Qt and the main OSG frame loop - while(!viewer->done()) - { - // process Qt events - this handles both events and paints the browser image - QCoreApplication::processEvents(QEventLoop::AllEvents, 100); - - viewer->frame(); - } - - return 0; - } -} diff --git a/examples/osgQtWidgets/CMakeLists.txt b/examples/osgQtWidgets/CMakeLists.txt deleted file mode 100644 index 670a29216..000000000 --- a/examples/osgQtWidgets/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -SET(TARGET_SRC - osgQtWidgets.cpp -) - -IF(CMAKE_COMPILER_IS_GNUCXX) - # Remove -pedantic flag as it barfs on Qt headers - STRING(REGEX REPLACE "-pedantic" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") -ENDIF() - -if ( QT4_FOUND ) - SET(TARGET_EXTERNAL_LIBRARIES ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTOPENGL_LIBRARY} ${QT_QTWEBKIT_LIBRARY}) - INCLUDE_DIRECTORIES(${QT_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR} ${QT_QTOPENGL_INCLUDE_DIR} ${QT_QTGUI_INCLUDE_DIR} ${QT_QTWEBKIT_INCLUDE_DIR} ) -endif( QT4_FOUND ) - -SET(TARGET_ADDED_LIBRARIES osgWidget osgQt) - -#### end var setup ### -SET ( EXAMPLE_NAME osgQtWidgets ) -SETUP_EXAMPLE(${EXAMPLE_NAME}) - -IF ( Qt5Widgets_FOUND ) - qt5_use_modules( example_${EXAMPLE_NAME} OpenGL WebKitWidgets ) -ENDIF( Qt5Widgets_FOUND ) diff --git a/examples/osgQtWidgets/osgQtWidgets.cpp b/examples/osgQtWidgets/osgQtWidgets.cpp deleted file mode 100644 index 0e1603147..000000000 --- a/examples/osgQtWidgets/osgQtWidgets.cpp +++ /dev/null @@ -1,512 +0,0 @@ -/* OpenSceneGraph example, osgcompositeviewer. -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -*/ - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -//#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - - -// Thread that runs the viewer's frame loop as we can't run Qt in the background... -class ViewerFrameThread : public OpenThreads::Thread -{ - public: - - ViewerFrameThread(osgViewer::ViewerBase* viewerBase, bool doQApplicationExit): - _viewerBase(viewerBase), - _doQApplicationExit(doQApplicationExit) {} - - ~ViewerFrameThread() - { - cancel(); - while(isRunning()) - { - OpenThreads::Thread::YieldCurrentThread(); - } - } - - int cancel() - { - _viewerBase->setDone(true); - return 0; - } - - void run() - { - int result = _viewerBase->run(); - - if (_doQApplicationExit) QApplication::exit(result); - } - - osg::ref_ptr _viewerBase; - bool _doQApplicationExit; -}; - - -class MyPushButton : public QPushButton -{ -public: - MyPushButton(const QString& text) : QPushButton(text) {} - -protected: - virtual void mousePressEvent(QMouseEvent* e) - { - bool ok = false; -#if QT_VERSION >= 0x040500 - int val = QInputDialog::getInt(this, "Get integer", "Please enter an integer between 0 and pi", 0, 0, 3, 1, &ok); -#else - int val = QInputDialog::getInteger(this, "Get integer", "Please enter an integer between 0 and pi", 0, 0, 3, 1, &ok); -#endif - std::cout << "Ok was " << (ok ? "" : "not") << " pressed, val is " << val << std::endl; - } -}; - - -//We would need to document the following somewhere in order to guide people on -//what they need to use... -// -//---------------------------------------------- -//There are two angles to consider. -// -//1. If someone wants a widget in their Qt app to be an OSG-rendered scene, they -//need GraphicsWindowQt (in the osgViewerQtContext example) or QOSGWidget (in the -//osgViewerQt example). These two allow both OSG and Qt to manage their threads -//in a way which is optimal to them. We've used QOSGWidget in the past and had -//trouble when Qt tried to overlay other widgets over the QOSGWidget (since OSG -//did its rendering independently of Qt, it would overwrite what Qt had drawn). I -//haven't tried GraphicsWindowQt yet, but I expect since it uses QGLWidget, it -//will result in Qt knowing when OSG has drawn and be able to do overlays at the -//right time. Eventually GraphicsWindowQt can be brought into osgViewer I imagine... -// -//2. If someone wants to bring Qt widgets inside their OSG scene (to do HUDs or -//an interface on a computer screen which is inside the 3D scene, or even -//floating Qt widgets, for example). That's where QGraphicsViewAdapter + -//QWidgetImage will be useful. -//---------------------------------------------- - - -int main(int argc, char **argv) -{ - // Qt requires that we construct the global QApplication before creating any widgets. - QApplication app(argc, argv); - - // use an ArgumentParser object to manage the program arguments. - osg::ArgumentParser arguments(&argc,argv); - - // true = run osgViewer in a separate thread than Qt - // false = interleave osgViewer and Qt in the main thread - bool useFrameLoopThread = false; - if (arguments.read("--no-frame-thread")) useFrameLoopThread = false; - if (arguments.read("--frame-thread")) useFrameLoopThread = true; - - // true = use QWidgetImage - // false = use QWebViewImage - bool useWidgetImage = false; - if (arguments.read("--useWidgetImage")) useWidgetImage = true; - - // true = use QWebView in a QWidgetImage to compare to QWebViewImage - // false = make an interesting widget - bool useBrowser = false; - if (arguments.read("--useBrowser")) useBrowser = true; - - // true = use a QLabel for text - // false = use a QTextEdit for text - // (only applies if useWidgetImage == true and useBrowser == false) - bool useLabel = false; - if (arguments.read("--useLabel")) useLabel = true; - - // true = make a Qt window with the same content to compare to - // QWebViewImage/QWidgetImage - // false = use QWebViewImage/QWidgetImage (depending on useWidgetImage) - bool sanityCheck = false; - if (arguments.read("--sanityCheck")) sanityCheck = true; - - // Add n floating windows inside the QGraphicsScene. - int numFloatingWindows = 0; - while (arguments.read("--numFloatingWindows", numFloatingWindows)); - - // true = Qt widgets will be displayed on a quad inside the 3D scene - // false = Qt widgets will be an overlay over the scene (like a HUD) - bool inScene = true; - if (arguments.read("--fullscreen")) { inScene = false; } - - - osg::ref_ptr root = new osg::Group; - - if (!useWidgetImage) - { - //------------------------------------------------------------------- - // QWebViewImage test - //------------------------------------------------------------------- - // Note: When the last few issues with QWidgetImage are fixed, - // QWebViewImage and this if() {} section can be removed since - // QWidgetImage can display a QWebView just like QWebViewImage. Use - // --useWidgetImage --useBrowser to see that in action. - - if (!sanityCheck) - { - osg::ref_ptr image = new osgQt::QWebViewImage; - - if (arguments.argc()>1) image->navigateTo((arguments[1])); - else image->navigateTo("http://www.openscenegraph.org/"); - - osgWidget::GeometryHints hints(osg::Vec3(0.0f,0.0f,0.0f), - osg::Vec3(1.0f,0.0f,0.0f), - osg::Vec3(0.0f,0.0f,1.0f), - osg::Vec4(1.0f,1.0f,1.0f,1.0f), - osgWidget::GeometryHints::RESIZE_HEIGHT_TO_MAINTAINCE_ASPECT_RATIO); - - osg::ref_ptr browser = new osgWidget::Browser; - browser->assign(image.get(), hints); - - root->addChild(browser.get()); - } - else - { - // Sanity check, do the same thing as QGraphicsViewAdapter but in - // a separate Qt window. - QWebPage* webPage = new QWebPage; - webPage->settings()->setAttribute(QWebSettings::JavascriptEnabled, true); - webPage->settings()->setAttribute(QWebSettings::PluginsEnabled, true); - - QWebView* webView = new QWebView; - webView->setPage(webPage); - - if (arguments.argc()>1) webView->load(QUrl(arguments[1])); - else webView->load(QUrl("http://www.openscenegraph.org/")); - - QGraphicsScene* graphicsScene = new QGraphicsScene; - graphicsScene->addWidget(webView); - - QGraphicsView* graphicsView = new QGraphicsView; - graphicsView->setScene(graphicsScene); - - QMainWindow* mainWindow = new QMainWindow; - //mainWindow->setLayout(new QVBoxLayout); - mainWindow->setCentralWidget(graphicsView); - mainWindow->setGeometry(50, 50, 1024, 768); - mainWindow->show(); - mainWindow->raise(); - } - } - else - { - //------------------------------------------------------------------- - // QWidgetImage test - //------------------------------------------------------------------- - // QWidgetImage still has some issues, some examples are: - // - // 1. Editing in the QTextEdit doesn't work. Also when started with - // --useBrowser, editing in the search field on YouTube doesn't - // work. But that same search field when using QWebViewImage - // works... And editing in the text field in the pop-up getInteger - // dialog works too. All these cases use QGraphicsViewAdapter - // under the hood, so why do some work and others don't? - // - // <<< FIXED, need TextEditorInteraction >>> - // - // a) osgQtBrowser --useWidgetImage [--fullscreen] (optional) - // b) Try to click in the QTextEdit and type, or to select text - // and drag-and-drop it somewhere else in the QTextEdit. These - // don't work. - // c) osgQtBrowser --useWidgetImage --sanityCheck - // d) Try the operations in b), they all work. - // e) osgQtBrowser --useWidgetImage --useBrowser [--fullscreen] - // f) Try to click in the search field and type, it doesn't work. - // g) osgQtBrowser - // h) Try the operation in f), it works. - // - // 2. Operations on floating windows (--numFloatingWindows 1 or more). - // Moving by dragging the titlebar, clicking the close button, - // resizing them, none of these work. I wonder if it's because the - // OS manages those functions (they're functions of the window - // decorations) so we need to do something special for that? But - // in --sanityCheck mode they work. - // - // a) osgQtBrowser --useWidgetImage --numFloatingWindows 1 [--fullscreen] - // b) Try to drag the floating window, click the close button, or - // drag its sides to resize it. None of these work. - // c) osgQtBrowser --useWidgetImage --numFloatingWindows 1 --sanityCheck - // d) Try the operations in b), all they work. - // e) osgQtBrowser --useWidgetImage [--fullscreen] - // f) Click the button so that the getInteger() dialog is - // displayed, then try to move that dialog or close it with the - // close button, these don't work. - // g) osgQtBrowser --useWidgetImage --sanityCheck - // h) Try the operation in f), it works. - // - // 3. (Minor) The QGraphicsView's scrollbars don't appear when - // using QWidgetImage or QWebViewImage. QGraphicsView is a - // QAbstractScrollArea and it should display scrollbars as soon as - // the scene is too large to fit the view. - // - // <<< FIXED >>> - // - // a) osgQtBrowser --useWidgetImage --fullscreen - // b) Resize the OSG window so it's smaller than the QTextEdit. - // Scrollbars should appear but don't. - // c) osgQtBrowser --useWidgetImage --sanityCheck - // d) Try the operation in b), scrollbars appear. Even if you have - // floating windows (by clicking the button or by adding - // --numFloatingWindows 1) and move them outside the view, - // scrollbars appear too. You can't test that case in OSG for - // now because of problem 2 above, but that's pretty cool. - // - // 4. (Minor) In sanity check mode, the widget added to the - // QGraphicsView is centered. With QGraphicsViewAdapter, it is not. - // - // a) osgQtBrowser --useWidgetImage [--fullscreen] - // b) The QTextEdit and button are not in the center of the image - // generated by the QGraphicsViewAdapter. - // c) osgQtBrowser --useWidgetImage --sanityCheck - // d) The QTextEdit and button are in the center of the - // QGraphicsView. - - - QWidget* widget = 0; - if (useBrowser) - { - QWebPage* webPage = new QWebPage; - webPage->settings()->setAttribute(QWebSettings::JavascriptEnabled, true); - webPage->settings()->setAttribute(QWebSettings::PluginsEnabled, true); - - QWebView* webView = new QWebView; - webView->setPage(webPage); - - if (arguments.argc()>1) webView->load(QUrl(arguments[1])); - else webView->load(QUrl("http://www.youtube.com/")); - - widget = webView; - } - else - { - widget = new QWidget; - widget->setLayout(new QVBoxLayout); - - QString text("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque velit turpis, euismod ac ultrices et, molestie non nisi. Nullam egestas dignissim enim, quis placerat nulla suscipit sed. Donec molestie elementum risus sit amet sodales. Nunc consectetur congue neque, at viverra massa pharetra fringilla. Integer vitae mi sem. Donec dapibus semper elit nec sollicitudin. Vivamus egestas ultricies felis, in mollis mi facilisis quis. Nam suscipit bibendum eros sed cursus. Suspendisse mollis suscipit hendrerit. Etiam magna eros, convallis non congue vel, faucibus ac augue. Integer ante ante, porta in ornare ullamcorper, congue nec nibh. Etiam congue enim vitae enim sollicitudin fringilla. Mauris mattis, urna in fringilla dapibus, ipsum sem feugiat purus, ac hendrerit felis arcu sed sapien. Integer id velit quam, sit amet dignissim tortor. Sed mi tortor, placerat ac luctus id, tincidunt et urna. Nulla sed nunc ante.Sed ut sodales enim. Ut sollicitudin ultricies magna, vel ultricies ante venenatis id. Cras luctus mi in lectus rhoncus malesuada. Sed ac sollicitudin nisi. Nunc venenatis congue quam, et suscipit diam consectetur id. Donec vel enim ac enim elementum bibendum ut quis augue. Nulla posuere suscipit dolor, id convallis tortor congue eu. Vivamus sagittis consectetur dictum. Duis a ante quis dui varius fermentum. In hac habitasse platea dictumst. Nam dapibus dolor eu felis eleifend in scelerisque dolor ultrices. Donec arcu lectus, fringilla ut interdum non, tristique id dolor. Morbi sagittis sagittis volutpat. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Duis venenatis ultrices euismod.Nam sit amet convallis libero. Integer lectus urna, eleifend et sollicitudin non, porttitor vel erat. Vestibulum pulvinar egestas leo, a porttitor turpis ullamcorper et. Vestibulum in ornare turpis. Ut nec libero a sem mattis iaculis quis id purus. Praesent ante neque, dictum vitae pretium vel, iaculis luctus dui. Etiam luctus tellus vel nunc suscipit a ullamcorper nisl semper. Nunc dapibus, eros in sodales dignissim, orci lectus egestas felis, sit amet vehicula tortor dolor eu quam. Vivamus pellentesque convallis quam aliquet pellentesque. Phasellus facilisis arcu ac orci fringilla aliquet. Donec sed euismod augue. Duis eget orci sit amet neque tempor fringilla. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; In hac habitasse platea dictumst. Duis sollicitudin, lacus ac pellentesque lacinia, lacus magna pulvinar purus, pulvinar porttitor est nibh quis augue.Duis eleifend, massa sit amet mattis fringilla, elit turpis venenatis libero, sed convallis turpis diam sit amet ligula. Morbi non dictum turpis. Integer porttitor condimentum elit, sit amet sagittis nibh ultrices sit amet. Mauris ac arcu augue, id aliquet mauris. Donec ultricies urna id enim accumsan at pharetra dui adipiscing. Nunc luctus rutrum molestie. Curabitur libero ipsum, viverra at pulvinar ut, porttitor et neque. Aliquam sit amet dolor et purus sagittis adipiscing. Nam sit amet hendrerit sem. Etiam varius, ligula non ultricies dignissim, sapien dui commodo urna, eu vehicula enim nunc molestie augue. Fusce euismod, erat vitae pharetra tempor, quam eros tincidunt lorem, ut iaculis ligula erat vitae nibh. Aenean eu ultricies dolor. Curabitur suscipit viverra bibendum.Sed egestas adipiscing mi in egestas. Proin in neque in nibh blandit consequat nec quis tortor. Vestibulum sed interdum justo. Sed volutpat velit vitae elit pulvinar aliquam egestas elit rutrum. Proin lorem nibh, bibendum vitae sollicitudin condimentum, pulvinar ut turpis. Maecenas iaculis, mauris in consequat ultrices, ante erat blandit mi, vel fermentum lorem turpis eget sem. Integer ultrices tristique erat sit amet volutpat. In sit amet diam et nunc congue pellentesque at in dolor. Mauris eget orci orci. Integer posuere augue ornare tortor tempus elementum. Quisque iaculis, nunc ac cursus fringilla, magna elit cursus eros, id feugiat diam eros et tellus. Etiam consectetur ultrices erat quis rhoncus. Mauris eu lacinia neque. Curabitur suscipit feugiat tellus in dictum. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed aliquam tempus ante a tempor. Praesent viverra erat quis sapien pretium rutrum. Praesent dictum scelerisque venenatis.Proin bibendum lectus eget nisl lacinia porta. Morbi eu erat in sapien malesuada vulputate. Cras non elit quam. Ut dictum urna quis nisl feugiat ac sollicitudin libero luctus. Donec leo mauris, varius at luctus eget, placerat quis arcu. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Etiam tristique, mauris ut lacinia elementum, mauris erat consequat massa, ac gravida nisi tellus vitae purus. Curabitur consectetur ultricies commodo. Cras pulvinar orci nec enim adipiscing tristique. Ut ornare orci id est fringilla sit amet blandit libero pellentesque. Vestibulum tincidunt sapien ut enim venenatis vestibulum ultricies ipsum tristique. Mauris tempus eleifend varius. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse vitae dui ac quam gravida semper. In ac enim ac ligula rutrum porttitor.Integer dictum sagittis leo, at convallis sapien facilisis eget. Etiam cursus bibendum tortor, faucibus aliquam lectus ullamcorper sed. Nulla pulvinar posuere quam, ut sagittis ligula tincidunt ut. Nulla convallis velit ut enim condimentum pulvinar. Quisque gravida accumsan scelerisque. Proin pellentesque nisi cursus tortor aliquet dapibus. Duis vel eros orci. Sed eget purus ligula. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ullamcorper porta congue. Nunc id velit ut neque malesuada consequat in eu nisi. Nulla facilisi. Quisque pellentesque magna vitae nisl euismod ac accumsan tellus feugiat.Nulla facilisi. Integer quis orci lectus, non aliquam nisi. Vivamus varius porta est, ac porttitor orci blandit mattis. Sed dapibus facilisis dapibus. Duis tincidunt leo ac tortor faucibus hendrerit. Morbi sit amet sapien risus, vel luctus enim. Aliquam sagittis nunc id purus aliquam lobortis. Duis posuere viverra dui, sit amet convallis sem vulputate at. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque pellentesque, lectus id imperdiet commodo, diam diam faucibus lectus, sit amet vestibulum tortor lacus viverra eros.Maecenas nec augue lectus. Duis nec arcu eget lorem tempus sollicitudin suscipit vitae arcu. Nullam vitae mauris lectus. Vivamus id risus neque, dignissim vehicula diam. Cras rhoncus velit sed velit iaculis ac dignissim turpis luctus. Suspendisse potenti. Sed vitae ligula a ligula ornare rutrum sit amet ut quam. Duis tincidunt, nibh vitae iaculis adipiscing, dolor orci cursus arcu, vel congue tortor quam eget arcu. Suspendisse tellus felis, blandit ac accumsan vitae, fringilla id lorem. Duis tempor lorem mollis est congue ut imperdiet velit laoreet. Nullam interdum cursus mollis. Pellentesque non mauris accumsan elit laoreet viverra ut at risus. Proin rutrum sollicitudin sem, vitae ultricies augue sagittis vel. Cras quis vehicula neque. Aliquam erat volutpat. Aliquam erat volutpat. Praesent non est erat, accumsan rutrum lacus. Pellentesque tristique molestie aliquet. Cras ullamcorper facilisis faucibus. In non lorem quis velit lobortis pulvinar.Phasellus non sem ipsum. Praesent ut libero quis turpis viverra semper. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In hac habitasse platea dictumst. Donec at velit tellus. Fusce commodo pharetra tincidunt. Proin lacus enim, fringilla a fermentum ut, vestibulum ut nibh. Duis commodo dolor vel felis vehicula at egestas neque bibendum. Phasellus malesuada dictum ante in aliquam. Curabitur interdum semper urna, nec placerat justo gravida in. Praesent quis mauris massa. Pellentesque porttitor lacinia tincidunt. Phasellus egestas viverra elit vel blandit. Sed dapibus nisi et lectus pharetra dignissim. Mauris hendrerit lectus nec purus dapibus condimentum. Sed ac eros nulla. Aenean semper sapien a nibh aliquam lobortis. Aliquam elementum euismod sapien, in dapibus leo dictum et. Pellentesque augue neque, ultricies non viverra eu, tincidunt ac arcu. Morbi ut porttitor lectus."); - - if (useLabel) - { - QLabel* label = new QLabel(text); - label->setWordWrap(true); - label->setTextInteractionFlags(Qt::TextEditorInteraction); - - QPalette palette = label->palette(); - palette.setColor(QPalette::Highlight, Qt::darkBlue); - palette.setColor(QPalette::HighlightedText, Qt::white); - label->setPalette(palette); - - QScrollArea* scrollArea = new QScrollArea; - scrollArea->setWidget(label); - - widget->layout()->addWidget(scrollArea); - } - else - { - QTextEdit* textEdit = new QTextEdit(text); - textEdit->setReadOnly(false); - textEdit->setTextInteractionFlags(Qt::TextEditorInteraction); - - QPalette palette = textEdit->palette(); - palette.setColor(QPalette::Highlight, Qt::darkBlue); - palette.setColor(QPalette::HighlightedText, Qt::white); - textEdit->setPalette(palette); - - widget->layout()->addWidget(textEdit); - } - - QPushButton* button = new MyPushButton("Button"); - widget->layout()->addWidget(button); - - widget->setGeometry(0, 0, 800, 600); - } - - QGraphicsScene* graphicsScene = 0; - - if (!sanityCheck) - { - osg::ref_ptr widgetImage = new osgQt::QWidgetImage(widget); -#if (QT_VERSION >= QT_VERSION_CHECK(4, 5, 0)) - widgetImage->getQWidget()->setAttribute(Qt::WA_TranslucentBackground); -#endif - widgetImage->getQGraphicsViewAdapter()->setBackgroundColor(QColor(0, 0, 0, 0)); - //widgetImage->getQGraphicsViewAdapter()->resize(800, 600); - graphicsScene = widgetImage->getQGraphicsViewAdapter()->getQGraphicsScene(); - - osg::Camera* camera = 0; // Will stay NULL in the inScene case. - osg::Geometry* quad = osg::createTexturedQuadGeometry(osg::Vec3(0,0,0), osg::Vec3(1,0,0), osg::Vec3(0,1,0), 1, 1); - osg::Geode* geode = new osg::Geode; - geode->addDrawable(quad); - - osg::MatrixTransform* mt = new osg::MatrixTransform; - - osg::Texture2D* texture = new osg::Texture2D(widgetImage.get()); - texture->setResizeNonPowerOfTwoHint(false); - texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); - texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); - texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE); - mt->getOrCreateStateSet()->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON); - - osgViewer::InteractiveImageHandler* handler; - if (inScene) - { - mt->setMatrix(osg::Matrix::rotate(osg::Vec3(0,1,0), osg::Vec3(0,0,1))); - mt->addChild(geode); - - handler = new osgViewer::InteractiveImageHandler(widgetImage.get()); - } - else // fullscreen - { - // The HUD camera's viewport needs to follow the size of the - // window. MyInteractiveImageHandler will make sure of this. - // As for the quad and the camera's projection, setting the - // projection resize policy to FIXED takes care of them, so - // they can stay the same: (0,1,0,1) with a quad that fits. - - // Set the HUD camera's projection and viewport to match the screen. - camera = new osg::Camera; - camera->setProjectionResizePolicy(osg::Camera::FIXED); - camera->setProjectionMatrix(osg::Matrix::ortho2D(0,1,0,1)); - camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); - camera->setViewMatrix(osg::Matrix::identity()); - camera->setClearMask(GL_DEPTH_BUFFER_BIT); - camera->setRenderOrder(osg::Camera::POST_RENDER); - camera->addChild(geode); - camera->setViewport(0, 0, 1024, 768); - - mt->addChild(camera); - - handler = new osgViewer::InteractiveImageHandler(widgetImage.get(), texture, camera); - } - - mt->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); - mt->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON); - mt->getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); - mt->getOrCreateStateSet()->setAttribute(new osg::Program); - - osg::Group* overlay = new osg::Group; - overlay->addChild(mt); - - root->addChild(overlay); - - quad->setEventCallback(handler); - quad->setCullCallback(handler); - } - else - { - // Sanity check, do the same thing as QWidgetImage and - // QGraphicsViewAdapter but in a separate Qt window. - - graphicsScene = new QGraphicsScene; - graphicsScene->addWidget(widget); - - QGraphicsView* graphicsView = new QGraphicsView; - graphicsView->setScene(graphicsScene); - - QMainWindow* mainWindow = new QMainWindow; - mainWindow->setCentralWidget(graphicsView); - mainWindow->setGeometry(50, 50, 1024, 768); - mainWindow->show(); - mainWindow->raise(); - } - - // Add numFloatingWindows windows to the graphicsScene. - for (unsigned int i = 0; i < (unsigned int)numFloatingWindows; ++i) - { - QWidget* window = new QWidget(0, Qt::Window); - window->setWindowTitle(QString("Window %1").arg(i)); - window->setLayout(new QVBoxLayout); - window->layout()->addWidget(new QLabel(QString("This window %1").arg(i))); - window->layout()->addWidget(new MyPushButton(QString("Button in window %1").arg(i))); - window->setGeometry(100, 100, 300, 300); - - QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(0, Qt::Window); - proxy->setWidget(window); - proxy->setFlag(QGraphicsItem::ItemIsMovable, true); - - graphicsScene->addItem(proxy); - } - - } - - root->addChild(osgDB::readNodeFile("cow.osg.(15,0,5).trans.(0.1,0.1,0.1).scale")); - - osg::ref_ptr viewer = new osgViewer::Viewer(arguments); - viewer->setSceneData(root.get()); - viewer->setCameraManipulator(new osgGA::TrackballManipulator()); - viewer->addEventHandler(new osgGA::StateSetManipulator(root->getOrCreateStateSet())); - viewer->addEventHandler(new osgViewer::StatsHandler); - viewer->addEventHandler(new osgViewer::WindowSizeHandler); - - viewer->setUpViewInWindow(50, 50, 1024, 768); - viewer->getEventQueue()->windowResize(0, 0, 1024, 768); - - if (useFrameLoopThread) - { - // create a thread to run the viewer's frame loop - ViewerFrameThread viewerThread(viewer.get(), true); - viewerThread.startThread(); - - // now start the standard Qt event loop, then exists when the viewerThead sends the QApplication::exit() signal. - return QApplication::exec(); - - } - else - { - // run the frame loop, interleaving Qt and the main OSG frame loop - while(!viewer->done()) - { - // process Qt events - this handles both events and paints the browser image - QCoreApplication::processEvents(QEventLoop::AllEvents, 100); - - viewer->frame(); - } - - return 0; - } -} diff --git a/examples/osgqfont/CMakeLists.txt b/examples/osgqfont/CMakeLists.txt deleted file mode 100644 index 3902ecc38..000000000 --- a/examples/osgqfont/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -#this file is automatically generated - -ADD_DEFINITIONS(-DUSE_QT4) - -SET(TARGET_SRC osgqfont.cpp ) -SET(TARGET_ADDED_LIBRARIES osgQt osgText) -IF ( NOT Qt5Widgets_FOUND ) - INCLUDE_DIRECTORIES( ${QT_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR} ${QT_QTGUI_INCLUDE_DIR} ${QT_QTOPENGL_INCLUDE_DIR} ) - SET(TARGET_EXTERNAL_LIBRARIES ${QT_QTCORE_LIBRARY_RELEASE} ${QT_QTGUI_LIBRARY_RELEASE} ${QT_QTOPENGL_LIBRARY_RELEASE} ) -ENDIF() - -#### end var setup ### -SET ( EXAMPLE_NAME osgqfont ) -SETUP_EXAMPLE(${EXAMPLE_NAME}) - -IF ( Qt5Widgets_FOUND ) - qt5_use_modules( example_${EXAMPLE_NAME} Widgets OpenGL ) -ENDIF( Qt5Widgets_FOUND ) diff --git a/examples/osgqfont/osgqfont.cpp b/examples/osgqfont/osgqfont.cpp deleted file mode 100644 index c30820ee0..000000000 --- a/examples/osgqfont/osgqfont.cpp +++ /dev/null @@ -1,564 +0,0 @@ -/* OpenSceneGraph example, osgtext. -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -*/ - -#include -#include -#include - -#include -#include - -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include - -osg::Group* createHUDText() -{ - - osg::Group* rootNode = new osg::Group; - - osgText::Font* font = new osgText::Font(new osgQt::QFontImplementation(QFont("Arial"))); - - osg::Geode* geode = new osg::Geode; - rootNode->addChild(geode); - - float windowHeight = 1024.0f; - float windowWidth = 1280.0f; - float margin = 50.0f; - - -//////////////////////////////////////////////////////////////////////////////////////////////////////// -// -// Examples of how to set up different text layout -// - - osg::Vec4 layoutColor(1.0f,1.0f,0.0f,1.0f); - float layoutCharacterSize = 20.0f; - - { - osgText::Text* text = new osgText::Text; - text->setFont(font); - text->setColor(layoutColor); - text->setCharacterSize(layoutCharacterSize); - text->setPosition(osg::Vec3(margin,windowHeight-margin,0.0f)); - - // the default layout is left to right, typically used in languages - // originating from europe such as English, French, German, Spanish etc.. - text->setLayout(osgText::Text::LEFT_TO_RIGHT); - - text->setText("text->setLayout(osgText::Text::LEFT_TO_RIGHT);"); - geode->addDrawable(text); - } - - { - osgText::Text* text = new osgText::Text; - text->setFont(font); - text->setColor(layoutColor); - text->setCharacterSize(layoutCharacterSize); - text->setPosition(osg::Vec3(windowWidth-margin,windowHeight-margin,0.0f)); - - // right to left layouts would be used for hebrew or arabic fonts. - text->setLayout(osgText::Text::RIGHT_TO_LEFT); - text->setAlignment(osgText::Text::RIGHT_BASE_LINE); - - text->setText("text->setLayout(osgText::Text::RIGHT_TO_LEFT);"); - geode->addDrawable(text); - } - - { - osgText::Text* text = new osgText::Text; - text->setFont(font); - text->setColor(layoutColor); - text->setPosition(osg::Vec3(margin,windowHeight-margin,0.0f)); - text->setCharacterSize(layoutCharacterSize); - - // vertical font layout would be used for asian fonts. - text->setLayout(osgText::Text::VERTICAL); - - text->setText("text->setLayout(osgText::Text::VERTICAL);"); - geode->addDrawable(text); - } - - -//////////////////////////////////////////////////////////////////////////////////////////////////////// -// -// Examples of how to set up different font resolution -// - - osg::Vec4 fontSizeColor(0.0f,1.0f,1.0f,1.0f); - float fontSizeCharacterSize = 30; - - osg::Vec3 cursor = osg::Vec3(margin*2,windowHeight-margin*2,0.0f); - - { - osgText::Text* text = new osgText::Text; - text->setFont(font); - text->setColor(fontSizeColor); - text->setCharacterSize(fontSizeCharacterSize); - text->setPosition(cursor); - - // use text that uses 10 by 10 texels as a target resolution for fonts. - text->setFontResolution(10,10); // blocky but small texture memory usage - - text->setText("text->setFontResolution(10,10); // blocky but small texture memory usage"); - geode->addDrawable(text); - } - - cursor.y() -= fontSizeCharacterSize; - { - osgText::Text* text = new osgText::Text; - text->setFont(font); - text->setColor(fontSizeColor); - text->setCharacterSize(fontSizeCharacterSize); - text->setPosition(cursor); - - // use text that uses 20 by 20 texels as a target resolution for fonts. - text->setFontResolution(20,20); // smoother but higher texture memory usage (but still quite low). - - text->setText("text->setFontResolution(20,20); // smoother but higher texture memory usage (but still quite low)."); - geode->addDrawable(text); - } - - cursor.y() -= fontSizeCharacterSize; - { - osgText::Text* text = new osgText::Text; - text->setFont(font); - text->setColor(fontSizeColor); - text->setCharacterSize(fontSizeCharacterSize); - text->setPosition(cursor); - - // use text that uses 40 by 40 texels as a target resolution for fonts. - text->setFontResolution(40,40); // even smoother but again higher texture memory usage. - - text->setText("text->setFontResolution(40,40); // even smoother but again higher texture memory usage."); - geode->addDrawable(text); - } - - -//////////////////////////////////////////////////////////////////////////////////////////////////////// -// -// Examples of how to set up different sized text -// - - osg::Vec4 characterSizeColor(1.0f,0.0f,1.0f,1.0f); - - cursor.y() -= fontSizeCharacterSize*2.0f; - - { - osgText::Text* text = new osgText::Text; - text->setFont(font); - text->setColor(characterSizeColor); - text->setFontResolution(20,20); - text->setPosition(cursor); - - // use text that is 20 units high. - text->setCharacterSize(20); // small - - text->setText("text->setCharacterSize(20.0f); // small"); - geode->addDrawable(text); - } - - cursor.y() -= 30.0f; - { - osgText::Text* text = new osgText::Text; - text->setFont(font); - text->setColor(characterSizeColor); - text->setFontResolution(30,30); - text->setPosition(cursor); - - // use text that is 30 units high. - text->setCharacterSize(30.0f); // medium - - text->setText("text->setCharacterSize(30.0f); // medium"); - geode->addDrawable(text); - } - - cursor.y() -= 50.0f; - { - osgText::Text* text = new osgText::Text; - text->setFont(font); - text->setColor(characterSizeColor); - text->setFontResolution(40,40); - text->setPosition(cursor); - - // use text that is 60 units high. - text->setCharacterSize(60.0f); // large - - text->setText("text->setCharacterSize(60.0f); // large"); - geode->addDrawable(text); - } - - -//////////////////////////////////////////////////////////////////////////////////////////////////////// -// -// Examples of how to set up different alignments -// - - osg::Vec4 alignmentSizeColor(0.0f,1.0f,0.0f,1.0f); - float alignmentCharacterSize = 25.0f; - cursor.x() = 640; - cursor.y() = margin*4.0f; - - typedef std::pair AlignmentPair; - typedef std::vector AlignmentList; - AlignmentList alignmentList; - alignmentList.push_back(AlignmentPair(osgText::Text::LEFT_TOP,"text->setAlignment(\nosgText::Text::LEFT_TOP);")); - alignmentList.push_back(AlignmentPair(osgText::Text::LEFT_CENTER,"text->setAlignment(\nosgText::Text::LEFT_CENTER);")); - alignmentList.push_back(AlignmentPair(osgText::Text::LEFT_BOTTOM,"text->setAlignment(\nosgText::Text::LEFT_BOTTOM);")); - alignmentList.push_back(AlignmentPair(osgText::Text::CENTER_TOP,"text->setAlignment(\nosgText::Text::CENTER_TOP);")); - alignmentList.push_back(AlignmentPair(osgText::Text::CENTER_CENTER,"text->setAlignment(\nosgText::Text::CENTER_CENTER);")); - alignmentList.push_back(AlignmentPair(osgText::Text::CENTER_BOTTOM,"text->setAlignment(\nosgText::Text::CENTER_BOTTOM);")); - alignmentList.push_back(AlignmentPair(osgText::Text::RIGHT_TOP,"text->setAlignment(\nosgText::Text::RIGHT_TOP);")); - alignmentList.push_back(AlignmentPair(osgText::Text::RIGHT_CENTER,"text->setAlignment(\nosgText::Text::RIGHT_CENTER);")); - alignmentList.push_back(AlignmentPair(osgText::Text::RIGHT_BOTTOM,"text->setAlignment(\nosgText::Text::RIGHT_BOTTOM);")); - alignmentList.push_back(AlignmentPair(osgText::Text::LEFT_BASE_LINE,"text->setAlignment(\nosgText::Text::LEFT_BASE_LINE);")); - alignmentList.push_back(AlignmentPair(osgText::Text::CENTER_BASE_LINE,"text->setAlignment(\nosgText::Text::CENTER_BASE_LINE);")); - alignmentList.push_back(AlignmentPair(osgText::Text::RIGHT_BASE_LINE,"text->setAlignment(\nosgText::Text::RIGHT_BASE_LINE);")); - alignmentList.push_back(AlignmentPair(osgText::Text::LEFT_BOTTOM_BASE_LINE,"text->setAlignment(\nosgText::Text::LEFT_BOTTOM_BASE_LINE);")); - alignmentList.push_back(AlignmentPair(osgText::Text::CENTER_BOTTOM_BASE_LINE,"text->setAlignment(\nosgText::Text::CENTER_BOTTOM_BASE_LINE);")); - alignmentList.push_back(AlignmentPair(osgText::Text::RIGHT_BOTTOM_BASE_LINE,"text->setAlignment(\nosgText::Text::RIGHT_BOTTOM_BASE_LINE);")); - - - osg::Sequence* sequence = new osg::Sequence; - { - for(AlignmentList::iterator itr=alignmentList.begin(); - itr!=alignmentList.end(); - ++itr) - { - osg::Geode* alignmentGeode = new osg::Geode; - sequence->addChild(alignmentGeode); - sequence->setTime(sequence->getNumChildren(), 1.0f); - - osgText::Text* text = new osgText::Text; - text->setFont(font); - text->setColor(alignmentSizeColor); - text->setCharacterSize(alignmentCharacterSize); - text->setPosition(cursor); - text->setDrawMode(osgText::Text::TEXT|osgText::Text::ALIGNMENT|osgText::Text::BOUNDINGBOX); - - text->setAlignment(itr->first); - text->setText(itr->second); - - alignmentGeode->addDrawable(text); - - - } - - } - - sequence->setMode(osg::Sequence::START); - sequence->setInterval(osg::Sequence::LOOP, 0, -1); - sequence->setDuration(1.0f, -1); - - rootNode->addChild(sequence); - - -//////////////////////////////////////////////////////////////////////////////////////////////////////// -// -// Examples of how to set up different fonts... -// - - cursor.x() = margin*2.0f; - cursor.y() = margin*2.0f; - - osg::Vec4 fontColor(1.0f,0.5f,0.0f,1.0f); - float fontCharacterSize = 20.0f; - float spacing = 40.0f; - - { - osgText::Text* text = new osgText::Text; - text->setColor(fontColor); - text->setPosition(cursor); - text->setCharacterSize(fontCharacterSize); - - text->setFont(0); - text->setText("text->setFont(0); // inbuilt font."); - geode->addDrawable(text); - - cursor.x() = text->getBoundingBox().xMax() + spacing ; - } - - { - osgText::Font* arial = new osgText::Font(new osgQt::QFontImplementation(QFont("Arial"))); - - osgText::Text* text = new osgText::Text; - text->setColor(fontColor); - text->setPosition(cursor); - text->setCharacterSize(fontCharacterSize); - - text->setFont(arial); - text->setText(arial!=0? - "text->setFont(\"fonts/arial.ttf\");": - "unable to load \"fonts/arial.ttf\""); - geode->addDrawable(text); - - cursor.x() = text->getBoundingBox().xMax() + spacing ; - } - - { - osgText::Font* times = new osgText::Font(new osgQt::QFontImplementation(QFont("Times"))); - - osgText::Text* text = new osgText::Text; - text->setColor(fontColor); - text->setPosition(cursor); - text->setCharacterSize(fontCharacterSize); - - geode->addDrawable(text); - text->setFont(times); - text->setText(times!=0? - "text->setFont(\"fonts/times.ttf\");": - "unable to load \"fonts/times.ttf\""); - - cursor.x() = text->getBoundingBox().xMax() + spacing ; - } - - cursor.x() = margin*2.0f; - cursor.y() = margin; - - { - osgText::Font* dirtydoz = new osgText::Font(new osgQt::QFontImplementation(QFont("Times"))); - - osgText::Text* text = new osgText::Text; - text->setColor(fontColor); - text->setPosition(cursor); - text->setCharacterSize(fontCharacterSize); - - text->setFont(dirtydoz); - text->setText(dirtydoz!=0? - "text->setFont(\"fonts/dirtydoz.ttf\");": - "unable to load \"fonts/dirtydoz.ttf\""); - geode->addDrawable(text); - - cursor.x() = text->getBoundingBox().xMax() + spacing ; - } - - { - osgText::Font* fudd = new osgText::Font(new osgQt::QFontImplementation(QFont("Times"))); - - osgText::Text* text = new osgText::Text; - text->setColor(fontColor); - text->setPosition(cursor); - text->setCharacterSize(fontCharacterSize); - - text->setFont(fudd); - text->setText(fudd!=0? - "text->setFont(\"fonts/fudd.ttf\");": - "unable to load \"fonts/fudd.ttf\""); - geode->addDrawable(text); - - cursor.x() = text->getBoundingBox().xMax() + spacing ; - } - - return rootNode; -} - - - - -// create text which sits in 3D space such as would be inserted into a normal model -osg::Group* create3DText(const osg::Vec3& center,float radius) -{ - - osg::Geode* geode = new osg::Geode; - -//////////////////////////////////////////////////////////////////////////////////////////////////////// -// -// Examples of how to set up axis/orientation alignments -// - - float characterSize=radius*0.2f; - - osg::Vec3 pos(center.x()-radius*.5f,center.y()-radius*.5f,center.z()-radius*.5f); - - osgText::Text* text1 = new osgText::Text; - text1->setFont(new osgText::Font(new osgQt::QFontImplementation(QFont("Times")))); - text1->setCharacterSize(characterSize); - text1->setPosition(pos); - text1->setAxisAlignment(osgText::Text::XY_PLANE); - text1->setText("XY_PLANE"); - geode->addDrawable(text1); - - osgText::Text* text2 = new osgText::Text; - text2->setFont(new osgText::Font(new osgQt::QFontImplementation(QFont("Times")))); - text2->setCharacterSize(characterSize); - text2->setPosition(pos); - text2->setAxisAlignment(osgText::Text::YZ_PLANE); - text2->setText("YZ_PLANE"); - geode->addDrawable(text2); - - osgText::Text* text3 = new osgText::Text; - text3->setFont(new osgText::Font(new osgQt::QFontImplementation(QFont("Times")))); - text3->setCharacterSize(characterSize); - text3->setPosition(pos); - text3->setAxisAlignment(osgText::Text::XZ_PLANE); - text3->setText("XZ_PLANE"); - geode->addDrawable(text3); - - - osgText::Text* text4 = new osgText::Text; - text4->setFont(new osgText::Font(new osgQt::QFontImplementation(QFont("Times")))); - text4->setCharacterSize(characterSize); - text4->setPosition(center); - text4->setAxisAlignment(osgText::Text::SCREEN); - - osg::Vec4 characterSizeModeColor(1.0f,0.0f,0.5f,1.0f); - - osgText::Text* text5 = new osgText::Text; - text5->setColor(characterSizeModeColor); - text5->setFont(new osgText::Font(new osgQt::QFontImplementation(QFont("Times")))); - //text5->setCharacterSize(characterSize); - text5->setCharacterSize(32.0f); // medium - text5->setPosition(center - osg::Vec3(0.0, 0.0, 0.2)); - text5->setAxisAlignment(osgText::Text::SCREEN); - text5->setCharacterSizeMode(osgText::Text::SCREEN_COORDS); - text5->setText("CharacterSizeMode SCREEN_COORDS(size 32.0)"); - geode->addDrawable(text5); - - osgText::Text* text6 = new osgText::Text; - text6->setColor(characterSizeModeColor); - text6->setFont(new osgText::Font(new osgQt::QFontImplementation(QFont("Times")))); - text6->setCharacterSize(characterSize); - text6->setPosition(center - osg::Vec3(0.0, 0.0, 0.4)); - text6->setAxisAlignment(osgText::Text::SCREEN); - text6->setCharacterSizeMode(osgText::Text::OBJECT_COORDS_WITH_MAXIMUM_SCREEN_SIZE_CAPPED_BY_FONT_HEIGHT); - text6->setText("CharacterSizeMode OBJECT_COORDS_WITH_MAXIMUM_SCREEN_SIZE_CAPPED_BY_FONT_HEIGHT"); - geode->addDrawable(text6); - - osgText::Text* text7 = new osgText::Text; - text7->setColor(characterSizeModeColor); - text7->setFont(new osgText::Font(new osgQt::QFontImplementation(QFont("Times")))); - text7->setCharacterSize(characterSize); - text7->setPosition(center - osg::Vec3(0.0, 0.0, 0.6)); - text7->setAxisAlignment(osgText::Text::SCREEN); - text7->setCharacterSizeMode(osgText::Text::OBJECT_COORDS); - text7->setText("CharacterSizeMode OBJECT_COORDS (default)"); - geode->addDrawable(text7); - -#if 1 - // reproduce outline bounding box compute problem with backdrop on. - text4->setBackdropType(osgText::Text::OUTLINE); - text4->setDrawMode(osgText::Text::TEXT | osgText::Text::BOUNDINGBOX); -#endif - - text4->setText("SCREEN"); - geode->addDrawable(text4); - - osg::ShapeDrawable* shape = new osg::ShapeDrawable(new osg::Sphere(center,characterSize*0.2f)); - shape->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::ON); - geode->addDrawable(shape); - - osg::Group* rootNode = new osg::Group; - rootNode->addChild(geode); - - return rootNode; -} - -class MainWindow : public QWidget { -public: - MainWindow() - { - osg::ref_ptr traits = new osg::GraphicsContext::Traits(osg::DisplaySettings::instance().get()); - traits->width = width(); - traits->height = height(); - traits->doubleBuffer = true; - osgQt::GraphicsWindowQt* graphicsWindow = new osgQt::GraphicsWindowQt(traits.get()); - - QGridLayout* grid = new QGridLayout; - grid->setMargin(0); - grid->addWidget(graphicsWindow->getGLWidget(), 0, 0); - setLayout(grid); - - _viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded); - - osg::Camera* camera = _viewer.getCamera(); - camera->setGraphicsContext(graphicsWindow); - camera->setViewport(new osg::Viewport(0, 0, width(), height())); - - startTimer(10); - } - - virtual void paintEvent(QPaintEvent* /*event*/) - { - _viewer.frame(); - } - virtual void timerEvent(QTimerEvent* /*event*/) - { - _viewer.frame(); - } - - void setSceneData(osg::Node* node) - { - _viewer.setSceneData(node); - } - void setCameraManipulator(osgGA::CameraManipulator* manipulator, bool resetPosition = true) - { - _viewer.setCameraManipulator(manipulator, resetPosition); - } - -private: - osgViewer::Viewer _viewer; -}; - -int main(int argc, char** argv) -{ - QApplication app(argc, argv); - - // prepare scene. - osg::Vec3 center(0.0f,0.0f,0.0f); - float radius = 1.0f; - - // create the hud. - osg::ref_ptr camera = new osg::Camera; - camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); - camera->setProjectionMatrixAsOrtho2D(0,1280,0,1024); - camera->setViewMatrix(osg::Matrix::identity()); - camera->setClearMask(GL_DEPTH_BUFFER_BIT); - camera->addChild(createHUDText()); - camera->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF); - - // make sure the root node is group so we can add extra nodes to it. - osg::ref_ptr group = new osg::Group; - group->addChild(camera.get()); - group->addChild(create3DText(center, radius)); - - // The qt window - MainWindow widget; - - // set the scene to render - widget.setSceneData(group.get()); - widget.setCameraManipulator(new osgGA::TrackballManipulator); - - widget.setGeometry(100, 100, 800, 600); - widget.show(); - - return app.exec(); -} diff --git a/examples/osgviewerQt/CMakeLists.txt b/examples/osgviewerQt/CMakeLists.txt deleted file mode 100644 index ae601494d..000000000 --- a/examples/osgviewerQt/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -SET( TARGET_SRC - osgviewerQt.cpp -) - -IF ( NOT Qt5Widgets_FOUND ) - IF( QT4_FOUND ) - SET(TARGET_EXTERNAL_LIBRARIES ${QT_QTCORE_LIBRARY_RELEASE} ${QT_QTGUI_LIBRARY_RELEASE} - ${QT_QTOPENGL_LIBRARY_RELEASE} ) - ADD_DEFINITIONS(-DUSE_QT4) - ELSE( QT4_FOUND ) - SET(TARGET_EXTERNAL_LIBRARIES ${QT_LIBRARIES} ) - ENDIF( QT4_FOUND ) - - INCLUDE_DIRECTORIES( ${QT_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR} ${QT_QTGUI_INCLUDE_DIR} - ${QT_QTOPENGL_INCLUDE_DIR} ) -ENDIF() - -SET(TARGET_ADDED_LIBRARIES osgWidget osgQt) - -SET( EXAMPLE_NAME osgviewerQt ) - -SETUP_EXAMPLE( ${EXAMPLE_NAME} ) - -IF ( Qt5Widgets_FOUND ) - qt5_use_modules( example_${EXAMPLE_NAME} Widgets OpenGL ) -ENDIF( Qt5Widgets_FOUND ) - diff --git a/examples/osgviewerQt/osgviewerQt.cpp b/examples/osgviewerQt/osgviewerQt.cpp deleted file mode 100644 index 1a2eac464..000000000 --- a/examples/osgviewerQt/osgviewerQt.cpp +++ /dev/null @@ -1,119 +0,0 @@ -#include -#include -#include - -#include -#include - -#include - -#include - -#include - -#include - -class ViewerWidget : public QWidget, public osgViewer::CompositeViewer -{ -public: - ViewerWidget(QWidget* parent = 0, Qt::WindowFlags f = 0, osgViewer::ViewerBase::ThreadingModel threadingModel=osgViewer::CompositeViewer::SingleThreaded) : QWidget(parent, f) - { - setThreadingModel(threadingModel); - - // disable the default setting of viewer.done() by pressing Escape. - setKeyEventSetsDone(0); - - QWidget* widget1 = addViewWidget( createGraphicsWindow(0,0,100,100), osgDB::readRefNodeFile("cow.osgt") ); - QWidget* widget2 = addViewWidget( createGraphicsWindow(0,0,100,100), osgDB::readRefNodeFile("glider.osgt") ); - QWidget* widget3 = addViewWidget( createGraphicsWindow(0,0,100,100), osgDB::readRefNodeFile("axes.osgt") ); - QWidget* widget4 = addViewWidget( createGraphicsWindow(0,0,100,100), osgDB::readRefNodeFile("fountain.osgt") ); - QWidget* popupWidget = addViewWidget( createGraphicsWindow(900,100,320,240,"Popup window",true), osgDB::readRefNodeFile("dumptruck.osgt") ); - popupWidget->show(); - - QGridLayout* grid = new QGridLayout; - grid->addWidget( widget1, 0, 0 ); - grid->addWidget( widget2, 0, 1 ); - grid->addWidget( widget3, 1, 0 ); - grid->addWidget( widget4, 1, 1 ); - setLayout( grid ); - - connect( &_timer, SIGNAL(timeout()), this, SLOT(update()) ); - _timer.start( 10 ); - } - - QWidget* addViewWidget( osgQt::GraphicsWindowQt* gw, osg::ref_ptr scene ) - { - osgViewer::View* view = new osgViewer::View; - addView( view ); - - osg::Camera* camera = view->getCamera(); - camera->setGraphicsContext( gw ); - - const osg::GraphicsContext::Traits* traits = gw->getTraits(); - - camera->setClearColor( osg::Vec4(0.2, 0.2, 0.6, 1.0) ); - camera->setViewport( new osg::Viewport(0, 0, traits->width, traits->height) ); - camera->setProjectionMatrixAsPerspective(30.0f, static_cast(traits->width)/static_cast(traits->height), 1.0f, 10000.0f ); - - view->setSceneData( scene ); - view->addEventHandler( new osgViewer::StatsHandler ); - view->setCameraManipulator( new osgGA::MultiTouchTrackballManipulator ); - gw->setTouchEventsEnabled( true ); - return gw->getGLWidget(); - } - - osgQt::GraphicsWindowQt* createGraphicsWindow( int x, int y, int w, int h, const std::string& name="", bool windowDecoration=false ) - { - osg::DisplaySettings* ds = osg::DisplaySettings::instance().get(); - osg::ref_ptr traits = new osg::GraphicsContext::Traits; - traits->windowName = name; - traits->windowDecoration = windowDecoration; - traits->x = x; - traits->y = y; - traits->width = w; - traits->height = h; - traits->doubleBuffer = true; - traits->alpha = ds->getMinimumNumAlphaBits(); - traits->stencil = ds->getMinimumNumStencilBits(); - traits->sampleBuffers = ds->getMultiSamples(); - traits->samples = ds->getNumMultiSamples(); - - return new osgQt::GraphicsWindowQt(traits.get()); - } - - virtual void paintEvent( QPaintEvent* /*event*/ ) - { frame(); } - -protected: - - QTimer _timer; -}; - -int main( int argc, char** argv ) -{ - osg::ArgumentParser arguments(&argc, argv); - -#if QT_VERSION >= 0x050000 - // Qt5 is currently crashing and reporting "Cannot make QOpenGLContext current in a different thread" when the viewer is run multi-threaded, this is regression from Qt4 - osgViewer::ViewerBase::ThreadingModel threadingModel = osgViewer::ViewerBase::SingleThreaded; -#else - osgViewer::ViewerBase::ThreadingModel threadingModel = osgViewer::ViewerBase::CullDrawThreadPerContext; -#endif - - while (arguments.read("--SingleThreaded")) threadingModel = osgViewer::ViewerBase::SingleThreaded; - while (arguments.read("--CullDrawThreadPerContext")) threadingModel = osgViewer::ViewerBase::CullDrawThreadPerContext; - while (arguments.read("--DrawThreadPerContext")) threadingModel = osgViewer::ViewerBase::DrawThreadPerContext; - while (arguments.read("--CullThreadPerCameraDrawThreadPerContext")) threadingModel = osgViewer::ViewerBase::CullThreadPerCameraDrawThreadPerContext; - -#if QT_VERSION >= 0x040800 - // Required for multithreaded QGLWidget on Linux/X11, see http://blog.qt.io/blog/2011/06/03/threaded-opengl-in-4-8/ - if (threadingModel != osgViewer::ViewerBase::SingleThreaded) - QApplication::setAttribute(Qt::AA_X11InitThreads); -#endif - - QApplication app(argc, argv); - ViewerWidget* viewWidget = new ViewerWidget(0, Qt::Widget, threadingModel); - viewWidget->setGeometry( 100, 100, 800, 600 ); - viewWidget->show(); - return app.exec(); -} diff --git a/include/osgQt/Export b/include/osgQt/Export deleted file mode 100644 index 41efb3c45..000000000 --- a/include/osgQt/Export +++ /dev/null @@ -1,52 +0,0 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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. -*/ - -// The following symbol has a underscore suffix for compatibility. -#ifndef OSGQT_EXPORT_ -#define OSGQT_EXPORT_ 1 - -#include - -#if defined(_MSC_VER) && defined(OSG_DISABLE_MSVC_WARNINGS) - #pragma warning( disable : 4244 ) - #pragma warning( disable : 4251 ) - #pragma warning( disable : 4267 ) - #pragma warning( disable : 4275 ) - #pragma warning( disable : 4290 ) - #pragma warning( disable : 4786 ) - #pragma warning( disable : 4305 ) - #pragma warning( disable : 4996 ) -#endif - -#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__) - # if defined( OSG_LIBRARY_STATIC ) - # define OSGQT_EXPORT - # elif defined( OSGQT_LIBRARY ) - # define OSGQT_EXPORT __declspec(dllexport) - # else - # define OSGQT_EXPORT __declspec(dllimport) - #endif -#else - #define OSGQT_EXPORT -#endif - -#endif - - -/** - -\namespace osgQt - -The osgQt utility library provides various classes to aid the integration of OpenSceneGraph and Qt. - -*/ diff --git a/include/osgQt/GraphicsWindowQt b/include/osgQt/GraphicsWindowQt deleted file mode 100644 index 9ed8bb2a1..000000000 --- a/include/osgQt/GraphicsWindowQt +++ /dev/null @@ -1,195 +0,0 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 2009 Wang Rui - * - * 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 OSGVIEWER_GRAPHICSWINDOWQT -#define OSGVIEWER_GRAPHICSWINDOWQT - -#include -#include -#include - -#include -#include -#include -#include -#include - -class QInputEvent; -class QGestureEvent; - -namespace osgViewer { - class ViewerBase; -} - -namespace osgQt -{ - -// forward declarations -class GraphicsWindowQt; - -#if 0 -/// The function sets the WindowingSystem to Qt. -void OSGQT_EXPORT initQtWindowingSystem(); -#endif - -/** The function sets the viewer that will be used after entering - * the Qt main loop (QCoreApplication::exec()). - * - * The function also initializes internal structures required for proper - * scene rendering. - * - * The method must be called from main thread. */ -void OSGQT_EXPORT setViewer( osgViewer::ViewerBase *viewer ); - - -class OSGQT_EXPORT GLWidget : public QGLWidget -{ - typedef QGLWidget inherited; - -public: - - GLWidget( QWidget* parent = NULL, const QGLWidget* shareWidget = NULL, Qt::WindowFlags f = 0, bool forwardKeyEvents = false ); - GLWidget( QGLContext* context, QWidget* parent = NULL, const QGLWidget* shareWidget = NULL, Qt::WindowFlags f = 0, bool forwardKeyEvents = false ); - GLWidget( const QGLFormat& format, QWidget* parent = NULL, const QGLWidget* shareWidget = NULL, Qt::WindowFlags f = 0, bool forwardKeyEvents = false ); - virtual ~GLWidget(); - - inline void setGraphicsWindow( GraphicsWindowQt* gw ) { _gw = gw; } - inline GraphicsWindowQt* getGraphicsWindow() { return _gw; } - inline const GraphicsWindowQt* getGraphicsWindow() const { return _gw; } - - inline bool getForwardKeyEvents() const { return _forwardKeyEvents; } - virtual void setForwardKeyEvents( bool f ) { _forwardKeyEvents = f; } - - inline bool getTouchEventsEnabled() const { return _touchEventsEnabled; } - void setTouchEventsEnabled( bool e ); - - void setKeyboardModifiers( QInputEvent* event ); - - virtual void keyPressEvent( QKeyEvent* event ); - virtual void keyReleaseEvent( QKeyEvent* event ); - virtual void mousePressEvent( QMouseEvent* event ); - virtual void mouseReleaseEvent( QMouseEvent* event ); - virtual void mouseDoubleClickEvent( QMouseEvent* event ); - virtual void mouseMoveEvent( QMouseEvent* event ); - virtual void wheelEvent( QWheelEvent* event ); - virtual bool gestureEvent( QGestureEvent* event ); - -protected: - - int getNumDeferredEvents() - { - QMutexLocker lock(&_deferredEventQueueMutex); - return _deferredEventQueue.count(); - } - void enqueueDeferredEvent(QEvent::Type eventType, QEvent::Type removeEventType = QEvent::None) - { - QMutexLocker lock(&_deferredEventQueueMutex); - - if (removeEventType != QEvent::None) - { - if (_deferredEventQueue.removeOne(removeEventType)) - _eventCompressor.remove(eventType); - } - - if (_eventCompressor.find(eventType) == _eventCompressor.end()) - { - _deferredEventQueue.enqueue(eventType); - _eventCompressor.insert(eventType); - } - } - void processDeferredEvents(); - - friend class GraphicsWindowQt; - GraphicsWindowQt* _gw; - - QMutex _deferredEventQueueMutex; - QQueue _deferredEventQueue; - QSet _eventCompressor; - - bool _touchEventsEnabled; - - bool _forwardKeyEvents; - qreal _devicePixelRatio; - - virtual void resizeEvent( QResizeEvent* event ); - virtual void moveEvent( QMoveEvent* event ); - virtual void glDraw(); - virtual bool event( QEvent* event ); -}; - -class OSGQT_EXPORT GraphicsWindowQt : public osgViewer::GraphicsWindow -{ -public: - GraphicsWindowQt( osg::GraphicsContext::Traits* traits, QWidget* parent = NULL, const QGLWidget* shareWidget = NULL, Qt::WindowFlags f = 0 ); - GraphicsWindowQt( GLWidget* widget ); - virtual ~GraphicsWindowQt(); - - inline GLWidget* getGLWidget() { return _widget; } - inline const GLWidget* getGLWidget() const { return _widget; } - - /// deprecated - inline GLWidget* getGraphWidget() { return _widget; } - /// deprecated - inline const GLWidget* getGraphWidget() const { return _widget; } - - struct WindowData : public osg::Referenced - { - WindowData( GLWidget* widget = NULL, QWidget* parent = NULL ): _widget(widget), _parent(parent) {} - GLWidget* _widget; - QWidget* _parent; - }; - - bool init( QWidget* parent, const QGLWidget* shareWidget, Qt::WindowFlags f ); - - static QGLFormat traits2qglFormat( const osg::GraphicsContext::Traits* traits ); - static void qglFormat2traits( const QGLFormat& format, osg::GraphicsContext::Traits* traits ); - static osg::GraphicsContext::Traits* createTraits( const QGLWidget* widget ); - - virtual bool setWindowRectangleImplementation( int x, int y, int width, int height ); - virtual void getWindowRectangle( int& x, int& y, int& width, int& height ); - virtual bool setWindowDecorationImplementation( bool windowDecoration ); - virtual bool getWindowDecoration() const; - virtual void grabFocus(); - virtual void grabFocusIfPointerInWindow(); - virtual void raiseWindow(); - virtual void setWindowName( const std::string& name ); - virtual std::string getWindowName(); - virtual void useCursor( bool cursorOn ); - virtual void setCursor( MouseCursor cursor ); - inline bool getTouchEventsEnabled() const { return _widget->getTouchEventsEnabled(); } - virtual void setTouchEventsEnabled( bool e ) { _widget->setTouchEventsEnabled(e); } - - - virtual bool valid() const; - virtual bool realizeImplementation(); - virtual bool isRealizedImplementation() const; - virtual void closeImplementation(); - virtual bool makeCurrentImplementation(); - virtual bool releaseContextImplementation(); - virtual void swapBuffersImplementation(); - virtual void runOperations(); - - virtual void requestWarpPointer( float x, float y ); - -protected: - - friend class GLWidget; - GLWidget* _widget; - bool _ownsWidget; - QCursor _currentCursor; - bool _realized; -}; - -} - -#endif diff --git a/include/osgQt/QFontImplementation b/include/osgQt/QFontImplementation deleted file mode 100644 index 5f06c066e..000000000 --- a/include/osgQt/QFontImplementation +++ /dev/null @@ -1,52 +0,0 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 2009-2010 Mathias Froehlich - * - * 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 QFontImplementation_H -#define QFontImplementation_H - -#include -#include -#include - -#include - -#include - -namespace osgQt { - -class OSGQT_EXPORT QFontImplementation : public osgText::Font::FontImplementation -{ -public: - QFontImplementation(const QFont& font); - virtual ~QFontImplementation(); - - virtual std::string getFileName() const; - - virtual bool supportsMultipleFontResolutions() const { return true; } - - virtual osgText::Glyph* getGlyph(const osgText::FontResolution& fontRes, unsigned int charcode); - - virtual osgText::Glyph3D* getGlyph3D(const osgText::FontResolution& /*fontRes*/, unsigned int /*charcode*/) { return 0; } - - virtual osg::Vec2 getKerning(const osgText::FontResolution& fontRes, unsigned int leftcharcode, unsigned int rightcharcode, osgText::KerningType kerningType); - - virtual bool hasVertical() const; - -protected: - - std::string _filename; - QFont _font; -}; - -} - -#endif diff --git a/include/osgQt/QGraphicsViewAdapter b/include/osgQt/QGraphicsViewAdapter deleted file mode 100644 index 62fd46496..000000000 --- a/include/osgQt/QGraphicsViewAdapter +++ /dev/null @@ -1,124 +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. -*/ - -#ifndef QGRAPHICSVIEWADAPTER -#define QGRAPHICSVIEWADAPTER - -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -namespace osgQt -{ - -extern OSGQT_EXPORT QCoreApplication* getOrCreateQApplication(); - -class OSGQT_EXPORT QGraphicsViewAdapter : public QObject -{ - Q_OBJECT - - public: - - QGraphicsViewAdapter(osg::Image* image, QWidget* widget); - - void setUpKeyMap(); - - bool sendPointerEvent(int x, int y, int buttonMask); - - - bool sendKeyEvent(int key, bool keyDown); - - - void setFrameLastRendered(const osg::FrameStamp* frameStamp); - - void clearWriteBuffer(); - - bool requiresRendering() const { return _requiresRendering; } - void render(); - - void assignImage(unsigned int i); - - void resize(int width, int height); - - void setBackgroundColor(QColor color) { _backgroundColor = color; } - QColor getBackgroundColor() const { return _backgroundColor; } - - /** The 'background widget' will ignore mouse/keyboard events and let following handlers handle them - It is mainly used for integrating scene graph and full-screen UIs - */ - void setBackgroundWidget(QWidget* w) { _backgroundWidget = w; } - QWidget* getBackgroundWidget() { return _backgroundWidget; } - - QGraphicsView* getQGraphicsView() { return _graphicsView; } - QGraphicsScene* getQGraphicsScene() { return _graphicsScene; } - - protected: - - bool handlePointerEvent(int x, int y, int buttonMask); - bool handleKeyEvent(int key, bool keyDown); - QWidget* getWidgetAt(const QPoint& pos); - - osg::observer_ptr _image; - QWidget* _backgroundWidget; - - int _previousButtonMask; - int _previousMouseX; - int _previousMouseY; - int _previousQtMouseX; - int _previousQtMouseY; - bool _previousSentEvent; - bool _requiresRendering; - - int _width; - int _height; - - typedef std::map KeyMap; - KeyMap _keyMap; - Qt::KeyboardModifiers _qtKeyModifiers; - - QColor _backgroundColor; - QPointer _graphicsView; - QPointer _graphicsScene; - QPointer _widget; - - OpenThreads::Mutex _qimagesMutex; - OpenThreads::Mutex _qresizeMutex; - unsigned int _previousFrameNumber; - bool _newImageAvailable; - unsigned int _currentRead; - unsigned int _currentWrite; - unsigned int _previousWrite; - QImage _qimages[3]; - - virtual void customEvent ( QEvent * event ) ; - - private slots: - - void repaintRequestedSlot(const QList ®ions); - void repaintRequestedSlot(const QRectF ®ion); - -}; - -} - -#endif diff --git a/include/osgQt/QWebViewImage b/include/osgQt/QWebViewImage deleted file mode 100644 index 24d48c7e0..000000000 --- a/include/osgQt/QWebViewImage +++ /dev/null @@ -1,109 +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. -*/ - -#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) - -#if QT_VERSION >= 0x050000 -# include -#else -# include -#endif - - -#include -#include -#include - -namespace osgQt -{ - -class QWebViewImage : public osgWidget::BrowserImage -{ - public: - - 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()); - } - - 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 clearWriteBuffer() - { - _adapter->clearWriteBuffer(); - } - - void render() - { - if (_adapter->requiresRendering()) _adapter->render(); - } - - virtual bool requiresUpdateCall() const { return true; } - virtual void update( osg::NodeVisitor* nv ) { render(); } - - 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); - } - - protected: - - QPointer _adapter; - QPointer _webView; - QPointer _webPage; -}; - -} - -#endif - -#endif diff --git a/include/osgQt/QWidgetImage b/include/osgQt/QWidgetImage deleted file mode 100644 index bd368127c..000000000 --- a/include/osgQt/QWidgetImage +++ /dev/null @@ -1,60 +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. -*/ - -#ifndef QWIDGETIMAGE -#define QWIDGETIMAGE - -#include -#include -#include - -namespace osgQt -{ - -class OSGQT_EXPORT QWidgetImage : public osg::Image -{ - public: - - QWidgetImage( QWidget* widget=0 ); - - QWidget* getQWidget() { return _widget; } - QGraphicsViewAdapter* getQGraphicsViewAdapter() { return _adapter; } - - virtual bool requiresUpdateCall() const { return true; } - virtual void update( osg::NodeVisitor* /*nv*/ ) { render(); } - - void clearWriteBuffer(); - - void render(); - - /// Overridden scaleImage used to catch cases where the image is - /// fullscreen and the window is resized. - virtual void scaleImage(int s,int t,int r, GLenum newDataType); - - 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; - QPointer _widget; -}; - -} - -#endif diff --git a/packaging/pkgconfig/openscenegraph-osgQt.pc.in b/packaging/pkgconfig/openscenegraph-osgQt.pc.in deleted file mode 100644 index 7b310e49f..000000000 --- a/packaging/pkgconfig/openscenegraph-osgQt.pc.in +++ /dev/null @@ -1,14 +0,0 @@ -# pkg-config source file - -prefix=@CMAKE_INSTALL_PREFIX@ -exec_prefix=${prefix} -libdir=${exec_prefix}/lib@LIB_POSTFIX@ -includedir=${prefix}/include - -Name: openscenegraph-osgQt -Description: osgQt utility library. -Version: @OPENSCENEGRAPH_VERSION@ -Requires: openscenegraph-osgWidget openscenegraph-osgDB openscenegraph-osgUtil openscenegraph-osg openthreads -Conflicts: -Libs: -L${libdir} -losgQt@CMAKE_BUILD_POSTFIX@ -Cflags: -I${includedir} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bea40f360..797440a85 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -35,8 +35,4 @@ FOREACH( mylibfolder ENDFOREACH() -IF ((QT4_FOUND OR Qt5Widgets_FOUND) AND NOT ANDROID) - ADD_SUBDIRECTORY(osgQt) -ENDIF() - diff --git a/src/osgPlugins/CMakeLists.txt b/src/osgPlugins/CMakeLists.txt index ca24ff801..36d1d17e1 100644 --- a/src/osgPlugins/CMakeLists.txt +++ b/src/osgPlugins/CMakeLists.txt @@ -234,10 +234,6 @@ IF(FREETYPE_FOUND) ADD_SUBDIRECTORY(freetype) ENDIF() -IF (QT4_FOUND) - ADD_SUBDIRECTORY(qfont) -ENDIF() - IF(ZLIB_FOUND) ADD_SUBDIRECTORY(zip) ENDIF() diff --git a/src/osgPlugins/qfont/CMakeLists.txt b/src/osgPlugins/qfont/CMakeLists.txt deleted file mode 100644 index 141121cc3..000000000 --- a/src/osgPlugins/qfont/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -INCLUDE_DIRECTORIES(${QT_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR} ) - -SET(TARGET_SRC ReaderQFont.cpp) -SET(TARGET_ADDED_LIBRARIES osgText osgQt) - -SET(TARGET_LIBRARIES_VARS ${QT_QTCORE_LIBRARY_RELEASE} ${QT_QTGUI_LIBRARY_RELEASE}) -SETUP_PLUGIN(qfont) diff --git a/src/osgPlugins/qfont/ReaderQFont.cpp b/src/osgPlugins/qfont/ReaderQFont.cpp deleted file mode 100644 index 4b04ad412..000000000 --- a/src/osgPlugins/qfont/ReaderQFont.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 2009-2010 Mathias Froehlich - * - * 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 -#include -#include - -#include -#include -#include -#include - -#include - -namespace osgQFont { - -class ReaderQFont : public osgDB::ReaderWriter -{ - public: - ReaderQFont() - { - supportsExtension("qfont", "Qt font meta loader"); - } - - virtual const char* className() const { return "QFont Font Reader"; } - - virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* /*options*/) const - { - if (!acceptsExtension(osgDB::getLowerCaseFileExtension(file))) - return ReadResult::FILE_NOT_HANDLED; - - if (!QApplication::instance()) - { - OSG_WARN << "Trying to load qfont \"" << file << "\" from within a non qt application!" << std::endl; - return ReadResult::FILE_NOT_FOUND; - } - - if (!QFontDatabase::supportsThreadedFontRendering() && QApplication::instance()->thread() != QThread::currentThread()) - { - OSG_WARN << "Trying to load qfont \"" << file << "\" from a non gui thread " - "within qt application without threaded font rendering!" << std::endl; - return ReadResult::FILE_NOT_FOUND; - } - - QFont font; - if (!font.fromString(QString::fromStdString(osgDB::getNameLessExtension(file)))) - return ReadResult::FILE_NOT_FOUND; - - return new osgText::Font(new osgQt::QFontImplementation(font)); - } -}; - -// now register with Registry to instantiate the above -// reader/writer. -REGISTER_OSGPLUGIN(qfont, ReaderQFont) - -} diff --git a/src/osgQt/CMakeLists.txt b/src/osgQt/CMakeLists.txt deleted file mode 100644 index 2c33e57ab..000000000 --- a/src/osgQt/CMakeLists.txt +++ /dev/null @@ -1,83 +0,0 @@ - -IF(DYNAMIC_OPENSCENEGRAPH) - ADD_DEFINITIONS(-DOSGQT_LIBRARY) -ELSE() - ADD_DEFINITIONS(-DOSG_LIBRARY_STATIC) -ENDIF() - -SET(LIB_NAME osgQt) -SET(HEADER_PATH ${OpenSceneGraph_SOURCE_DIR}/include/${LIB_NAME}) - -SET(SOURCES_H - ${HEADER_PATH}/QGraphicsViewAdapter -) - -IF ( Qt5Widgets_FOUND ) - QT5_WRAP_CPP( SOURCES_H_MOC ${SOURCES_H} OPTIONS - "-fosgQt/QGraphicsViewAdapter" ) - set(OSGQT_QT_VERSION 5) -ELSE() - QT4_WRAP_CPP( SOURCES_H_MOC ${SOURCES_H} OPTIONS "-f" ) - set(OSGQT_QT_VERSION 4) -ENDIF() - -SET(OSGQT_VERSION_HEADER "${PROJECT_BINARY_DIR}/include/osgQt/Version") -CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/Version.in" ${OSGQT_VERSION_HEADER}) - -SET(TARGET_H - ${HEADER_PATH}/Export - ${HEADER_PATH}/GraphicsWindowQt - ${HEADER_PATH}/QFontImplementation - ${HEADER_PATH}/QGraphicsViewAdapter - ${HEADER_PATH}/QWidgetImage - ${HEADER_PATH}/QWebViewImage - ${OSGQT_VERSION_HEADER} -) - - -# FIXME: For OS X, need flag for Framework or dylib -SET(TARGET_SRC - GraphicsWindowQt.cpp - QFontImplementation.cpp - QGraphicsViewAdapter.cpp - QWidgetImage.cpp - ${SOURCES_H_MOC} - ${OPENSCENEGRAPH_VERSIONINFO_RC} -) - -SET(TARGET_LIBRARIES - osgWidget - osgDB - osgUtil - osg - OpenThreads -) - -IF(CMAKE_COMPILER_IS_GNUCXX) - # Remove -pedantic flag as it barfs on Qt headers - STRING(REGEX REPLACE "-pedantic" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") -ENDIF() - -# FIXME: This should work but something with the LINK_WITH_VARIABLES macro is not working -#SET(TARGET_LIBRARIES_VARS -# QT_QTCORE_LIBRARY -# QT_QTGUI_LIBRARY -# QT_QTOPENGL_LIBRARY -#) - -IF( QT4_FOUND ) - INCLUDE_DIRECTORIES( ${QT_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR} ${QT_QTGUI_INCLUDE_DIR} ${QT_QTOPENGL_INCLUDE_DIR} ) - SET(TARGET_LIBRARIES - ${TARGET_LIBRARIES} - ${QT_QTCORE_LIBRARY} - ${QT_QTGUI_LIBRARY} - ${QT_QTOPENGL_LIBRARY} -) - -ENDIF( QT4_FOUND ) - -SETUP_LIBRARY(${LIB_NAME}) - -IF ( Qt5Widgets_FOUND ) - qt5_use_modules( ${LIB_NAME} Widgets OpenGL ) -ENDIF ( Qt5Widgets_FOUND ) diff --git a/src/osgQt/GraphicsWindowQt.cpp b/src/osgQt/GraphicsWindowQt.cpp deleted file mode 100644 index 3695ee50d..000000000 --- a/src/osgQt/GraphicsWindowQt.cpp +++ /dev/null @@ -1,1064 +0,0 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 2009 Wang Rui - * - * 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 -#include -#include -#include -#include - -#if (QT_VERSION>=QT_VERSION_CHECK(4, 6, 0)) -# define USE_GESTURES -# include -# include -#endif - -using namespace osgQt; - - -class QtKeyboardMap -{ - -public: - QtKeyboardMap() - { - mKeyMap[Qt::Key_Escape ] = osgGA::GUIEventAdapter::KEY_Escape; - mKeyMap[Qt::Key_Delete ] = osgGA::GUIEventAdapter::KEY_Delete; - mKeyMap[Qt::Key_Home ] = osgGA::GUIEventAdapter::KEY_Home; - mKeyMap[Qt::Key_Enter ] = osgGA::GUIEventAdapter::KEY_KP_Enter; - mKeyMap[Qt::Key_End ] = osgGA::GUIEventAdapter::KEY_End; - mKeyMap[Qt::Key_Return ] = osgGA::GUIEventAdapter::KEY_Return; - mKeyMap[Qt::Key_PageUp ] = osgGA::GUIEventAdapter::KEY_Page_Up; - mKeyMap[Qt::Key_PageDown ] = osgGA::GUIEventAdapter::KEY_Page_Down; - mKeyMap[Qt::Key_Left ] = osgGA::GUIEventAdapter::KEY_Left; - mKeyMap[Qt::Key_Right ] = osgGA::GUIEventAdapter::KEY_Right; - mKeyMap[Qt::Key_Up ] = osgGA::GUIEventAdapter::KEY_Up; - mKeyMap[Qt::Key_Down ] = osgGA::GUIEventAdapter::KEY_Down; - mKeyMap[Qt::Key_Backspace ] = osgGA::GUIEventAdapter::KEY_BackSpace; - mKeyMap[Qt::Key_Tab ] = osgGA::GUIEventAdapter::KEY_Tab; - mKeyMap[Qt::Key_Space ] = osgGA::GUIEventAdapter::KEY_Space; - mKeyMap[Qt::Key_Delete ] = osgGA::GUIEventAdapter::KEY_Delete; - mKeyMap[Qt::Key_Alt ] = osgGA::GUIEventAdapter::KEY_Alt_L; - mKeyMap[Qt::Key_Shift ] = osgGA::GUIEventAdapter::KEY_Shift_L; - mKeyMap[Qt::Key_Control ] = osgGA::GUIEventAdapter::KEY_Control_L; - mKeyMap[Qt::Key_Meta ] = osgGA::GUIEventAdapter::KEY_Meta_L; - - mKeyMap[Qt::Key_F1 ] = osgGA::GUIEventAdapter::KEY_F1; - mKeyMap[Qt::Key_F2 ] = osgGA::GUIEventAdapter::KEY_F2; - mKeyMap[Qt::Key_F3 ] = osgGA::GUIEventAdapter::KEY_F3; - mKeyMap[Qt::Key_F4 ] = osgGA::GUIEventAdapter::KEY_F4; - mKeyMap[Qt::Key_F5 ] = osgGA::GUIEventAdapter::KEY_F5; - mKeyMap[Qt::Key_F6 ] = osgGA::GUIEventAdapter::KEY_F6; - mKeyMap[Qt::Key_F7 ] = osgGA::GUIEventAdapter::KEY_F7; - mKeyMap[Qt::Key_F8 ] = osgGA::GUIEventAdapter::KEY_F8; - mKeyMap[Qt::Key_F9 ] = osgGA::GUIEventAdapter::KEY_F9; - mKeyMap[Qt::Key_F10 ] = osgGA::GUIEventAdapter::KEY_F10; - mKeyMap[Qt::Key_F11 ] = osgGA::GUIEventAdapter::KEY_F11; - mKeyMap[Qt::Key_F12 ] = osgGA::GUIEventAdapter::KEY_F12; - mKeyMap[Qt::Key_F13 ] = osgGA::GUIEventAdapter::KEY_F13; - mKeyMap[Qt::Key_F14 ] = osgGA::GUIEventAdapter::KEY_F14; - mKeyMap[Qt::Key_F15 ] = osgGA::GUIEventAdapter::KEY_F15; - mKeyMap[Qt::Key_F16 ] = osgGA::GUIEventAdapter::KEY_F16; - mKeyMap[Qt::Key_F17 ] = osgGA::GUIEventAdapter::KEY_F17; - mKeyMap[Qt::Key_F18 ] = osgGA::GUIEventAdapter::KEY_F18; - mKeyMap[Qt::Key_F19 ] = osgGA::GUIEventAdapter::KEY_F19; - mKeyMap[Qt::Key_F20 ] = osgGA::GUIEventAdapter::KEY_F20; - - mKeyMap[Qt::Key_hyphen ] = '-'; - mKeyMap[Qt::Key_Equal ] = '='; - - mKeyMap[Qt::Key_division ] = osgGA::GUIEventAdapter::KEY_KP_Divide; - mKeyMap[Qt::Key_multiply ] = osgGA::GUIEventAdapter::KEY_KP_Multiply; - mKeyMap[Qt::Key_Minus ] = '-'; - mKeyMap[Qt::Key_Plus ] = '+'; - //mKeyMap[Qt::Key_H ] = osgGA::GUIEventAdapter::KEY_KP_Home; - //mKeyMap[Qt::Key_ ] = osgGA::GUIEventAdapter::KEY_KP_Up; - //mKeyMap[92 ] = osgGA::GUIEventAdapter::KEY_KP_Page_Up; - //mKeyMap[86 ] = osgGA::GUIEventAdapter::KEY_KP_Left; - //mKeyMap[87 ] = osgGA::GUIEventAdapter::KEY_KP_Begin; - //mKeyMap[88 ] = osgGA::GUIEventAdapter::KEY_KP_Right; - //mKeyMap[83 ] = osgGA::GUIEventAdapter::KEY_KP_End; - //mKeyMap[84 ] = osgGA::GUIEventAdapter::KEY_KP_Down; - //mKeyMap[85 ] = osgGA::GUIEventAdapter::KEY_KP_Page_Down; - mKeyMap[Qt::Key_Insert ] = osgGA::GUIEventAdapter::KEY_KP_Insert; - //mKeyMap[Qt::Key_Delete ] = osgGA::GUIEventAdapter::KEY_KP_Delete; - } - - ~QtKeyboardMap() - { - } - - int remapKey(QKeyEvent* event) - { - KeyMap::iterator itr = mKeyMap.find(event->key()); - if (itr == mKeyMap.end()) - { - return int(*(event->text().toLatin1().data())); - } - else - return itr->second; - } - - private: - typedef std::map KeyMap; - KeyMap mKeyMap; -}; - -static QtKeyboardMap s_QtKeyboardMap; - - -/// The object responsible for the scene re-rendering. -class HeartBeat : public QObject { -public: - int _timerId; - osg::Timer _lastFrameStartTime; - osg::observer_ptr< osgViewer::ViewerBase > _viewer; - - virtual ~HeartBeat(); - - void init( osgViewer::ViewerBase *viewer ); - void stopTimer(); - void timerEvent( QTimerEvent *event ); - - static HeartBeat* instance(); -private: - HeartBeat(); - - static QPointer heartBeat; -}; - -QPointer HeartBeat::heartBeat; - -#if (QT_VERSION < QT_VERSION_CHECK(5, 2, 0)) - #define GETDEVICEPIXELRATIO() 1.0 -#else - #define GETDEVICEPIXELRATIO() devicePixelRatio() -#endif - -GLWidget::GLWidget( QWidget* parent, const QGLWidget* shareWidget, Qt::WindowFlags f, bool forwardKeyEvents ) -: QGLWidget(parent, shareWidget, f), -_gw( NULL ), -_touchEventsEnabled( false ), -_forwardKeyEvents( forwardKeyEvents ) -{ - _devicePixelRatio = GETDEVICEPIXELRATIO(); -} - -GLWidget::GLWidget( QGLContext* context, QWidget* parent, const QGLWidget* shareWidget, Qt::WindowFlags f, - bool forwardKeyEvents ) -: QGLWidget(context, parent, shareWidget, f), -_gw( NULL ), -_touchEventsEnabled( false ), -_forwardKeyEvents( forwardKeyEvents ) -{ - _devicePixelRatio = GETDEVICEPIXELRATIO(); -} - -GLWidget::GLWidget( const QGLFormat& format, QWidget* parent, const QGLWidget* shareWidget, Qt::WindowFlags f, - bool forwardKeyEvents ) -: QGLWidget(format, parent, shareWidget, f), -_gw( NULL ), -_touchEventsEnabled( false ), -_forwardKeyEvents( forwardKeyEvents ) -{ - _devicePixelRatio = GETDEVICEPIXELRATIO(); -} - -GLWidget::~GLWidget() -{ - // close GraphicsWindowQt and remove the reference to us - if( _gw ) - { - _gw->close(); - _gw->_widget = NULL; - _gw = NULL; - } -} - -void GLWidget::setTouchEventsEnabled(bool e) -{ -#ifdef USE_GESTURES - if (e==_touchEventsEnabled) - return; - - _touchEventsEnabled = e; - - if (_touchEventsEnabled) - { - grabGesture(Qt::PinchGesture); - } - else - { - ungrabGesture(Qt::PinchGesture); - } -#endif -} - -void GLWidget::processDeferredEvents() -{ - QQueue deferredEventQueueCopy; - { - QMutexLocker lock(&_deferredEventQueueMutex); - deferredEventQueueCopy = _deferredEventQueue; - _eventCompressor.clear(); - _deferredEventQueue.clear(); - } - - while (!deferredEventQueueCopy.isEmpty()) - { - QEvent event(deferredEventQueueCopy.dequeue()); - QGLWidget::event(&event); - } -} - -bool GLWidget::event( QEvent* event ) -{ -#ifdef USE_GESTURES - if ( event->type()==QEvent::Gesture ) - return gestureEvent(static_cast(event)); -#endif - - // QEvent::Hide - // - // workaround "Qt-workaround" that does glFinish before hiding the widget - // (the Qt workaround was seen at least in Qt 4.6.3 and 4.7.0) - // - // Qt makes the context current, performs glFinish, and releases the context. - // This makes the problem in OSG multithreaded environment as the context - // is active in another thread, thus it can not be made current for the purpose - // of glFinish in this thread. - - // QEvent::ParentChange - // - // Reparenting GLWidget may create a new underlying window and a new GL context. - // Qt will then call doneCurrent on the GL context about to be deleted. The thread - // where old GL context was current has no longer current context to render to and - // we cannot make new GL context current in this thread. - - // We workaround above problems by deferring execution of problematic event requests. - // These events has to be enqueue and executed later in a main GUI thread (GUI operations - // outside the main thread are not allowed) just before makeCurrent is called from the - // right thread. The good place for doing that is right after swap in a swapBuffersImplementation. - - if (event->type() == QEvent::Hide) - { - // enqueue only the last of QEvent::Hide and QEvent::Show - enqueueDeferredEvent(QEvent::Hide, QEvent::Show); - return true; - } - else if (event->type() == QEvent::Show) - { - // enqueue only the last of QEvent::Show or QEvent::Hide - enqueueDeferredEvent(QEvent::Show, QEvent::Hide); - return true; - } - else if (event->type() == QEvent::ParentChange) - { - // enqueue only the last QEvent::ParentChange - enqueueDeferredEvent(QEvent::ParentChange); - return true; - } - - // perform regular event handling - return QGLWidget::event( event ); -} - -void GLWidget::setKeyboardModifiers( QInputEvent* event ) -{ - int modkey = event->modifiers() & (Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier); - unsigned int mask = 0; - if ( modkey & Qt::ShiftModifier ) mask |= osgGA::GUIEventAdapter::MODKEY_SHIFT; - if ( modkey & Qt::ControlModifier ) mask |= osgGA::GUIEventAdapter::MODKEY_CTRL; - if ( modkey & Qt::AltModifier ) mask |= osgGA::GUIEventAdapter::MODKEY_ALT; - _gw->getEventQueue()->getCurrentEventState()->setModKeyMask( mask ); -} - -void GLWidget::resizeEvent( QResizeEvent* event ) -{ - const QSize& size = event->size(); - - int scaled_width = static_cast(size.width()*_devicePixelRatio); - int scaled_height = static_cast(size.height()*_devicePixelRatio); - _gw->resized( x(), y(), scaled_width, scaled_height); - _gw->getEventQueue()->windowResize( x(), y(), scaled_width, scaled_height ); - _gw->requestRedraw(); -} - -void GLWidget::moveEvent( QMoveEvent* event ) -{ - const QPoint& pos = event->pos(); - int scaled_width = static_cast(width()*_devicePixelRatio); - int scaled_height = static_cast(height()*_devicePixelRatio); - _gw->resized( pos.x(), pos.y(), scaled_width, scaled_height ); - _gw->getEventQueue()->windowResize( pos.x(), pos.y(), scaled_width, scaled_height ); -} - -void GLWidget::glDraw() -{ - _gw->requestRedraw(); -} - -void GLWidget::keyPressEvent( QKeyEvent* event ) -{ - setKeyboardModifiers( event ); - int value = s_QtKeyboardMap.remapKey( event ); - _gw->getEventQueue()->keyPress( value ); - - // this passes the event to the regular Qt key event processing, - // among others, it closes popup windows on ESC and forwards the event to the parent widgets - if( _forwardKeyEvents ) - inherited::keyPressEvent( event ); -} - -void GLWidget::keyReleaseEvent( QKeyEvent* event ) -{ - if( event->isAutoRepeat() ) - { - event->ignore(); - } - else - { - setKeyboardModifiers( event ); - int value = s_QtKeyboardMap.remapKey( event ); - _gw->getEventQueue()->keyRelease( value ); - } - - // this passes the event to the regular Qt key event processing, - // among others, it closes popup windows on ESC and forwards the event to the parent widgets - if( _forwardKeyEvents ) - inherited::keyReleaseEvent( event ); -} - -void GLWidget::mousePressEvent( QMouseEvent* event ) -{ - int button = 0; - switch ( event->button() ) - { - case Qt::LeftButton: button = 1; break; - case Qt::MidButton: button = 2; break; - case Qt::RightButton: button = 3; break; - case Qt::NoButton: button = 0; break; - default: button = 0; break; - } - setKeyboardModifiers( event ); - _gw->getEventQueue()->mouseButtonPress( event->x()*_devicePixelRatio, event->y()*_devicePixelRatio, button ); -} - -void GLWidget::mouseReleaseEvent( QMouseEvent* event ) -{ - int button = 0; - switch ( event->button() ) - { - case Qt::LeftButton: button = 1; break; - case Qt::MidButton: button = 2; break; - case Qt::RightButton: button = 3; break; - case Qt::NoButton: button = 0; break; - default: button = 0; break; - } - setKeyboardModifiers( event ); - _gw->getEventQueue()->mouseButtonRelease( event->x()*_devicePixelRatio, event->y()*_devicePixelRatio, button ); -} - -void GLWidget::mouseDoubleClickEvent( QMouseEvent* event ) -{ - int button = 0; - switch ( event->button() ) - { - case Qt::LeftButton: button = 1; break; - case Qt::MidButton: button = 2; break; - case Qt::RightButton: button = 3; break; - case Qt::NoButton: button = 0; break; - default: button = 0; break; - } - setKeyboardModifiers( event ); - _gw->getEventQueue()->mouseDoubleButtonPress( event->x()*_devicePixelRatio, event->y()*_devicePixelRatio, button ); -} - -void GLWidget::mouseMoveEvent( QMouseEvent* event ) -{ - setKeyboardModifiers( event ); - _gw->getEventQueue()->mouseMotion( event->x()*_devicePixelRatio, event->y()*_devicePixelRatio ); -} - -void GLWidget::wheelEvent( QWheelEvent* event ) -{ - setKeyboardModifiers( event ); - _gw->getEventQueue()->mouseScroll( - event->orientation() == Qt::Vertical ? - (event->delta()>0 ? osgGA::GUIEventAdapter::SCROLL_UP : osgGA::GUIEventAdapter::SCROLL_DOWN) : - (event->delta()>0 ? osgGA::GUIEventAdapter::SCROLL_LEFT : osgGA::GUIEventAdapter::SCROLL_RIGHT) ); -} - -#ifdef USE_GESTURES -static osgGA::GUIEventAdapter::TouchPhase translateQtGestureState( Qt::GestureState state ) -{ - osgGA::GUIEventAdapter::TouchPhase touchPhase; - switch ( state ) - { - case Qt::GestureStarted: - touchPhase = osgGA::GUIEventAdapter::TOUCH_BEGAN; - break; - case Qt::GestureUpdated: - touchPhase = osgGA::GUIEventAdapter::TOUCH_MOVED; - break; - case Qt::GestureFinished: - case Qt::GestureCanceled: - touchPhase = osgGA::GUIEventAdapter::TOUCH_ENDED; - break; - default: - touchPhase = osgGA::GUIEventAdapter::TOUCH_UNKNOWN; - }; - - return touchPhase; -} -#endif - - -bool GLWidget::gestureEvent( QGestureEvent* qevent ) -{ -#ifndef USE_GESTURES - return false; -#else - - bool accept = false; - - if ( QPinchGesture* pinch = static_cast(qevent->gesture(Qt::PinchGesture) ) ) - { - const QPointF qcenterf = pinch->centerPoint(); - const float angle = pinch->totalRotationAngle(); - const float scale = pinch->totalScaleFactor(); - - const QPoint pinchCenterQt = mapFromGlobal(qcenterf.toPoint()); - const osg::Vec2 pinchCenter( pinchCenterQt.x(), pinchCenterQt.y() ); - - //We don't have absolute positions of the two touches, only a scale and rotation - //Hence we create pseudo-coordinates which are reasonable, and centered around the - //real position - const float radius = float(width()+height())/4.0f; - const osg::Vec2 vector( scale*cos(angle)*radius, scale*sin(angle)*radius); - const osg::Vec2 p0 = pinchCenter+vector; - const osg::Vec2 p1 = pinchCenter-vector; - - osg::ref_ptr event = 0; - const osgGA::GUIEventAdapter::TouchPhase touchPhase = translateQtGestureState( pinch->state() ); - if ( touchPhase==osgGA::GUIEventAdapter::TOUCH_BEGAN ) - { - event = _gw->getEventQueue()->touchBegan(0 , touchPhase, p0[0], p0[1] ); - } - else if ( touchPhase==osgGA::GUIEventAdapter::TOUCH_MOVED ) - { - event = _gw->getEventQueue()->touchMoved( 0, touchPhase, p0[0], p0[1] ); - } - else - { - event = _gw->getEventQueue()->touchEnded( 0, touchPhase, p0[0], p0[1], 1 ); - } - - if ( event ) - { - event->addTouchPoint( 1, touchPhase, p1[0], p1[1] ); - accept = true; - } - } - - if ( accept ) - qevent->accept(); - - return accept; -#endif -} - - - -GraphicsWindowQt::GraphicsWindowQt( osg::GraphicsContext::Traits* traits, QWidget* parent, const QGLWidget* shareWidget, Qt::WindowFlags f ) -: _realized(false) -{ - - _widget = NULL; - _traits = traits; - init( parent, shareWidget, f ); -} - -GraphicsWindowQt::GraphicsWindowQt( GLWidget* widget ) -: _realized(false) -{ - _widget = widget; - _traits = _widget ? createTraits( _widget ) : new osg::GraphicsContext::Traits; - init( NULL, NULL, 0 ); -} - -GraphicsWindowQt::~GraphicsWindowQt() -{ - close(); - - // remove reference from GLWidget - if ( _widget ) - _widget->_gw = NULL; -} - -bool GraphicsWindowQt::init( QWidget* parent, const QGLWidget* shareWidget, Qt::WindowFlags f ) -{ - // update _widget and parent by WindowData - WindowData* windowData = _traits.get() ? dynamic_cast(_traits->inheritedWindowData.get()) : 0; - if ( !_widget ) - _widget = windowData ? windowData->_widget : NULL; - if ( !parent ) - parent = windowData ? windowData->_parent : NULL; - - // create widget if it does not exist - _ownsWidget = _widget == NULL; - if ( !_widget ) - { - // shareWidget - if ( !shareWidget ) { - GraphicsWindowQt* sharedContextQt = dynamic_cast(_traits->sharedContext.get()); - if ( sharedContextQt ) - shareWidget = sharedContextQt->getGLWidget(); - } - - // WindowFlags - Qt::WindowFlags flags = f | Qt::Window | Qt::CustomizeWindowHint; - if ( _traits->windowDecoration ) - flags |= Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowSystemMenuHint -#if (QT_VERSION_CHECK(4, 5, 0) <= QT_VERSION) - | Qt::WindowCloseButtonHint -#endif - ; - - // create widget - _widget = new GLWidget( traits2qglFormat( _traits.get() ), parent, shareWidget, flags ); - } - - // set widget name and position - // (do not set it when we inherited the widget) - if ( _ownsWidget ) - { - _widget->setWindowTitle( _traits->windowName.c_str() ); - _widget->move( _traits->x, _traits->y ); - if ( !_traits->supportsResize ) _widget->setFixedSize( _traits->width, _traits->height ); - else _widget->resize( _traits->width, _traits->height ); - } - - // initialize widget properties - _widget->setAutoBufferSwap( false ); - _widget->setMouseTracking( true ); - _widget->setFocusPolicy( Qt::WheelFocus ); - _widget->setGraphicsWindow( this ); - useCursor( _traits->useCursor ); - - // initialize State - setState( new osg::State ); - getState()->setGraphicsContext(this); - - // initialize contextID - if ( _traits.valid() && _traits->sharedContext.valid() ) - { - getState()->setContextID( _traits->sharedContext->getState()->getContextID() ); - incrementContextIDUsageCount( getState()->getContextID() ); - } - else - { - getState()->setContextID( osg::GraphicsContext::createNewContextID() ); - } - - // make sure the event queue has the correct window rectangle size and input range - getEventQueue()->syncWindowRectangleWithGraphicsContext(); - - return true; -} - -QGLFormat GraphicsWindowQt::traits2qglFormat( const osg::GraphicsContext::Traits* traits ) -{ - QGLFormat format( QGLFormat::defaultFormat() ); - - format.setAlphaBufferSize( traits->alpha ); - format.setRedBufferSize( traits->red ); - format.setGreenBufferSize( traits->green ); - format.setBlueBufferSize( traits->blue ); - format.setDepthBufferSize( traits->depth ); - format.setStencilBufferSize( traits->stencil ); - format.setSampleBuffers( traits->sampleBuffers ); - format.setSamples( traits->samples ); - - format.setAlpha( traits->alpha>0 ); - format.setDepth( traits->depth>0 ); - format.setStencil( traits->stencil>0 ); - format.setDoubleBuffer( traits->doubleBuffer ); - format.setSwapInterval( traits->vsync ? 1 : 0 ); - format.setStereo( traits->quadBufferStereo ? 1 : 0 ); - - return format; -} - -void GraphicsWindowQt::qglFormat2traits( const QGLFormat& format, osg::GraphicsContext::Traits* traits ) -{ - traits->red = format.redBufferSize(); - traits->green = format.greenBufferSize(); - traits->blue = format.blueBufferSize(); - traits->alpha = format.alpha() ? format.alphaBufferSize() : 0; - traits->depth = format.depth() ? format.depthBufferSize() : 0; - traits->stencil = format.stencil() ? format.stencilBufferSize() : 0; - - traits->sampleBuffers = format.sampleBuffers() ? 1 : 0; - traits->samples = format.samples(); - - traits->quadBufferStereo = format.stereo(); - traits->doubleBuffer = format.doubleBuffer(); - - traits->vsync = format.swapInterval() >= 1; -} - -osg::GraphicsContext::Traits* GraphicsWindowQt::createTraits( const QGLWidget* widget ) -{ - osg::GraphicsContext::Traits *traits = new osg::GraphicsContext::Traits; - - qglFormat2traits( widget->format(), traits ); - - QRect r = widget->geometry(); - traits->x = r.x(); - traits->y = r.y(); - traits->width = r.width(); - traits->height = r.height(); - - traits->windowName = widget->windowTitle().toLocal8Bit().data(); - Qt::WindowFlags f = widget->windowFlags(); - traits->windowDecoration = ( f & Qt::WindowTitleHint ) && - ( f & Qt::WindowMinMaxButtonsHint ) && - ( f & Qt::WindowSystemMenuHint ); - QSizePolicy sp = widget->sizePolicy(); - traits->supportsResize = sp.horizontalPolicy() != QSizePolicy::Fixed || - sp.verticalPolicy() != QSizePolicy::Fixed; - - return traits; -} - -bool GraphicsWindowQt::setWindowRectangleImplementation( int x, int y, int width, int height ) -{ - if ( _widget == NULL ) - return false; - - _widget->setGeometry( x, y, width, height ); - return true; -} - -void GraphicsWindowQt::getWindowRectangle( int& x, int& y, int& width, int& height ) -{ - if ( _widget ) - { - const QRect& geom = _widget->geometry(); - x = geom.x(); - y = geom.y(); - width = geom.width(); - height = geom.height(); - } -} - -bool GraphicsWindowQt::setWindowDecorationImplementation( bool windowDecoration ) -{ - Qt::WindowFlags flags = Qt::Window|Qt::CustomizeWindowHint;//|Qt::WindowStaysOnTopHint; - if ( windowDecoration ) - flags |= Qt::WindowTitleHint|Qt::WindowMinMaxButtonsHint|Qt::WindowSystemMenuHint; - _traits->windowDecoration = windowDecoration; - - if ( _widget ) - { - _widget->setWindowFlags( flags ); - - return true; - } - - return false; -} - -bool GraphicsWindowQt::getWindowDecoration() const -{ - return _traits->windowDecoration; -} - -void GraphicsWindowQt::grabFocus() -{ - if ( _widget ) - _widget->setFocus( Qt::ActiveWindowFocusReason ); -} - -void GraphicsWindowQt::grabFocusIfPointerInWindow() -{ - if ( _widget->underMouse() ) - _widget->setFocus( Qt::ActiveWindowFocusReason ); -} - -void GraphicsWindowQt::raiseWindow() -{ - if ( _widget ) - _widget->raise(); -} - -void GraphicsWindowQt::setWindowName( const std::string& name ) -{ - if ( _widget ) - _widget->setWindowTitle( name.c_str() ); -} - -std::string GraphicsWindowQt::getWindowName() -{ - return _widget ? _widget->windowTitle().toStdString() : ""; -} - -void GraphicsWindowQt::useCursor( bool cursorOn ) -{ - if ( _widget ) - { - _traits->useCursor = cursorOn; - if ( !cursorOn ) _widget->setCursor( Qt::BlankCursor ); - else _widget->setCursor( _currentCursor ); - } -} - -void GraphicsWindowQt::setCursor( MouseCursor cursor ) -{ - if ( cursor==InheritCursor && _widget ) - { - _widget->unsetCursor(); - } - - switch ( cursor ) - { - case NoCursor: _currentCursor = Qt::BlankCursor; break; - case RightArrowCursor: case LeftArrowCursor: _currentCursor = Qt::ArrowCursor; break; - case InfoCursor: _currentCursor = Qt::SizeAllCursor; break; - case DestroyCursor: _currentCursor = Qt::ForbiddenCursor; break; - case HelpCursor: _currentCursor = Qt::WhatsThisCursor; break; - case CycleCursor: _currentCursor = Qt::ForbiddenCursor; break; - case SprayCursor: _currentCursor = Qt::SizeAllCursor; break; - case WaitCursor: _currentCursor = Qt::WaitCursor; break; - case TextCursor: _currentCursor = Qt::IBeamCursor; break; - case CrosshairCursor: _currentCursor = Qt::CrossCursor; break; - case HandCursor: _currentCursor = Qt::OpenHandCursor; break; - case UpDownCursor: _currentCursor = Qt::SizeVerCursor; break; - case LeftRightCursor: _currentCursor = Qt::SizeHorCursor; break; - case TopSideCursor: case BottomSideCursor: _currentCursor = Qt::UpArrowCursor; break; - case LeftSideCursor: case RightSideCursor: _currentCursor = Qt::SizeHorCursor; break; - case TopLeftCorner: _currentCursor = Qt::SizeBDiagCursor; break; - case TopRightCorner: _currentCursor = Qt::SizeFDiagCursor; break; - case BottomRightCorner: _currentCursor = Qt::SizeBDiagCursor; break; - case BottomLeftCorner: _currentCursor = Qt::SizeFDiagCursor; break; - default: break; - }; - if ( _widget ) _widget->setCursor( _currentCursor ); -} - -bool GraphicsWindowQt::valid() const -{ - return _widget && _widget->isValid(); -} - -bool GraphicsWindowQt::realizeImplementation() -{ - // save the current context - // note: this will save only Qt-based contexts - const QGLContext *savedContext = QGLContext::currentContext(); - - // initialize GL context for the widget - if ( !valid() ) - _widget->glInit(); - - // make current - _realized = true; - bool result = makeCurrent(); - _realized = false; - - // fail if we do not have current context - if ( !result ) - { - if ( savedContext ) - const_cast< QGLContext* >( savedContext )->makeCurrent(); - - OSG_WARN << "Window realize: Can make context current." << std::endl; - return false; - } - - _realized = true; - - // make sure the event queue has the correct window rectangle size and input range - getEventQueue()->syncWindowRectangleWithGraphicsContext(); - - // make this window's context not current - // note: this must be done as we will probably make the context current from another thread - // and it is not allowed to have one context current in two threads - if( !releaseContext() ) - OSG_WARN << "Window realize: Can not release context." << std::endl; - - // restore previous context - if ( savedContext ) - const_cast< QGLContext* >( savedContext )->makeCurrent(); - - return true; -} - -bool GraphicsWindowQt::isRealizedImplementation() const -{ - return _realized; -} - -void GraphicsWindowQt::closeImplementation() -{ - if ( _widget ) - _widget->close(); - _realized = false; -} - -void GraphicsWindowQt::runOperations() -{ - // While in graphics thread this is last chance to do something useful before - // graphics thread will execute its operations. - if (_widget->getNumDeferredEvents() > 0) - _widget->processDeferredEvents(); - - if (QGLContext::currentContext() != _widget->context()) - _widget->makeCurrent(); - - GraphicsWindow::runOperations(); -} - -bool GraphicsWindowQt::makeCurrentImplementation() -{ - if (_widget->getNumDeferredEvents() > 0) - _widget->processDeferredEvents(); - - _widget->makeCurrent(); - - return true; -} - -bool GraphicsWindowQt::releaseContextImplementation() -{ - _widget->doneCurrent(); - return true; -} - -void GraphicsWindowQt::swapBuffersImplementation() -{ - _widget->swapBuffers(); - - // FIXME: the processDeferredEvents should really be executed in a GUI (main) thread context but - // I couln't find any reliable way to do this. For now, lets hope non of *GUI thread only operations* will - // be executed in a QGLWidget::event handler. On the other hand, calling GUI only operations in the - // QGLWidget event handler is an indication of a Qt bug. - if (_widget->getNumDeferredEvents() > 0) - _widget->processDeferredEvents(); - - // We need to call makeCurrent here to restore our previously current context - // which may be changed by the processDeferredEvents function. - if (QGLContext::currentContext() != _widget->context()) - _widget->makeCurrent(); -} - -void GraphicsWindowQt::requestWarpPointer( float x, float y ) -{ - if ( _widget ) - QCursor::setPos( _widget->mapToGlobal(QPoint((int)x,(int)y)) ); -} - -class QtWindowingSystem : public osg::GraphicsContext::WindowingSystemInterface -{ -public: - - QtWindowingSystem() - { - OSG_INFO << "QtWindowingSystemInterface()" << std::endl; - } - - ~QtWindowingSystem() - { - if (osg::Referenced::getDeleteHandler()) - { - osg::Referenced::getDeleteHandler()->setNumFramesToRetainObjects(0); - osg::Referenced::getDeleteHandler()->flushAll(); - } - } - - // Access the Qt windowing system through this singleton class. - static QtWindowingSystem* getInterface() - { - static QtWindowingSystem* qtInterface = new QtWindowingSystem; - return qtInterface; - } - - // Return the number of screens present in the system - virtual unsigned int getNumScreens( const osg::GraphicsContext::ScreenIdentifier& /*si*/ ) - { - OSG_WARN << "osgQt: getNumScreens() not implemented yet." << std::endl; - return 0; - } - - // Return the resolution of specified screen - // (0,0) is returned if screen is unknown - virtual void getScreenSettings( const osg::GraphicsContext::ScreenIdentifier& /*si*/, osg::GraphicsContext::ScreenSettings & /*resolution*/ ) - { - OSG_WARN << "osgQt: getScreenSettings() not implemented yet." << std::endl; - } - - // Set the resolution for given screen - virtual bool setScreenSettings( const osg::GraphicsContext::ScreenIdentifier& /*si*/, const osg::GraphicsContext::ScreenSettings & /*resolution*/ ) - { - OSG_WARN << "osgQt: setScreenSettings() not implemented yet." << std::endl; - return false; - } - - // Enumerates available resolutions - virtual void enumerateScreenSettings( const osg::GraphicsContext::ScreenIdentifier& /*screenIdentifier*/, osg::GraphicsContext::ScreenSettingsList & /*resolution*/ ) - { - OSG_WARN << "osgQt: enumerateScreenSettings() not implemented yet." << std::endl; - } - - // Create a graphics context with given traits - virtual osg::GraphicsContext* createGraphicsContext( osg::GraphicsContext::Traits* traits ) - { - if (traits->pbuffer) - { - OSG_WARN << "osgQt: createGraphicsContext - pbuffer not implemented yet." << std::endl; - return NULL; - } - else - { - osg::ref_ptr< GraphicsWindowQt > window = new GraphicsWindowQt( traits ); - if (window->valid()) return window.release(); - else return NULL; - } - } - -private: - - // No implementation for these - QtWindowingSystem( const QtWindowingSystem& ); - QtWindowingSystem& operator=( const QtWindowingSystem& ); -}; - -#if 1 -REGISTER_WINDOWINGSYSTEMINTERFACE(Qt, QtWindowingSystem) -#else - -// declare C entry point for static compilation. -extern "C" void OSGQT_EXPORT graphicswindow_Qt(void) -{ - osg::GraphicsContext::setWindowingSystemInterface(QtWindowingSystem::getInterface()); -} - - -void osgQt::initQtWindowingSystem() -{ - graphicswindow_Qt(); -} -#endif - - -void osgQt::setViewer( osgViewer::ViewerBase *viewer ) -{ - HeartBeat::instance()->init( viewer ); -} - - -/// Constructor. Must be called from main thread. -HeartBeat::HeartBeat() : _timerId( 0 ) -{ -} - - -/// Destructor. Must be called from main thread. -HeartBeat::~HeartBeat() -{ - stopTimer(); -} - -HeartBeat* HeartBeat::instance() -{ - if (!heartBeat) - { - heartBeat = new HeartBeat(); - } - return heartBeat; -} - -void HeartBeat::stopTimer() -{ - if ( _timerId != 0 ) - { - killTimer( _timerId ); - _timerId = 0; - } -} - - -/// Initializes the loop for viewer. Must be called from main thread. -void HeartBeat::init( osgViewer::ViewerBase *viewer ) -{ - if( _viewer == viewer ) - return; - - stopTimer(); - - _viewer = viewer; - - if( viewer ) - { - _timerId = startTimer( 0 ); - _lastFrameStartTime.setStartTick( 0 ); - } -} - - -void HeartBeat::timerEvent( QTimerEvent * /*event*/ ) -{ - osg::ref_ptr< osgViewer::ViewerBase > viewer; - if( !_viewer.lock( viewer ) ) - { - // viewer has been deleted -> stop timer - stopTimer(); - return; - } - - // limit the frame rate - if( viewer->getRunMaxFrameRate() > 0.0) - { - double dt = _lastFrameStartTime.time_s(); - double minFrameTime = 1.0 / viewer->getRunMaxFrameRate(); - if (dt < minFrameTime) - OpenThreads::Thread::microSleep(static_cast(1000000.0*(minFrameTime-dt))); - } - else - { - // avoid excessive CPU loading when no frame is required in ON_DEMAND mode - if( viewer->getRunFrameScheme() == osgViewer::ViewerBase::ON_DEMAND ) - { - double dt = _lastFrameStartTime.time_s(); - if (dt < 0.01) - OpenThreads::Thread::microSleep(static_cast(1000000.0*(0.01-dt))); - } - - // record start frame time - _lastFrameStartTime.setStartTick(); - - // make frame - if( viewer->getRunFrameScheme() == osgViewer::ViewerBase::ON_DEMAND ) - { - if( viewer->checkNeedToDoFrame() ) - { - viewer->frame(); - } - } - else - { - viewer->frame(); - } - } -} diff --git a/src/osgQt/QFontImplementation.cpp b/src/osgQt/QFontImplementation.cpp deleted file mode 100644 index 37fbba286..000000000 --- a/src/osgQt/QFontImplementation.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 2009-2010 Mathias Froehlich - * - * 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 - -#include -#include -#include - -#include -#include -#include -#include - -namespace osgQt { - -QFontImplementation::QFontImplementation(const QFont& font) : - _filename(font.toString().toStdString() + ".qfont"), - _font(font) -{ -} - -QFontImplementation::~QFontImplementation() -{ -} - -std::string -QFontImplementation::getFileName() const -{ - return _filename; -} - -osgText::Glyph* -QFontImplementation::getGlyph(const osgText::FontResolution& fontRes, unsigned int charcode) -{ - unsigned int fontSize = fontRes.second; - _font.setPixelSize(fontSize); - - float coord_scale = 1.0f/float(fontSize); - - QFontMetrics fontMetrics(_font); - QFontMetricsF fontMetricsF(_font); - - QRect rect = fontMetrics.boundingRect(QChar(charcode)); - QRectF rectF = fontMetricsF.boundingRect(QChar(charcode)); - - int margin = 1; - - int imageWidth = rect.width() + 2*margin; - int imageHeight = rect.height() + 2*margin; - - // Now paint the glyph into the image - QImage image(imageWidth, imageHeight, QImage::Format_ARGB32); - image.fill(0); - QPainter painter(&image); - painter.setRenderHint(QPainter::TextAntialiasing); - - painter.setFont(_font); - - painter.setBackgroundMode(Qt::TransparentMode); - painter.setBrush(Qt::white); - painter.setPen(Qt::white); - - painter.drawText(margin - rect.left(), imageHeight - 1 - (margin + rect.bottom()), QString(QChar(charcode))); - painter.end(); - - // Transfer the rendered image to osg - osg::ref_ptr glyph = new osgText::Glyph(_facade, charcode); - - unsigned int dataSize = imageWidth*imageHeight; - unsigned char* data = new unsigned char[dataSize]; - - // copy the qimage into the texture memory - for (int x = 0; x < imageWidth; ++x) - { - for (int y = 0; y < imageHeight; ++y) - { - data[x + y*imageWidth] = qAlpha(image.pixel(x, imageHeight - 1 - y)); - } - } - - // the glyph texture in osg - glyph->setImage(imageWidth, imageHeight, 1, - OSGTEXT_GLYPH_INTERNALFORMAT, - OSGTEXT_GLYPH_FORMAT, GL_UNSIGNED_BYTE, - data, - osg::Image::USE_NEW_DELETE, - 1); - glyph->setInternalTextureFormat(OSGTEXT_GLYPH_INTERNALFORMAT); - - glyph->setWidth((float)imageWidth * coord_scale); - glyph->setHeight((float)imageHeight * coord_scale); - - // Layout parameters - float leftBearing = fontMetricsF.leftBearing(QChar(charcode)); - float rightBearing = fontMetricsF.rightBearing(QChar(charcode)); - - // for horizonal layout - osg::Vec2 bottomLeft(leftBearing - margin, - rectF.bottom() - margin); - glyph->setHorizontalBearing(bottomLeft * coord_scale); - glyph->setHorizontalAdvance(fontMetricsF.width(QChar(charcode)) * coord_scale); - - // for vertical layout - osg::Vec2 topMiddle(- margin + 0.5*(leftBearing - rect.width() - rightBearing), - rectF.top() - margin); - glyph->setVerticalBearing(topMiddle * coord_scale); - glyph->setVerticalAdvance((rectF.height() + fontMetricsF.overlinePos() - fontMetricsF.xHeight()) * coord_scale); - - // ... ready - //addGlyph(fontRes, charcode, glyph.get()); - - return glyph.release(); -} - -osg::Vec2 -QFontImplementation::getKerning(const osgText::FontResolution& /*fontRes*/, unsigned int /*leftcharcode*/, unsigned int /*rightcharcode*/, osgText::KerningType /*kerningType*/) -{ - return osg::Vec2(0, 0); -} - -bool -QFontImplementation::hasVertical() const -{ - return true; -} - -} diff --git a/src/osgQt/QGraphicsViewAdapter.cpp b/src/osgQt/QGraphicsViewAdapter.cpp deleted file mode 100644 index 4d0200e7c..000000000 --- a/src/osgQt/QGraphicsViewAdapter.cpp +++ /dev/null @@ -1,613 +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 -#include - -#include - -#include -#include - -#include -#include -#include -#include - -#define MYQKEYEVENT 2000 -#define MYQPOINTEREVENT 2001 - -namespace osgQt -{ - -QCoreApplication* getOrCreateQApplication() -{ - if (QApplication::instance()==0) - { - static char** argv = 0; - static int argc = 0; - static QApplication app(argc,argv); - } - return QApplication::instance(); -} - -class MyQKeyEvent : public QEvent -{ -public: - MyQKeyEvent( int key, bool down ): - QEvent( QEvent::Type(MYQKEYEVENT) ), - _key(key), _down(down) {} - - int _key; - bool _down; -}; - -struct MyQPointerEvent : public QEvent -{ - MyQPointerEvent(int x, int y, unsigned int buttonMask): - QEvent( QEvent::Type(MYQPOINTEREVENT) ), - _x(x), _y(y),_buttonMask(buttonMask) {} - - int _x, _y; - unsigned int _buttonMask; -}; - - -const QImage::Format s_imageFormat = QImage::Format_ARGB32_Premultiplied; - -QGraphicsViewAdapter::QGraphicsViewAdapter(osg::Image* image, QWidget* widget): - _image(image), - _backgroundWidget(0), - _previousButtonMask(0), - _previousMouseX(-1), - _previousMouseY(-1), - _previousQtMouseX(-1), - _previousQtMouseY(-1), - _previousSentEvent(false), - _requiresRendering(false), - _qtKeyModifiers(Qt::NoModifier), - _backgroundColor(255, 255, 255), - _widget(widget) -{ - // make sure we have a valid QApplication before we start creating widgets. - getOrCreateQApplication(); - - - setUpKeyMap(); - - _graphicsScene = new QGraphicsScene; - _graphicsScene->addWidget(widget); - - _graphicsView = new QGraphicsView; - _graphicsView->setScene(_graphicsScene); - _graphicsView->viewport()->setParent(0); - -#if (QT_VERSION_CHECK(4, 5, 0) <= QT_VERSION) - _graphicsScene->setStickyFocus(true); -#endif - - _width = static_cast(_graphicsScene->width()); - _height = static_cast(_graphicsScene->height()); - - _qimages[0] = QImage(QSize(_width, _height), s_imageFormat); - _qimages[1] = QImage(QSize(_width, _height), s_imageFormat); - _qimages[2] = QImage(QSize(_width, _height), s_imageFormat); - - _currentRead = 0; - _currentWrite = 1; - _previousWrite = 2; - _previousFrameNumber = osg::UNINITIALIZED_FRAME_NUMBER; - _newImageAvailable = false; - - connect(_graphicsScene, SIGNAL(changed(const QList &)), - this, SLOT(repaintRequestedSlot(const QList &))); - connect(_graphicsScene, SIGNAL(sceneRectChanged(const QRectF &)), - this, SLOT(repaintRequestedSlot(const QRectF &))); - - assignImage(0); -} - -void QGraphicsViewAdapter::repaintRequestedSlot(const QList&) -{ - // OSG_NOTICE<<"QGraphicsViewAdapter::repaintRequestedSlot"<type()==MYQKEYEVENT) - { - MyQKeyEvent* keyEvent = (MyQKeyEvent*)event; - handleKeyEvent(keyEvent->_key, keyEvent->_down); - } - else if (event->type()==MYQPOINTEREVENT) - { - MyQPointerEvent* pointerEvent = (MyQPointerEvent*)event; - handlePointerEvent(pointerEvent->_x, pointerEvent->_y, pointerEvent->_buttonMask); - } -} - - -void QGraphicsViewAdapter::setUpKeyMap() -{ - _keyMap[osgGA::GUIEventAdapter::KEY_BackSpace] = Qt::Key_Backspace; - _keyMap[osgGA::GUIEventAdapter::KEY_Tab] = Qt::Key_Tab; - _keyMap[osgGA::GUIEventAdapter::KEY_Linefeed] = Qt::Key_Return; // No LineFeed in Qt! - _keyMap[osgGA::GUIEventAdapter::KEY_Clear] = Qt::Key_Clear; - _keyMap[osgGA::GUIEventAdapter::KEY_Return] = Qt::Key_Return; - _keyMap[osgGA::GUIEventAdapter::KEY_Pause] = Qt::Key_Pause; - _keyMap[osgGA::GUIEventAdapter::KEY_Scroll_Lock] = Qt::Key_ScrollLock; - _keyMap[osgGA::GUIEventAdapter::KEY_Sys_Req] = Qt::Key_SysReq; - _keyMap[osgGA::GUIEventAdapter::KEY_Escape] = Qt::Key_Escape; - _keyMap[osgGA::GUIEventAdapter::KEY_Delete] = Qt::Key_Delete; - - _keyMap[osgGA::GUIEventAdapter::KEY_Home] = Qt::Key_Home; - _keyMap[osgGA::GUIEventAdapter::KEY_Left] = Qt::Key_Left; - _keyMap[osgGA::GUIEventAdapter::KEY_Up] = Qt::Key_Up; - _keyMap[osgGA::GUIEventAdapter::KEY_Right] = Qt::Key_Right; - _keyMap[osgGA::GUIEventAdapter::KEY_Down] = Qt::Key_Down; - _keyMap[osgGA::GUIEventAdapter::KEY_Prior] = Qt::Key_Left; // no Prior in Qt - _keyMap[osgGA::GUIEventAdapter::KEY_Page_Up] = Qt::Key_PageUp; - _keyMap[osgGA::GUIEventAdapter::KEY_Next] = Qt::Key_Right; // No Next in Qt - _keyMap[osgGA::GUIEventAdapter::KEY_Page_Down] = Qt::Key_PageDown; - _keyMap[osgGA::GUIEventAdapter::KEY_End] = Qt::Key_End; - _keyMap[osgGA::GUIEventAdapter::KEY_Begin] = Qt::Key_Home; // No Begin in Qt - - _keyMap[osgGA::GUIEventAdapter::KEY_Select] = Qt::Key_Select; - _keyMap[osgGA::GUIEventAdapter::KEY_Print] = Qt::Key_Print; - _keyMap[osgGA::GUIEventAdapter::KEY_Execute] = Qt::Key_Execute; - _keyMap[osgGA::GUIEventAdapter::KEY_Insert] = Qt::Key_Insert; - //_keyMap[osgGA::GUIEventAdapter::KEY_Undo] = Qt::Key_; // no Undo - //_keyMap[osgGA::GUIEventAdapter::KEY_Redo] = Qt::Key_; // no Redo - _keyMap[osgGA::GUIEventAdapter::KEY_Menu] = Qt::Key_Menu; - _keyMap[osgGA::GUIEventAdapter::KEY_Find] = Qt::Key_Search; // no Qt Find - _keyMap[osgGA::GUIEventAdapter::KEY_Cancel] = Qt::Key_Cancel; - _keyMap[osgGA::GUIEventAdapter::KEY_Help] = Qt::Key_Help; - _keyMap[osgGA::GUIEventAdapter::KEY_Break] = Qt::Key_Escape; // no break - _keyMap[osgGA::GUIEventAdapter::KEY_Mode_switch] = Qt::Key_Mode_switch; - _keyMap[osgGA::GUIEventAdapter::KEY_Script_switch] = Qt::Key_Mode_switch; // no Script switch - _keyMap[osgGA::GUIEventAdapter::KEY_Num_Lock] = Qt::Key_NumLock; - - _keyMap[osgGA::GUIEventAdapter::KEY_Shift_L] = Qt::Key_Shift; - _keyMap[osgGA::GUIEventAdapter::KEY_Shift_R] = Qt::Key_Shift; - _keyMap[osgGA::GUIEventAdapter::KEY_Control_L] = Qt::Key_Control; - _keyMap[osgGA::GUIEventAdapter::KEY_Control_R] = Qt::Key_Control; - _keyMap[osgGA::GUIEventAdapter::KEY_Caps_Lock] = Qt::Key_CapsLock; - _keyMap[osgGA::GUIEventAdapter::KEY_Shift_Lock] = Qt::Key_CapsLock; - - _keyMap[osgGA::GUIEventAdapter::KEY_Meta_L] = Qt::Key_Meta; // Qt doesn't have a Meta L - _keyMap[osgGA::GUIEventAdapter::KEY_Meta_R] = Qt::Key_Meta; // Qt doesn't have a Meta R - _keyMap[osgGA::GUIEventAdapter::KEY_Alt_L] = Qt::Key_Alt; // Qt doesn't have a Alt L - _keyMap[osgGA::GUIEventAdapter::KEY_Alt_R] = Qt::Key_Alt; // Qt doesn't have a Alt R - _keyMap[osgGA::GUIEventAdapter::KEY_Super_L] = Qt::Key_Super_L; - _keyMap[osgGA::GUIEventAdapter::KEY_Super_R] = Qt::Key_Super_R; - _keyMap[osgGA::GUIEventAdapter::KEY_Hyper_L] = Qt::Key_Hyper_L; - _keyMap[osgGA::GUIEventAdapter::KEY_Hyper_R] = Qt::Key_Hyper_R; - - _keyMap[osgGA::GUIEventAdapter::KEY_KP_Space] = Qt::Key_Space; - _keyMap[osgGA::GUIEventAdapter::KEY_KP_Tab] = Qt::Key_Tab; - _keyMap[osgGA::GUIEventAdapter::KEY_KP_Enter] = Qt::Key_Enter; - _keyMap[osgGA::GUIEventAdapter::KEY_KP_F1] = Qt::Key_F1; - _keyMap[osgGA::GUIEventAdapter::KEY_KP_F2] = Qt::Key_F2; - _keyMap[osgGA::GUIEventAdapter::KEY_KP_F3] = Qt::Key_F3; - _keyMap[osgGA::GUIEventAdapter::KEY_KP_F4] = Qt::Key_F4; - _keyMap[osgGA::GUIEventAdapter::KEY_KP_Home] = Qt::Key_Home; - _keyMap[osgGA::GUIEventAdapter::KEY_KP_Left] = Qt::Key_Left; - _keyMap[osgGA::GUIEventAdapter::KEY_KP_Up] = Qt::Key_Up; - _keyMap[osgGA::GUIEventAdapter::KEY_KP_Right] = Qt::Key_Right; - _keyMap[osgGA::GUIEventAdapter::KEY_KP_Down] = Qt::Key_Down; - _keyMap[osgGA::GUIEventAdapter::KEY_KP_Prior] = Qt::Key_Left; - _keyMap[osgGA::GUIEventAdapter::KEY_KP_Page_Up] = Qt::Key_PageUp; - _keyMap[osgGA::GUIEventAdapter::KEY_KP_Next] = Qt::Key_Right; - _keyMap[osgGA::GUIEventAdapter::KEY_KP_Page_Down] = Qt::Key_PageDown; - _keyMap[osgGA::GUIEventAdapter::KEY_KP_End] = Qt::Key_End; - - // _keyMap[osgGA::GUIEventAdapter::KEY_KP_Begin] = Qt::Key_Begin; - _keyMap[osgGA::GUIEventAdapter::KEY_KP_Insert] = Qt::Key_Insert; - _keyMap[osgGA::GUIEventAdapter::KEY_KP_Delete] = Qt::Key_Delete; - _keyMap[osgGA::GUIEventAdapter::KEY_KP_Equal] = Qt::Key_Equal; - _keyMap[osgGA::GUIEventAdapter::KEY_KP_Multiply] = Qt::Key_Asterisk; - _keyMap[osgGA::GUIEventAdapter::KEY_KP_Add] = Qt::Key_Plus; - //_keyMap[osgGA::GUIEventAdapter::KEY_KP_Separator] = Qt::Key_; - _keyMap[osgGA::GUIEventAdapter::KEY_KP_Subtract] = Qt::Key_Minus; - _keyMap[osgGA::GUIEventAdapter::KEY_KP_Decimal] = Qt::Key_Period; - _keyMap[osgGA::GUIEventAdapter::KEY_KP_Divide] = Qt::Key_division; - _keyMap[osgGA::GUIEventAdapter::KEY_KP_0] = Qt::Key_0; - _keyMap[osgGA::GUIEventAdapter::KEY_KP_1] = Qt::Key_1; - _keyMap[osgGA::GUIEventAdapter::KEY_KP_2] = Qt::Key_2; - _keyMap[osgGA::GUIEventAdapter::KEY_KP_3] = Qt::Key_3; - _keyMap[osgGA::GUIEventAdapter::KEY_KP_4] = Qt::Key_4; - _keyMap[osgGA::GUIEventAdapter::KEY_KP_5] = Qt::Key_5; - _keyMap[osgGA::GUIEventAdapter::KEY_KP_6] = Qt::Key_6; - _keyMap[osgGA::GUIEventAdapter::KEY_KP_7] = Qt::Key_7; - _keyMap[osgGA::GUIEventAdapter::KEY_KP_8] = Qt::Key_8; - _keyMap[osgGA::GUIEventAdapter::KEY_KP_9] = Qt::Key_9; - - _keyMap[osgGA::GUIEventAdapter::KEY_F1] = Qt::Key_F1; - _keyMap[osgGA::GUIEventAdapter::KEY_F2] = Qt::Key_F2; - _keyMap[osgGA::GUIEventAdapter::KEY_F3] = Qt::Key_F3; - _keyMap[osgGA::GUIEventAdapter::KEY_F4] = Qt::Key_F4; - _keyMap[osgGA::GUIEventAdapter::KEY_F5] = Qt::Key_F5; - _keyMap[osgGA::GUIEventAdapter::KEY_F6] = Qt::Key_F6; - _keyMap[osgGA::GUIEventAdapter::KEY_F7] = Qt::Key_F7; - _keyMap[osgGA::GUIEventAdapter::KEY_F8] = Qt::Key_F8; - _keyMap[osgGA::GUIEventAdapter::KEY_F9] = Qt::Key_F9; - _keyMap[osgGA::GUIEventAdapter::KEY_F10] = Qt::Key_F10; - _keyMap[osgGA::GUIEventAdapter::KEY_F11] = Qt::Key_F11; - _keyMap[osgGA::GUIEventAdapter::KEY_F12] = Qt::Key_F12; - _keyMap[osgGA::GUIEventAdapter::KEY_F13] = Qt::Key_F13; - _keyMap[osgGA::GUIEventAdapter::KEY_F14] = Qt::Key_F14; - _keyMap[osgGA::GUIEventAdapter::KEY_F15] = Qt::Key_F15; - _keyMap[osgGA::GUIEventAdapter::KEY_F16] = Qt::Key_F16; - _keyMap[osgGA::GUIEventAdapter::KEY_F17] = Qt::Key_F17; - _keyMap[osgGA::GUIEventAdapter::KEY_F18] = Qt::Key_F18; - _keyMap[osgGA::GUIEventAdapter::KEY_F19] = Qt::Key_F19; - _keyMap[osgGA::GUIEventAdapter::KEY_F20] = Qt::Key_F20; - _keyMap[osgGA::GUIEventAdapter::KEY_F21] = Qt::Key_F21; - _keyMap[osgGA::GUIEventAdapter::KEY_F22] = Qt::Key_F22; - _keyMap[osgGA::GUIEventAdapter::KEY_F23] = Qt::Key_F23; - _keyMap[osgGA::GUIEventAdapter::KEY_F24] = Qt::Key_F24; - _keyMap[osgGA::GUIEventAdapter::KEY_F25] = Qt::Key_F25; - _keyMap[osgGA::GUIEventAdapter::KEY_F26] = Qt::Key_F26; - _keyMap[osgGA::GUIEventAdapter::KEY_F27] = Qt::Key_F27; - _keyMap[osgGA::GUIEventAdapter::KEY_F28] = Qt::Key_F28; - _keyMap[osgGA::GUIEventAdapter::KEY_F29] = Qt::Key_F29; - _keyMap[osgGA::GUIEventAdapter::KEY_F30] = Qt::Key_F30; - _keyMap[osgGA::GUIEventAdapter::KEY_F31] = Qt::Key_F31; - _keyMap[osgGA::GUIEventAdapter::KEY_F32] = Qt::Key_F32; - _keyMap[osgGA::GUIEventAdapter::KEY_F33] = Qt::Key_F33; - _keyMap[osgGA::GUIEventAdapter::KEY_F34] = Qt::Key_F34; - _keyMap[osgGA::GUIEventAdapter::KEY_F35] = Qt::Key_F35; - -} - -QWidget* QGraphicsViewAdapter::getWidgetAt(const QPoint& pos) -{ - QWidget* childAt = _graphicsView->childAt(pos); - if(childAt) - { - return childAt; - } - - QGraphicsItem* item = _graphicsView->itemAt(pos); - if(item /*&& item->contains(item->mapFromScene(pos))*/) - { - QGraphicsProxyWidget* p = qgraphicsitem_cast(item); - if(p) - { - childAt = p->widget(); - QWidget* c; - while( (c = childAt->childAt(childAt->mapFromGlobal(pos)))!=0 ) - { - childAt = c; - } - - // Widgets like QTextEdit will automatically add child scroll area widgets - // that will be selected by childAt(), we have to change to parents at that moment - // Hardcoded by the internal widget's name 'qt_scrollarea_viewport' at present - if (childAt->objectName() == "qt_scrollarea_viewport") - { - childAt = childAt->parentWidget(); - } - return childAt; - } - } - return NULL; -} - -bool QGraphicsViewAdapter::sendPointerEvent(int x, int y, int buttonMask) -{ - _previousQtMouseX = x; - _previousQtMouseY = _graphicsView->size().height() - y; - - QPoint pos(_previousQtMouseX, _previousQtMouseY); - - QWidget* targetWidget = getWidgetAt(pos); - OSG_INFO << "Get " << (targetWidget ? targetWidget->metaObject()->className() : std::string("NULL")) - << " at global pos " << x << ", " << y << std::endl; - - if (_backgroundWidget && _backgroundWidget == targetWidget) - { - // Mouse is at background widget, so ignore such events - return false; - } - - if (targetWidget != NULL || (_previousSentEvent && buttonMask != 0)) - { - QCoreApplication::postEvent(this, new MyQPointerEvent(x,y,buttonMask)); - OSG_INFO<<"sendPointerEvent("<size().height()-y; - - bool leftButtonPressed = (buttonMask & osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON)!=0; - bool middleButtonPressed = (buttonMask & osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON)!=0; - bool rightButtonPressed = (buttonMask & osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON)!=0; - - bool prev_leftButtonPressed = (_previousButtonMask & osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON)!=0; - bool prev_middleButtonPressed = (_previousButtonMask & osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON)!=0; - bool prev_rightButtonPressed = (_previousButtonMask & osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON)!=0; - - OSG_INFO<<"leftButtonPressed "<mapFromGlobal(globalPos); - QContextMenuEvent* cme = new QContextMenuEvent(QContextMenuEvent::Mouse, localPos, globalPos); - QCoreApplication::postEvent(targetWidget, cme); - } - } - } - - if (eventType==QEvent::MouseButtonPress) - { - _image->sendFocusHint(true); - if (targetWidget) targetWidget->setFocus(Qt::MouseFocusReason); - } - - QMouseEvent event(eventType, globalPos, qtButton, qtMouseButtons, 0); - QCoreApplication::sendEvent(_graphicsView->viewport(), &event); - - _previousButtonMask = buttonMask; - } - else if (x != _previousMouseX || y != _previousMouseY) - { - QMouseEvent event(QEvent::MouseMove, globalPos, Qt::NoButton, qtMouseButtons, 0); - QCoreApplication::sendEvent(_graphicsView->viewport(), &event); - - _previousMouseX = x; - _previousMouseY = y; - } - - return true; -} - -bool QGraphicsViewAdapter::sendKeyEvent(int key, bool keyDown) -{ - QPoint pos(_previousQtMouseX, _previousQtMouseY); - QWidget* targetWidget = getWidgetAt(pos); - if (_backgroundWidget && _backgroundWidget == targetWidget) - { - // Mouse is at background widget, so ignore such events - return false; - } - - if (targetWidget != NULL) - { - QCoreApplication::postEvent(this, new MyQKeyEvent(key,keyDown)); - return true; - } - - return false; -} - -bool QGraphicsViewAdapter::handleKeyEvent(int key, bool keyDown) -{ - QEvent::Type eventType = keyDown ? QEvent::KeyPress : QEvent::KeyRelease; - - OSG_INFO<<"sendKeyEvent("<second; - } - else - { - qtkey = (Qt::Key)key; - input = QChar(key); - } - - QKeyEvent event(eventType, qtkey, _qtKeyModifiers, input); - QCoreApplication::sendEvent(_graphicsScene.data(), &event); - return true; -} - -void QGraphicsViewAdapter::setFrameLastRendered(const osg::FrameStamp* frameStamp) -{ - OSG_INFO<<"setFrameLastRendered("<getFrameNumber()<<")"<getFrameNumber()) - { - { - OpenThreads::ScopedLock lock(_qimagesMutex); - - // make sure that _previousFrameNumber hasn't been updated by another thread since we entered this branch. - if (_previousFrameNumber==frameStamp->getFrameNumber()) return; - _previousFrameNumber = frameStamp->getFrameNumber(); - - std::swap(_currentRead, _previousWrite); - _newImageAvailable = false; - } - - assignImage(_currentRead); - } -} - -void QGraphicsViewAdapter::clearWriteBuffer() -{ - QImage& image = _qimages[_currentWrite]; - image.fill(_backgroundColor.rgba ()); - image = QGLWidget::convertToGLFormat(image); - - // swap the write buffers in a thread safe way - OpenThreads::ScopedLock lock(_qimagesMutex); - std::swap(_currentWrite, _previousWrite); - _newImageAvailable = true; -} - -void QGraphicsViewAdapter::render() -{ - OSG_INFO<<"Current write = "<<_currentWrite< lock(_qresizeMutex); - if (_graphicsView->size().width() != _width || _graphicsView->size().height() != _height) - { - _graphicsView->setGeometry(0, 0, _width, _height); - _graphicsView->viewport()->setGeometry(0, 0, _width, _height); - - _widget->setGeometry(0, 0, _width, _height); - } - - if (image.width() != _width || image.height() != _height) - { - _qimages[_currentWrite] = QImage(_width, _height, s_imageFormat); - image = _qimages[_currentWrite]; - } - OSG_INFO << "render image " << _currentWrite << " with size (" << _width << "," << _height << ")" <render(&painter, destinationRect, sourceRect, Qt::IgnoreAspectRatio); - painter.end(); -#elif 0 - QPixmap pixmap(QPixmap::grabWidget(_graphicsView.data(), QRect(0, 0, image.width(), image.height()))); - image = pixmap.toImage(); -#else - // paint the image with the graphics view - QPixmap pixmap(image.width(), image.height()); - // Clear the image otherwise there are artifacts for some widgets that overpaint. - pixmap.fill(Qt::transparent); - QPainter painter(&pixmap); - - QRectF destinationRect(0, 0, image.width(), image.height()); - QRect sourceRect(0, 0, image.width(), image.height()); - _graphicsView->render(&painter, destinationRect, _graphicsView->viewport()->rect()); - painter.end(); - - image = pixmap.toImage(); -#endif - - // convert into OpenGL format - flipping around the Y axis and swizzling the pixels - image = QGLWidget::convertToGLFormat(image); - - // swap the write buffers in a thread safe way - OpenThreads::ScopedLock lock(_qimagesMutex); - std::swap(_currentWrite, _previousWrite); - _newImageAvailable = true; -} - -void QGraphicsViewAdapter::assignImage(unsigned int i) -{ - QImage& image = _qimages[i]; - unsigned char* data = image.bits(); - - OSG_INFO<<"assignImage("< lock(_qresizeMutex); - _width = width; - _height = height; - } - - // Force an update so render() will be called. - _graphicsScene->update(_graphicsScene->sceneRect()); -} - -} diff --git a/src/osgQt/QWidgetImage.cpp b/src/osgQt/QWidgetImage.cpp deleted file mode 100644 index 17475b4cb..000000000 --- a/src/osgQt/QWidgetImage.cpp +++ /dev/null @@ -1,66 +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 -#include - -namespace osgQt -{ - -QWidgetImage::QWidgetImage( QWidget* widget ) -{ - // make sure we have a valid QApplication before we start creating widgets. - getOrCreateQApplication(); - - _widget = widget; - _adapter = new QGraphicsViewAdapter(this, _widget.data()); -} - -bool QWidgetImage::sendFocusHint(bool focus) -{ - QFocusEvent event(focus ? QEvent::FocusIn : QEvent::FocusOut, Qt::OtherFocusReason); - QCoreApplication::sendEvent(_widget, &event); - return true; -} - -void QWidgetImage::clearWriteBuffer() -{ - _adapter->clearWriteBuffer(); -} - -void QWidgetImage::render() -{ - if (_adapter->requiresRendering()) _adapter->render(); -} - -void QWidgetImage::scaleImage(int s,int t,int /*r*/, GLenum /*newDataType*/) -{ - _adapter->resize(s, t); -} - -void QWidgetImage::setFrameLastRendered(const osg::FrameStamp* frameStamp) -{ - _adapter->setFrameLastRendered(frameStamp); -} - -bool QWidgetImage::sendPointerEvent(int x, int y, int buttonMask) -{ - return _adapter->sendPointerEvent(x,y,buttonMask); -} - -bool QWidgetImage::sendKeyEvent(int key, bool keyDown) -{ - return _adapter->sendKeyEvent(key, keyDown); -} - -} diff --git a/src/osgQt/Version.in b/src/osgQt/Version.in deleted file mode 100644 index dc1a673e2..000000000 --- a/src/osgQt/Version.in +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef OSGQT_VERSION -#define OSGQT_VERSION - -#define OSGQT_QT_VERSION @OSGQT_QT_VERSION@ - -#include -#if (QT_VERSION < QT_VERSION_CHECK(OSGQT_QT_VERSION,0,0)) -#error "Qt version mismatch detected! Make sure to compile applications using osgQt with the same major Qt version that osgQt has been compiled against." -#endif - - -#endif