KXmlGui

kshortcutwidget.cpp
1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2007 Andreas Hartmetz <ahartmetz@gmail.com>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "kshortcutwidget.h"
9#include "ui_kshortcutwidget.h"
10
11class KShortcutWidgetPrivate
12{
13public:
14 KShortcutWidgetPrivate(KShortcutWidget *qq)
15 : q(qq)
16 {
17 }
18
19 // private slots
20 void priKeySequenceChanged(const QKeySequence &);
21 void altKeySequenceChanged(const QKeySequence &);
22
23 // members
24 KShortcutWidget *const q;
25 Ui::KShortcutWidget ui;
27 bool holdChangedSignal;
28};
29
30KShortcutWidget::KShortcutWidget(QWidget *parent)
31 : QWidget(parent)
32 , d(new KShortcutWidgetPrivate(this))
33{
34 d->holdChangedSignal = false;
35 d->ui.setupUi(this);
36 connect(d->ui.priEditor, &KKeySequenceWidget::keySequenceChanged, this, [this](const QKeySequence &keyseq) {
37 d->priKeySequenceChanged(keyseq);
38 });
39 connect(d->ui.altEditor, &KKeySequenceWidget::keySequenceChanged, this, [this](const QKeySequence &keyseq) {
40 d->altKeySequenceChanged(keyseq);
41 });
42}
43
44KShortcutWidget::~KShortcutWidget() = default;
45
46void KShortcutWidget::setModifierlessAllowed(bool allow)
47{
48 d->ui.priEditor->setModifierlessAllowed(allow);
49 d->ui.altEditor->setModifierlessAllowed(allow);
50}
51
52bool KShortcutWidget::isModifierlessAllowed()
53{
54 return d->ui.priEditor->isModifierlessAllowed();
55}
56
57void KShortcutWidget::setClearButtonsShown(bool show)
58{
59 d->ui.priEditor->setClearButtonShown(show);
60 d->ui.altEditor->setClearButtonShown(show);
61}
62
63QList<QKeySequence> KShortcutWidget::shortcut() const
64{
66 ret << d->ui.priEditor->keySequence() << d->ui.altEditor->keySequence();
67 return ret;
68}
69
71{
72 d->ui.priEditor->setCheckActionCollections(actionCollections);
73 d->ui.altEditor->setCheckActionCollections(actionCollections);
74}
75
76// slot
78{
79 d->ui.priEditor->applyStealShortcut();
80 d->ui.altEditor->applyStealShortcut();
81}
82
83// slot
84void KShortcutWidget::setShortcut(const QList<QKeySequence> &newSc)
85{
86 if (newSc == d->cut) {
87 return;
88 }
89
90 d->holdChangedSignal = true;
91
92 if (!newSc.isEmpty()) {
93 d->ui.priEditor->setKeySequence(newSc.first());
94 }
95
96 if (newSc.size() > 1) {
97 d->ui.altEditor->setKeySequence(newSc.at(1));
98 }
99
100 d->holdChangedSignal = false;
101
102 Q_EMIT shortcutChanged(d->cut);
103}
104
105// slot
106void KShortcutWidget::clearShortcut()
107{
108 setShortcut(QList<QKeySequence>());
109}
110
111// private slot
112void KShortcutWidgetPrivate::priKeySequenceChanged(const QKeySequence &seq)
113{
114 if (cut.isEmpty()) {
115 cut << seq;
116 } else {
117 cut[0] = seq;
118 }
119
120 if (!holdChangedSignal) {
121 Q_EMIT q->shortcutChanged(cut);
122 }
123}
124
125// private slot
126void KShortcutWidgetPrivate::altKeySequenceChanged(const QKeySequence &seq)
127{
128 if (cut.size() <= 1) {
129 cut << seq;
130 } else {
131 cut[1] = seq;
132 }
133
134 if (!holdChangedSignal) {
135 Q_EMIT q->shortcutChanged(cut);
136 }
137}
138
139#include "moc_kshortcutwidget.cpp"
void keySequenceChanged(const QKeySequence &seq)
This signal is emitted when the current key sequence has changed, be it by user input or programmatic...
void setCheckActionCollections(const QList< KActionCollection * > &actionCollections)
Set a list of action collections to check against for conflictuous shortcut.
void applyStealShortcut()
Actually remove the shortcut that the user wanted to steal, from the action that was using it.
const_reference at(qsizetype i) const const
T & first()
bool isEmpty() const const
qsizetype size() const const
Q_EMITQ_EMIT
QList< T > findChildren(Qt::FindChildOptions options) const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void setupUi(QWidget *widget)
void show()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:21:12 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.