KConfig

kstandardshortcut.cpp
1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 1997 Stefan Taferner <taferner@alpin.or.at>
4 SPDX-FileCopyrightText: 2000 Nicolas Hadacek <haadcek@kde.org>
5 SPDX-FileCopyrightText: 2001, 2002 Ellis Whitehead <ellis@kde.org>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8*/
9
10#include "kstandardshortcut.h"
11#include "kstandardshortcutwatcher.h"
12
13#include "kconfig.h"
14#include "kconfigwatcher.h"
15#include "ksharedconfig.h"
16#include <kconfiggroup.h>
17
18#include <QCoreApplication>
19#include <QDebug>
20#include <QKeySequence>
21
23{
24struct KStandardShortcutInfo {
25 //! The standard shortcut id. @see StandardShortcut
27
28 /**
29 * Unique name for the given accel. The name is used to save the user
30 * settings. It's not representable. Use description for that.
31 * @warning NEVER EVER CHANGE IT OR TRANSLATE IT!
32 */
33 const char *name;
34
35 //! Localized label for user-visible display, including translation context.
36 struct {
37 const char *text;
38 const char *context;
39 } description;
40
41 //! The keys for this shortcut
42 int cutDefault, cutDefault2;
43
44 //! A shortcut that is created with @a cutDefault and @cutDefault2
46
47 //! If this struct is initialized. If not initialized @cut is not valid
48 bool isInitialized;
49
50 // Category of this Shortcut
51 Category category;
52};
53
54#define CTRL(x) QKeyCombination(Qt::CTRL | Qt::Key_##x).toCombined()
55#define SHIFT(x) QKeyCombination(Qt::SHIFT | Qt::Key_##x).toCombined()
56#define CTRLALT(x) QKeyCombination(Qt::CTRL | Qt::ALT | Qt::Key_##x).toCombined()
57#define CTRLSHIFT(x) QKeyCombination(Qt::CTRL | Qt::SHIFT | Qt::Key_##x).toCombined()
58#define ALT(x) QKeyCombination(Qt::ALT | Qt::Key_##x).toCombined()
59#define ALTSHIFT(x) QKeyCombination(Qt::ALT | Qt::SHIFT | Qt::Key_##x).toCombined()
60#define CTRLMETA(x) QKeyCombination(Qt::CTRL | Qt::META | Qt::Key_##x).toCombined()
61
62/** Array of predefined KStandardShortcutInfo objects, which cover all
63 the "standard" accelerators. Each enum value from StandardShortcut
64 should appear in this table.
65*/
66// STUFF WILL BREAK IF YOU DON'T READ THIS!!!
67// Read the comments of the big enum in kstandardshortcut.h before you change anything!
68static KStandardShortcutInfo g_infoStandardShortcut[] = {
69 // Group File,
70 {AccelNone, nullptr, {nullptr, nullptr}, 0, 0, QList<QKeySequence>(), false, Category::InvalidCategory},
71 {Open, "Open", QT_TRANSLATE_NOOP3("KStandardShortcut", "Open", "@action"), CTRL(O), 0, QList<QKeySequence>(), false, Category::File},
72 {New, "New", QT_TRANSLATE_NOOP3("KStandardShortcut", "New", "@action"), CTRL(N), 0, QList<QKeySequence>(), false, Category::File},
73 {Close, "Close", QT_TRANSLATE_NOOP3("KStandardShortcut", "Close", "@action"), CTRL(W), CTRL(Escape), QList<QKeySequence>(), false, Category::File},
74 {Save, "Save", QT_TRANSLATE_NOOP3("KStandardShortcut", "Save", "@action"), CTRL(S), 0, QList<QKeySequence>(), false, Category::File},
75 {Print, "Print", QT_TRANSLATE_NOOP3("KStandardShortcut", "Print", "@action"), CTRL(P), 0, QList<QKeySequence>(), false, Category::File},
76 {Quit, "Quit", QT_TRANSLATE_NOOP3("KStandardShortcut", "Quit", "@action"), CTRL(Q), 0, QList<QKeySequence>(), false, Category::Navigation},
77
78 // Group Edit
79 {Undo, "Undo", QT_TRANSLATE_NOOP3("KStandardShortcut", "Undo", "@action"), CTRL(Z), 0, QList<QKeySequence>(), false, Category::Edit},
80 {Redo, "Redo", QT_TRANSLATE_NOOP3("KStandardShortcut", "Redo", "@action"), CTRLSHIFT(Z), 0, QList<QKeySequence>(), false, Category::Edit},
81 // Both "Cut" and "Delete" use Shift+Delete, but this is okay; see
82 // https://commits.kde.org/kxmlgui/8eabbf6725386e716b7536c71a9181dfe5d959f0
83 {Cut, "Cut", QT_TRANSLATE_NOOP3("KStandardShortcut", "Cut", "@action"), CTRL(X), SHIFT(Delete), QList<QKeySequence>(), false, Category::Edit},
84 {Copy, "Copy", QT_TRANSLATE_NOOP3("KStandardShortcut", "Copy", "@action"), CTRL(C), CTRL(Insert), QList<QKeySequence>(), false, Category::Edit},
85 {Paste, "Paste", QT_TRANSLATE_NOOP3("KStandardShortcut", "Paste", "@action"), CTRL(V), SHIFT(Insert), QList<QKeySequence>(), false, Category::Edit},
87 "Paste Selection",
88 QT_TRANSLATE_NOOP3("KStandardShortcut", "Paste Selection", "@action"),
89 CTRLSHIFT(Insert),
90 0,
92 false,
93 Category::Edit},
94
95 {SelectAll, "SelectAll", QT_TRANSLATE_NOOP3("KStandardShortcut", "Select All", "@action"), CTRL(A), 0, QList<QKeySequence>(), false, Category::Edit},
96 {Deselect, "Deselect", QT_TRANSLATE_NOOP3("KStandardShortcut", "Deselect", "@action"), CTRLSHIFT(A), 0, QList<QKeySequence>(), false, Category::Edit},
98 "DeleteWordBack",
99 QT_TRANSLATE_NOOP3("KStandardShortcut", "Delete Word Backwards", "@action"),
100#if defined(Q_OS_MACOS)
101 ALT(Backspace),
102#else
103 CTRL(Backspace),
104#endif
105 0,
107 false,
108 Category::Edit},
110 "DeleteWordForward",
111 QT_TRANSLATE_NOOP3("KStandardShortcut", "Delete Word Forward", "@action"),
112#if defined(Q_OS_MACOS)
113 ALT(Delete),
114#else
115 CTRL(Delete),
116#endif
117 0,
119 false,
120 Category::Edit},
121
122 {Find, "Find", QT_TRANSLATE_NOOP3("KStandardShortcut", "Find", "@action"), CTRL(F), 0, QList<QKeySequence>(), false, Category::Edit},
123 {FindNext, "FindNext", QT_TRANSLATE_NOOP3("KStandardShortcut", "Find Next", "@action"), Qt::Key_F3, 0, QList<QKeySequence>(), false, Category::Edit},
124 {FindPrev, "FindPrev", QT_TRANSLATE_NOOP3("KStandardShortcut", "Find Prev", "@action"), SHIFT(F3), 0, QList<QKeySequence>(), false, Category::Edit},
125 {Replace, "Replace", QT_TRANSLATE_NOOP3("KStandardShortcut", "Replace", "@action"), CTRL(R), 0, QList<QKeySequence>(), false, Category::Edit},
126
127 // Group Navigation
128 {Home,
129 "Home",
130 QT_TRANSLATE_NOOP3("KStandardShortcut", "Home", "@action Go to main page"),
131 ALT(Home),
134 false,
135 Category::Navigation},
136 {Begin,
137 "Begin",
138 QT_TRANSLATE_NOOP3("KStandardShortcut", "Begin", "@action Beginning of document"),
139#if defined(Q_OS_MACOS)
140 CTRL(Up),
141#else
142 CTRL(Home),
143#endif
144 0,
146 false,
147 Category::Navigation},
148 {End,
149 "End",
150 QT_TRANSLATE_NOOP3("KStandardShortcut", "End", "@action End of document"),
151#if defined(Q_OS_MACOS)
152 CTRL(Down),
153#else
154 CTRL(End),
155#endif
156 0,
158 false,
159 Category::Navigation},
160 {Prior, "Prior", QT_TRANSLATE_NOOP3("KStandardShortcut", "Prior", "@action"), Qt::Key_PageUp, 0, QList<QKeySequence>(), false, Category::Navigation},
161 {Next,
162 "Next",
163 QT_TRANSLATE_NOOP3("KStandardShortcut", "Next", "@action Opposite to Prior"),
165 0,
167 false,
168 Category::Navigation},
169
170 {Up, "Up", QT_TRANSLATE_NOOP3("KStandardShortcut", "Up", "@action"), ALT(Up), 0, QList<QKeySequence>(), false, Category::Navigation},
171 {Back, "Back", QT_TRANSLATE_NOOP3("KStandardShortcut", "Back", "@action"), ALT(Left), Qt::Key_Back, QList<QKeySequence>(), false, Category::Navigation},
172 {Forward,
173 "Forward",
174 QT_TRANSLATE_NOOP3("KStandardShortcut", "Forward", "@action"),
175 ALT(Right),
178 false,
179 Category::Navigation},
180 {Reload,
181 "Reload",
182 QT_TRANSLATE_NOOP3("KStandardShortcut", "Reload", "@action"),
186 false,
187 Category::Navigation},
188
190 "BeginningOfLine",
191 QT_TRANSLATE_NOOP3("KStandardShortcut", "Beginning of Line", "@action"),
192#if defined(Q_OS_MACOS)
193 CTRL(Left),
194#else
196#endif
197 0,
199 false,
200 Category::Navigation},
201 {EndOfLine,
202 "EndOfLine",
203 QT_TRANSLATE_NOOP3("KStandardShortcut", "End of Line", "@action"),
204#if defined(Q_OS_MACOS)
205 CTRL(Right),
206#else
208#endif
209 0,
211 false,
212 Category::Navigation},
213 {GotoLine, "GotoLine", QT_TRANSLATE_NOOP3("KStandardShortcut", "Go to Line", "@action"), CTRL(G), 0, QList<QKeySequence>(), false, Category::Navigation},
215 "BackwardWord",
216 QT_TRANSLATE_NOOP3("KStandardShortcut", "Backward Word", "@action"),
217#if defined(Q_OS_MACOS)
218 ALT(Left),
219#else
220 CTRL(Left),
221#endif
222 0,
224 false,
225 Category::Navigation},
227 "ForwardWord",
228 QT_TRANSLATE_NOOP3("KStandardShortcut", "Forward Word", "@action"),
229#if defined(Q_OS_MACOS)
230 ALT(Right),
231#else
232 CTRL(Right),
233#endif
234 0,
236 false,
237 Category::Navigation},
238
240 "AddBookmark",
241 QT_TRANSLATE_NOOP3("KStandardShortcut", "Add Bookmark", "@action"),
242 CTRL(B),
243 0,
245 false,
246 Category::Navigation},
247 {ZoomIn, "ZoomIn", QT_TRANSLATE_NOOP3("KStandardShortcut", "Zoom In", "@action"), CTRL(Plus), CTRL(Equal), QList<QKeySequence>(), false, Category::View},
248 {ZoomOut, "ZoomOut", QT_TRANSLATE_NOOP3("KStandardShortcut", "Zoom Out", "@action"), CTRL(Minus), 0, QList<QKeySequence>(), false, Category::View},
249 {FullScreen,
250 "FullScreen",
251 QT_TRANSLATE_NOOP3("KStandardShortcut", "Full Screen Mode", "@action"),
252#if defined(Q_OS_MACOS)
253 CTRLMETA(F),
254#else
255 CTRLSHIFT(F),
256#endif
257 0,
259 false,
260 Category::View},
261
262 {ShowMenubar, "ShowMenubar", QT_TRANSLATE_NOOP3("KStandardShortcut", "Show Menu Bar", "@action"), CTRL(M), 0, QList<QKeySequence>(), false, Category::View},
263 {TabNext,
264 "Activate Next Tab",
265 QT_TRANSLATE_NOOP3("KStandardShortcut", "Activate Next Tab", "@action"),
266 CTRL(PageDown),
267 CTRL(BracketRight),
269 false,
270 Category::Navigation},
271 {TabPrev,
272 "Activate Previous Tab",
273 QT_TRANSLATE_NOOP3("KStandardShortcut", "Activate Previous Tab", "@action"),
274 CTRL(PageUp),
275 CTRL(BracketLeft),
277 false,
278 Category::Navigation},
279
280 // Group Help
281 {Help, "Help", QT_TRANSLATE_NOOP3("KStandardShortcut", "Help", "@action"), Qt::Key_F1, 0, QList<QKeySequence>(), false, Category::Help},
282 {WhatsThis, "WhatsThis", QT_TRANSLATE_NOOP3("KStandardShortcut", "What's This", "@action"), SHIFT(F1), 0, QList<QKeySequence>(), false, Category::Help},
283
284 // Group TextCompletion
286 "TextCompletion",
287 QT_TRANSLATE_NOOP3("KStandardShortcut", "Text Completion", "@action"),
288 CTRL(E),
289 0,
291 false,
292 Category::Edit},
294 "PrevCompletion",
295 QT_TRANSLATE_NOOP3("KStandardShortcut", "Previous Completion Match", "@action"),
296 CTRL(Up),
297 0,
299 false,
300 Category::Edit},
302 "NextCompletion",
303 QT_TRANSLATE_NOOP3("KStandardShortcut", "Next Completion Match", "@action"),
304 CTRL(Down),
305 0,
307 false,
308 Category::Edit},
310 "SubstringCompletion",
311 QT_TRANSLATE_NOOP3("KStandardShortcut", "Substring Completion", "@action"),
312 CTRL(T),
313 0,
315 false,
316 Category::Edit},
317
318 {RotateUp,
319 "RotateUp",
320 QT_TRANSLATE_NOOP3("KStandardShortcut", "Previous Item in List", "@action"),
322 0,
324 false,
325 Category::Navigation},
326 {RotateDown,
327 "RotateDown",
328 QT_TRANSLATE_NOOP3("KStandardShortcut", "Next Item in List", "@action"),
330 0,
332 false,
333 Category::Navigation},
334
335 {OpenRecent, "OpenRecent", QT_TRANSLATE_NOOP3("KStandardShortcut", "Open Recent", "@action"), 0, 0, QList<QKeySequence>(), false, Category::File},
336 {SaveAs, "SaveAs", QT_TRANSLATE_NOOP3("KStandardShortcut", "Save As", "@action"), CTRLSHIFT(S), 0, QList<QKeySequence>(), false, Category::File},
337 {Revert, "Revert", QT_TRANSLATE_NOOP3("KStandardShortcut", "Revert", "@action"), 0, 0, QList<QKeySequence>(), false, Category::Edit},
338 {PrintPreview, "PrintPreview", QT_TRANSLATE_NOOP3("KStandardShortcut", "Print Preview", "@action"), 0, 0, QList<QKeySequence>(), false, Category::File},
339 {Mail, "Mail", QT_TRANSLATE_NOOP3("KStandardShortcut", "Mail", "@action"), 0, 0, QList<QKeySequence>(), false, Category::Help},
340 {Clear, "Clear", QT_TRANSLATE_NOOP3("KStandardShortcut", "Clear", "@action"), 0, 0, QList<QKeySequence>(), false, Category::Edit},
341 {ActualSize,
342 "ActualSize",
343 QT_TRANSLATE_NOOP3("KStandardShortcut", "Zoom to Actual Size", "@action"),
344 CTRL(0),
345 0,
347 false,
348 Category::View},
349 {FitToPage, "FitToPage", QT_TRANSLATE_NOOP3("KStandardShortcut", "Fit To Page", "@action"), 0, 0, QList<QKeySequence>(), false, Category::View},
350 {FitToWidth, "FitToWidth", QT_TRANSLATE_NOOP3("KStandardShortcut", "Fit To Width", "@action"), 0, 0, QList<QKeySequence>(), false, Category::View},
351 {FitToHeight, "FitToHeight", QT_TRANSLATE_NOOP3("KStandardShortcut", "Fit To Height", "@action"), 0, 0, QList<QKeySequence>(), false, Category::View},
352 {Zoom, "Zoom", QT_TRANSLATE_NOOP3("KStandardShortcut", "Zoom", "@action"), 0, 0, QList<QKeySequence>(), false, Category::View},
353 {Goto, "Goto", QT_TRANSLATE_NOOP3("KStandardShortcut", "Goto", "@action"), 0, 0, QList<QKeySequence>(), false, Category::Navigation},
354 {GotoPage, "GotoPage", QT_TRANSLATE_NOOP3("KStandardShortcut", "Goto Page", "@action"), 0, 0, QList<QKeySequence>(), false, Category::Navigation},
356 "DocumentBack",
357 QT_TRANSLATE_NOOP3("KStandardShortcut", "Document Back", "@action"),
358 ALTSHIFT(Left),
359 0,
361 false,
362 Category::Navigation},
364 "DocumentForward",
365 QT_TRANSLATE_NOOP3("KStandardShortcut", "Document Forward", "@action"),
366 ALTSHIFT(Right),
367 0,
369 false,
370 Category::Navigation},
372 "EditBookmarks",
373 QT_TRANSLATE_NOOP3("KStandardShortcut", "Edit Bookmarks", "@action"),
374 0,
375 0,
377 false,
378 Category::Navigation},
379 {Spelling, "Spelling", QT_TRANSLATE_NOOP3("KStandardShortcut", "Spelling", "@action"), 0, 0, QList<QKeySequence>(), false, Category::Edit},
380 {ShowToolbar, "ShowToolbar", QT_TRANSLATE_NOOP3("KStandardShortcut", "Show Toolbar", "@action"), 0, 0, QList<QKeySequence>(), false, Category::View},
381 {ShowStatusbar, "ShowStatusbar", QT_TRANSLATE_NOOP3("KStandardShortcut", "Show Statusbar", "@action"), 0, 0, QList<QKeySequence>(), false, Category::View},
383 "KeyBindings",
384 QT_TRANSLATE_NOOP3("KStandardShortcut", "Key Bindings", "@action"),
385 CTRLALT(Comma),
386 0,
388 false,
389 Category::Settings},
391 "Preferences",
392 QT_TRANSLATE_NOOP3("KStandardShortcut", "Configure Application", "@action"),
393 CTRLSHIFT(Comma),
394 0,
396 false,
397 Category::Settings},
399 "ConfigureToolbars",
400 QT_TRANSLATE_NOOP3("KStandardShortcut", "Configure Toolbars", "@action"),
401 0,
402 0,
404 false,
405 Category::Settings},
407 "ConfigureNotifications",
408 QT_TRANSLATE_NOOP3("KStandardShortcut", "Configure Notifications", "@action"),
409 0,
410 0,
412 false,
413 Category::Settings},
414 {ReportBug, "ReportBug", QT_TRANSLATE_NOOP3("KStandardShortcut", "Report Bug", "@action"), 0, 0, QList<QKeySequence>(), false, Category::Help},
416 "SwitchApplicationLanguage",
417 QT_TRANSLATE_NOOP3("KStandardShortcut", "Configure Language…", "@action"),
418 0,
419 0,
421 false,
422 Category::Settings},
423 {AboutApp, "AboutApp", QT_TRANSLATE_NOOP3("KStandardShortcut", "About Application", "@action"), 0, 0, QList<QKeySequence>(), false, Category::Help},
424 {AboutKDE, "AboutKDE", QT_TRANSLATE_NOOP3("KStandardShortcut", "About KDE", "@action"), 0, 0, QList<QKeySequence>(), false, Category::Help},
425 // Both "Cut" and "Delete" use Shift+Delete, but this is okay; see
426 // https://commits.kde.org/kxmlgui/8eabbf6725386e716b7536c71a9181dfe5d959f0
427 {DeleteFile, "DeleteFile", QT_TRANSLATE_NOOP3("KStandardShortcut", "Delete", "@action"), SHIFT(Delete), 0, QList<QKeySequence>(), false, Category::File},
428 {RenameFile, "RenameFile", QT_TRANSLATE_NOOP3("KStandardShortcut", "Rename", "@action"), Qt::Key_F2, 0, QList<QKeySequence>(), false, Category::File},
430 "MoveToTrash",
431 QT_TRANSLATE_NOOP3("KStandardShortcut", "Move to Trash", "@action"),
433 0,
435 false,
436 Category::File},
437 {Donate, "Donate", QT_TRANSLATE_NOOP3("KStandardShortcut", "Donate", "@action"), 0, 0, QList<QKeySequence>(), false, Category::Help},
439 "ShowHideHiddenFiles",
440 QT_TRANSLATE_NOOP3("KStandardShortcut", "Show/Hide Hidden Files", "@action"),
441 CTRL(H),
442 ALT(Period),
444 false,
445 Category::View},
447 "CreateFolder",
448 QT_TRANSLATE_NOOP3("KStandardShortcut", "Create Folder", "@action"),
449 CTRLSHIFT(N),
450 0,
452 false,
453 Category::File},
455 "OpenMainMenu",
456 QT_TRANSLATE_NOOP3("KStandardShortcut", "Open Main Menu", "@action referring to the menu bar or a hamburger menu"),
458 0,
460 false,
461 Category::View},
463 "OpenContextMenu",
464 QT_TRANSLATE_NOOP3("KStandardShortcut", "Open Context Menu", "@action"),
466 SHIFT(F10),
468 false,
469 Category::View},
470
471 // dummy entry to catch simple off-by-one errors. Insert new entries before this line.
472 {AccelNone, nullptr, {nullptr, nullptr}, 0, 0, QList<QKeySequence>(), false, Category::InvalidCategory}};
473
474/** Search for the KStandardShortcutInfo object associated with the given @p id.
475 Return a dummy entry with no name and an empty shortcut if @p id is invalid.
476*/
477static KStandardShortcutInfo *guardedStandardShortcutInfo(StandardShortcut id)
478{
479 if (id >= static_cast<int>(sizeof(g_infoStandardShortcut) / sizeof(KStandardShortcutInfo)) || id < 0) {
480 qWarning() << "KStandardShortcut: id not found!";
481 return &g_infoStandardShortcut[AccelNone];
482 } else {
483 return &g_infoStandardShortcut[id];
484 }
485}
486
487// Sanitize the list for duplicates. For some reason some
488// people have kdeglobals entries like
489// Close=Ctrl+W; Ctrl+Esc; Ctrl+W; Ctrl+Esc;
490// having the same shortcut more than once in the shortcut
491// declaration is clearly bogus so fix it
492static void sanitizeShortcutList(QList<QKeySequence> *list)
493{
494 for (int i = 0; i < list->size(); ++i) {
495 const QKeySequence &ks = list->at(i);
496 int other = list->indexOf(ks, i + 1);
497 while (other != -1) {
498 list->removeAt(other);
499 other = list->indexOf(ks, other);
500 }
501 }
502}
503
504/** Initialize the accelerator @p id by checking if it is overridden
505 in the configuration file (and if it isn't, use the default).
506 On X11, if QApplication was initialized with GUI disabled,
507 the default will always be used.
508*/
510{
511 KStandardShortcutInfo *info = guardedStandardShortcutInfo(id);
512
513 // All three are needed.
514 if (info->id != AccelNone) {
515 Q_ASSERT(info->description.text);
516 Q_ASSERT(info->description.context);
517 Q_ASSERT(info->name);
518 }
519
520 KConfigGroup cg(KSharedConfig::openConfig(), QStringLiteral("Shortcuts"));
521
522 if (cg.hasKey(info->name)) {
523 QString s = cg.readEntry(info->name);
524 if (s != QLatin1String("none")) {
525 info->cut = QKeySequence::listFromString(s);
526 sanitizeShortcutList(&info->cut);
527 } else {
528 info->cut = QList<QKeySequence>();
529 }
530 } else {
531 info->cut = hardcodedDefaultShortcut(id);
532 }
533
534 info->isInitialized = true;
535}
536
538{
539 KStandardShortcutInfo *info = guardedStandardShortcutInfo(id);
540 // If the action has no standard shortcut associated there is nothing to
541 // save
542 if (info->id == AccelNone) {
543 return;
544 }
545
546 KConfigGroup cg(KSharedConfig::openConfig(), QStringLiteral("Shortcuts"));
547
548 info->cut = newShortcut;
549 bool sameAsDefault = (newShortcut == hardcodedDefaultShortcut(id));
550
551 if (sameAsDefault) {
552 // If the shortcut is the equal to the hardcoded one we remove it from
553 // kdeglobal if necessary and return.
554 if (cg.hasKey(info->name)) {
556 cg.sync();
557 }
558
559 return;
560 }
561
562 // Write the changed shortcut to kdeglobals
563 sanitizeShortcutList(&info->cut);
565 cg.sync();
566}
567
572
574{
575 KStandardShortcutInfo *info = guardedStandardShortcutInfo(id);
576 return QCoreApplication::translate("KStandardShortcut", info->description.text, info->description.context);
577}
578
579// TODO: Add psWhatsThis entry to KStandardShortcutInfo
581{
582 // KStandardShortcutInfo* info = guardedStandardShortcutInfo( id );
583 // if( info && info->whatsThis )
584 // return i18n(info->whatsThis);
585 // else
586 return QString();
587}
588
590{
591 KStandardShortcutInfo *info = guardedStandardShortcutInfo(id);
592
593 if (!info->isInitialized) {
594 initialize(id);
595 }
596
597 return info->cut;
598}
599
601{
602 if (!seq.isEmpty()) {
603 for (const KStandardShortcutInfo &shortcutInfo : g_infoStandardShortcut) {
604 const StandardShortcut id = shortcutInfo.id;
605 if (id != AccelNone) {
606 if (!shortcutInfo.isInitialized) {
607 initialize(id);
608 }
609 if (shortcutInfo.cut.contains(seq)) {
610 return id;
611 }
612 }
613 }
614 }
615 return AccelNone;
616}
617
619{
620 for (const KStandardShortcutInfo &shortcutInfo : g_infoStandardShortcut) {
621 if (QLatin1StringView(shortcutInfo.name) == name) {
622 return shortcutInfo.id;
623 }
624 }
625 return AccelNone;
626}
627
629{
631 KStandardShortcutInfo *info = guardedStandardShortcutInfo(id);
632
633 if (info->cutDefault != 0) {
634 cut << info->cutDefault;
635 }
636
637 if (info->cutDefault2 != 0) {
638 if (cut.isEmpty()) {
639 cut << QKeySequence();
640 }
641
642 cut << info->cutDefault2;
643 }
644
645 return cut;
646}
647
649{
650 return guardedStandardShortcutInfo(id)->category;
651}
652
654{
655 return shortcut(Open);
656}
658{
659 return shortcut(New);
660}
662{
663 return shortcut(Close);
664}
666{
667 return shortcut(Save);
668}
670{
671 return shortcut(Print);
672}
674{
675 return shortcut(Quit);
676}
678{
679 return shortcut(Cut);
680}
682{
683 return shortcut(Copy);
684}
686{
687 return shortcut(Paste);
688}
702{
703 return shortcut(Undo);
704}
706{
707 return shortcut(Redo);
708}
710{
711 return shortcut(Find);
712}
714{
715 return shortcut(FindNext);
716}
718{
719 return shortcut(FindPrev);
720}
722{
723 return shortcut(Replace);
724}
726{
727 return shortcut(Home);
728}
730{
731 return shortcut(Begin);
732}
734{
735 return shortcut(End);
736}
742{
743 return shortcut(EndOfLine);
744}
746{
747 return shortcut(Prior);
748}
750{
751 return shortcut(Next);
752}
758{
759 return shortcut(ForwardWord);
760}
762{
763 return shortcut(GotoLine);
764}
766{
767 return shortcut(AddBookmark);
768}
770{
771 return shortcut(TabNext);
772}
774{
775 return shortcut(TabPrev);
776}
778{
779 return shortcut(FullScreen);
780}
782{
783 return shortcut(ZoomIn);
784}
786{
787 return shortcut(ZoomOut);
788}
790{
791 return shortcut(Help);
792}
806{
807 return shortcut(RotateUp);
808}
810{
811 return shortcut(RotateDown);
812}
818{
819 return shortcut(WhatsThis);
820}
822{
823 return shortcut(Reload);
824}
826{
827 return shortcut(SelectAll);
828}
830{
831 return shortcut(Up);
832}
834{
835 return shortcut(Back);
836}
838{
839 return shortcut(Forward);
840}
842{
843 return shortcut(ShowMenubar);
844}
846{
847 return shortcut(DeleteFile);
848}
850{
851 return shortcut(RenameFile);
852}
858{
859 return shortcut(MoveToTrash);
860}
862{
863 return shortcut(Preferences);
864}
877}
@ Notify
Notify remote KConfigWatchers of changes (requires DBus support) Implied persistent.
Definition kconfigbase.h:51
@ Persistent
Save this entry when saving the config object.
Definition kconfigbase.h:38
@ Global
Save the entry to the global KDE config file instead of the application specific config file.
Definition kconfigbase.h:42
A class for one specific group in a KConfig object.
T readEntry(const QString &key, const T &aDefault) const
Reads the value of an entry specified by pKey in the current group.
bool hasKey(const QString &key) const
Checks whether the key has an entry in this group.
void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags=Normal)
Writes a value to the configuration object.
void deleteEntry(const QString &pKey, WriteConfigFlags pFlags=Normal)
Deletes the entry specified by pKey in the current group.
bool sync() override
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
Creates a KSharedConfig object to manipulate a configuration file.
Convenient methods for access to the common accelerator keys in the key configuration.
const QList< QKeySequence > & beginningOfLine()
Go to beginning of current line.
const QList< QKeySequence > & nextCompletion()
Iterate through a list when completion returns multiple items.
const QList< QKeySequence > & begin()
Go to beginning of the document.
const QList< QKeySequence > & rotateDown()
Help users iterate through a list of entries.
const QList< QKeySequence > & close()
Close current document.
const QList< QKeySequence > & substringCompletion()
Find a string within another string or list of strings.
const QList< QKeySequence > & reload()
Reload.
const QList< QKeySequence > & cut()
Cut selected area and store it in the clipboard.
static KStandardShortcutInfo * guardedStandardShortcutInfo(StandardShortcut id)
Search for the KStandardShortcutInfo object associated with the given id.
Category category(StandardShortcut id)
Returns the appropriate category for the given StandardShortcut id.
const QList< QKeySequence > & undo()
Undo last operation.
const QList< QKeySequence > & zoomIn()
Zoom in.
const QList< QKeySequence > & print()
Print current document.
const QList< QKeySequence > & zoomOut()
Zoom out.
const QList< QKeySequence > & addBookmark()
Add current page to bookmarks.
const QList< QKeySequence > & next()
Scroll down one page.
const QList< QKeySequence > & deleteWordBack()
Delete a word back from mouse/cursor position.
const QList< QKeySequence > & openMainMenu()
Open a main menu like the menu bar or a hamburger menu.
const QList< QKeySequence > & find()
Initiate a 'find' request in the current document.
const QList< QKeySequence > & forward()
Forward.
const QList< QKeySequence > & paste()
Paste contents of clipboard at mouse/cursor position.
QString label(StandardShortcut id)
Returns a localized label for user-visible display.
const QList< QKeySequence > & fullScreen()
Full Screen Mode.
const QList< QKeySequence > & end()
Go to end of the document.
QString name(StandardShortcut id)
Returns a unique name for the given accel.
const QList< QKeySequence > & save()
Save current document.
const QList< QKeySequence > & home()
Go to home page.
const QList< QKeySequence > & copy()
Copy selected area into the clipboard.
const QList< QKeySequence > & tabPrev()
Previous Tab.
const QList< QKeySequence > & up()
Up.
const QList< QKeySequence > & backwardWord()
BackwardWord.
const QList< QKeySequence > & renameFile()
Rename files or folders.
const QList< QKeySequence > & endOfLine()
Go to end of current line.
const QList< QKeySequence > & forwardWord()
ForwardWord.
const QList< QKeySequence > & completion()
Complete text in input widgets.
QString whatsThis(StandardShortcut)
Returns an extended WhatsThis description for the given accelerator.
const QList< QKeySequence > & findPrev()
Find a previous instance of a stored 'find'.
const QList< QKeySequence > & tabNext()
Next Tab.
const QList< QKeySequence > & moveToTrash()
Moves files or folders to the trash.
const QList< QKeySequence > & preferences()
Opens the app's settings window.
const QList< QKeySequence > & deleteFile()
Permanently delete files or folders.
const QList< QKeySequence > & quit()
Quit the program.
const QList< QKeySequence > & createFolder()
Create a folder.
const QList< QKeySequence > & open()
Open file.
QList< QKeySequence > hardcodedDefaultShortcut(StandardShortcut id)
Returns the hardcoded default shortcut for id.
const QList< QKeySequence > & showHideHiddenFiles()
Shows or hides hidden files.
const QList< QKeySequence > & showMenubar()
Show Menu Bar.
StandardShortcut findByName(const QString &name)
Return the StandardShortcut id of the standard accelerator action which has name as its name,...
const QList< QKeySequence > & prevCompletion()
Iterate through a list when completion returns multiple items.
const QList< QKeySequence > & shortcut(StandardShortcut id)
Returns the keybinding for accel.
void saveShortcut(StandardShortcut id, const QList< QKeySequence > &newShortcut)
Saves the new shortcut cut for standard accel id.
const QList< QKeySequence > & deleteWordForward()
Delete a word forward from mouse/cursor position.
const QList< QKeySequence > & openNew()
Create a new document (or whatever).
const QList< QKeySequence > & findNext()
Find the next instance of a stored 'find' Default: F3.
const QList< QKeySequence > & prior()
Scroll up one page.
const QList< QKeySequence > & back()
Back.
static KStandardShortcutInfo g_infoStandardShortcut[]
Array of predefined KStandardShortcutInfo objects, which cover all the "standard" accelerators.
const QList< QKeySequence > & selectAll()
Select all.
const QList< QKeySequence > & replace()
Find and replace matches.
void initialize(StandardShortcut id)
Initialize the accelerator id by checking if it is overridden in the configuration file (and if it is...
const QList< QKeySequence > & gotoLine()
Go to line.
const QList< QKeySequence > & openContextMenu()
Open a context menu for the object with keyboard focus.
const QList< QKeySequence > & pasteSelection()
Paste the selection at mouse/cursor position.
Category
Categories in which the standard shortcuts can be classified.
const QList< QKeySequence > & redo()
Redo last operation.
const QList< QKeySequence > & help()
Help the user in the current situation.
const QList< QKeySequence > & rotateUp()
Help users iterate through a list of entries.
StandardShortcut
Defines the identifier of all standard accelerators.
@ DeleteFile
Permanently delete files or folders.
@ KeyBindings
Display the configure key bindings dialog.
@ Close
Close current document.
@ ShowHideHiddenFiles
Toggle showing or hiding hidden files.
@ TabPrev
Previous Tab.
@ OpenContextMenu
Open a context menu for the object with keyboard focus. Necessary for accessibility.
@ Cut
Cut selected area and store it in the clipboard.
@ OpenMainMenu
Open a main menu like the menu bar or a hamburger menu. Necessary for accessibility.
@ ConfigureToolbars
Display the toolbar configuration dialog.
@ AboutApp
Display the application's About dialog.
@ Paste
Paste contents of clipboard at mouse/cursor position.
@ Help
Help the user in the current situation.
@ Mail
Send the current document by mail.
@ Quit
Quit the program.
@ Home
Go to home page.
@ Spelling
Pop up the spell checker.
@ Zoom
Select the current zoom level.
@ DeleteWordBack
Delete a word back from mouse/cursor position.
@ FitToWidth
Fit the document view to the width of the current window.
@ FitToPage
Fit the document view to the size of the current window.
@ Begin
Go to beginning of the document.
@ Undo
Undo last operation.
@ ShowMenubar
Show Menu Bar.
@ DocumentForward
Move forward (document style menu).
@ Print
Print current document.
@ Donate
Open donation page on kde.org.
@ Save
Save current document.
@ EndOfLine
Go to end of current line.
@ FitToHeight
Fit the document view to the height of the current window.
@ DocumentBack
Move back (document style menu).
@ AddBookmark
Add current page to bookmarks.
@ FullScreen
Full Screen mode.
@ Revert
Revert the current document to the last saved version.
@ EditBookmarks
Edit the application bookmarks.
@ New
Create a new document.
@ PrintPreview
Show a print preview of the current document.
@ FindPrev
Find a previous instance of a stored 'find'.
@ AboutKDE
Display the About KDE dialog.
@ Preferences
Display the preferences/options dialog.
@ ShowToolbar
Show/Hide the toolbar.
@ FindNext
Find the next instance of a stored 'find'.
@ Redo
Redo last operation.
@ RenameFile
Rename files or folders.
@ RotateDown
Help users iterate through a list of entries.
@ RotateUp
Help users iterate through a list of entries.
@ WhatsThis
What's This button.
@ ReportBug
Display the Report Bug dialog.
@ End
Go to end of the document.
@ MoveToTrash
Move files or folders to the trash.
@ CreateFolder
Create a folder.
@ PasteSelection
Paste the selection at mouse/cursor position.
@ NextCompletion
Iterate through a list when completion returns multiple items.
@ OpenRecent
Open a recently used document.
@ TextCompletion
Complete text in input widgets.
@ Next
Scroll down one page.
@ ShowStatusbar
Show/Hide the statusbar.
@ ActualSize
View the document at its actual size.
@ DeleteWordForward
Delete a word forward from mouse/cursor position.
@ BackwardWord
BackwardWord.
@ Copy
Copy selected area into the clipboard.
@ SaveAs
Save the current document under a different name.
@ ForwardWord
ForwardWord.
@ GotoPage
Go to a specific page.
@ Clear
Clear the content of the focus widget.
@ Find
Initiate a 'find' request in the current document.
@ SwitchApplicationLanguage
Display the Switch Application Language dialog.
@ PrevCompletion
Iterate through a list when completion returns multiple items.
@ BeginningOfLine
Go to beginning of current line.
@ ConfigureNotifications
Display the notifications configuration dialog.
@ Goto
Jump to some specific location in the document.
@ SubstringCompletion
Find a string within another string or list of strings.
@ Replace
Find and replace matches.
@ Prior
Scroll up one page.
@ Deselect
Deselect any selected elements.
QString translate(const char *context, const char *sourceText, const char *disambiguation, int n)
bool isEmpty() const const
QList< QKeySequence > listFromString(const QString &str, SequenceFormat format)
QString listToString(const QList< QKeySequence > &list, SequenceFormat format)
const_reference at(qsizetype i) const const
bool isEmpty() const const
void removeAt(qsizetype i)
qsizetype size() const const
QString fromLatin1(QByteArrayView str)
qsizetype indexOf(const QRegularExpression &re, qsizetype from) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 3 2025 11:54:33 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.