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
61/** Array of predefined KStandardShortcutInfo objects, which cover all
62 the "standard" accelerators. Each enum value from StandardShortcut
63 should appear in this table.
64*/
65// STUFF WILL BREAK IF YOU DON'T READ THIS!!!
66// Read the comments of the big enum in kstandardshortcut.h before you change anything!
67static KStandardShortcutInfo g_infoStandardShortcut[] = {
68 // Group File,
69 {AccelNone, nullptr, {nullptr, nullptr}, 0, 0, QList<QKeySequence>(), false, Category::InvalidCategory},
70 {Open, "Open", QT_TRANSLATE_NOOP3("KStandardShortcut", "Open", "@action"), CTRL(O), 0, QList<QKeySequence>(), false, Category::File},
71 {New, "New", QT_TRANSLATE_NOOP3("KStandardShortcut", "New", "@action"), CTRL(N), 0, QList<QKeySequence>(), false, Category::File},
72 {Close, "Close", QT_TRANSLATE_NOOP3("KStandardShortcut", "Close", "@action"), CTRL(W), CTRL(Escape), QList<QKeySequence>(), false, Category::File},
73 {Save, "Save", QT_TRANSLATE_NOOP3("KStandardShortcut", "Save", "@action"), CTRL(S), 0, QList<QKeySequence>(), false, Category::File},
74 {Print, "Print", QT_TRANSLATE_NOOP3("KStandardShortcut", "Print", "@action"), CTRL(P), 0, QList<QKeySequence>(), false, Category::File},
75 {Quit, "Quit", QT_TRANSLATE_NOOP3("KStandardShortcut", "Quit", "@action"), CTRL(Q), 0, QList<QKeySequence>(), false, Category::Navigation},
76
77 // Group Edit
78 {Undo, "Undo", QT_TRANSLATE_NOOP3("KStandardShortcut", "Undo", "@action"), CTRL(Z), 0, QList<QKeySequence>(), false, Category::Edit},
79 {Redo, "Redo", QT_TRANSLATE_NOOP3("KStandardShortcut", "Redo", "@action"), CTRLSHIFT(Z), 0, QList<QKeySequence>(), false, Category::Edit},
80 // Both "Cut" and "Delete" use Shift+Delete, but this is okay; see
81 // https://commits.kde.org/kxmlgui/8eabbf6725386e716b7536c71a9181dfe5d959f0
82 {Cut, "Cut", QT_TRANSLATE_NOOP3("KStandardShortcut", "Cut", "@action"), CTRL(X), SHIFT(Delete), QList<QKeySequence>(), false, Category::Edit},
83 {Copy, "Copy", QT_TRANSLATE_NOOP3("KStandardShortcut", "Copy", "@action"), CTRL(C), CTRL(Insert), QList<QKeySequence>(), false, Category::Edit},
84 {Paste, "Paste", QT_TRANSLATE_NOOP3("KStandardShortcut", "Paste", "@action"), CTRL(V), SHIFT(Insert), QList<QKeySequence>(), false, Category::Edit},
86 "Paste Selection",
87 QT_TRANSLATE_NOOP3("KStandardShortcut", "Paste Selection", "@action"),
88 CTRLSHIFT(Insert),
89 0,
91 false,
92 Category::Edit},
93
94 {SelectAll, "SelectAll", QT_TRANSLATE_NOOP3("KStandardShortcut", "Select All", "@action"), CTRL(A), 0, QList<QKeySequence>(), false, Category::Edit},
95 {Deselect, "Deselect", QT_TRANSLATE_NOOP3("KStandardShortcut", "Deselect", "@action"), CTRLSHIFT(A), 0, QList<QKeySequence>(), false, Category::Edit},
97 "DeleteWordBack",
98 QT_TRANSLATE_NOOP3("KStandardShortcut", "Delete Word Backwards", "@action"),
99 CTRL(Backspace),
100 0,
102 false,
103 Category::Edit},
105 "DeleteWordForward",
106 QT_TRANSLATE_NOOP3("KStandardShortcut", "Delete Word Forward", "@action"),
107 CTRL(Delete),
108 0,
110 false,
111 Category::Edit},
112
113 {Find, "Find", QT_TRANSLATE_NOOP3("KStandardShortcut", "Find", "@action"), CTRL(F), 0, QList<QKeySequence>(), false, Category::Edit},
114 {FindNext, "FindNext", QT_TRANSLATE_NOOP3("KStandardShortcut", "Find Next", "@action"), Qt::Key_F3, 0, QList<QKeySequence>(), false, Category::Edit},
115 {FindPrev, "FindPrev", QT_TRANSLATE_NOOP3("KStandardShortcut", "Find Prev", "@action"), SHIFT(F3), 0, QList<QKeySequence>(), false, Category::Edit},
116 {Replace, "Replace", QT_TRANSLATE_NOOP3("KStandardShortcut", "Replace", "@action"), CTRL(R), 0, QList<QKeySequence>(), false, Category::Edit},
117
118 // Group Navigation
119 {Home,
120 "Home",
121 QT_TRANSLATE_NOOP3("KStandardShortcut", "Home", "@action Go to main page"),
122 ALT(Home),
125 false,
126 Category::Navigation},
127 {Begin,
128 "Begin",
129 QT_TRANSLATE_NOOP3("KStandardShortcut", "Begin", "@action Beginning of document"),
130 CTRL(Home),
131 0,
133 false,
134 Category::Navigation},
135 {End, "End", QT_TRANSLATE_NOOP3("KStandardShortcut", "End", "@action End of document"), CTRL(End), 0, QList<QKeySequence>(), false, Category::Navigation},
136 {Prior, "Prior", QT_TRANSLATE_NOOP3("KStandardShortcut", "Prior", "@action"), Qt::Key_PageUp, 0, QList<QKeySequence>(), false, Category::Navigation},
137 {Next,
138 "Next",
139 QT_TRANSLATE_NOOP3("KStandardShortcut", "Next", "@action Opposite to Prior"),
141 0,
143 false,
144 Category::Navigation},
145
146 {Up, "Up", QT_TRANSLATE_NOOP3("KStandardShortcut", "Up", "@action"), ALT(Up), 0, QList<QKeySequence>(), false, Category::Navigation},
147 {Back, "Back", QT_TRANSLATE_NOOP3("KStandardShortcut", "Back", "@action"), ALT(Left), Qt::Key_Back, QList<QKeySequence>(), false, Category::Navigation},
148 {Forward,
149 "Forward",
150 QT_TRANSLATE_NOOP3("KStandardShortcut", "Forward", "@action"),
151 ALT(Right),
154 false,
155 Category::Navigation},
156 {Reload,
157 "Reload",
158 QT_TRANSLATE_NOOP3("KStandardShortcut", "Reload", "@action"),
162 false,
163 Category::Navigation},
164
166 "BeginningOfLine",
167 QT_TRANSLATE_NOOP3("KStandardShortcut", "Beginning of Line", "@action"),
169 0,
171 false,
172 Category::Navigation},
173 {EndOfLine,
174 "EndOfLine",
175 QT_TRANSLATE_NOOP3("KStandardShortcut", "End of Line", "@action"),
177 0,
179 false,
180 Category::Navigation},
181 {GotoLine, "GotoLine", QT_TRANSLATE_NOOP3("KStandardShortcut", "Go to Line", "@action"), CTRL(G), 0, QList<QKeySequence>(), false, Category::Navigation},
183 "BackwardWord",
184 QT_TRANSLATE_NOOP3("KStandardShortcut", "Backward Word", "@action"),
185 CTRL(Left),
186 0,
188 false,
189 Category::Navigation},
191 "ForwardWord",
192 QT_TRANSLATE_NOOP3("KStandardShortcut", "Forward Word", "@action"),
193 CTRL(Right),
194 0,
196 false,
197 Category::Navigation},
198
200 "AddBookmark",
201 QT_TRANSLATE_NOOP3("KStandardShortcut", "Add Bookmark", "@action"),
202 CTRL(B),
203 0,
205 false,
206 Category::Navigation},
207 {ZoomIn, "ZoomIn", QT_TRANSLATE_NOOP3("KStandardShortcut", "Zoom In", "@action"), CTRL(Plus), CTRL(Equal), QList<QKeySequence>(), false, Category::View},
208 {ZoomOut, "ZoomOut", QT_TRANSLATE_NOOP3("KStandardShortcut", "Zoom Out", "@action"), CTRL(Minus), 0, QList<QKeySequence>(), false, Category::View},
209 {FullScreen,
210 "FullScreen",
211 QT_TRANSLATE_NOOP3("KStandardShortcut", "Full Screen Mode", "@action"),
212 CTRLSHIFT(F),
213 0,
215 false,
216 Category::View},
217
218 {ShowMenubar, "ShowMenubar", QT_TRANSLATE_NOOP3("KStandardShortcut", "Show Menu Bar", "@action"), CTRL(M), 0, QList<QKeySequence>(), false, Category::View},
219 {TabNext,
220 "Activate Next Tab",
221 QT_TRANSLATE_NOOP3("KStandardShortcut", "Activate Next Tab", "@action"),
222 CTRL(PageDown),
223 CTRL(BracketRight),
225 false,
226 Category::Navigation},
227 {TabPrev,
228 "Activate Previous Tab",
229 QT_TRANSLATE_NOOP3("KStandardShortcut", "Activate Previous Tab", "@action"),
230 CTRL(PageUp),
231 CTRL(BracketLeft),
233 false,
234 Category::Navigation},
235
236 // Group Help
237 {Help, "Help", QT_TRANSLATE_NOOP3("KStandardShortcut", "Help", "@action"), Qt::Key_F1, 0, QList<QKeySequence>(), false, Category::Help},
238 {WhatsThis, "WhatsThis", QT_TRANSLATE_NOOP3("KStandardShortcut", "What's This", "@action"), SHIFT(F1), 0, QList<QKeySequence>(), false, Category::Help},
239
240 // Group TextCompletion
242 "TextCompletion",
243 QT_TRANSLATE_NOOP3("KStandardShortcut", "Text Completion", "@action"),
244 CTRL(E),
245 0,
247 false,
248 Category::Edit},
250 "PrevCompletion",
251 QT_TRANSLATE_NOOP3("KStandardShortcut", "Previous Completion Match", "@action"),
252 CTRL(Up),
253 0,
255 false,
256 Category::Edit},
258 "NextCompletion",
259 QT_TRANSLATE_NOOP3("KStandardShortcut", "Next Completion Match", "@action"),
260 CTRL(Down),
261 0,
263 false,
264 Category::Edit},
266 "SubstringCompletion",
267 QT_TRANSLATE_NOOP3("KStandardShortcut", "Substring Completion", "@action"),
268 CTRL(T),
269 0,
271 false,
272 Category::Edit},
273
274 {RotateUp,
275 "RotateUp",
276 QT_TRANSLATE_NOOP3("KStandardShortcut", "Previous Item in List", "@action"),
278 0,
280 false,
281 Category::Navigation},
282 {RotateDown,
283 "RotateDown",
284 QT_TRANSLATE_NOOP3("KStandardShortcut", "Next Item in List", "@action"),
286 0,
288 false,
289 Category::Navigation},
290
291 {OpenRecent, "OpenRecent", QT_TRANSLATE_NOOP3("KStandardShortcut", "Open Recent", "@action"), 0, 0, QList<QKeySequence>(), false, Category::File},
292 {SaveAs, "SaveAs", QT_TRANSLATE_NOOP3("KStandardShortcut", "Save As", "@action"), CTRLSHIFT(S), 0, QList<QKeySequence>(), false, Category::File},
293 {Revert, "Revert", QT_TRANSLATE_NOOP3("KStandardShortcut", "Revert", "@action"), 0, 0, QList<QKeySequence>(), false, Category::Edit},
294 {PrintPreview, "PrintPreview", QT_TRANSLATE_NOOP3("KStandardShortcut", "Print Preview", "@action"), 0, 0, QList<QKeySequence>(), false, Category::File},
295 {Mail, "Mail", QT_TRANSLATE_NOOP3("KStandardShortcut", "Mail", "@action"), 0, 0, QList<QKeySequence>(), false, Category::Help},
296 {Clear, "Clear", QT_TRANSLATE_NOOP3("KStandardShortcut", "Clear", "@action"), 0, 0, QList<QKeySequence>(), false, Category::Edit},
297 {ActualSize,
298 "ActualSize",
299 QT_TRANSLATE_NOOP3("KStandardShortcut", "Zoom to Actual Size", "@action"),
300 CTRL(0),
301 0,
303 false,
304 Category::View},
305 {FitToPage, "FitToPage", QT_TRANSLATE_NOOP3("KStandardShortcut", "Fit To Page", "@action"), 0, 0, QList<QKeySequence>(), false, Category::View},
306 {FitToWidth, "FitToWidth", QT_TRANSLATE_NOOP3("KStandardShortcut", "Fit To Width", "@action"), 0, 0, QList<QKeySequence>(), false, Category::View},
307 {FitToHeight, "FitToHeight", QT_TRANSLATE_NOOP3("KStandardShortcut", "Fit To Height", "@action"), 0, 0, QList<QKeySequence>(), false, Category::View},
308 {Zoom, "Zoom", QT_TRANSLATE_NOOP3("KStandardShortcut", "Zoom", "@action"), 0, 0, QList<QKeySequence>(), false, Category::View},
309 {Goto, "Goto", QT_TRANSLATE_NOOP3("KStandardShortcut", "Goto", "@action"), 0, 0, QList<QKeySequence>(), false, Category::Navigation},
310 {GotoPage, "GotoPage", QT_TRANSLATE_NOOP3("KStandardShortcut", "Goto Page", "@action"), 0, 0, QList<QKeySequence>(), false, Category::Navigation},
312 "DocumentBack",
313 QT_TRANSLATE_NOOP3("KStandardShortcut", "Document Back", "@action"),
314 ALTSHIFT(Left),
315 0,
317 false,
318 Category::Navigation},
320 "DocumentForward",
321 QT_TRANSLATE_NOOP3("KStandardShortcut", "Document Forward", "@action"),
322 ALTSHIFT(Right),
323 0,
325 false,
326 Category::Navigation},
328 "EditBookmarks",
329 QT_TRANSLATE_NOOP3("KStandardShortcut", "Edit Bookmarks", "@action"),
330 0,
331 0,
333 false,
334 Category::Navigation},
335 {Spelling, "Spelling", QT_TRANSLATE_NOOP3("KStandardShortcut", "Spelling", "@action"), 0, 0, QList<QKeySequence>(), false, Category::Edit},
336 {ShowToolbar, "ShowToolbar", QT_TRANSLATE_NOOP3("KStandardShortcut", "Show Toolbar", "@action"), 0, 0, QList<QKeySequence>(), false, Category::View},
337 {ShowStatusbar, "ShowStatusbar", QT_TRANSLATE_NOOP3("KStandardShortcut", "Show Statusbar", "@action"), 0, 0, QList<QKeySequence>(), false, Category::View},
339 "KeyBindings",
340 QT_TRANSLATE_NOOP3("KStandardShortcut", "Key Bindings", "@action"),
341 CTRLALT(Comma),
342 0,
344 false,
345 Category::Settings},
347 "Preferences",
348 QT_TRANSLATE_NOOP3("KStandardShortcut", "Configure Application", "@action"),
349 CTRLSHIFT(Comma),
350 0,
352 false,
353 Category::Settings},
355 "ConfigureToolbars",
356 QT_TRANSLATE_NOOP3("KStandardShortcut", "Configure Toolbars", "@action"),
357 0,
358 0,
360 false,
361 Category::Settings},
363 "ConfigureNotifications",
364 QT_TRANSLATE_NOOP3("KStandardShortcut", "Configure Notifications", "@action"),
365 0,
366 0,
368 false,
369 Category::Settings},
370 {ReportBug, "ReportBug", QT_TRANSLATE_NOOP3("KStandardShortcut", "Report Bug", "@action"), 0, 0, QList<QKeySequence>(), false, Category::Help},
372 "SwitchApplicationLanguage",
373 QT_TRANSLATE_NOOP3("KStandardShortcut", "Configure Language…", "@action"),
374 0,
375 0,
377 false,
378 Category::Settings},
379 {AboutApp, "AboutApp", QT_TRANSLATE_NOOP3("KStandardShortcut", "About Application", "@action"), 0, 0, QList<QKeySequence>(), false, Category::Help},
380 {AboutKDE, "AboutKDE", QT_TRANSLATE_NOOP3("KStandardShortcut", "About KDE", "@action"), 0, 0, QList<QKeySequence>(), false, Category::Help},
381 // Both "Cut" and "Delete" use Shift+Delete, but this is okay; see
382 // https://commits.kde.org/kxmlgui/8eabbf6725386e716b7536c71a9181dfe5d959f0
383 {DeleteFile, "DeleteFile", QT_TRANSLATE_NOOP3("KStandardShortcut", "Delete", "@action"), SHIFT(Delete), 0, QList<QKeySequence>(), false, Category::File},
384 {RenameFile, "RenameFile", QT_TRANSLATE_NOOP3("KStandardShortcut", "Rename", "@action"), Qt::Key_F2, 0, QList<QKeySequence>(), false, Category::File},
386 "MoveToTrash",
387 QT_TRANSLATE_NOOP3("KStandardShortcut", "Move to Trash", "@action"),
389 0,
391 false,
392 Category::File},
393 {Donate, "Donate", QT_TRANSLATE_NOOP3("KStandardShortcut", "Donate", "@action"), 0, 0, QList<QKeySequence>(), false, Category::Help},
395 "ShowHideHiddenFiles",
396 QT_TRANSLATE_NOOP3("KStandardShortcut", "Show/Hide Hidden Files", "@action"),
397 CTRL(H),
398 ALT(Period),
400 false,
401 Category::View},
403 "CreateFolder",
404 QT_TRANSLATE_NOOP3("KStandardShortcut", "Create Folder", "@action"),
405 CTRLSHIFT(N),
406 0,
408 false,
409 Category::File},
411 "OpenMainMenu",
412 QT_TRANSLATE_NOOP3("KStandardShortcut", "Open Main Menu", "@action referring to the menu bar or a hamburger menu"),
414 0,
416 false,
417 Category::View},
419 "OpenContextMenu",
420 QT_TRANSLATE_NOOP3("KStandardShortcut", "Open Context Menu", "@action"),
422 SHIFT(F10),
424 false,
425 Category::View},
426
427 // dummy entry to catch simple off-by-one errors. Insert new entries before this line.
428 {AccelNone, nullptr, {nullptr, nullptr}, 0, 0, QList<QKeySequence>(), false, Category::InvalidCategory}};
429
430/** Search for the KStandardShortcutInfo object associated with the given @p id.
431 Return a dummy entry with no name and an empty shortcut if @p id is invalid.
432*/
433static KStandardShortcutInfo *guardedStandardShortcutInfo(StandardShortcut id)
434{
435 if (id >= static_cast<int>(sizeof(g_infoStandardShortcut) / sizeof(KStandardShortcutInfo)) || id < 0) {
436 qWarning() << "KStandardShortcut: id not found!";
437 return &g_infoStandardShortcut[AccelNone];
438 } else {
439 return &g_infoStandardShortcut[id];
440 }
441}
442
443// Sanitize the list for duplicates. For some reason some
444// people have kdeglobals entries like
445// Close=Ctrl+W; Ctrl+Esc; Ctrl+W; Ctrl+Esc;
446// having the same shortcut more than once in the shortcut
447// declaration is clearly bogus so fix it
448static void sanitizeShortcutList(QList<QKeySequence> *list)
449{
450 for (int i = 0; i < list->size(); ++i) {
451 const QKeySequence &ks = list->at(i);
452 int other = list->indexOf(ks, i + 1);
453 while (other != -1) {
454 list->removeAt(other);
455 other = list->indexOf(ks, other);
456 }
457 }
458}
459
460/** Initialize the accelerator @p id by checking if it is overridden
461 in the configuration file (and if it isn't, use the default).
462 On X11, if QApplication was initialized with GUI disabled,
463 the default will always be used.
464*/
466{
467 KStandardShortcutInfo *info = guardedStandardShortcutInfo(id);
468
469 // All three are needed.
470 if (info->id != AccelNone) {
471 Q_ASSERT(info->description.text);
472 Q_ASSERT(info->description.context);
473 Q_ASSERT(info->name);
474 }
475
476 KConfigGroup cg(KSharedConfig::openConfig(), QStringLiteral("Shortcuts"));
477
478 if (cg.hasKey(info->name)) {
479 QString s = cg.readEntry(info->name);
480 if (s != QLatin1String("none")) {
481 info->cut = QKeySequence::listFromString(s);
482 sanitizeShortcutList(&info->cut);
483 } else {
484 info->cut = QList<QKeySequence>();
485 }
486 } else {
487 info->cut = hardcodedDefaultShortcut(id);
488 }
489
490 info->isInitialized = true;
491}
492
494{
495 KStandardShortcutInfo *info = guardedStandardShortcutInfo(id);
496 // If the action has no standard shortcut associated there is nothing to
497 // save
498 if (info->id == AccelNone) {
499 return;
500 }
501
502 KConfigGroup cg(KSharedConfig::openConfig(), QStringLiteral("Shortcuts"));
503
504 info->cut = newShortcut;
505 bool sameAsDefault = (newShortcut == hardcodedDefaultShortcut(id));
506
507 if (sameAsDefault) {
508 // If the shortcut is the equal to the hardcoded one we remove it from
509 // kdeglobal if necessary and return.
510 if (cg.hasKey(info->name)) {
512 cg.sync();
513 }
514
515 return;
516 }
517
518 // Write the changed shortcut to kdeglobals
519 sanitizeShortcutList(&info->cut);
521 cg.sync();
522}
523
528
530{
531 KStandardShortcutInfo *info = guardedStandardShortcutInfo(id);
532 return QCoreApplication::translate("KStandardShortcut", info->description.text, info->description.context);
533}
534
535// TODO: Add psWhatsThis entry to KStandardShortcutInfo
537{
538 // KStandardShortcutInfo* info = guardedStandardShortcutInfo( id );
539 // if( info && info->whatsThis )
540 // return i18n(info->whatsThis);
541 // else
542 return QString();
543}
544
546{
547 KStandardShortcutInfo *info = guardedStandardShortcutInfo(id);
548
549 if (!info->isInitialized) {
550 initialize(id);
551 }
552
553 return info->cut;
554}
555
557{
558 if (!seq.isEmpty()) {
559 for (const KStandardShortcutInfo &shortcutInfo : g_infoStandardShortcut) {
560 const StandardShortcut id = shortcutInfo.id;
561 if (id != AccelNone) {
562 if (!shortcutInfo.isInitialized) {
563 initialize(id);
564 }
565 if (shortcutInfo.cut.contains(seq)) {
566 return id;
567 }
568 }
569 }
570 }
571 return AccelNone;
572}
573
575{
576 for (const KStandardShortcutInfo &shortcutInfo : g_infoStandardShortcut) {
577 if (QLatin1StringView(shortcutInfo.name) == name) {
578 return shortcutInfo.id;
579 }
580 }
581 return AccelNone;
582}
583
585{
587 KStandardShortcutInfo *info = guardedStandardShortcutInfo(id);
588
589 if (info->cutDefault != 0) {
590 cut << info->cutDefault;
591 }
592
593 if (info->cutDefault2 != 0) {
594 if (cut.isEmpty()) {
595 cut << QKeySequence();
596 }
597
598 cut << info->cutDefault2;
599 }
600
601 return cut;
602}
603
605{
606 return guardedStandardShortcutInfo(id)->category;
607}
608
610{
611 return shortcut(Open);
612}
614{
615 return shortcut(New);
616}
618{
619 return shortcut(Close);
620}
622{
623 return shortcut(Save);
624}
626{
627 return shortcut(Print);
628}
630{
631 return shortcut(Quit);
632}
634{
635 return shortcut(Cut);
636}
638{
639 return shortcut(Copy);
640}
642{
643 return shortcut(Paste);
644}
658{
659 return shortcut(Undo);
660}
662{
663 return shortcut(Redo);
664}
666{
667 return shortcut(Find);
668}
670{
671 return shortcut(FindNext);
672}
674{
675 return shortcut(FindPrev);
676}
678{
679 return shortcut(Replace);
680}
682{
683 return shortcut(Home);
684}
686{
687 return shortcut(Begin);
688}
690{
691 return shortcut(End);
692}
698{
699 return shortcut(EndOfLine);
700}
702{
703 return shortcut(Prior);
704}
706{
707 return shortcut(Next);
708}
714{
715 return shortcut(ForwardWord);
716}
718{
719 return shortcut(GotoLine);
720}
722{
723 return shortcut(AddBookmark);
724}
726{
727 return shortcut(TabNext);
728}
730{
731 return shortcut(TabPrev);
732}
734{
735 return shortcut(FullScreen);
736}
738{
739 return shortcut(ZoomIn);
740}
742{
743 return shortcut(ZoomOut);
744}
746{
747 return shortcut(Help);
748}
762{
763 return shortcut(RotateUp);
764}
766{
767 return shortcut(RotateDown);
768}
774{
775 return shortcut(WhatsThis);
776}
778{
779 return shortcut(Reload);
780}
782{
783 return shortcut(SelectAll);
784}
786{
787 return shortcut(Up);
788}
790{
791 return shortcut(Back);
792}
794{
795 return shortcut(Forward);
796}
798{
799 return shortcut(ShowMenubar);
800}
802{
803 return shortcut(DeleteFile);
804}
806{
807 return shortcut(RenameFile);
808}
814{
815 return shortcut(MoveToTrash);
816}
818{
819 return shortcut(Preferences);
820}
833}
@ 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-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:55:52 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.