From: vsr Date: Mon, 17 Oct 2011 10:07:30 +0000 (+0000) Subject: 0020512: EDF 1113 OTHER : Using webkit to display documentation X-Git-Tag: V6_4_0a1~21 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=106f8059b6ad2a76fc50849004a7dc3a26903917;p=modules%2Fgui.git 0020512: EDF 1113 OTHER : Using webkit to display documentation Process PDF files --- diff --git a/src/Qtx/QtxWebBrowser.cxx b/src/Qtx/QtxWebBrowser.cxx index 34e354422..98e39eb61 100644 --- a/src/Qtx/QtxWebBrowser.cxx +++ b/src/Qtx/QtxWebBrowser.cxx @@ -27,6 +27,7 @@ #include "QtxSearchTool.h" #include +#include #include #include #include @@ -151,6 +152,7 @@ QtxWebBrowser::QtxWebBrowser() : QMainWindow( 0 ) QWidget* frame = new QWidget( this ); myWebView = new QWebView( frame ); + myWebView->page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks ); myFindPanel = new QtxSearchTool( frame, myWebView, QtxSearchTool::Basic | QtxSearchTool::Case | QtxSearchTool::Wrap, Qt::Horizontal ); @@ -177,6 +179,7 @@ QtxWebBrowser::QtxWebBrowser() : QMainWindow( 0 ) main->setSpacing( 3 ); connect( myWebView, SIGNAL( titleChanged( QString ) ), SLOT( adjustTitle() ) ); + connect( myWebView, SIGNAL( linkClicked( QUrl ) ), SLOT( linkClicked( QUrl ) ) ); setCentralWidget( frame ); setFocusProxy( myWebView ); @@ -365,11 +368,45 @@ void QtxWebBrowser::updateData() } } +/*! + \brief Clear internal data map + \internal +*/ void QtxWebBrowser::clearData() { myData.clear(); } +/*! + \brief Called when users activated any link at the page + \internal +*/ +void QtxWebBrowser::linkClicked( const QUrl& url ) +{ + myWebView->page()->setLinkDelegationPolicy( QWebPage::DontDelegateLinks ); + myWebView->load( url ); + if ( url.scheme() == "file" ) { + QString filename = url.toLocalFile(); + if ( QFileInfo( filename ).suffix().toLower() == "pdf" ) { +#ifdef WIN32 + ::system( QString( "start %2" ).arg( filename ).toLatin1().constData() ); +#else + // special processing of PDF files + QStringList readers; + readers << "xdg-open" << "acroread" << "kpdf" << "kghostview" << "xpdf"; + foreach ( QString r, readers ) { + QString reader = QString( "/usr/bin/%1" ).arg( r ); + if ( QFileInfo( reader ).exists() ) { + ::system( QString( "%1 %2 &" ).arg( reader ).arg( url.toLocalFile() ).toLatin1().constData() ); + break; + } + } +#endif // WIN32 + } + } + myWebView->page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks ); +} + /*! \brief Update title of the window \internal diff --git a/src/Qtx/QtxWebBrowser.h b/src/Qtx/QtxWebBrowser.h index d96914a66..f48f7f0ca 100644 --- a/src/Qtx/QtxWebBrowser.h +++ b/src/Qtx/QtxWebBrowser.h @@ -36,6 +36,7 @@ class QAction; class QMenu; class QToolBar; class QWebView; +class QUrl; class QtxSearchTool; class QTX_EXPORT QtxWebBrowser : public QMainWindow @@ -61,6 +62,9 @@ private: void updateData(); static void clearData(); +protected slots: + virtual void linkClicked( const QUrl& ); + private slots: void adjustTitle();