From: san Date: Wed, 17 Nov 2010 13:11:11 +0000 (+0000) Subject: Possibility to disable keyboard search in tree view. X-Git-Tag: V5_1_10~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d4a81a6e9d93a2e09da149c84388f9bf90f6a5c7;p=modules%2Fgui.git Possibility to disable keyboard search in tree view. Search tool not get the alpha numeric key events from watched widget. --- diff --git a/src/Qtx/QtxSearchTool.cxx b/src/Qtx/QtxSearchTool.cxx index dbb40df12..674a91e79 100644 --- a/src/Qtx/QtxSearchTool.cxx +++ b/src/Qtx/QtxSearchTool.cxx @@ -694,66 +694,32 @@ bool QtxSearchTool::eventFilter( QObject* o, QEvent* e ) switch ( e->type() ) { case QEvent::KeyPress: - if ( myWatched && o == myWatched ) - { + if ( o == myWatched ) { QKeyEvent* ke = (QKeyEvent*)e; - int key = ke->key(); - QString ttf = myData->text(); QString text = ke->text(); - if ( isVisible() ) - { - switch ( key ) - { - case Qt::Key_Escape: - hide(); - return true; - case Qt::Key_Backspace: - ttf.chop( 1 ); - break; - case Qt::Key_Return: - case Qt::Key_Enter: - findNext(); - return true; - default: - if ( text.isEmpty() || !text[0].isPrint() ) - return QFrame::eventFilter( o, e ); - ttf += text; - } - } - else - { - if ( text.isEmpty() || !isEnabled() || !text[0].isPrint() || myActivators == None ) - return QFrame::eventFilter( o, e ); - + if ( !isVisible() ) { if ( text.startsWith( '/' ) && myActivators & SlashKey ) { myData->clear(); find(); return true; } - else if ( !( myActivators & PrintKey ) ) + else if ( myActivators & PrintKey && text[0].isPrint() ) { - return QFrame::eventFilter( o, e ); - } - - ttf = text; - show(); + myData->setText( text ); + find( text ); + return true; + } } - myData->setText( ttf ); - find( ttf ); } - break; // case QEvent::KeyPress + break; case QEvent::FocusIn: case QEvent::FocusOut: if ( focused() ) - { myAutoHideTimer->stop(); - } else if ( isVisible() && isAutoHideEnabled() ) - { myAutoHideTimer->start(); - } break; default: break; diff --git a/src/Qtx/QtxTreeView.cxx b/src/Qtx/QtxTreeView.cxx index b6e159979..bf84aa366 100644 --- a/src/Qtx/QtxTreeView.cxx +++ b/src/Qtx/QtxTreeView.cxx @@ -470,7 +470,8 @@ void QtxTreeView::Header::contextMenuEvent( QContextMenuEvent* e ) \param parent parent widget */ QtxTreeView::QtxTreeView( QWidget* parent ) -: QTreeView( parent ) + : QTreeView( parent ), + myKeySearchEnabled( true ) { setHeader( new Header( false, this ) ); } @@ -481,7 +482,9 @@ QtxTreeView::QtxTreeView( QWidget* parent ) \param parent parent widget */ QtxTreeView::QtxTreeView( const bool enableSortMenu, QWidget* parent ) -: QTreeView( parent ) + : QTreeView( parent ), + myKeySearchEnabled( true ) + { setHeader( new Header( enableSortMenu, this ) ); } @@ -772,4 +775,31 @@ void QtxTreeView::emitSortingEnabled( bool enabled ) emit( sortingEnabled( enabled ) ); } +/*! + \brief Returns true if the keyboard search is enabled. +*/ +bool QtxTreeView::isKeyboardSearchEnabled() const +{ + return myKeySearchEnabled; +} + +/*! + \brief Enable/disable the keyboard search. +*/ +void QtxTreeView::setKeyboardSearchEnabled( bool on ) +{ + myKeySearchEnabled = on; +} + +/*! + \brief Moves to and selects the item best matching the string search. + If keyboard search is disabled or no item is found nothing happens. + \param search is pattern string +*/ +void QtxTreeView::keyboardSearch( const QString& search ) +{ + if ( isKeyboardSearchEnabled() ) + QAbstractItemView::keyboardSearch( search ); +} + #include diff --git a/src/Qtx/QtxTreeView.h b/src/Qtx/QtxTreeView.h index be47a4ab2..bdb2409a0 100644 --- a/src/Qtx/QtxTreeView.h +++ b/src/Qtx/QtxTreeView.h @@ -63,6 +63,11 @@ public: void expandTo( const QModelIndex& ); + bool isKeyboardSearchEnabled() const; + void setKeyboardSearchEnabled( bool ); + + void keyboardSearch( const QString& ); + protected slots: void onHeaderClicked(); void rowsAboutToBeRemoved( const QModelIndex&, int, int ); @@ -82,6 +87,9 @@ signals: private: void emitSortingEnabled( bool ); + private: + bool myKeySearchEnabled; + friend class QtxTreeView::Header; };