From: vsr Date: Tue, 21 Feb 2012 16:07:59 +0000 (+0000) Subject: Fix bug: it is impossible to remove user schemas by pressing [Delete] key. X-Git-Tag: V6_5_0a1~39 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=35be58b96333214db7f4defbf7292913d9c11df5;p=modules%2Fgui.git Fix bug: it is impossible to remove user schemas by pressing [Delete] key. --- diff --git a/src/Style/Style_PrefDlg.cxx b/src/Style/Style_PrefDlg.cxx index ca5951ab0..db142c069 100644 --- a/src/Style/Style_PrefDlg.cxx +++ b/src/Style/Style_PrefDlg.cxx @@ -632,6 +632,7 @@ Style_PrefDlg::Style_PrefDlg( QWidget* parent ) setButtonPosition( Right, Close ); setDialogFlags( AlignOnce ); myStylesList->setEditTriggers( QAbstractItemView::EditKeyPressed ); + myStylesList->installEventFilter( this ); QStringList globalStyles = resourceMgr()->styles( Style_ResourceMgr::Global ); QStringList userStyles = resourceMgr()->styles( Style_ResourceMgr::User ); @@ -718,23 +719,30 @@ void Style_PrefDlg::accept() \brief Process key press event \param e key event */ -void Style_PrefDlg::keyPressEvent( QKeyEvent* e ) +bool Style_PrefDlg::eventFilter( QObject* o, QEvent* e ) { - if ( e->key() == Qt::Key_Delete ) { - QListWidgetItem* item = myStylesList->currentItem(); - if ( item && item->data( TypeRole ).toInt() == User ) { - if ( QMessageBox::question( this, - tr( "Delete user theme" ), - tr( "Remove theme %1?" ).arg( item->text() ), - QMessageBox::Yes | QMessageBox::No, - QMessageBox::Yes ) == QMessageBox::Yes ) { - resourceMgr()->remove( item->data( NameRole ).toString() ); - resourceMgr()->save(); - delete item; + if ( o == myStylesList && e->type() == QEvent::KeyPress ) { + QKeyEvent* ke = (QKeyEvent*)e; + if ( ke->key() == Qt::Key_Delete ) { + QListWidgetItem* item = myStylesList->currentItem(); + if ( item && item->data( TypeRole ).toInt() == User ) { + if ( QMessageBox::question( this, + tr( "Delete user theme" ), + tr( "Remove theme %1?" ).arg( item->text() ), + QMessageBox::Yes | QMessageBox::No, + QMessageBox::Yes ) == QMessageBox::Yes ) { + resourceMgr()->remove( item->data( NameRole ).toString() ); + resourceMgr()->save(); + delete item; + } } } + if ( ke->key() == Qt::Key_Enter || ke->key() == Qt::Key_Return ) { +// onApply(); +// return true; + } } - QtxDialog::keyPressEvent( e ); + return QtxDialog::eventFilter( o, e ); } /*! diff --git a/src/Style/Style_PrefDlg.h b/src/Style/Style_PrefDlg.h index 264d72422..b710c3f79 100644 --- a/src/Style/Style_PrefDlg.h +++ b/src/Style/Style_PrefDlg.h @@ -58,9 +58,7 @@ public: ~Style_PrefDlg(); void accept(); - -protected: - void keyPressEvent( QKeyEvent* ); + bool eventFilter( QObject*, QEvent* ); private: Style_ResourceMgr* resourceMgr();