]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Fix bug: it is impossible to remove user schemas by pressing [Delete] key.
authorvsr <vsr@opencascade.com>
Tue, 21 Feb 2012 16:07:59 +0000 (16:07 +0000)
committervsr <vsr@opencascade.com>
Tue, 21 Feb 2012 16:07:59 +0000 (16:07 +0000)
src/Style/Style_PrefDlg.cxx
src/Style/Style_PrefDlg.h

index ca5951ab046ad73ca60a99defdeae89e90e5a25a..db142c0693630a9174a982b6d57ce4b8008c3cd2 100644 (file)
@@ -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 );
 }
 
 /*!
index 264d72422f2db9cd864f241e2a1b4f4095026d50..b710c3f7946e6ab39bca88dfb5ab22e383d839e7 100644 (file)
@@ -58,9 +58,7 @@ public:
   ~Style_PrefDlg();
 
   void               accept();
-
-protected:
-  void               keyPressEvent( QKeyEvent* );
+  bool               eventFilter( QObject*, QEvent* );
 
 private:
   Style_ResourceMgr* resourceMgr();