diff --git a/src/Mod/PartDesign/Gui/TaskChamferParameters.cpp b/src/Mod/PartDesign/Gui/TaskChamferParameters.cpp index 615c24a021..5fcc8c3d7d 100644 --- a/src/Mod/PartDesign/Gui/TaskChamferParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskChamferParameters.cpp @@ -25,6 +25,7 @@ #ifndef _PreComp_ # include +# include # include # include #endif @@ -86,21 +87,21 @@ TaskChamferParameters::TaskChamferParameters(ViewProviderDressUp *DressUpView, Q this, SLOT(onButtonRefRemove(bool))); // Create context menu - QAction* action = new QAction(tr("Remove"), this); - action->setShortcut(QKeySequence::Delete); + deleteAction = new QAction(tr("Remove"), this); + deleteAction->setShortcut(QKeySequence::Delete); #if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) // display shortcut behind the context menu entry - action->setShortcutVisibleInContextMenu(true); + deleteAction->setShortcutVisibleInContextMenu(true); #endif - ui->listWidgetReferences->addAction(action); + ui->listWidgetReferences->addAction(deleteAction); // if there is only one item, it cannot be deleted if (ui->listWidgetReferences->count() == 1) { - action->setEnabled(false); - action->setStatusTip(tr("There must be at least one item")); + deleteAction->setEnabled(false); + deleteAction->setStatusTip(tr("There must be at least one item")); ui->buttonRefRemove->setEnabled(false); ui->buttonRefRemove->setToolTip(tr("There must be at least one item")); } - connect(action, SIGNAL(triggered()), this, SLOT(onRefDeleted())); + connect(deleteAction, SIGNAL(triggered()), this, SLOT(onRefDeleted())); ui->listWidgetReferences->setContextMenuPolicy(Qt::ActionsContextMenu); connect(ui->listWidgetReferences, SIGNAL(itemClicked(QListWidgetItem*)), @@ -119,13 +120,12 @@ void TaskChamferParameters::onSelectionChanged(const Gui::SelectionChanges& msg) if (msg.Type == Gui::SelectionChanges::AddSelection) { if (referenceSelected(msg)) { - QAction *action = ui->listWidgetReferences->actions().at(0); // we have only one action if (selectionMode == refAdd) { ui->listWidgetReferences->addItem(QString::fromStdString(msg.pSubName)); // it might be the second one so we can enable the context menu if (ui->listWidgetReferences->count() > 1) { - action->setEnabled(true); - action->setStatusTip(QString()); + deleteAction->setEnabled(true); + deleteAction->setStatusTip(QString()); ui->buttonRefRemove->setEnabled(true); ui->buttonRefRemove->setToolTip(tr("Click button to enter selection mode,\nclick again to end selection")); } @@ -136,8 +136,8 @@ void TaskChamferParameters::onSelectionChanged(const Gui::SelectionChanges& msg) Gui::Selection().clearSelection(); // if there is only one item left, it cannot be deleted if (ui->listWidgetReferences->count() == 1) { - action->setEnabled(false); - action->setStatusTip(tr("There must be at least one item")); + deleteAction->setEnabled(false); + deleteAction->setStatusTip(tr("There must be at least one item")); ui->buttonRefRemove->setEnabled(false); ui->buttonRefRemove->setToolTip(tr("There must be at least one item")); // we must also end the selection mode @@ -195,9 +195,8 @@ void TaskChamferParameters::onRefDeleted(void) // if there is only one item left, it cannot be deleted if (ui->listWidgetReferences->count() == 1) { - QAction *action = ui->listWidgetReferences->actions().at(0); // we have only one action - action->setEnabled(false); - action->setStatusTip(tr("There must be at least one item")); + deleteAction->setEnabled(false); + deleteAction->setStatusTip(tr("There must be at least one item")); ui->buttonRefRemove->setEnabled(false); ui->buttonRefRemove->setToolTip(tr("There must be at least one item")); } @@ -224,6 +223,31 @@ TaskChamferParameters::~TaskChamferParameters() delete ui; } +bool TaskChamferParameters::event(QEvent *e) +{ + // in case another instance takes key events, accept the overridden key event + if (e && e->type() == QEvent::ShortcutOverride) { + QKeyEvent * kevent = static_cast(e); + if (kevent->modifiers() == Qt::NoModifier) { + if (kevent->key() == Qt::Key_Delete) { + kevent->accept(); + return true; + } + } + } + // if we have a Del key, trigger the deleteAction + else if (e && e->type() == QEvent::KeyPress) { + QKeyEvent * kevent = static_cast(e); + if (kevent->key() == Qt::Key_Delete) { + if (deleteAction->isEnabled()) + deleteAction->trigger(); + return true; + } + } + + return TaskDressUpParameters::event(e); +} + void TaskChamferParameters::changeEvent(QEvent *e) { TaskBox::changeEvent(e); diff --git a/src/Mod/PartDesign/Gui/TaskChamferParameters.h b/src/Mod/PartDesign/Gui/TaskChamferParameters.h index 5826c8fdfc..ad8b8345e8 100644 --- a/src/Mod/PartDesign/Gui/TaskChamferParameters.h +++ b/src/Mod/PartDesign/Gui/TaskChamferParameters.h @@ -47,11 +47,13 @@ private Q_SLOTS: protected: virtual void clearButtons(const selectionModes notThis); + bool event(QEvent *e); void changeEvent(QEvent *e); virtual void onSelectionChanged(const Gui::SelectionChanges& msg); double getLength(void) const; private: + QAction* deleteAction; Ui_TaskChamferParameters* ui; }; diff --git a/src/Mod/PartDesign/Gui/TaskDraftParameters.cpp b/src/Mod/PartDesign/Gui/TaskDraftParameters.cpp index c32af9e2aa..353b8425f5 100644 --- a/src/Mod/PartDesign/Gui/TaskDraftParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskDraftParameters.cpp @@ -27,6 +27,7 @@ #ifndef _PreComp_ # include # include +# include # include # include #endif @@ -100,21 +101,21 @@ TaskDraftParameters::TaskDraftParameters(ViewProviderDressUp *DressUpView, QWidg this, SLOT(onButtonLine(bool))); // Create context menu - QAction* action = new QAction(tr("Remove"), this); - action->setShortcut(QKeySequence::Delete); + deleteAction = new QAction(tr("Remove"), this); + deleteAction->setShortcut(QKeySequence::Delete); #if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) // display shortcut behind the context menu entry - action->setShortcutVisibleInContextMenu(true); + deleteAction->setShortcutVisibleInContextMenu(true); #endif - ui->listWidgetReferences->addAction(action); + ui->listWidgetReferences->addAction(deleteAction); // if there is only one item, it cannot be deleted if (ui->listWidgetReferences->count() == 1) { - action->setEnabled(false); - action->setStatusTip(tr("There must be at least one item")); + deleteAction->setEnabled(false); + deleteAction->setStatusTip(tr("There must be at least one item")); ui->buttonRefRemove->setEnabled(false); ui->buttonRefRemove->setToolTip(tr("There must be at least one item")); } - connect(action, SIGNAL(triggered()), this, SLOT(onRefDeleted())); + connect(deleteAction, SIGNAL(triggered()), this, SLOT(onRefDeleted())); ui->listWidgetReferences->setContextMenuPolicy(Qt::ActionsContextMenu); connect(ui->listWidgetReferences, SIGNAL(itemClicked(QListWidgetItem*)), @@ -141,13 +142,12 @@ void TaskDraftParameters::onSelectionChanged(const Gui::SelectionChanges& msg) if (msg.Type == Gui::SelectionChanges::AddSelection) { if (referenceSelected(msg)) { - QAction *action = ui->listWidgetReferences->actions().at(0); // we have only one action if (selectionMode == refAdd) { ui->listWidgetReferences->addItem(QString::fromStdString(msg.pSubName)); // it might be the second one so we can enable the context menu if (ui->listWidgetReferences->count() > 1) { - action->setEnabled(true); - action->setStatusTip(QString()); + deleteAction->setEnabled(true); + deleteAction->setStatusTip(QString()); ui->buttonRefRemove->setEnabled(true); ui->buttonRefRemove->setToolTip(tr("Click button to enter selection mode,\nclick again to end selection")); } @@ -158,8 +158,8 @@ void TaskDraftParameters::onSelectionChanged(const Gui::SelectionChanges& msg) Gui::Selection().clearSelection(); // if there is only one item left, it cannot be deleted if (ui->listWidgetReferences->count() == 1) { - action->setEnabled(false); - action->setStatusTip(tr("There must be at least one item")); + deleteAction->setEnabled(false); + deleteAction->setStatusTip(tr("There must be at least one item")); ui->buttonRefRemove->setEnabled(false); ui->buttonRefRemove->setToolTip(tr("There must be at least one item")); // we must also end the selection mode @@ -269,9 +269,8 @@ void TaskDraftParameters::onRefDeleted(void) // if there is only one item left, it cannot be deleted if (ui->listWidgetReferences->count() == 1) { - QAction *action = ui->listWidgetReferences->actions().at(0); // we have only one action - action->setEnabled(false); - action->setStatusTip(tr("There must be at least one item")); + deleteAction->setEnabled(false); + deleteAction->setStatusTip(tr("There must be at least one item")); ui->buttonRefRemove->setEnabled(false); ui->buttonRefRemove->setToolTip(tr("There must be at least one item")); } @@ -330,6 +329,31 @@ TaskDraftParameters::~TaskDraftParameters() delete ui; } +bool TaskDraftParameters::event(QEvent *e) +{ + // in case another instance takes key events, accept the overridden key event + if (e && e->type() == QEvent::ShortcutOverride) { + QKeyEvent * kevent = static_cast(e); + if (kevent->modifiers() == Qt::NoModifier) { + if (kevent->key() == Qt::Key_Delete) { + kevent->accept(); + return true; + } + } + } + // if we have a Del key, trigger the deleteAction + else if (e && e->type() == QEvent::KeyPress) { + QKeyEvent * kevent = static_cast(e); + if (kevent->key() == Qt::Key_Delete) { + if (deleteAction->isEnabled()) + deleteAction->trigger(); + return true; + } + } + + return TaskDressUpParameters::event(e); +} + void TaskDraftParameters::changeEvent(QEvent *e) { TaskBox::changeEvent(e); diff --git a/src/Mod/PartDesign/Gui/TaskDraftParameters.h b/src/Mod/PartDesign/Gui/TaskDraftParameters.h index 3134e5cc69..e2b139deb9 100644 --- a/src/Mod/PartDesign/Gui/TaskDraftParameters.h +++ b/src/Mod/PartDesign/Gui/TaskDraftParameters.h @@ -55,10 +55,12 @@ private Q_SLOTS: protected: virtual void clearButtons(const selectionModes notThis); + bool event(QEvent *e); void changeEvent(QEvent *e); virtual void onSelectionChanged(const Gui::SelectionChanges& msg); private: + QAction* deleteAction; Ui_TaskDraftParameters* ui; }; diff --git a/src/Mod/PartDesign/Gui/TaskFilletParameters.cpp b/src/Mod/PartDesign/Gui/TaskFilletParameters.cpp index 93da8b44a0..4583885410 100644 --- a/src/Mod/PartDesign/Gui/TaskFilletParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskFilletParameters.cpp @@ -226,6 +226,7 @@ TaskFilletParameters::~TaskFilletParameters() bool TaskFilletParameters::event(QEvent *e) { + // in case another instance takes key events, accept the overridden key event if (e && e->type() == QEvent::ShortcutOverride) { QKeyEvent * kevent = static_cast(e); if (kevent->modifiers() == Qt::NoModifier) { @@ -235,6 +236,7 @@ bool TaskFilletParameters::event(QEvent *e) } } } + // if we have a Del key, trigger the deleteAction else if (e && e->type() == QEvent::KeyPress) { QKeyEvent * kevent = static_cast(e); if (kevent->key() == Qt::Key_Delete) { diff --git a/src/Mod/PartDesign/Gui/TaskThicknessParameters.cpp b/src/Mod/PartDesign/Gui/TaskThicknessParameters.cpp index 496a64e54e..edd4e98e87 100644 --- a/src/Mod/PartDesign/Gui/TaskThicknessParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskThicknessParameters.cpp @@ -25,6 +25,7 @@ #ifndef _PreComp_ # include +# include # include # include #endif @@ -102,21 +103,21 @@ TaskThicknessParameters::TaskThicknessParameters(ViewProviderDressUp *DressUpVie this, SLOT(onJoinTypeChanged(int))); // Create context menu - QAction* action = new QAction(tr("Remove"), this); - action->setShortcut(QKeySequence::Delete); + deleteAction = new QAction(tr("Remove"), this); + deleteAction->setShortcut(QKeySequence::Delete); #if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) // display shortcut behind the context menu entry - action->setShortcutVisibleInContextMenu(true); + deleteAction->setShortcutVisibleInContextMenu(true); #endif - ui->listWidgetReferences->addAction(action); + ui->listWidgetReferences->addAction(deleteAction); // if there is only one item, it cannot be deleted if (ui->listWidgetReferences->count() == 1) { - action->setEnabled(false); - action->setStatusTip(tr("There must be at least one item")); + deleteAction->setEnabled(false); + deleteAction->setStatusTip(tr("There must be at least one item")); ui->buttonRefRemove->setEnabled(false); ui->buttonRefRemove->setToolTip(tr("There must be at least one item")); } - connect(action, SIGNAL(triggered()), this, SLOT(onRefDeleted())); + connect(deleteAction, SIGNAL(triggered()), this, SLOT(onRefDeleted())); ui->listWidgetReferences->setContextMenuPolicy(Qt::ActionsContextMenu); connect(ui->listWidgetReferences, SIGNAL(itemClicked(QListWidgetItem*)), @@ -141,13 +142,12 @@ void TaskThicknessParameters::onSelectionChanged(const Gui::SelectionChanges& ms if (msg.Type == Gui::SelectionChanges::AddSelection) { if (referenceSelected(msg)) { - QAction *action = ui->listWidgetReferences->actions().at(0); // we have only one action if (selectionMode == refAdd) { ui->listWidgetReferences->addItem(QString::fromStdString(msg.pSubName)); // it might be the second one so we can enable the context menu if (ui->listWidgetReferences->count() > 1) { - action->setEnabled(true); - action->setStatusTip(QString()); + deleteAction->setEnabled(true); + deleteAction->setStatusTip(QString()); ui->buttonRefRemove->setEnabled(true); ui->buttonRefRemove->setToolTip(tr("Click button to enter selection mode,\nclick again to end selection")); } @@ -158,8 +158,8 @@ void TaskThicknessParameters::onSelectionChanged(const Gui::SelectionChanges& ms Gui::Selection().clearSelection(); // if there is only one item left, it cannot be deleted if (ui->listWidgetReferences->count() == 1) { - action->setEnabled(false); - action->setStatusTip(tr("There must be at least one item")); + deleteAction->setEnabled(false); + deleteAction->setStatusTip(tr("There must be at least one item")); ui->buttonRefRemove->setEnabled(false); ui->buttonRefRemove->setToolTip(tr("There must be at least one item")); // we must also end the selection mode @@ -217,9 +217,8 @@ void TaskThicknessParameters::onRefDeleted(void) // if there is only one item left, it cannot be deleted if (ui->listWidgetReferences->count() == 1) { - QAction *action = ui->listWidgetReferences->actions().at(0); // we have only one action - action->setEnabled(false); - action->setStatusTip(tr("There must be at least one item")); + deleteAction->setEnabled(false); + deleteAction->setStatusTip(tr("There must be at least one item")); ui->buttonRefRemove->setEnabled(false); ui->buttonRefRemove->setToolTip(tr("There must be at least one item")); } @@ -252,7 +251,6 @@ void TaskThicknessParameters::onModeChanged(int mode) { pcThickness->getDocument()->recomputeFeature(pcThickness); } - double TaskThicknessParameters::getValue(void) const { return ui->Value->value().getValue(); @@ -302,6 +300,31 @@ TaskThicknessParameters::~TaskThicknessParameters() delete ui; } +bool TaskThicknessParameters::event(QEvent *e) +{ + // in case another instance takes key events, accept the overridden key event + if (e && e->type() == QEvent::ShortcutOverride) { + QKeyEvent * kevent = static_cast(e); + if (kevent->modifiers() == Qt::NoModifier) { + if (kevent->key() == Qt::Key_Delete) { + kevent->accept(); + return true; + } + } + } + // if we have a Del key, trigger the deleteAction + else if (e && e->type() == QEvent::KeyPress) { + QKeyEvent * kevent = static_cast(e); + if (kevent->key() == Qt::Key_Delete) { + if (deleteAction->isEnabled()) + deleteAction->trigger(); + return true; + } + } + + return TaskDressUpParameters::event(e); +} + void TaskThicknessParameters::changeEvent(QEvent *e) { TaskBox::changeEvent(e); diff --git a/src/Mod/PartDesign/Gui/TaskThicknessParameters.h b/src/Mod/PartDesign/Gui/TaskThicknessParameters.h index b090f37369..fb6c490e32 100644 --- a/src/Mod/PartDesign/Gui/TaskThicknessParameters.h +++ b/src/Mod/PartDesign/Gui/TaskThicknessParameters.h @@ -55,10 +55,12 @@ private Q_SLOTS: protected: virtual void clearButtons(const selectionModes notThis); + bool event(QEvent *e); void changeEvent(QEvent *e); virtual void onSelectionChanged(const Gui::SelectionChanges& msg); private: + QAction* deleteAction; Ui_TaskThicknessParameters* ui; };