From: rnv Date: Fri, 7 Oct 2011 14:05:40 +0000 (+0000) Subject: Implementation of the "0020512: EDF 1113 OTHER : Using webkit to display documentatio... X-Git-Tag: V6_4_0a1~43 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=742ddeb02c1d47cb23cabc819d41ba75150b8a84;p=modules%2Fgui.git Implementation of the "0020512: EDF 1113 OTHER : Using webkit to display documentation" issue. --- diff --git a/adm_local/unix/config_files/check_qt.m4 b/adm_local/unix/config_files/check_qt.m4 index 659544823..c7413d700 100644 --- a/adm_local/unix/config_files/check_qt.m4 +++ b/adm_local/unix/config_files/check_qt.m4 @@ -112,6 +112,7 @@ elif test -z $QTDIR ; then QTXML_CPPFLAGS=`$PKG_CONFIG --cflags "QtXml >= $QT_REQUIRED_VERSION"` QTASSISTANT_CPPFLAGS=`$PKG_CONFIG --cflags "QtAssistant >= $QT_REQUIRED_VERSION"` QTNETWORK_CPPFLAGS=`$PKG_CONFIG --cflags "QtNetwork >= $QT_REQUIRED_VERSION"` + QTWEBKIT_CPPFLAGS=`$PKG_CONFIG --cflags "QtWebKit >= $QT_REQUIRED_VERSION"` QTCORE_LDFLAGS=`$PKG_CONFIG --libs "QtCore >= $QT_REQUIRED_VERSION"` QTGUI_LDFLAGS=`$PKG_CONFIG --libs "QtGui >= $QT_REQUIRED_VERSION"` @@ -119,6 +120,7 @@ elif test -z $QTDIR ; then QTXML_LDFLAGS=`$PKG_CONFIG --libs "QtXml >= $QT_REQUIRED_VERSION"` QTASSISTANT_LDFLAGS=`$PKG_CONFIG --libs "QtAssistant >= $QT_REQUIRED_VERSION"` QTNETWORK_LDFLAGS=`$PKG_CONFIG --libs "QtNetwork >= $QT_REQUIRED_VERSION"` + QTWEBKIT_LDFLAGS=`$PKG_CONFIG --libs "QtWebKit >= $QT_REQUIRED_VERSION"` else AC_MSG_WARN(Qt not found) fi @@ -438,13 +440,14 @@ then QTCORE_CPPFLAGS="${QT_BASE}/QtCore" QTGUI_CPPFLAGS="${QT_BASE}/QtGui" QTOPENGL_CPPFLAGS="${QT_BASE}/QtOpenGL" + QTWEBKIT_CPPFLAGS="${QT_BASE}/QtWebKit" QTXML_CPPFLAGS="${QT_BASE}/QtXml" QTASSISTANT_CPPFLAGS="${QT_BASE}/QtAssistant" QTNETWORK_CPPFLAGS="${QT_BASE}/QtNetwork" fi - QT_INCLUDES="$QT_BASE $QTCORE_CPPFLAGS $QTGUI_CPPFLAGS $QTOPENGL_CPPFLAGS $QTXML_CPPFLAGS" + QT_INCLUDES="$QT_BASE $QTCORE_CPPFLAGS $QTGUI_CPPFLAGS $QTOPENGL_CPPFLAGS $QTXML_CPPFLAGS $QTWEBKIT_CPPFLAGS" QT_ASSISANT_INCLUDES="$QTASSISTANT_CPPFLAGS $QTNETWORK_CPPFLAGS" QT_MT_INCLUDES="${QT_INCLUDES}" @@ -522,12 +525,12 @@ then if test "x$QT_USING_PKGCONFIG" = "xyes" then QT_CORE_LIBS="$QTCORE_LDFLAGS $QTXML_LDFLAGS" - QT_GUI_LIBS="$QTGUI_LDFLAGS $QTOPENGL_LDFLAGS" + QT_GUI_LIBS="$QTGUI_LDFLAGS $QTOPENGL_LDFLAGS $QTWEBKIT_LDFLAGS" QT_ASSISTANT_LIBS="$QTASSISTANT_LDFLAGS $QTNETWORK_LDFLAGS" else QT_CORE_LIBS="$QT_LIB_DIR -lQtCore -lQtXml" # gui libs - QT_GUI_LIBS="$QT_LIB_DIR -lQtGui -lQtOpenGL" + QT_GUI_LIBS="$QT_LIB_DIR -lQtGui -lQtOpenGL -lQtWebKit" # other libs (currently not used) QT_OTHER_LIBS="$QT_LIB_DIR" # other libs (can be used if necessary) diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index f93f8c3ca..8e2df790b 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -89,6 +89,7 @@ #include #include #include +#include #include @@ -233,6 +234,16 @@ extern "C" LIGHTAPP_EXPORT SUIT_Application* createApplication() /*! \var global preferences of LightApp */ LightApp_Preferences* LightApp_Application::_prefs_ = 0; + +static inline QString getFile(){ +#ifdef WIN32 + return QString( "file://" ); +#else + return QString( "file:" ); +#endif +} + + /*! \class LightApp_Application Application containing LightApp module @@ -258,6 +269,11 @@ LightApp_Application::LightApp_Application() SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); QPixmap aLogo = aResMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false ); + + QtxWebBrowser::setData("BROWSER_ICON", aResMgr->loadPixmap( "LightApp", tr( "BROWSER_ICON" ))); + QtxWebBrowser::setData("BROWSER_TITLE", tr("BROWSER_TITLE")); + QtxWebBrowser::setData("BROWSER_FILEMENU", tr("BROWSER_FILEMENU")); + QtxWebBrowser::setData("BROWSER_EXIT", tr("BROWSER_EXIT")); desktop()->setWindowIcon( aLogo ); desktop()->setDockableMenuBar( false ); @@ -908,11 +924,7 @@ public: const QString& theContext = QString() ) : myApp( theApp ), myParams( theParams ), -#ifdef WIN32 - myHelpFile( "file://" + theHelpFile ), -#else - myHelpFile( "file:" + theHelpFile ), -#endif + myHelpFile( getFile() + theHelpFile ), myContext( theContext ), myStatus(0), myLApp( app ) @@ -970,19 +982,24 @@ void LightApp_Application::onHelpContentsModule() anApp.append( quote ); #endif QString aParams = resMgr->stringValue("ExternalBrowser", "parameters"); + bool useExtBrowser = resMgr->booleanValue("ExternalBrowser", "use_external_browser", false ); - if ( !anApp.isEmpty() ) - { - RunBrowser* rs = new RunBrowser( this, anApp, aParams, helpFile ); - rs->start(); - } - else - { - if ( SUIT_MessageBox::question( desktop(), tr( "WRN_WARNING" ), tr( "DEFINE_EXTERNAL_BROWSER" ), - SUIT_MessageBox::Yes | SUIT_MessageBox::No, - SUIT_MessageBox::Yes ) == SUIT_MessageBox::Yes ) - - showPreferences( tr( "PREF_APP" ) ); + if( useExtBrowser ) { + if ( !anApp.isEmpty() ) + { + RunBrowser* rs = new RunBrowser( this, anApp, aParams, helpFile ); + rs->start(); + } + else + { + if ( SUIT_MessageBox::question( desktop(), tr( "WRN_WARNING" ), tr( "DEFINE_EXTERNAL_BROWSER" ), + SUIT_MessageBox::Yes | SUIT_MessageBox::No, + SUIT_MessageBox::Yes ) == SUIT_MessageBox::Yes ) + + showPreferences( tr( "PREF_APP" ) ); + } + } else { + QtxWebBrowser::loadUrl(getFile() + helpFile); } } @@ -1019,19 +1036,26 @@ void LightApp_Application::onHelpContextModule( const QString& theComponentName, anApp.prepend( quote ); anApp.append( quote ); #endif - QString aParams = resMgr->stringValue("ExternalBrowser", "parameters"); - if ( !anApp.isEmpty() ) - { - RunBrowser* rs = new RunBrowser( this, anApp, aParams, helpFile, theContext ); - rs->start(); - } - else - { - if ( SUIT_MessageBox::question( desktop(), tr( "WRN_WARNING" ), tr( "DEFINE_EXTERNAL_BROWSER" ), - SUIT_MessageBox::Yes | SUIT_MessageBox::No, - SUIT_MessageBox::Yes ) == SUIT_MessageBox::Yes ) - showPreferences( tr( "PREF_APP" ) ); + bool useExtBrowser = resMgr->booleanValue("ExternalBrowser", "use_external_browser", false ); + + if(useExtBrowser) { + QString aParams = resMgr->stringValue("ExternalBrowser", "parameters"); + + if ( !anApp.isEmpty() ) + { + RunBrowser* rs = new RunBrowser( this, anApp, aParams, helpFile, theContext ); + rs->start(); + } + else + { + if ( SUIT_MessageBox::question( desktop(), tr( "WRN_WARNING" ), tr( "DEFINE_EXTERNAL_BROWSER" ), + SUIT_MessageBox::Yes | SUIT_MessageBox::No, + SUIT_MessageBox::Yes ) == SUIT_MessageBox::Yes ) + showPreferences( tr( "PREF_APP" ) ); + } + } else { + QtxWebBrowser::loadUrl(getFile() + helpFile, theContext ); } } @@ -1960,7 +1984,7 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref ) pref->setItemProperty( "max", 1440, autoSaveInterval ); pref->setItemProperty( "special", tr( "PREF_AUTO_SAVE_DISABLED" ), autoSaveInterval ); - int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab ); + int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab, LightApp_Preferences::Auto, "ExternalBrowser", "use_external_browser"); QString platform; #ifdef WIN32 platform = "winapplication"; @@ -2693,6 +2717,14 @@ void LightApp_Application::preferencesChanged( const QString& sec, const QString if ( dynamic_cast( desktop() ) ) dynamic_cast( desktop() )->workstack()->setOpaqueResize( opaqueResize ); } + + if ( sec == "ExternalBrowser" && param == "use_external_browser" ) { + if ( resMgr->booleanValue("ExternalBrowser", "use_external_browser", false ) ) + { + if(QtxWebBrowser::webBrowser()) + QtxWebBrowser::webBrowser()->close(); + } + } } /*! diff --git a/src/LightApp/resources/LightApp.xml b/src/LightApp/resources/LightApp.xml index 3bb43ac56..ee455e71c 100644 --- a/src/LightApp/resources/LightApp.xml +++ b/src/LightApp/resources/LightApp.xml @@ -229,6 +229,7 @@
+
diff --git a/src/LightApp/resources/LightApp_images.ts b/src/LightApp/resources/LightApp_images.ts index 98d12bcfc..40c6ee93b 100644 --- a/src/LightApp/resources/LightApp_images.ts +++ b/src/LightApp/resources/LightApp_images.ts @@ -31,5 +31,9 @@ APP_MODULE_ICO icon_module.png + + BROWSER_ICON + icon_default.png + diff --git a/src/LightApp/resources/LightApp_msg_en.ts b/src/LightApp/resources/LightApp_msg_en.ts index efd0a8d79..ad8bbae25 100644 --- a/src/LightApp/resources/LightApp_msg_en.ts +++ b/src/LightApp/resources/LightApp_msg_en.ts @@ -50,6 +50,18 @@ CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITASENTRY_COLUMN Entry + + BROWSER_TITLE + SALOME Help Browser + + + BROWSER_FILEMENU + &File + + + BROWSER_EXIT + &Exit + LightApp_Application diff --git a/src/Qtx/Makefile.am b/src/Qtx/Makefile.am index 5a3954c65..b4a0ad703 100755 --- a/src/Qtx/Makefile.am +++ b/src/Qtx/Makefile.am @@ -77,7 +77,8 @@ salomeinclude_HEADERS = \ QtxWorkspace.h \ QtxWorkspaceAction.h \ QtxWorkstack.h \ - QtxWorkstackAction.h + QtxWorkstackAction.h \ + QtxWebBrowser.h #VSR: not yet migrated to Qt4 files # \ @@ -135,7 +136,8 @@ dist_libqtx_la_SOURCES = \ QtxWorkspace.cxx \ QtxWorkspaceAction.cxx \ QtxWorkstack.cxx \ - QtxWorkstackAction.cxx + QtxWorkstackAction.cxx \ + QtxWebBrowser.cxx #VSR: not yet migrated to Qt4 files # \ @@ -184,7 +186,8 @@ MOC_FILES = \ QtxWorkspace_moc.cxx \ QtxWorkspaceAction_moc.cxx \ QtxWorkstack_moc.cxx \ - QtxWorkstackAction_moc.cxx + QtxWorkstackAction_moc.cxx \ + QtxWebBrowser_moc.cxx #VSR: not yet migrated to Qt4 files # \ diff --git a/src/Qtx/QtxWebBrowser.cxx b/src/Qtx/QtxWebBrowser.cxx new file mode 100644 index 000000000..0c4286ca0 --- /dev/null +++ b/src/Qtx/QtxWebBrowser.cxx @@ -0,0 +1,218 @@ +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// 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 GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File: QtxWebBrowser.cxx +// Author: Roman NIKOLAEV +// +#include "QtxWebBrowser.h" + +#include +#include +#include +#include +#include + +//! The only one instance of web browser +QtxWebBrowser* QtxWebBrowser::myBrowser = 0; + +//!Internal data map to store resources of the browser. +QMap QtxWebBrowser::myData; + +/*! + \class QtxWebBrowser + + \brief The QtxWebBrowser provides a window that can display a html pages. + + Only one instance of the QtxWebBrowser class can be created. To access the browser + window, use static method QtxWebBrowser::webBrowser(), which creates an + instance of the QtxWebBrowser widget (if it is not yet creaed) and returns a + pointer to it. + + You should not destroy this instance - it is done automatically after + closing of the browser window. To closing window programmatically use + method close(). + + To set visual properties of the browser use static method setData(). + + Following code demonstrate how to use web browser: + + \code + int main(int argc, char *argv[]) + { + QApplication app(argc, argv); + + //Set icon, title and menu items. + QtxWebBrowser::setData("BROWSER_TITLE", tr("Web Browser")); + + QPixmap pixmap(":/icon.png"); + QtxWebBrowser::setData("BROWSER_ICON", pixmap); + + QtxWebBrowser::setData("BROWSER_FILEMENU", tr("&File")); + QtxWebBrowser::setData("BROWSER_EXIT", tr("&Exit")); + + + //Show web page + QtxWebBrowser::loadUrl("file:///data/index.html", "anchor1"); + + return app.exec(); + } + + \endcode + + This code will create the browser window and open /data/index.html + file in "anchor1" context. +*/ + +/*! + \brief Constructor. + + Construct the web browser. +*/ +QtxWebBrowser::QtxWebBrowser() +: QMainWindow(0) +{ + setAttribute( Qt::WA_DeleteOnClose ); + myWebView = new QWebView(this); + + QToolBar *toolBar = addToolBar(tr("Navigation")); + toolBar->addAction(myWebView->pageAction(QWebPage::Back)); + toolBar->addAction(myWebView->pageAction(QWebPage::Forward)); + + QString title = getStringValue("BROWSER_TITLE"); + if(!title.isEmpty()) + setWindowTitle(title); + + QIcon icon = getIconValue("BROWSER_ICON"); + if(!icon.isNull()) + setWindowIcon(icon); + + QString fmenu = getStringValue("BROWSER_FILEMENU"); + if ( fmenu.isEmpty() ) { + fmenu = tr("&File"); + } + QMenu *menu = menuBar()->addMenu(fmenu); + + QString item = getStringValue("BROWSER_EXIT"); + if ( item.isEmpty() ) { + item = tr("&Exit"); + } + menu->addAction( item, this, SLOT(close())); + + connect(myWebView, SIGNAL(titleChanged(QString)), SLOT(adjustTitle())); + setCentralWidget(myWebView); +} + +/*! + \brief Destructor. +*/ +QtxWebBrowser::~QtxWebBrowser() +{ + myBrowser = 0; +} + +/*! + \brief Create instance of the QtxWebBrowser. + \return instance of the QtxWebBrowser. +*/ +QtxWebBrowser* QtxWebBrowser::webBrowser() { + if( myBrowser == 0 ) + myBrowser = new QtxWebBrowser(); + return myBrowser; +} + +/*! + \brief Load given url addres and context. + \param theUlr url address to load. + \param theContext url context to load. +*/ +void QtxWebBrowser::loadUrl(const QString& theUrl , const QString theContext ) { + QString anUrl = theUrl; + if( !theContext.isEmpty() ) + anUrl += "#" + theContext; + + Qtx::alignWidget(webBrowser(), (QWidget*)QApplication::desktop(),Qtx::AlignHCenter); + webBrowser()->show(); + webBrowser()->myWebView->load(QUrl(anUrl)); + webBrowser()->setFocus(); + webBrowser()->activateWindow(); + webBrowser()->raise(); +} + +/*! + \brief Set browser settings from. + + This method can be used to setup the browser look-n-feel. + + All the browser parameters can be defined via resources file: + - \c "BROWSER_TITLE" : title of the browser + - \c "BROWSER_ICON" : icon of the browser + - \c "BROWSER_FILEMENU" : name of the browser menu + - \c "BROWSER_EXIT" : name of the browser menu item + + \param key name of the property + \param val value of the property + +*/ +void QtxWebBrowser::setData( const QString& key, const QVariant& val ) { + myData.insert(key, val); +} + +/*! + \brief Get string by name from the internal data map. + \internal +*/ +QString QtxWebBrowser::getStringValue(const QString& key) { + QString val; + if(myData.contains(key)) { + QVariant v = myData[key]; + if( v.type() == QVariant::String ) { + val = v.toString(); + } + } + return val; +} + +/*! + \brief Get icon by name from the internal data map. + \internal +*/ +QIcon QtxWebBrowser::getIconValue(const QString& key) { + QIcon val; + if(myData.contains(key)) { + QVariant v = myData[key]; + if( v.type() == QVariant::Pixmap ) { + val = v.value(); + } + } + return val; +} + +/*! + \brief Update title of the window. + \internal +*/ +void QtxWebBrowser::adjustTitle() +{ + QString title = getStringValue("BROWSER_TITLE"); + title.isEmpty() ? title = myWebView->title() : title += " : " + myWebView->title(); + setWindowTitle(title); +} diff --git a/src/Qtx/QtxWebBrowser.h b/src/Qtx/QtxWebBrowser.h new file mode 100644 index 000000000..e0b777ab4 --- /dev/null +++ b/src/Qtx/QtxWebBrowser.h @@ -0,0 +1,65 @@ +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// 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 GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File: QtxWebBrowser.h +// Author: Roman NIKOLAEV +// + +#ifndef QTXWEBBROWSER_H +#define QTXWEBBROWSER_H + +#include "Qtx.h" + +#include +#include +#include + + +class QTX_EXPORT QtxWebBrowser : public QMainWindow +{ + Q_OBJECT + +private: + QtxWebBrowser(); + +public: + virtual ~QtxWebBrowser(); + + static QtxWebBrowser* webBrowser(); + static void loadUrl( const QString& theUrl, const QString theContext = QString() ); + static void setData( const QString& key, const QVariant& val ); + +private: + QString getStringValue(const QString& key); + QIcon getIconValue(const QString& key); + +private slots: + void adjustTitle(); + +private: + static QtxWebBrowser* myBrowser; + QWebView* myWebView; + static QMap myData; + +}; + +#endif // QTXWEBBROWSER_H