PartDesign: [skip ci] workaround for ambiguous Delete key event
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
|
||||
#ifndef _PreComp_
|
||||
# include <QAction>
|
||||
# include <QKeyEvent>
|
||||
#endif
|
||||
|
||||
#include "ui_TaskFilletParameters.h"
|
||||
@@ -84,21 +85,21 @@ TaskFilletParameters::TaskFilletParameters(ViewProviderDressUp *DressUpView, QWi
|
||||
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(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
|
||||
@@ -114,13 +115,12 @@ void TaskFilletParameters::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"));
|
||||
}
|
||||
@@ -131,8 +131,8 @@ void TaskFilletParameters::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
|
||||
@@ -173,9 +173,8 @@ void TaskFilletParameters::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"));
|
||||
}
|
||||
@@ -203,6 +202,29 @@ TaskFilletParameters::~TaskFilletParameters()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
bool TaskFilletParameters::event(QEvent *e)
|
||||
{
|
||||
if (e && e->type() == QEvent::ShortcutOverride) {
|
||||
QKeyEvent * kevent = static_cast<QKeyEvent*>(e);
|
||||
if (kevent->modifiers() == Qt::NoModifier) {
|
||||
if (kevent->key() == Qt::Key_Delete) {
|
||||
kevent->accept();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (e && e->type() == QEvent::KeyPress) {
|
||||
QKeyEvent * kevent = static_cast<QKeyEvent*>(e);
|
||||
if (kevent->key() == Qt::Key_Delete) {
|
||||
if (deleteAction->isEnabled())
|
||||
deleteAction->trigger();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return TaskDressUpParameters::event(e);
|
||||
}
|
||||
|
||||
void TaskFilletParameters::changeEvent(QEvent *e)
|
||||
{
|
||||
TaskBox::changeEvent(e);
|
||||
|
||||
@@ -48,10 +48,12 @@ private Q_SLOTS:
|
||||
protected:
|
||||
double getLength(void) const;
|
||||
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_TaskFilletParameters* ui;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user