mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
kdeui: deal with TODO related to KKeySequenceWidget
it is simple - as soon as a second key sequence is added to action it will be a partial match with itself (atleast) Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
40d573ff43
commit
d077f26ce5
4 changed files with 44 additions and 34 deletions
|
@ -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
|
||||
|
|
|
@ -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<QAction*> 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<QAction*> 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<KAction*> 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<KAction*>(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;
|
||||
|
|
|
@ -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:
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue