From aef87aeec506f5a5dde39cd2599f7584b32064f3 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 13 Sep 2018 11:13:33 +0200 Subject: [PATCH] Ignore key events in dialogs and let parent task panel handle them The affected dialogs are: * Texture mapping * Cross-sections * Extrusion * Revolution --- src/Gui/TextureMapping.cpp | 20 +++++++++++++++++++- src/Gui/TextureMapping.h | 2 ++ src/Mod/Part/Gui/CrossSections.cpp | 8 ++++++++ src/Mod/Part/Gui/CrossSections.h | 1 + src/Mod/Part/Gui/DlgExtrusion.cpp | 8 ++++++++ src/Mod/Part/Gui/DlgExtrusion.h | 1 + src/Mod/Part/Gui/DlgRevolution.cpp | 7 +++++++ src/Mod/Part/Gui/DlgRevolution.h | 1 + 8 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/Gui/TextureMapping.cpp b/src/Gui/TextureMapping.cpp index 1d1cc02f93..2fbd3293ab 100644 --- a/src/Gui/TextureMapping.cpp +++ b/src/Gui/TextureMapping.cpp @@ -29,6 +29,7 @@ # include # include # include +# include #endif #include @@ -55,6 +56,9 @@ TextureMapping::TextureMapping(QWidget* parent, Qt::WindowFlags fl) ui->setupUi(this); ui->checkGlobal->hide(); + // set a dummy string which is not a valid file name + fileName = QLatin1String("<>"); + // add all supported QImage formats QStringList formats; QList qtformats = QImageReader::supportedImageFormats(); @@ -111,11 +115,25 @@ void TextureMapping::changeEvent(QEvent *e) } } +void TextureMapping::keyPressEvent(QKeyEvent *e) +{ + // The texture mapping dialog is embedded into a task panel + // which is a parent widget and will handle the event + e->ignore(); +} + void TextureMapping::on_fileChooser_fileNameSelected(const QString& s) { QImage image; if (!image.load(s)) { - QMessageBox::warning(this, tr("No image"), tr("The specified file is not a valid image file.")); + // This slot is always invoked when leaving the focus of the line edit + // and to avoid to run into an infinite loop of popping up the dialog + // there is a check to report the last selected file name (which might + // be an empty string) only once. + if (fileName != s) { + QMessageBox::warning(this, tr("No image"), tr("The specified file is not a valid image file.")); + fileName = s; + } return; } diff --git a/src/Gui/TextureMapping.h b/src/Gui/TextureMapping.h index 58927f6434..f7ff6ef141 100644 --- a/src/Gui/TextureMapping.h +++ b/src/Gui/TextureMapping.h @@ -50,11 +50,13 @@ private Q_SLOTS: protected: void changeEvent(QEvent *e); + void keyPressEvent(QKeyEvent *e); private: SoGroup* grp; SoTexture2* tex; SoTextureCoordinateEnvironment* env; + QString fileName; Ui_TextureMapping* ui; }; diff --git a/src/Mod/Part/Gui/CrossSections.cpp b/src/Mod/Part/Gui/CrossSections.cpp index 97cc87516a..b28d86995c 100644 --- a/src/Mod/Part/Gui/CrossSections.cpp +++ b/src/Mod/Part/Gui/CrossSections.cpp @@ -34,6 +34,7 @@ # include # include # include +# include # include # include # include @@ -176,6 +177,13 @@ void CrossSections::changeEvent(QEvent *e) } } +void CrossSections::keyPressEvent(QKeyEvent* ke) +{ + // The cross-sections dialog is embedded into a task panel + // which is a parent widget and will handle the event + ke->ignore(); +} + void CrossSections::accept() { apply(); diff --git a/src/Mod/Part/Gui/CrossSections.h b/src/Mod/Part/Gui/CrossSections.h index 379d1981d5..b22a9b8add 100644 --- a/src/Mod/Part/Gui/CrossSections.h +++ b/src/Mod/Part/Gui/CrossSections.h @@ -51,6 +51,7 @@ public: protected: void changeEvent(QEvent *e); + void keyPressEvent(QKeyEvent*); private Q_SLOTS: void on_xyPlane_clicked(); diff --git a/src/Mod/Part/Gui/DlgExtrusion.cpp b/src/Mod/Part/Gui/DlgExtrusion.cpp index 41985e5133..ffad75b6e2 100644 --- a/src/Mod/Part/Gui/DlgExtrusion.cpp +++ b/src/Mod/Part/Gui/DlgExtrusion.cpp @@ -34,6 +34,7 @@ # include # include # include +# include # include # include # include @@ -147,6 +148,13 @@ void DlgExtrusion::changeEvent(QEvent *e) QDialog::changeEvent(e); } +void DlgExtrusion::keyPressEvent(QKeyEvent* ke) +{ + // The extrusion dialog is embedded into a task panel + // which is a parent widget and will handle the event + ke->ignore(); +} + void DlgExtrusion::on_rbDirModeCustom_toggled(bool on) { if(on) //this check prevents dual fire of dirmode changed - on radio buttons, one will come on, and other will come off, causing two events. diff --git a/src/Mod/Part/Gui/DlgExtrusion.h b/src/Mod/Part/Gui/DlgExtrusion.h index 318e632815..b6822392a9 100644 --- a/src/Mod/Part/Gui/DlgExtrusion.h +++ b/src/Mod/Part/Gui/DlgExtrusion.h @@ -65,6 +65,7 @@ protected: void findShapes(); bool canExtrude(const TopoDS_Shape&) const; void changeEvent(QEvent *e); + void keyPressEvent(QKeyEvent*); private Q_SLOTS: void on_rbDirModeCustom_toggled(bool on); diff --git a/src/Mod/Part/Gui/DlgRevolution.cpp b/src/Mod/Part/Gui/DlgRevolution.cpp index f03184bdd5..e6c2c95159 100644 --- a/src/Mod/Part/Gui/DlgRevolution.cpp +++ b/src/Mod/Part/Gui/DlgRevolution.cpp @@ -315,6 +315,13 @@ void DlgRevolution::changeEvent(QEvent *e) } } +void DlgRevolution::keyPressEvent(QKeyEvent* ke) +{ + // The revolution dialog is embedded into a task panel + // which is a parent widget and will handle the event + ke->ignore(); +} + void DlgRevolution::findShapes() { App::Document* activeDoc = App::GetApplication().getActiveDocument(); diff --git a/src/Mod/Part/Gui/DlgRevolution.h b/src/Mod/Part/Gui/DlgRevolution.h index daaadcd60e..2c0fcbcb82 100644 --- a/src/Mod/Part/Gui/DlgRevolution.h +++ b/src/Mod/Part/Gui/DlgRevolution.h @@ -56,6 +56,7 @@ public: protected: void changeEvent(QEvent *e); + void keyPressEvent(QKeyEvent*); private Q_SLOTS: void on_selectLine_clicked();