KXmlGui

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

KDE's Doxygen guidelines are available online.