diff --git a/kdeui/dialogs/kshortcutseditor.cpp b/kdeui/dialogs/kshortcutseditor.cpp index 77291ab8..8b58f840 100644 --- a/kdeui/dialogs/kshortcutseditor.cpp +++ b/kdeui/dialogs/kshortcutseditor.cpp @@ -56,6 +56,7 @@ public: const KShortcutsEditor::LetterShortcuts letterShortcuts); void _k_slotKeySequenceChanged(); + void _k_slotStealShortcut(); KShortcutsEditor* parent; KShortcutsEditor::ActionTypes actiontypes; @@ -117,6 +118,35 @@ void KShortcutsEditorPrivate::_k_slotKeySequenceChanged() emit parent->keyChange(); } +void KShortcutsEditorPrivate::_k_slotStealShortcut() +{ + KKeySequenceWidget* senderkswidget = qobject_cast(parent->sender()); + Q_ASSERT(senderkswidget != nullptr); + // it is already asked for, not going to bail and revert at any point + senderkswidget->applyStealShortcut(); + foreach (KKeySequenceWidget *kswidget, keysequencewidgets) { + if (kswidget == senderkswidget) { + // that is the thief + continue; + } + QAction* action = qvariant_cast(kswidget->property("_k_action")); + Q_ASSERT(action != nullptr); + const bool global = kswidget->property("_k_global").toBool(); + KAction* kaction = qobject_cast(action); + // block signals, the key sequence of the thief changed + kswidget->blockSignals(true); + if (global) { + Q_ASSERT(kaction != nullptr); + kswidget->setKeySequence(kaction->globalShortcut(KAction::ActiveShortcut)); + } else if (kaction) { + kswidget->setKeySequence(kaction->shortcut(KAction::ActiveShortcut)); + } else { + kswidget->setKeySequence(action->shortcut()); + } + kswidget->blockSignals(false); + } +} + KShortcutsEditor::KShortcutsEditor(KActionCollection *collection, QWidget *parent, ActionTypes actionTypes, LetterShortcuts allowLetterShortcuts) @@ -235,6 +265,10 @@ void KShortcutsEditor::addCollection(KActionCollection *collection, const QStrin localkswidget, SIGNAL(keySequenceChanged(QKeySequence)), this, SLOT(_k_slotKeySequenceChanged()) ); + connect( + localkswidget, SIGNAL(stealShortcut(QKeySequence,KAction*)), + this, SLOT(_k_slotStealShortcut()) + ); d->treewidget->setItemWidget(actionitem, 1, localkswidget); d->keysequencewidgets.append(localkswidget); } @@ -263,6 +297,10 @@ void KShortcutsEditor::addCollection(KActionCollection *collection, const QStrin globalkswidget, SIGNAL(keySequenceChanged(QKeySequence)), this, SLOT(_k_slotKeySequenceChanged()) ); + connect( + globalkswidget, SIGNAL(stealShortcut(QKeySequence,KAction*)), + this, SLOT(_k_slotStealShortcut()) + ); d->treewidget->setItemWidget(actionitem, 2, globalkswidget); d->keysequencewidgets.append(globalkswidget); } diff --git a/kdeui/dialogs/kshortcutseditor.h b/kdeui/dialogs/kshortcutseditor.h index 12930628..c3afcd61 100644 --- a/kdeui/dialogs/kshortcutseditor.h +++ b/kdeui/dialogs/kshortcutseditor.h @@ -21,14 +21,13 @@ #define KSHORTCUTSEDITOR_H #include +#include +#include #include -class KActionCollection; -class KConfigGroup; class KShortcutsEditorPrivate; - /** * @short Widget for configuration of KAccel and KGlobalAccel. * @@ -142,6 +141,7 @@ public Q_SLOTS: private: Q_PRIVATE_SLOT(d, void _k_slotKeySequenceChanged()) + Q_PRIVATE_SLOT(d, void _k_slotStealShortcut()) friend class KShortcutsDialog; friend class KShortcutsEditorPrivate;