From 16e7bc441a8b91089a95ef386de6bbe9552fef4e Mon Sep 17 00:00:00 2001 From: rnv Date: Fri, 10 Jun 2016 11:24:31 +0300 Subject: [PATCH] Porting to the Qt-5.6.x. --- CMakeLists.txt | 10 + adm_local/cmake_files/FindSalomeQt5.cmake | 35 ++- adm_local/cmake_files/UseQtExt.cmake | 42 +++- src/CMakeLists.txt | 4 +- src/LightApp/LightApp_Application.cxx | 14 +- src/Qtx/CMakeLists.txt | 10 +- src/Qtx/QtxWebBrowser.cxx | 127 +++++++---- src/Qtx/QtxWebBrowser.h | 16 +- src/Style/Style_Salome.cxx | 260 ++++------------------ src/Style/Style_Salome.h | 11 +- 10 files changed, 256 insertions(+), 273 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e834cbe4..4a9a15cdc 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -154,9 +154,19 @@ IF(NOT SALOME_BUILD_WITH_QT5) FIND_PACKAGE(SalomeQt4 REQUIRED COMPONENTS QtCore QtGui QtXml QtWebKit QtOpenGL QtNetwork) ADD_DEFINITIONS("-DUSE_SALOME_STYLE") SET(QT_SALOME_VERSION 4) + SET(SALOME_GUI_ENABLE_QTXWEBBROWSER TRUE) ELSE() FIND_PACKAGE(SalomeQt5 REQUIRED) SET(QT_SALOME_VERSION 5) + SET(SALOME_GUI_ENABLE_QTXWEBBROWSER TRUE) + IF(NOT "${QT_VERSION}" VERSION_LESS "5.6.0") + # Check that WebEngine component was found + IF(NOT Qt5WebEngine_FOUND) + SET(SALOME_GUI_ENABLE_QTXWEBBROWSER FALSE) + ADD_DEFINITIONS("-DDISABLE_QTXWEBBROWSER") + MESSAGE("Qt5WebEngine is not found, SALOME internal help browser will be unavailable !") + ENDIF() + ENDIF() ENDIF() # PyQt diff --git a/adm_local/cmake_files/FindSalomeQt5.cmake b/adm_local/cmake_files/FindSalomeQt5.cmake index 31168f3ad..8e723d0f4 100644 --- a/adm_local/cmake_files/FindSalomeQt5.cmake +++ b/adm_local/cmake_files/FindSalomeQt5.cmake @@ -26,18 +26,38 @@ # Qt5_FIND_COMPONENTS variable is set here to prevent ParaView to reset list of Qt5 modules, # just to avoid extra dependencies -SET(Qt5_FIND_COMPONENTS Core Gui Widgets Network Xml OpenGL PrintSupport WebKit WebKitWidgets Help Test Sql Sensors Positioning Quick Qml Multimedia MultimediaWidgets WebChannel UiTools) - -IF(NOT WIN32) - LIST(APPEND Qt5_FIND_COMPONENTS X11Extras) -ENDIF() SET(QT_INCLUDES) SET(QT_DEFINITIONS) SET(QT_LIBRARIES) +# Find Qt5Core to get Qt version +SET(Qt5_FIND_COMPONENTS QtCore) +SALOME_FIND_PACKAGE_AND_DETECT_CONFLICTS(Qt5Core Qt5Core_INCLUDE_DIRS 1 ENVVAR QT5_ROOT_DIR) +IF(Qt5Core_FOUND) + LIST(APPEND QT_INCLUDES ${Qt5Core_INCLUDE_DIRS}) + LIST(APPEND QT_DEFINITIONS ${Qt5Core_DEFINITIONS}) + LIST(APPEND QT_LIBRARIES ${Qt5Core_LIBRARIES}) + SET(QT_VERSION "${Qt5Core_VERSION}") +ENDIF() + +SET(Qt5_FIND_COMPONENTS Gui Widgets Network Xml OpenGL PrintSupport Help Test Sql Sensors Positioning Quick Qml Multimedia MultimediaWidgets WebChannel UiTools) -FOREACH(_Qt5_COMPONENT ${Qt5_FIND_COMPONENTS}) - SET(_Qt5_COMPONENT Qt5${_Qt5_COMPONENT}) +IF ("${QT_VERSION}" VERSION_LESS "5.6.0") + LIST(APPEND Qt5_FIND_COMPONENTS WebKit WebKitWidgets) +ELSE() + LIST(APPEND Qt5_OPTIONAL_COMPONENTS WebEngine WebEngineWidgets) +ENDIF() + +IF(NOT WIN32) + LIST(APPEND Qt5_FIND_COMPONENTS X11Extras) +ENDIF() + +FOREACH(_Qt5_COMPONENT_ ${Qt5_FIND_COMPONENTS} ${Qt5_OPTIONAL_COMPONENTS}) + SET(_Qt5_COMPONENT Qt5${_Qt5_COMPONENT_}) + LIST(FIND Qt5_OPTIONAL_COMPONENTS ${_Qt5_COMPONENT_} idx) + IF(${idx} GREATER -1) + SET(Salome${_Qt5_COMPONENT}_FIND_QUIETLY TRUE) + ENDIF() SALOME_FIND_PACKAGE_AND_DETECT_CONFLICTS(${_Qt5_COMPONENT} ${_Qt5_COMPONENT}_INCLUDE_DIRS 1 ENVVAR QT5_ROOT_DIR) LIST(APPEND QT_INCLUDES ${${_Qt5_COMPONENT}_INCLUDE_DIRS}) LIST(APPEND QT_DEFINITIONS ${${_Qt5_COMPONENT}_DEFINITIONS}) @@ -64,7 +84,6 @@ IF(Qt5Core_FOUND) SALOME_ACCUMULATE_HEADERS(QT_INCLUDES) SALOME_ACCUMULATE_ENVIRONMENT(PATH ${LINGUIST_PATH}) SALOME_ACCUMULATE_ENVIRONMENT(LD_LIBRARY_PATH ${Qt5Core_LIBRARIES}) - SET(QT_VERSION "${Qt5Core_VERSION}") GET_FILENAME_COMPONENT(Qt5_DIR ${Qt5Core_DIR} PATH) FILE(TO_NATIVE_PATH "${Qt5_DIR}/Qt5" Qt5_DIR) SET(SalomeQt5_COMPONENTS ${Qt5_FIND_COMPONENTS}) diff --git a/adm_local/cmake_files/UseQtExt.cmake b/adm_local/cmake_files/UseQtExt.cmake index 95985b7b7..db787c6ac 100644 --- a/adm_local/cmake_files/UseQtExt.cmake +++ b/adm_local/cmake_files/UseQtExt.cmake @@ -47,7 +47,47 @@ MACRO(QT_WRAP_MOC) IF (QT_VERSION VERSION_LESS "5.0") QT4_WRAP_CPP(${ARGN}) ELSE() - QT5_WRAP_CPP(${ARGN}) + QT5_WRAP_CPP(${ARGN}) + # Workaround to avoid problem with bug in moc preprocessor: + # The problem is reproduced on Linux in case if native system Qt is installed + # and "-I/usr/include" parameter is presented in the moc command line before + # custom Qt includes. This bug takes place in Qt-5.6.0 and newer. To avoid this + # bug move "-I/usr/include" parameter in the "moc parameters" file to the end + # of the "include section". + IF (NOT WIN32) + FOREACH(IT ${ARGN}) + GET_FILENAME_COMPONENT(IT ${IT} ABSOLUTE) + GET_FILENAME_COMPONENT(PFILE ${IT} NAME_WE) + SET(OUTFILE ${CMAKE_CURRENT_BINARY_DIR}/moc_${PFILE}.cpp_parameters) + IF(EXISTS ${OUTFILE}) + SET(NEW_CONTENT) + SET(IS_INCLUDE_SECTION TRUE) + SET(HAS_SYSTEM_INC FALSE) + FILE(READ ${OUTFILE} CONTENT) + STRING(REGEX REPLACE "\n" ";" CONTENT "${CONTENT}") + list(REMOVE_DUPLICATES CONTENT) + FOREACH(S ${CONTENT}) + IF("${S}" MATCHES "^-I") + IF("${S}" STREQUAL "-I/usr/include") + SET(HAS_SYSTEM_INC TRUE) + ELSE() + SET(NEW_CONTENT ${NEW_CONTENT} "${S}\n") + ENDIF() + ELSE() + SET(IS_INCLUDE_SECTION FALSE) + ENDIF() + IF(NOT IS_INCLUDE_SECTION) + IF(HAS_SYSTEM_INC) + SET(NEW_CONTENT ${NEW_CONTENT} "-I/usr/include\n") + SET(HAS_SYSTEM_INC FALSE) + ENDIF() + SET(NEW_CONTENT ${NEW_CONTENT} "${S}\n") + ENDIF() + ENDFOREACH() + FILE(WRITE ${OUTFILE} ${NEW_CONTENT}) + ENDIF() + ENDFOREACH() + ENDIF() ENDIF() ENDMACRO(QT_WRAP_MOC) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9d4490662..d1ebdb032 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,7 +22,9 @@ ## ADD_SUBDIRECTORY(CASCatch) ADD_SUBDIRECTORY(Qtx) -ADD_SUBDIRECTORY(HelpBrowser) +IF(SALOME_GUI_ENABLE_QTXWEBBROWSER) + ADD_SUBDIRECTORY(HelpBrowser) +ENDIF() ADD_SUBDIRECTORY(Style) ADD_SUBDIRECTORY(DDS) ADD_SUBDIRECTORY(QDS) diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 47671d41a..6f0bf2f67 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -457,9 +457,10 @@ void LightApp_Application::start() /*!Closeapplication.*/ void LightApp_Application::closeApplication() { +#ifndef DISABLE_QTXWEBBROWSER QProcess::startDetached( "HelpBrowser", QStringList() << QString( "--remove=%1" ).arg( QApplication::instance()->applicationPid() ) ); - +#endif CAM_Application::closeApplication(); } @@ -1148,8 +1149,12 @@ void LightApp_Application::onHelpContentsModule() anApp.append( quote ); #endif QString aParams = resMgr->stringValue("ExternalBrowser", "parameters"); +#if DISABLE_QTXWEBBROWSER + bool useExtBrowser = true; +#else bool useExtBrowser = resMgr->booleanValue("ExternalBrowser", "use_external_browser", false ); - +#endif + if( useExtBrowser ) { if ( !anApp.isEmpty() ) { RunBrowser* rs = new RunBrowser( this, anApp, aParams, helpFile ); @@ -2283,7 +2288,12 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref ) // ... "Study properties" group <> // ... "Help browser" group <> +#ifndef DISABLE_QTXWEBBROWSER int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab, LightApp_Preferences::Auto, "ExternalBrowser", "use_external_browser"); +#else + int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab ); +#endif + #ifdef WIN32 QString platform = "winapplication"; #else diff --git a/src/Qtx/CMakeLists.txt b/src/Qtx/CMakeLists.txt index 96dc1f8df..f25866f09 100755 --- a/src/Qtx/CMakeLists.txt +++ b/src/Qtx/CMakeLists.txt @@ -75,13 +75,16 @@ SET(_moc_HEADERS QtxToolTip.h QtxTreeView.h QtxValidator.h - QtxWebBrowser.h QtxWorkspace.h QtxWorkspaceAction.h QtxWorkstack.h QtxWorkstackAction.h ) +IF(SALOME_GUI_ENABLE_QTXWEBBROWSER) + SET(_moc_HEADERS ${_moc_HEADERS} QtxWebBrowser.h) +ENDIF() + # obsolete files: not migrated to Qt4 # _moc_HEADERS << QtxListBox.h QtxTable.h # TODO: migrate or remove? @@ -165,13 +168,16 @@ SET(_other_SOURCES QtxTranslator.cxx QtxTreeView.cxx QtxValidator.cxx - QtxWebBrowser.cxx QtxWorkspace.cxx QtxWorkspaceAction.cxx QtxWorkstack.cxx QtxWorkstackAction.cxx ) +IF(SALOME_GUI_ENABLE_QTXWEBBROWSER) + SET(_other_SOURCES ${_other_SOURCES} QtxWebBrowser.cxx) +ENDIF() + # obsolete files: not migrated to Qt4 # _other_SOURCES << QtxListBox.cxx QtxTable.cxx # TODO: migrate or remove? diff --git a/src/Qtx/QtxWebBrowser.cxx b/src/Qtx/QtxWebBrowser.cxx index 213fe4f86..48991f6be 100644 --- a/src/Qtx/QtxWebBrowser.cxx +++ b/src/Qtx/QtxWebBrowser.cxx @@ -43,9 +43,19 @@ #include #include #include -#include +#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0) + #include +#else + #include +#endif #include +// RNV: +// Since from Qt 5.6.0 version QtWebKit tool was removed, +// QtxWebBroswer is ported on QtWebEngine. So if it is built with Qt-5.6.0 +// and newer, it uses QtWebEngine. But for Qt-5.5.1 and Qt4 QtWebKit tool +// is used, to provide backward compatibility. + namespace { bool isLocalFile( const QUrl& url ) @@ -64,7 +74,7 @@ namespace class QtxWebBrowser::Searcher : public QtxSearchTool::Searcher { public: - Searcher( QWebView* ); + Searcher( WebView* ); ~Searcher(); bool find( const QString&, QtxSearchTool* ); @@ -74,7 +84,7 @@ public: bool findLast( const QString&, QtxSearchTool* ); private: - QWebView* myView; + WebView* myView; }; /*! @@ -82,7 +92,7 @@ private: \param view web view \internal */ -QtxWebBrowser::Searcher::Searcher( QWebView* view ) : myView( view ) +QtxWebBrowser::Searcher::Searcher( WebView* view ) : myView( view ) { } @@ -103,10 +113,14 @@ QtxWebBrowser::Searcher::~Searcher() */ bool QtxWebBrowser::Searcher::find( const QString& text, QtxSearchTool* st ) { - QWebPage::FindFlags fl = 0; - if ( st->isCaseSensitive() ) fl = fl | QWebPage::FindCaseSensitively; - if ( st->isSearchWrapped() ) fl = fl | QWebPage::FindWrapsAroundDocument; + WebPage::FindFlags fl = 0; + if ( st->isCaseSensitive() ) fl = fl | WebPage::FindCaseSensitively; +#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0) + if ( st->isSearchWrapped() ) fl = fl | WebPage::FindWrapsAroundDocument; return myView->findText( text, fl ); +#else + myView->findText( text, fl, [this](bool found) { return found; }); +#endif } /*! @@ -130,10 +144,14 @@ bool QtxWebBrowser::Searcher::findNext( const QString& text, QtxSearchTool* st ) */ bool QtxWebBrowser::Searcher::findPrevious( const QString& text, QtxSearchTool* st ) { - QWebPage::FindFlags fl = QWebPage::FindBackward; - if ( st->isCaseSensitive() ) fl = fl | QWebPage::FindCaseSensitively; - if ( st->isSearchWrapped() ) fl = fl | QWebPage::FindWrapsAroundDocument; + WebPage::FindFlags fl = WebPage::FindBackward; + if ( st->isCaseSensitive() ) fl = fl | WebPage::FindCaseSensitively; +#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0) + if ( st->isSearchWrapped() ) fl = fl | WebPage::FindWrapsAroundDocument; return myView->findText( text, fl ); +#else + myView->findText( text, fl, [this](bool found) { return found; }); +#endif } /*! @@ -333,19 +351,26 @@ QtxWebBrowser::QtxWebBrowser( ) : QMainWindow( 0 ) QWidget* frame = new QWidget( this ); - myWebView = new QWebView( frame ); - - myWebView->pageAction( QWebPage::Copy )->setShortcut( QKeySequence::Copy ); - myWebView->addAction( myWebView->pageAction( QWebPage::Copy ) ); - myWebView->pageAction( QWebPage::OpenLinkInNewWindow )->setVisible( false ); - myWebView->pageAction( QWebPage::Back )->setText( tr( "Go Back" ) ); - myWebView->pageAction( QWebPage::Forward )->setText( tr( "Go Forward" ) ); - myWebView->pageAction( QWebPage::Reload )->setText( tr( "Refresh" ) ); - - myWebView->page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks ); - + myWebView = new WebView( frame ); + + myWebView->pageAction( WebPage::Copy )->setShortcut( QKeySequence::Copy ); + myWebView->addAction( myWebView->pageAction( WebPage::Copy ) ); +#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) + myWebView->pageAction( WebPage::OpenLinkInNewWindow )->setVisible( false ); +#endif + myWebView->pageAction( WebPage::Back )->setText( tr( "Go Back" ) ); + myWebView->pageAction( WebPage::Forward )->setText( tr( "Go Forward" ) ); + myWebView->pageAction( WebPage::Reload )->setText( tr( "Refresh" ) ); +#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0) + myWebView->page()->setLinkDelegationPolicy( WebPage::DelegateAllLinks ); +#endif + myFindPanel = new QtxSearchTool( frame, myWebView, - QtxSearchTool::Basic | QtxSearchTool::Case | QtxSearchTool::Wrap, +#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0) + QtxSearchTool::Basic | QtxSearchTool::Case | QtxSearchTool::Wrap, +#else + QtxSearchTool::Basic | QtxSearchTool::Case, +#endif Qt::Horizontal ); myFindPanel->setFrameStyle( QFrame::NoFrame | QFrame::Plain ); myFindPanel->setActivators( QtxSearchTool::SlashKey ); @@ -353,18 +378,18 @@ QtxWebBrowser::QtxWebBrowser( ) : QMainWindow( 0 ) myFindPanel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ); QToolBar* toolbar = addToolBar( tr( "Navigation" ) ); - toolbar->addAction( myWebView->pageAction( QWebPage::Back ) ); - toolbar->addAction( myWebView->pageAction( QWebPage::Forward ) ); - toolbar->addAction( myWebView->pageAction( QWebPage::Reload ) ); + toolbar->addAction( myWebView->pageAction( WebPage::Back ) ); + toolbar->addAction( myWebView->pageAction( WebPage::Forward ) ); + toolbar->addAction( myWebView->pageAction( WebPage::Reload ) ); QMenu* fileMenu = menuBar()->addMenu( tr( "&File" ) ); fileMenu->addAction( QPixmap( ":/images/open.png" ), tr( "&Open..." ), this, SLOT( open() ), QKeySequence( QKeySequence::Open ) ); fileMenu->addSeparator(); - fileMenu->addAction( myWebView->pageAction( QWebPage::Back ) ); - fileMenu->addAction( myWebView->pageAction( QWebPage::Forward ) ); - fileMenu->addAction( myWebView->pageAction( QWebPage::Reload ) ); + fileMenu->addAction( myWebView->pageAction( WebPage::Back ) ); + fileMenu->addAction( myWebView->pageAction( WebPage::Forward ) ); + fileMenu->addAction( myWebView->pageAction( WebPage::Reload ) ); fileMenu->addSeparator(); fileMenu->addAction( tr( "&Find in text..." ), myFindPanel, SLOT( find() ), @@ -390,16 +415,26 @@ QtxWebBrowser::QtxWebBrowser( ) : QMainWindow( 0 ) main->setSpacing( 3 ); connect( myWebView, SIGNAL( titleChanged( QString ) ), SLOT( adjustTitle() ) ); - connect( myWebView, SIGNAL( loadFinished( bool ) ), SLOT( finished( bool ) ) ); - connect( myWebView, SIGNAL( linkClicked( QUrl ) ), SLOT( linkClicked( QUrl ) ) ); + connect( myWebView, SIGNAL( loadFinished( bool ) ), SLOT( finished( bool ) ) ); + + connect( myWebView->pageAction( WebPage::DownloadLinkToDisk ), SIGNAL( triggered() ), + SLOT( linkAction() ) ); +#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0) + //QtWebKit case: + connect( myWebView, SIGNAL( linkClicked( QUrl ) ), SLOT( linkClicked( QUrl ) ) ); connect( myWebView->page(), SIGNAL( linkHovered( QString, QString, QString ) ), SLOT( linkHovered( QString, QString, QString ) ) ); - connect( myWebView->pageAction( QWebPage::DownloadLinkToDisk ), SIGNAL( triggered() ), + disconnect( myWebView->pageAction( WebPage::OpenLink ), 0, 0, 0 ); + connect( myWebView->pageAction( WebPage::OpenLink ), SIGNAL( triggered() ), SLOT( linkAction() ) ); - disconnect( myWebView->pageAction( QWebPage::OpenLink ), 0, 0, 0 ); - connect( myWebView->pageAction( QWebPage::OpenLink ), SIGNAL( triggered() ), +#else + //QtWebEngine (Qt-5.6.0) case: + connect( myWebView->page(), SIGNAL( linkHovered( QString ) ), + SLOT( linkHovered( QString ) ) ); + disconnect( myWebView->pageAction( WebPage::OpenLinkInThisWindow ), 0, 0, 0 ); + connect( myWebView->pageAction( WebPage::OpenLinkInThisWindow ), SIGNAL( triggered() ), SLOT( linkAction() ) ); - +#endif setCentralWidget( frame ); setFocusProxy( myWebView ); setWindowIcon( QPixmap( ":/images/appicon.png" ) ); @@ -488,9 +523,13 @@ void QtxWebBrowser::about() */ void QtxWebBrowser::linkClicked( const QUrl& url ) { - myWebView->page()->setLinkDelegationPolicy( QWebPage::DontDelegateLinks ); +#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0) + myWebView->page()->setLinkDelegationPolicy( WebPage::DontDelegateLinks ); +#endif myWebView->load( url ); - myWebView->page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks ); +#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0) + myWebView->page()->setLinkDelegationPolicy( WebPage::DelegateAllLinks ); +#endif } /*! @@ -500,11 +539,17 @@ void QtxWebBrowser::linkClicked( const QUrl& url ) \param content provides text within the link element, e.g., text inside an HTML anchor tag \internal */ + void QtxWebBrowser::linkHovered( const QString& link, const QString& /*title*/, const QString& /*context*/ ) +{ + linkHovered(link); +} + +void QtxWebBrowser::linkHovered( const QString& link) { QUrl url = link; if ( !link.isEmpty() && isLocalFile( url ) ) myLastUrl = url; - statusBar()->showMessage( link ); + statusBar()->showMessage( link ); } /*! @@ -540,10 +585,14 @@ void QtxWebBrowser::finished( bool ok ) void QtxWebBrowser::linkAction() { QObject* s = sender(); - if ( s == myWebView->pageAction( QWebPage::DownloadLinkToDisk ) ) { + if ( s == myWebView->pageAction( WebPage::DownloadLinkToDisk ) ) { saveLink( myLastUrl.path() ); } - else if ( s == myWebView->pageAction( QWebPage::OpenLink ) ) { +#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0) + if ( s == myWebView->pageAction( WebPage::OpenLink ) ) { +#else + if ( s == myWebView->pageAction( WebPage::OpenLinkInThisWindow ) ) { +#endif QString fileName = myLastUrl.path(); QString extension = QFileInfo( fileName ).suffix(); if ( extension != "html" && extension != "htm" ) { diff --git a/src/Qtx/QtxWebBrowser.h b/src/Qtx/QtxWebBrowser.h index 9b93ceb2b..5c5ff08ca 100644 --- a/src/Qtx/QtxWebBrowser.h +++ b/src/Qtx/QtxWebBrowser.h @@ -29,15 +29,26 @@ #include "Qtx.h" +#include #include #include #include +#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0) +// Web Kit +#define WebView QWebView +#define WebPage QWebPage +#else +// Web Engine +#define WebView QWebEngineView +#define WebPage QWebEnginePage +#endif + class QButtonGroup; class QCheckBox; class QLabel; class QPushButton; -class QWebView; +class WebView; class QtxResourceMgr; class QtxSearchTool; @@ -71,6 +82,7 @@ protected Q_SLOTS: virtual void about(); virtual void linkClicked( const QUrl& ); virtual void linkHovered( const QString&, const QString&, const QString& ); + virtual void linkHovered( const QString&) ; private Q_SLOTS: void open(); @@ -81,7 +93,7 @@ private Q_SLOTS: private: static QtxWebBrowser* myBrowser; static QtxResourceMgr* myResourceMgr; - QWebView* myWebView; + WebView* myWebView; QtxSearchTool* myFindPanel; QUrl myLastUrl; }; diff --git a/src/Style/Style_Salome.cxx b/src/Style/Style_Salome.cxx index de57552cf..f0c01a3ed 100644 --- a/src/Style/Style_Salome.cxx +++ b/src/Style/Style_Salome.cxx @@ -201,12 +201,7 @@ Style_Model* Style_Salome::myModel = 0; Use Style_Salome::apply() static function to set SALOME style to the application. */ -Style_Salome::Style_Salome() -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - : QWindowsStyle() -#else - : QCommonStyle() -#endif +Style_Salome::Style_Salome() : BaseStyle() { // initialize SALOME style resources Q_INIT_RESOURCE( Style ); @@ -326,12 +321,8 @@ Style_Model* Style_Salome::model() */ void Style_Salome::polish ( QApplication* app ) { -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QWindowsStyle::polish( app ); -#else - QCommonStyle::polish( app ); -#endif - + BaseStyle::polish( app ); + if ( checkDebugLevel(1) ) { return; } @@ -352,11 +343,7 @@ void Style_Salome::polish ( QApplication* app ) void Style_Salome::polish ( QWidget* w ) { if ( checkDebugLevel(2) ) { -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QWindowsStyle::polish( w ); -#else - QCommonStyle::polish( w ); -#endif + BaseStyle::polish( w ); return; } @@ -369,12 +356,7 @@ void Style_Salome::polish ( QWidget* w ) qobject_cast(w) || qobject_cast(w) ) w->setAttribute( Qt::WA_Hover ); } - -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QWindowsStyle::polish( w ); -#else - QCommonStyle::polish( w ); -#endif + BaseStyle::polish( w ); } /*! @@ -390,11 +372,7 @@ void Style_Salome::polish ( QWidget* w ) void Style_Salome::unpolish( QWidget* w ) { if ( checkDebugLevel(3) ) { -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QWindowsStyle::unpolish( w ); -#else - QCommonStyle::unpolish( w ); -#endif + BaseStyle::unpolish( w ); return; } @@ -407,12 +385,7 @@ void Style_Salome::unpolish( QWidget* w ) qobject_cast(w) || qobject_cast(w) ) w->setAttribute( Qt::WA_Hover, false ); } - -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QWindowsStyle::unpolish( w ); -#else - QCommonStyle::unpolish( w ); -#endif + BaseStyle::unpolish( w ); } /*! @@ -426,11 +399,7 @@ void Style_Salome::drawComplexControl( ComplexControl cc, const QStyleOptionComp QPainter* p, const QWidget* w ) const { if ( checkDebugLevel(4) ) { -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QWindowsStyle::drawComplexControl( cc, opt, p, w ); -#else - QCommonStyle::drawComplexControl( cc, opt, p, w ); -#endif + BaseStyle::drawComplexControl( cc, opt, p, w ); return; } @@ -582,11 +551,7 @@ void Style_Salome::drawComplexControl( ComplexControl cc, const QStyleOptionComp if ((slider->subControls & SC_SliderGroove) && groove.isValid()) { QStyleOptionSlider tmpSlider = *slider; tmpSlider.subControls = SC_SliderGroove; -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QWindowsStyle::drawComplexControl(cc, &tmpSlider, p, w); -#else - QCommonStyle::drawComplexControl(cc, &tmpSlider, p, w); -#endif + BaseStyle::drawComplexControl(cc, &tmpSlider, p, w); } if (slider->subControls & SC_SliderTickmarks) { QStyleOptionSlider tmpSlider = *slider; @@ -657,11 +622,7 @@ void Style_Salome::drawComplexControl( ComplexControl cc, const QStyleOptionComp if (w && ( qobject_cast(w->parentWidget() ) || ( toolbutton->state & State_AutoRaise && !( toolbutton->state & State_MouseOver ) ) ) ) { -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QWindowsStyle::drawComplexControl( cc, opt, p, w ); -#else - QCommonStyle::drawComplexControl( cc, opt, p, w ); -#endif + BaseStyle::drawComplexControl( cc, opt, p, w ); return; } int aMinDelta = (int)model()->widgetRounding( Style_Model::ButtonRadius ); @@ -743,11 +704,7 @@ void Style_Salome::drawComplexControl( ComplexControl cc, const QStyleOptionComp } } case CC_TitleBar: { -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QWindowsStyle::drawComplexControl( cc, opt, p, w ); -#else - QCommonStyle::drawComplexControl( cc, opt, p, w ); -#endif + BaseStyle::drawComplexControl( cc, opt, p, w ); break; } case CC_GroupBox: @@ -797,19 +754,11 @@ void Style_Salome::drawComplexControl( ComplexControl cc, const QStyleOptionComp break; } case CC_Dial: { -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QWindowsStyle::drawComplexControl( cc, opt, p, w ); -#else - QCommonStyle::drawComplexControl( cc, opt, p, w ); -#endif + BaseStyle::drawComplexControl( cc, opt, p, w ); break; } default: -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QWindowsStyle::drawComplexControl( cc, opt, p, w ); -#else - QCommonStyle::drawComplexControl( cc, opt, p, w ); -#endif + BaseStyle::drawComplexControl( cc, opt, p, w ); } } @@ -823,12 +772,8 @@ void Style_Salome::drawComplexControl( ComplexControl cc, const QStyleOptionComp void Style_Salome::drawControl( ControlElement ce, const QStyleOption* opt, QPainter* p, const QWidget* w ) const { - if ( checkDebugLevel(5) ) { -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QWindowsStyle::drawControl( ce, opt, p, w ); -#else - QCommonStyle::drawControl( ce, opt, p, w ); -#endif + if ( checkDebugLevel(5) ) { + BaseStyle::drawControl( ce, opt, p, w ); return; } @@ -957,11 +902,7 @@ void Style_Salome::drawControl( ControlElement ce, const QStyleOption* opt, break; } case CE_Splitter: { -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QWindowsStyle::drawControl( ce, opt, p, w ); -#else - QCommonStyle::drawControl( ce, opt, p, w ); -#endif + BaseStyle::drawControl( ce, opt, p, w ); QRect r = opt->rect; bool horiz = r.width() > r.height(); int aLen = model()->splitHandleLength(); @@ -1018,18 +959,10 @@ void Style_Salome::drawControl( ControlElement ce, const QStyleOption* opt, } QStyleOptionTab* copyTab = (QStyleOptionTab*)tab; copyTab->rect = oldRect; -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QWindowsStyle::drawControl( ce, copyTab, p, w ); -#else - QCommonStyle::drawControl( ce, copyTab, p, w ); -#endif + BaseStyle::drawControl( ce, copyTab, p, w ); } else -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QWindowsStyle::drawControl( ce, opt, p, w ); -#else - QCommonStyle::drawControl( ce, opt, p, w ); -#endif + BaseStyle::drawControl( ce, opt, p, w ); break; } case CE_MenuBarItem: @@ -1558,11 +1491,7 @@ void Style_Salome::drawControl( ControlElement ce, const QStyleOption* opt, break; } default: -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QWindowsStyle::drawControl( ce, opt, p, w ); -#else - QCommonStyle::drawControl( ce, opt, p, w ); -#endif + BaseStyle::drawControl( ce, opt, p, w ); break; } } @@ -1578,11 +1507,7 @@ void Style_Salome::drawPrimitive( PrimitiveElement pe, const QStyleOption* opt, QPainter* p, const QWidget* w ) const { if ( checkDebugLevel(6) ) { -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QWindowsStyle::drawPrimitive( pe, opt, p, w ); -#else - QCommonStyle::drawPrimitive( pe, opt, p, w ); -#endif + BaseStyle::drawPrimitive( pe, opt, p, w ); return; } @@ -1622,11 +1547,7 @@ void Style_Salome::drawPrimitive( PrimitiveElement pe, const QStyleOption* opt, break; } else -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QWindowsStyle::drawPrimitive( pe, opt, p, w ); -#else - QCommonStyle::drawPrimitive( pe, opt, p, w ); -#endif + BaseStyle::drawPrimitive( pe, opt, p, w ); } break; case PE_FrameFocusRect: { @@ -1642,11 +1563,7 @@ void Style_Salome::drawPrimitive( PrimitiveElement pe, const QStyleOption* opt, aBrdTopCol, aBrdBotCol, false, false, isHover, true ); } else { -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QWindowsStyle::drawPrimitive( pe, opt, p, w ); -#else - QCommonStyle::drawPrimitive( pe, opt, p, w ); -#endif + BaseStyle::drawPrimitive( pe, opt, p, w ); } break; } @@ -1913,11 +1830,8 @@ void Style_Salome::drawPrimitive( PrimitiveElement pe, const QStyleOption* opt, break; } case PE_Widget: { -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QWindowsStyle::drawPrimitive( pe, opt, p, w ); -#else - QCommonStyle::drawPrimitive( pe, opt, p, w ); -#endif + BaseStyle::drawPrimitive( pe, opt, p, w ); + if ( !w ) break; if( w->parent() && !qobject_cast((QWidget*)w) ) @@ -1931,11 +1845,7 @@ void Style_Salome::drawPrimitive( PrimitiveElement pe, const QStyleOption* opt, = qstyleoption_cast(opt)) { if (tbb->shape != QTabBar::RoundedNorth && tbb->shape != QTabBar::RoundedEast && tbb->shape != QTabBar::RoundedSouth && tbb->shape != QTabBar::RoundedWest) { -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QWindowsStyle::drawPrimitive( pe, opt, p, w ); -#else - QCommonStyle::drawPrimitive( pe, opt, p, w ); -#endif + BaseStyle::drawPrimitive( pe, opt, p, w ); break; } QRect aSelRect = tbb->selectedTabRect; @@ -2051,19 +1961,11 @@ void Style_Salome::drawPrimitive( PrimitiveElement pe, const QStyleOption* opt, aPal.setBrush( QPalette::AlternateBase, QBrush( gr_alt ) ); aWdg->setPalette( aPal ); } -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QWindowsStyle::drawPrimitive( pe, opt, p, w ); -#else - QCommonStyle::drawPrimitive( pe, opt, p, w ); -#endif + BaseStyle::drawPrimitive( pe, opt, p, w ); break; } default: -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QWindowsStyle::drawPrimitive( pe, opt, p, w ); -#else - QCommonStyle::drawPrimitive( pe, opt, p, w ); -#endif + BaseStyle::drawPrimitive( pe, opt, p, w ); } } @@ -2078,17 +1980,9 @@ int Style_Salome::pixelMetric( PixelMetric metric, const QStyleOption* opt, const QWidget* w ) const { if ( checkDebugLevel(7) ) { -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - return QWindowsStyle::pixelMetric( metric, opt, w ); -#else - return QCommonStyle::pixelMetric( metric, opt, w ); -#endif + return BaseStyle::pixelMetric( metric, opt, w ); } -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - int aRes = QWindowsStyle::pixelMetric( metric, opt, w ); -#else - int aRes = QCommonStyle::pixelMetric( metric, opt, w ); -#endif + int aRes = BaseStyle::pixelMetric( metric, opt, w ); switch( metric ) { case PM_SliderLength: { aRes += (int)((double)model()->sliderSize()/2); @@ -2125,17 +2019,9 @@ QSize Style_Salome::sizeFromContents( ContentsType ct, const QStyleOption* opt, const QSize& contentsSize, const QWidget* w ) const { if ( checkDebugLevel(8) ) { -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - return QWindowsStyle::sizeFromContents( ct, opt,contentsSize, w ); -#else - return QCommonStyle::sizeFromContents( ct, opt,contentsSize, w ); -#endif + return BaseStyle::sizeFromContents( ct, opt,contentsSize, w ); } -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QSize sz = QWindowsStyle::sizeFromContents( ct, opt, contentsSize, w ); -#else - QSize sz = QCommonStyle::sizeFromContents( ct, opt, contentsSize, w ); -#endif + QSize sz = BaseStyle::sizeFromContents( ct, opt, contentsSize, w ); switch (ct) { case CT_TabBarTab: if (const QStyleOptionTab *tab = qstyleoption_cast(opt)) { @@ -2164,13 +2050,9 @@ QSize Style_Salome::sizeFromContents( ContentsType ct, const QStyleOption* opt, QRect res = QRect( 0, 0, sz.width(), sz.height() ); int aHalfRect = (int)Style_Tools::getMaxRect( res, (int)model()->widgetRounding( Style_Model::EditRadius )/2 ); // left value -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QRect old_arrow = QWindowsStyle::subControlRect( CC_ComboBox, cmb, + + QRect old_arrow = BaseStyle::subControlRect( CC_ComboBox, cmb, SC_ComboBoxArrow, w ); -#else - QRect old_arrow = QCommonStyle::subControlRect( CC_ComboBox, cmb, - SC_ComboBoxArrow, w ); -#endif int aDelta = res.height() - old_arrow.width(); // right value if ( cmb->editable ) aDelta += aHalfRect; // for right of line edit internal @@ -2194,11 +2076,7 @@ QPixmap Style_Salome::standardPixmap(StandardPixmap stPixmap, const QStyleOption const QWidget *w) const { if ( checkDebugLevel(9) ) { -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - return QWindowsStyle::standardPixmap( stPixmap, opt, w ); -#else - return QCommonStyle::standardPixmap( stPixmap, opt, w ); -#endif + return BaseStyle::standardPixmap( stPixmap, opt, w ); } switch ( stPixmap ) @@ -2213,11 +2091,7 @@ QPixmap Style_Salome::standardPixmap(StandardPixmap stPixmap, const QStyleOption case SP_TitleBarMinButton: return QPixmap( minimize_xpm ); default: -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - return QWindowsStyle::standardPixmap( stPixmap, opt, w ); -#else - return QCommonStyle::standardPixmap( stPixmap, opt, w ); -#endif + return BaseStyle::standardPixmap( stPixmap, opt, w ); } } @@ -2234,7 +2108,7 @@ QIcon Style_Salome::standardIconImplementation( StandardPixmap standardIcon, { if ( checkDebugLevel(10) ) { #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - return QWindowsStyle::standardIconImplementation( standardIcon, opt, w ); + return BaseStyle::standardIconImplementation( standardIcon, opt, w ); #else return QCommonStyle::standardIcon( standardIcon, opt, w ); #endif @@ -2254,9 +2128,9 @@ QIcon Style_Salome::standardIconImplementation( StandardPixmap standardIcon, break; } #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - return QWindowsStyle::standardIconImplementation( standardIcon, opt, w ); + return BaseStyle::standardIconImplementation( standardIcon, opt, w ); #else - return QCommonStyle::standardIcon( standardIcon, opt, w ); + return BaseStyle::standardIcon( standardIcon, opt, w ); #endif } @@ -2273,17 +2147,9 @@ int Style_Salome::styleHint( StyleHint hint, const QStyleOption* opt, const QWid QStyleHintReturn* returnData ) const { if ( checkDebugLevel(11) ) { -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - return QWindowsStyle::styleHint( hint, opt, w, returnData ); -#else - return QCommonStyle::styleHint( hint, opt, w, returnData ); -#endif + return BaseStyle::styleHint( hint, opt, w, returnData ); } -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - int aRes = QWindowsStyle::styleHint( hint, opt, w, returnData ); -#else - int aRes = QCommonStyle::styleHint( hint, opt, w, returnData ); -#endif + int aRes = BaseStyle::styleHint( hint, opt, w, returnData ); switch( hint ) { case SH_Table_GridLineColor: { if ( opt ) @@ -2312,26 +2178,14 @@ QRect Style_Salome::subControlRect( ComplexControl cc, const QStyleOptionComplex SubControl sc, const QWidget* wid ) const { if ( checkDebugLevel(12) ) { -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - return QWindowsStyle::subControlRect( cc, opt, sc, wid ); -#else - return QCommonStyle::subControlRect( cc, opt, sc, wid ); -#endif + return BaseStyle::subControlRect( cc, opt, sc, wid ); } -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QRect res = QWindowsStyle::subControlRect( cc, opt, sc, wid ); -#else - QRect res = QCommonStyle::subControlRect( cc, opt, sc, wid ); -#endif + QRect res = BaseStyle::subControlRect( cc, opt, sc, wid ); switch ( cc ) { case CC_SpinBox: { int x = res.x(), w = res.width(), h = res.height(); if ( sc==SC_SpinBoxUp || sc==SC_SpinBoxDown ) { -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QRect frame_r = QWindowsStyle::subControlRect( cc, opt, SC_SpinBoxFrame, wid ); -#else - QRect frame_r = QCommonStyle::subControlRect( cc, opt, SC_SpinBoxFrame, wid ); -#endif + QRect frame_r = BaseStyle::subControlRect( cc, opt, SC_SpinBoxFrame, wid ); h = frame_r.height(); res.setX( x+w-h ); res.setWidth( h ); @@ -2367,11 +2221,7 @@ QRect Style_Salome::subControlRect( ComplexControl cc, const QStyleOptionComplex } case CC_ScrollBar: if (const QStyleOptionSlider *scrollbar = qstyleoption_cast(opt)) { -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QRect slider_r = QWindowsStyle::subControlRect( cc, opt, SC_ScrollBarSlider, wid ); -#else - QRect slider_r = QCommonStyle::subControlRect( cc, opt, SC_ScrollBarSlider, wid ); -#endif + QRect slider_r = BaseStyle::subControlRect( cc, opt, SC_ScrollBarSlider, wid ); int aRect = Style_Tools::getMaxRect( slider_r, (int)model()->widgetRounding( Style_Model::ButtonRadius ) ); switch( sc ) { case SC_ScrollBarSubPage: // between top/left button and slider @@ -2425,30 +2275,18 @@ QRect Style_Salome::subElementRect( SubElement se, const QStyleOption* opt, const QWidget* wid ) const { if ( checkDebugLevel(13) ) { -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - return QWindowsStyle::subElementRect( se, opt, wid ); -#else - return QCommonStyle::subElementRect( se, opt, wid ); -#endif + return BaseStyle::subElementRect( se, opt, wid ); } -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QRect res = QWindowsStyle::subElementRect( se, opt, wid ); -#else - QRect res = QCommonStyle::subElementRect( se, opt, wid ); -#endif + + QRect res = BaseStyle::subElementRect( se, opt, wid ); int aHalfRect = (int)Style_Tools::getMaxRect( res, (int)model()->widgetRounding( Style_Model::EditRadius )/2 ); int w = res.width(), h = res.height(); switch ( se ) { case SE_ComboBoxFocusRect: { -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QRect old_r = QWindowsStyle::subControlRect( CC_ComboBox, - qstyleoption_cast( opt ), - SC_ComboBoxArrow, wid ); -#else - QRect old_r = QCommonStyle::subControlRect( CC_ComboBox, + + QRect old_r = BaseStyle::subControlRect( CC_ComboBox, qstyleoption_cast( opt ), SC_ComboBoxArrow, wid ); -#endif int old_w = old_r.width(); res.setWidth( w-h+old_w-2 ); break; diff --git a/src/Style/Style_Salome.h b/src/Style/Style_Salome.h index 846022e9d..179c8dd3a 100644 --- a/src/Style/Style_Salome.h +++ b/src/Style/Style_Salome.h @@ -23,12 +23,14 @@ #ifndef STYLE_SALOME_H #define STYLE_SALOME_H -#include "Style.h" #include +#include "Style.h" #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) #include +#define BaseStyle QWindowsStyle #else #include +#define BaseStyle QCommonStyle #endif class Style_Model; @@ -37,12 +39,7 @@ class QWidget; class QPainter; class QtxResourceMgr; -class STYLE_SALOME_EXPORT Style_Salome -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) -: public QWindowsStyle -#else -: public QCommonStyle -#endif +class STYLE_SALOME_EXPORT Style_Salome : public BaseStyle { Q_OBJECT -- 2.39.2