mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
kdeui: handle shortcut stealing in KShortcutsEditor
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
383b6c53d0
commit
b64a94ac19
2 changed files with 41 additions and 3 deletions
|
@ -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<KKeySequenceWidget*>(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<QAction*>(kswidget->property("_k_action"));
|
||||
Q_ASSERT(action != nullptr);
|
||||
const bool global = kswidget->property("_k_global").toBool();
|
||||
KAction* kaction = qobject_cast<KAction*>(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);
|
||||
}
|
||||
|
|
|
@ -21,14 +21,13 @@
|
|||
#define KSHORTCUTSEDITOR_H
|
||||
|
||||
#include <kdeui_export.h>
|
||||
#include <kconfiggroup.h>
|
||||
#include <kactioncollection.h>
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
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;
|
||||
|
|
Loading…
Add table
Reference in a new issue