-// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2020 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
#include <QStatusBar>
#include <QToolBar>
#include <QVBoxLayout>
-#include <QWebView>
+#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0)
+ #include <QWebView>
+#else
+ #include <QWebEngineView>
+#endif
#include <QProcess>
+// 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 )
class QtxWebBrowser::Searcher : public QtxSearchTool::Searcher
{
public:
- Searcher( QWebView* );
+ Searcher( WebView* );
~Searcher();
bool find( const QString&, QtxSearchTool* );
bool findLast( const QString&, QtxSearchTool* );
private:
- QWebView* myView;
+ WebView* myView;
};
/*!
\param view web view
\internal
*/
-QtxWebBrowser::Searcher::Searcher( QWebView* view ) : myView( view )
+QtxWebBrowser::Searcher::Searcher( WebView* view ) : myView( view )
{
}
*/
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
+ bool textFound;
+ myView->findText( text, fl, [&](bool found) { textFound = found; });
+ return textFound;
+#endif
}
/*!
*/
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
+ bool textFound;
+ myView->findText( text, fl, [&](bool found) { textFound = found; });
+ return textFound;
+#endif
}
/*!
QGridLayout* l = new QGridLayout( this );
l->addWidget( new QLabel( QtxWebBrowser::tr( "You are opening the file" ), this ),
- 0, 0, 1, 4 );
+ 0, 0, 1, 4 );
l->addWidget( myFileName, 1, 1, 1, 3 );
l->addWidget( new QLabel( QtxWebBrowser::tr( "Please choose the action to be done" ), this ),
- 3, 0, 1, 4 );
+ 3, 0, 1, 4 );
l->addWidget( rbOpen, 4, 1, 1, 1 );
l->addWidget( myBrowse, 4, 2, 1, 1 );
l->addWidget( rbSave, 5, 1, 1, 3 );
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->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,
- Qt::Horizontal );
+#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 );
myFindPanel->setSearcher( new Searcher( myWebView ) );
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( 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 ) );
+ this, SLOT( open() ),
+ QKeySequence( QKeySequence::Open ) );
+ fileMenu->addSeparator();
+ 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() ),
- QKeySequence( QKeySequence::Find ) );
+ myFindPanel, SLOT( find() ),
+ QKeySequence( QKeySequence::Find ) );
fileMenu->addAction( tr( "&Find next" ),
- myFindPanel, SLOT( findNext() ),
- QKeySequence( QKeySequence::FindNext ) );
+ myFindPanel, SLOT( findNext() ),
+ QKeySequence( QKeySequence::FindNext ) );
fileMenu->addAction( tr( "&Find previous" ),
- myFindPanel, SLOT( findPrevious() ),
- QKeySequence( QKeySequence::FindPrevious ) );
+ myFindPanel, SLOT( findPrevious() ),
+ QKeySequence( QKeySequence::FindPrevious ) );
fileMenu->addSeparator();
fileMenu->addAction( QPixmap( ":/images/close.png" ), tr( "&Close" ),
- this, SLOT( close() ) );
+ this, SLOT( close() ) );
QMenu* helpMenu = menuBar()->addMenu( tr( "&Help" ) );
helpMenu->addAction( tr( "&About..." ),
- this, SLOT( about() ) );
+ this, SLOT( about() ) );
QVBoxLayout* main = new QVBoxLayout( frame );
main->addWidget( myWebView );
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->page(), SIGNAL( linkHovered( QString, QString, QString ) ),
- SLOT( linkHovered( QString, QString, QString ) ) );
- connect( myWebView->pageAction( QWebPage::DownloadLinkToDisk ), SIGNAL( activated() ),
- SLOT( linkAction() ) );
- disconnect( myWebView->pageAction( QWebPage::OpenLink ), 0, 0, 0 );
- connect( myWebView->pageAction( QWebPage::OpenLink ), SIGNAL( activated() ),
- SLOT( linkAction() ) );
+ 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 ) ) );
+ disconnect( myWebView->pageAction( WebPage::OpenLink ), 0, 0, 0 );
+ connect( myWebView->pageAction( WebPage::OpenLink ), SIGNAL( triggered() ),
+ SLOT( linkAction() ) );
+#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" ) );
void QtxWebBrowser::about()
{
QMessageBox::about( this, tr( "About %1" ).arg( tr( "Help Browser" ) ),
- QString( "SALOME %1" ).arg( tr( "Help Browser" ) ) );
+ QString( "SALOME %1" ).arg( tr( "Help Browser" ) ) );
}
/*!
*/
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
}
/*!
\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 );
}
/*!
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" ) {
myResourceMgr->setValue( resSection, actionParam, defAction );
myResourceMgr->setValue( resSection, repeatParam, defRepeat );
if ( defAction == Downloader::mOpen )
- myResourceMgr->setValue( resSection, programParam, defProgram );
+ myResourceMgr->setValue( resSection, programParam, defProgram );
}
}
switch( defAction ) {
\brief Load URL
\param url path to the file to be opened in the browser
*/
-void QtxWebBrowser::load( const QString& url )
+void QtxWebBrowser::load( const QString& link )
{
- QString u = url;
- if ( !u.isEmpty() )
- myWebView->load( QUrl( u.replace('\\', '/') ) );
+ QString linkPath = link;
+ linkPath.replace('\\', '/');
+ QUrl url = linkPath;
+ if ( !url.isEmpty() ) {
+ if ( url.scheme().isEmpty() ) url.setScheme( "file" );
+ myWebView->load( url );
+ }
}
/*!
void QtxWebBrowser::saveLink( const QString& fileName )
{
QString newFileName = QFileDialog::getSaveFileName( this, tr( "Save file" ), fileName,
- QString( "*.%1" ).arg( QFileInfo( fileName ).suffix() ) );
+ QString( "*.%1" ).arg( QFileInfo( fileName ).suffix() ) );
if ( !newFileName.isEmpty() &&
QFileInfo( newFileName ).canonicalFilePath() != QFileInfo( fileName ).canonicalFilePath() ) {
QFile toFile( newFileName );
QFile fromFile( fileName );
- if ( toFile.exists() && !toFile.remove() || !fromFile.copy( newFileName ) )
+ if (( toFile.exists() && !toFile.remove() ) ||
+ ( !fromFile.copy( newFileName ) ))
QMessageBox::warning( this, tr( "Error"), tr( "Can't save file:\n%1" ).arg( newFileName ) );
}
}