diff --git a/kdeui/dialogs/kshortcutseditor.cpp b/kdeui/dialogs/kshortcutseditor.cpp index 34a6a147..186b26fb 100644 --- a/kdeui/dialogs/kshortcutseditor.cpp +++ b/kdeui/dialogs/kshortcutseditor.cpp @@ -220,6 +220,7 @@ void KShortcutsEditor::addCollection(KActionCollection *collection, const QStrin } KKeySequenceWidget* localkswidget = new KKeySequenceWidget(d->treewidget); + localkswidget->setAssociatedAction(action); localkswidget->setModifierlessAllowed(d->allowlettershortcuts); localkswidget->setCheckForConflictsAgainst( KKeySequenceWidget::LocalShortcuts | KKeySequenceWidget::StandardShortcuts @@ -248,6 +249,7 @@ void KShortcutsEditor::addCollection(KActionCollection *collection, const QStrin } KKeySequenceWidget* globalkswidget = new KKeySequenceWidget(d->treewidget); + globalkswidget->setAssociatedAction(action); globalkswidget->setModifierlessAllowed(d->allowlettershortcuts); globalkswidget->setCheckForConflictsAgainst( KKeySequenceWidget::LocalShortcuts | KKeySequenceWidget::GlobalShortcuts diff --git a/kdeui/widgets/kkeysequencewidget.cpp b/kdeui/widgets/kkeysequencewidget.cpp index d69cfd41..6d19a491 100644 --- a/kdeui/widgets/kkeysequencewidget.cpp +++ b/kdeui/widgets/kkeysequencewidget.cpp @@ -169,9 +169,9 @@ public: KKeySequenceWidget::ShortcutTypes checkAgainstShortcutTypes; /** - * The list of action to check against for conflict shortcut + * The action to never consider when checking for conflict shortcut */ - QList checkList; // deprecated + QAction* associatedAction; /** * The list of action collections to check against for conflict shortcut @@ -197,9 +197,8 @@ KKeySequenceWidgetPrivate::KKeySequenceWidgetPrivate(KKeySequenceWidget *q) modifierKeys(0), isRecording(false), multiKeyShortcutsAllowed(true), - componentName(), - checkAgainstShortcutTypes(KKeySequenceWidget::LocalShortcuts & KKeySequenceWidget::GlobalShortcuts), - stealActions() + associatedAction(nullptr), + checkAgainstShortcutTypes(KKeySequenceWidget::LocalShortcuts & KKeySequenceWidget::GlobalShortcuts) { } @@ -346,15 +345,11 @@ bool KKeySequenceWidgetPrivate::conflictWithLocalShortcuts(const QKeySequence &k return false; } - // We have actions both in the deprecated checkList and the - // checkActionCollections list. Add all the actions to a single list to - // be able to process them in a single loop below. - // Note that this can't be done in setCheckActionCollections(), because we - // keep pointers to the action collections, and between the call to - // setCheckActionCollections() and this function some actions might already be - // removed from the collection again. + // Add all the actions to a single list to be able to process them in a single loop below. + // Note that this can't be done in setCheckActionCollections(), because pointers to the + // collections actions are kep, and between the call to setCheckActionCollections() and this function + // some actions might already be removed from the collection again. QList allActions; - allActions += checkList; foreach (KActionCollection* collection, checkActionCollections) { allActions += collection->actions(); } @@ -378,19 +373,16 @@ bool KKeySequenceWidgetPrivate::conflictWithLocalShortcuts(const QKeySequence &k // 1/2/3 key shortcuts. I think you can imagine. QList conflictingActions; - //find conflicting shortcuts with existing actions - foreach (QAction * qaction , allActions) { + // find conflicting shortcuts with existing actions + foreach (QAction* qaction , allActions) { + if (qaction == associatedAction) { + // the action shall not conflict with itself + continue; + } + KAction *kaction = qobject_cast(qaction); if (kaction) { - const QKeySequence kactionks = kaction->shortcut(); - if (kactionks.matches(keySequence) != QKeySequence::NoMatch) { - if (kactionks == oldKeySequence) { - // the action the shortcut of which is being changed - // TODO: the KKeySequenceWidget has to be associated with a QAction* to ensure - // that the action is never considered in conflicts matching - continue; - } - + if (kaction->shortcut().matches(keySequence) != QKeySequence::NoMatch) { // A conflict with a KAction. If that action is configurable ask the user what to // do. If not reject this keySequence. if (kaction->isShortcutConfigurable()) { @@ -544,10 +536,6 @@ KKeySequenceWidget::KKeySequenceWidget(QWidget *parent) connect(d->keyButton, SIGNAL(clicked()), this, SLOT(captureKeySequence())); connect(d->clearButton, SIGNAL(clicked()), this, SLOT(clearKeySequence())); connect(&d->modifierlessTimeout, SIGNAL(timeout()), this, SLOT(doneRecording())); - // TODO: how to adopt style changes at runtime? - /*QFont modFont = d->clearButton->font(); - modFont.setStyleHint(QFont::TypeWriter); - d->clearButton->setFont(modFont);*/ d->updateShortcutDisplay(); } @@ -566,6 +554,16 @@ void KKeySequenceWidget::setComponentName(const QString &componentName) d->componentName = componentName; } +void KKeySequenceWidget::setAssociatedAction(QAction *action) +{ + d->associatedAction = action; +} + +QAction* KKeySequenceWidget::associatedAction() +{ + return d->associatedAction; +} + bool KKeySequenceWidget::multiKeyShortcutsAllowed() const { return d->multiKeyShortcutsAllowed; diff --git a/kdeui/widgets/kkeysequencewidget.h b/kdeui/widgets/kkeysequencewidget.h index db75cd2a..a5923e62 100644 --- a/kdeui/widgets/kkeysequencewidget.h +++ b/kdeui/widgets/kkeysequencewidget.h @@ -217,6 +217,19 @@ public: */ void setComponentName(const QString &componentName); + /** + * Set action to never be consider when checking for conflicts + * + * @see associatedAction() + */ + void setAssociatedAction(QAction *action); + + /** + * Return the action to never be consider when checking for conflicts + * + * @see setAssociatedAction() + */ + QAction* associatedAction(); Q_SIGNALS: /** diff --git a/kdeui/widgets/kkeysequencewidget_p.h b/kdeui/widgets/kkeysequencewidget_p.h index f01f6e02..7f555666 100644 --- a/kdeui/widgets/kkeysequencewidget_p.h +++ b/kdeui/widgets/kkeysequencewidget_p.h @@ -33,12 +33,9 @@ public: } protected: - /** - * Reimplemented for internal reasons. - */ - virtual bool event(QEvent *event); - virtual void keyPressEvent(QKeyEvent *event); - virtual void keyReleaseEvent(QKeyEvent *event); + bool event(QEvent *event) final; + void keyPressEvent(QKeyEvent *event) final; + void keyReleaseEvent(QKeyEvent *event) final; private: KKeySequenceWidgetPrivate *const d;