24 #include <QtGui/QActionEvent> 25 #include <QtGui/QKeySequence> 26 #include <QtCore/QCharRef> 27 #include <QtCore/QMutableStringListIterator> 34 class KShortcutPrivate
40 QKeySequence alternate;
45 : d(new KShortcutPrivate)
47 qRegisterMetaType<KShortcut>();
51 : d(new KShortcutPrivate)
53 qRegisterMetaType<KShortcut>();
58 : d(new KShortcutPrivate)
60 qRegisterMetaType<KShortcut>();
66 : d(new KShortcutPrivate)
68 qRegisterMetaType<KShortcut>();
69 d->primary = keyQtPri;
70 d->alternate = keyQtAlt;
74 : d(new KShortcutPrivate)
76 d->primary = other.d->primary;
77 d->alternate = other.d->alternate;
81 : d(new KShortcutPrivate)
83 qRegisterMetaType<KShortcut>();
84 if (seqs.count() >= 1)
85 d->primary = seqs.at(0);
86 if (seqs.count() >= 2)
87 d->alternate = seqs.at(1);
91 : d(new KShortcutPrivate)
93 qRegisterMetaType<KShortcut>();
94 if (s == QLatin1String(
"none"))
97 QStringList sCuts = s.split(
"; ");
98 if (sCuts.count() > 2)
99 kWarning() <<
"asked to store more than two key sequences but can only hold two.";
102 for(
int i=0; i < sCuts.count(); i++)
103 if( sCuts[i].startsWith( QLatin1String(
"default(") ) )
104 sCuts[i] = sCuts[i].mid( 8, sCuts[i].length() - 9 );
106 if (sCuts.count() >= 1) {
107 QString k = sCuts.at(0);
108 k.replace(
"Win+",
"Meta+" );
109 k.replace(
"Plus",
"+");
110 k.replace(
"Minus",
"-");
111 d->primary = QKeySequence::fromString(k);
114 if (d->primary.isEmpty() && !k.isEmpty()) {
115 kDebug(240) <<
"unusable primary shortcut sequence " << sCuts[0];
119 if (sCuts.count() >= 2) {
120 QString k = sCuts.at(1);
121 k.replace(
"Win+",
"Meta+" );
122 d->alternate = QKeySequence::fromString(k);
123 if (d->alternate.isEmpty()) {
124 kDebug(240) <<
"unusable alternate shortcut sequence " << sCuts[1];
146 return d->primary.isEmpty() && d->alternate.isEmpty();
151 if (needle.isEmpty())
153 return d->primary == needle || d->alternate == needle;
158 if (needle.isEmpty())
161 bool primaryConflicts =
false;
162 bool alternateConflicts =
false;
164 if (!d->primary.isEmpty()) {
166 ( d->primary.matches(needle) == QKeySequence::NoMatch
167 && needle.matches(d->primary) == QKeySequence::NoMatch )
172 if (!d->alternate.isEmpty()) {
174 ( d->alternate.matches(needle) == QKeySequence::NoMatch
175 && needle.matches(d->alternate) == QKeySequence::NoMatch )
180 return primaryConflicts || alternateConflicts;
186 d->primary = newPrimary;
191 d->alternate = newAlternate;
196 if (keySeq.isEmpty())
199 if (d->primary == keySeq) {
201 d->primary = QKeySequence();
203 d->primary = d->alternate;
204 d->alternate = QKeySequence();
207 if (d->alternate == keySeq)
208 d->alternate = QKeySequence();
213 d->primary = other.d->primary;
214 d->alternate = other.d->alternate;
220 return (d->primary == other.d->primary && d->alternate == other.d->alternate);
230 return toList(RemoveEmpty);
237 if (!d->primary.isEmpty())
238 ret.append(d->primary);
239 if (!d->alternate.isEmpty())
240 ret.append(d->alternate);
242 ret.append(d->primary);
243 ret.append(d->alternate);
251 return toString(QKeySequence::PortableText);
257 foreach(
const QKeySequence &seq,
toList()) {
258 ret.append(seq.toString(format));
265 KShortcut::operator QVariant()
const 267 return qVariantFromValue(*
this);
bool contains(const QKeySequence &needle) const
Returns whether at least one of the key sequences is equal to needle.
bool conflictsWith(const QKeySequence &needle) const
Returns whether at least one of the key sequences conflicts witho needle.
KShortcut()
Creates a new empty shortcut.
remove empty QKeySequences, possibly changing the positions of QKeySequences due to the ensuing reshu...
QList< QKeySequence > toList(enum EmptyHandling handleEmpty=RemoveEmpty) const
The same as operator QList<QKeySequence>() If handleEmpty equals RemoveEmpty, empty key sequences wil...
Defines platform-independent classes for keyboard shortcut handling.
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
bool operator==(const KShortcut &other) const
Represents a keyboard shortcut.
KShortcut & operator=(const KShortcut &other)
Assignment operator.
if a shortcut is or becomes empty, let it stay as a placeholder
void remove(const QKeySequence &keySeq, enum EmptyHandling handleEmpty=RemoveEmpty)
Remove keySeq from this shortcut.
EmptyHandling
An enum about the behavior of operations that treat a KShortcut like a list of QKeySequences.
void setAlternate(const QKeySequence &keySeq)
Set the alternate key sequence of this shortcut to the given key sequence.
QKeySequence primary() const
Returns the primary key sequence of this shortcut.
QString toString() const
Returns a description of the shortcut as a semicolon-separated list of key sequences,...
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
void setPrimary(const QKeySequence &keySeq)
Set the primary key sequence of this shortcut to the given key sequence.
QKeySequence alternate() const
Returns the alternate key sequence of this shortcut.
bool isEmpty() const
Returns whether this shortcut contains any nonempty key sequences.
bool operator!=(const KShortcut &other) const