From: vsr Date: Sun, 16 Oct 2011 20:16:01 +0000 (+0000) Subject: Issue 0020512: EDF 1113 OTHER : Using webkit to display documentation X-Git-Tag: V6_4_0a1~26 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6673d6f0db539538f0d491a3fad3068a11650ebe;p=modules%2Fgui.git Issue 0020512: EDF 1113 OTHER : Using webkit to display documentation Additional improvement: provide search capabilities to the help browser --- diff --git a/src/Qtx/QtxSearchTool.cxx b/src/Qtx/QtxSearchTool.cxx index 816811f3c..76a95cf1e 100644 --- a/src/Qtx/QtxSearchTool.cxx +++ b/src/Qtx/QtxSearchTool.cxx @@ -270,7 +270,7 @@ static QWidget* wrapWidget( QWidget* parent, QWidget* w ) \param controls ORed controls flags (QtxSearchTool::Controls) \sa setWatchedWidget(), setControls() */ -QtxSearchTool::QtxSearchTool( QWidget* parent, QWidget* watched, int controls ) +QtxSearchTool::QtxSearchTool( QWidget* parent, QWidget* watched, int controls, Qt::Orientation orientation ) : QFrame( parent ), myWatched( watched ? watched : parent ), mySearcher( 0 ), @@ -279,7 +279,7 @@ QtxSearchTool::QtxSearchTool( QWidget* parent, QWidget* watched, int controls ) myAutoHideTimer( 0 ), myAutoHideEnabled( true ) { - init(); + init( orientation ); } /*! @@ -294,7 +294,7 @@ QtxSearchTool::QtxSearchTool( QWidget* parent, QWidget* watched, int controls ) \param controls ORed controls flags (QtxSearchTool::Controls) \sa setWatchedWidget(), setControls() */ -QtxSearchTool::QtxSearchTool( QWidget* parent, int controls ) +QtxSearchTool::QtxSearchTool( QWidget* parent, int controls, Qt::Orientation orientation ) : QFrame( parent ), myWatched( parent ), mySearcher( 0 ), @@ -303,7 +303,7 @@ QtxSearchTool::QtxSearchTool( QWidget* parent, int controls ) myAutoHideTimer( 0 ), myAutoHideEnabled( true ) { - init(); + init( orientation ); } /*! @@ -496,7 +496,7 @@ int QtxSearchTool::addCustomWidget( QWidget* w, int id ) wid = id < 0 ? --_wid : id; - QVBoxLayout* vbox = qobject_cast( layout() ); + QBoxLayout* vbox = qobject_cast( layout() ); w->setParent( this ); vbox->addWidget( w ); myWidgets.insert( wid, w ); @@ -871,25 +871,19 @@ void QtxSearchTool::modifierSwitched() \brief Initialize the search tool widget. \internal */ -void QtxSearchTool::init() +void QtxSearchTool::init( Qt::Orientation orientation ) { setFrameStyle( QFrame::StyledPanel | QFrame::Plain ); - QVBoxLayout* vbox = new QVBoxLayout(); - vbox->setSpacing( 0 ); - vbox->setMargin( 5 ); - setLayout( vbox ); myBtnWidget = new QWidget( this ); QHBoxLayout* myBtnWidget_layout = new QHBoxLayout( myBtnWidget ); myBtnWidget_layout->setSpacing( 0 ); myBtnWidget_layout->setMargin( 0 ); - vbox->addWidget( myBtnWidget ); myModWidget = new QWidget( this ); QHBoxLayout* myModWidget_layout = new QHBoxLayout( myModWidget ); myModWidget_layout->setSpacing( 0 ); myModWidget_layout->setMargin( 0 ); - vbox->addWidget( myModWidget ); myClose = new QToolButton( myBtnWidget ); myClose->setIcon( QIcon( close_xpm ) ); @@ -951,6 +945,14 @@ void QtxSearchTool::init() setShortcuts( QKeySequence( "Ctrl+S" ) ); setActivators( Any ); + + QBoxLayout* box = orientation == Qt::Vertical ? (QBoxLayout*)( new QVBoxLayout ) : (QBoxLayout*)( new QHBoxLayout ); + box->setSpacing( 0 ); + box->setMargin( 5 ); + box->addWidget( myBtnWidget ); + box->addWidget( myModWidget ); + setLayout( box ); + updateControls(); } diff --git a/src/Qtx/QtxSearchTool.h b/src/Qtx/QtxSearchTool.h index 7a293fe59..a7cc07123 100644 --- a/src/Qtx/QtxSearchTool.h +++ b/src/Qtx/QtxSearchTool.h @@ -79,8 +79,8 @@ public: Any = HotKey | SlashKey | StandardKey | PrintKey //!< search tool is activated by any of above mentioned ways } Activator; - QtxSearchTool( QWidget*, QWidget* = 0, int = All ); - QtxSearchTool( QWidget*, int = All ); + QtxSearchTool( QWidget*, QWidget* = 0, int = All, Qt::Orientation = Qt::Vertical ); + QtxSearchTool( QWidget*, int = All, Qt::Orientation = Qt::Vertical ); virtual ~QtxSearchTool(); QWidget* watchedWidget() const; @@ -129,7 +129,7 @@ private slots: void modifierSwitched(); private: - void init(); + void init( Qt::Orientation ); bool focused() const; void clearShortcuts(); void initShortcuts( const QList& ); diff --git a/src/Qtx/QtxWebBrowser.cxx b/src/Qtx/QtxWebBrowser.cxx index 79a2fa983..34e354422 100644 --- a/src/Qtx/QtxWebBrowser.cxx +++ b/src/Qtx/QtxWebBrowser.cxx @@ -24,18 +24,74 @@ // Author: Roman NIKOLAEV // #include "QtxWebBrowser.h" +#include "QtxSearchTool.h" #include #include #include #include #include +#include -//! The only one instance of web browser -QtxWebBrowser* QtxWebBrowser::myBrowser = 0; +/*! + \class WebViewSearcher + \brief A class is used with QtxSearchTool in order to search text within the web page + \internal +*/ +class WebViewSearcher : public QtxSearchTool::Searcher +{ +public: + WebViewSearcher( QWebView* ); + ~WebViewSearcher(); -//! Internal data map to store resources of the browser. -QMap QtxWebBrowser::myData; + bool find( const QString&, QtxSearchTool* ); + bool findNext( const QString&, QtxSearchTool* ); + bool findPrevious( const QString&, QtxSearchTool* ); + bool findFirst( const QString&, QtxSearchTool* ); + bool findLast( const QString&, QtxSearchTool* ); + +private: + QWebView* myView; +}; + +WebViewSearcher::WebViewSearcher( QWebView* view ) : myView( view ) +{ +} + +WebViewSearcher::~WebViewSearcher() +{ +} + +bool WebViewSearcher::find( const QString& text, QtxSearchTool* st ) +{ + QWebPage::FindFlags fl = 0; + if ( st->isCaseSensitive() ) fl = fl | QWebPage::FindCaseSensitively; + if ( st->isSearchWrapped() ) fl = fl | QWebPage::FindWrapsAroundDocument; + return myView->findText( text, fl ); +} + +bool WebViewSearcher::findNext( const QString& text, QtxSearchTool* st ) +{ + return find( text, st ); +} + +bool WebViewSearcher::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; + return myView->findText( text, fl ); +} + +bool WebViewSearcher::findFirst( const QString&, QtxSearchTool* ) +{ + return false; +} + +bool WebViewSearcher::findLast( const QString&, QtxSearchTool* ) +{ + return false; +} /*! \class QtxWebBrowser @@ -77,6 +133,12 @@ QMap QtxWebBrowser::myData; */ +//! The only one instance of web browser +QtxWebBrowser* QtxWebBrowser::myBrowser = 0; + +//! Internal data map to store resources of the browser. +QMap QtxWebBrowser::myData; + /*! \brief Constructor. @@ -85,19 +147,41 @@ QMap QtxWebBrowser::myData; QtxWebBrowser::QtxWebBrowser() : QMainWindow( 0 ) { setAttribute( Qt::WA_DeleteOnClose ); - myWebView = new QWebView(this); - + + QWidget* frame = new QWidget( this ); + + myWebView = new QWebView( frame ); + myFindPanel = new QtxSearchTool( frame, myWebView, + QtxSearchTool::Basic | QtxSearchTool::Case | QtxSearchTool::Wrap, + Qt::Horizontal ); + myFindPanel->setFrameStyle( QFrame::NoFrame | QFrame::Plain ); + myFindPanel->setActivators( QtxSearchTool::SlashKey ); + myFindPanel->setSearcher( new WebViewSearcher( myWebView ) ); + myFindPanel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ); + myToolbar = addToolBar( tr( "Navigation" ) ); myToolbar->addAction( myWebView->pageAction( QWebPage::Back ) ); myToolbar->addAction( myWebView->pageAction( QWebPage::Forward ) ); - myMenus[ File ] = menuBar()->addMenu( tr( "&File" ) ); - myActions[ Close ] = myMenus[ File ]->addAction( tr( "&Close" ), this, SLOT( close() ) ); + myMenus[ File ] = menuBar()->addMenu( tr( "&File" ) ); + myActions[ Find ] = myMenus[ File ]->addAction( tr( "&Find in text..." ), myFindPanel, SLOT( find() ), QKeySequence( QKeySequence::Find ) ); + myActions[ FindNext ] = myMenus[ File ]->addAction( tr( "&Find next" ), myFindPanel, SLOT( findNext() ), QKeySequence( QKeySequence::FindNext ) ); + myActions[ FindPrev ] = myMenus[ File ]->addAction( tr( "&Find previous" ), myFindPanel, SLOT( findPrevious() ), QKeySequence( QKeySequence::FindPrevious ) ); + myMenus[ File ]->addSeparator(); + myActions[ Close ] = myMenus[ File ]->addAction( tr( "&Close" ), this, SLOT( close() ) ); - connect( myWebView, SIGNAL( titleChanged( QString ) ), SLOT( adjustTitle() ) ); - setCentralWidget( myWebView ); + QVBoxLayout* main = new QVBoxLayout( frame ); + main->addWidget( myWebView ); + main->addWidget( myFindPanel ); + main->setMargin( 0 ); + main->setSpacing( 3 ); + connect( myWebView, SIGNAL( titleChanged( QString ) ), SLOT( adjustTitle() ) ); + + setCentralWidget( frame ); + setFocusProxy( myWebView ); updateData(); + qAddPostRoutine( QtxWebBrowser::clearData ); } /*! @@ -142,16 +226,22 @@ void QtxWebBrowser::loadUrl( const QString& url, const QString& anchor ) \brief Set browser settings from. This method can be used to setup the browser properties. - - \c "browser:title" : title of the browser window - - \c "browser:icon" : icon of the browser window - - \c "toolbar:title" : title of the toolbar - - \c "menu:file:title" : File menu of the browser - - \c "action:close:title" : File/Close menu item title - - \c "action:close:icon" : File/Close menu item icon - - \c "action:back:title" : Navigation/Back menu item title - - \c "action:back:icon" : Navigation/Back menu item icon - - \c "action:forward:title" : Navigation/Forward menu item title - - \c "action:forward:icon" : Navigation/Forward menu item icon + - \c "browser:title" : title of the browser window + - \c "browser:icon" : icon of the browser window + - \c "toolbar:title" : title of the toolbar + - \c "menu:file:title" : File menu of the browser + - \c "action:close:title" : File/Close menu item title + - \c "action:close:icon" : File/Close menu item icon + - \c "action:back:title" : Navigation/Back menu item title + - \c "action:back:icon" : Navigation/Back menu item icon + - \c "action:forward:title" : Navigation/Forward menu item title + - \c "action:forward:icon" : Navigation/Forward menu item icon + - \c "action:find:title" : File/Find menu item title + - \c "action:find:icon" : File/Find menu item icon + - \c "action:findnext:title" : File/Find Next menu item title + - \c "action:findnext:icon" : File/Find Next menu item icon + - \c "action:findprev:title" : File/Find Previous menu item title + - \c "action:findprev:icon" : File/Find Previous menu item icon \param key name of the property \param val value of the property @@ -243,6 +333,41 @@ void QtxWebBrowser::updateData() myWebView->pageAction( QWebPage::Forward )->setText( fwdTlt ); if ( !fwdIco.isNull() ) myWebView->pageAction( QWebPage::Forward )->setIcon( fwdIco ); + + // File/Find menu + QString findTlt = getStringValue( "action:find:title" ); + QIcon findIco = getIconValue( "action:find:icon" ); + if ( myActions.contains( Find ) ) { + if ( !findTlt.isEmpty() ) + myActions[ Find ]->setText( findTlt ); + if ( !findIco.isNull() ) + myActions[ Find ]->setIcon( findIco ); + } + + // File/Find Next menu + QString findNextTlt = getStringValue( "action:findnext:title" ); + QIcon findNextIco = getIconValue( "action:findnext:icon" ); + if ( myActions.contains( FindNext ) ) { + if ( !findNextTlt.isEmpty() ) + myActions[ FindNext ]->setText( findNextTlt ); + if ( !findNextIco.isNull() ) + myActions[ FindNext ]->setIcon( findNextIco ); + } + + // File/Find Previous menu + QString findPrevTlt = getStringValue( "action:findprev:title" ); + QIcon findPrevIco = getIconValue( "action:findprev:icon" ); + if ( myActions.contains( FindPrev ) ) { + if ( !findPrevTlt.isEmpty() ) + myActions[ FindPrev ]->setText( findPrevTlt ); + if ( !findPrevIco.isNull() ) + myActions[ FindPrev ]->setIcon( findPrevIco ); + } +} + +void QtxWebBrowser::clearData() +{ + myData.clear(); } /*! diff --git a/src/Qtx/QtxWebBrowser.h b/src/Qtx/QtxWebBrowser.h index ecdf82f0e..d96914a66 100644 --- a/src/Qtx/QtxWebBrowser.h +++ b/src/Qtx/QtxWebBrowser.h @@ -36,13 +36,14 @@ class QAction; class QMenu; class QToolBar; class QWebView; +class QtxSearchTool; class QTX_EXPORT QtxWebBrowser : public QMainWindow { Q_OBJECT enum { File }; - enum { Close }; + enum { Find, FindNext, FindPrev, Close }; private: QtxWebBrowser(); @@ -58,6 +59,7 @@ private: static QString getStringValue( const QString& ); static QIcon getIconValue( const QString& ); void updateData(); + static void clearData(); private slots: void adjustTitle(); @@ -69,6 +71,7 @@ private: QToolBar* myToolbar; QMap myMenus; QMap myActions; + QtxSearchTool* myFindPanel; }; #endif // QTXWEBBROWSER_H