KConfig

kstandardshortcut.cpp
1 /*
2  This file is part of the KDE libraries
3  SPDX-FileCopyrightText: 1997 Stefan Taferner <[email protected]>
4  SPDX-FileCopyrightText: 2000 Nicolas Hadacek <[email protected]>
5  SPDX-FileCopyrightText: 2001, 2002 Ellis Whitehead <[email protected]>
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 {
24 struct 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
52 };
53 
54 #define CTRL(x) Qt::CTRL | Qt::Key_##x
55 #define SHIFT(x) Qt::SHIFT | Qt::Key_##x
56 #define CTRLALT(x) Qt::CTRL | Qt::ALT | Qt::Key_##x
57 #define CTRLSHIFT(x) Qt::CTRL | Qt::SHIFT | Qt::Key_##x
58 #define ALT(x) Qt::ALT | Qt::Key_##x
59 #define ALTSHIFT(x) Qt::ALT | Qt::SHIFT | Qt::Key_##x
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!
67 static 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"),
159  Qt::Key_F5,
162  false,
163  Category::Navigation},
164 
166  "BeginningOfLine",
167  QT_TRANSLATE_NOOP3("KStandardShortcut", "Beginning of Line", "@action"),
168  Qt::Key_Home,
169  0,
171  false,
172  Category::Navigation},
173  {EndOfLine,
174  "EndOfLine",
175  QT_TRANSLATE_NOOP3("KStandardShortcut", "End of Line", "@action"),
176  Qt::Key_End,
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},
182  {BackwardWord,
183  "BackwardWord",
184  QT_TRANSLATE_NOOP3("KStandardShortcut", "Backward Word", "@action"),
185  CTRL(Left),
186  0,
188  false,
189  Category::Navigation},
190  {ForwardWord,
191  "ForwardWord",
192  QT_TRANSLATE_NOOP3("KStandardShortcut", "Forward Word", "@action"),
193  CTRL(Right),
194  0,
196  false,
197  Category::Navigation},
198 
199  {AddBookmark,
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"),
277  Qt::Key_Up,
278  0,
280  false,
281  Category::Navigation},
282  {RotateDown,
283  "RotateDown",
284  QT_TRANSLATE_NOOP3("KStandardShortcut", "Next Item in List", "@action"),
285  Qt::Key_Down,
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, "ActualSize", QT_TRANSLATE_NOOP3("KStandardShortcut", "Zoom to Actual Size", "@action"), CTRL(0), 0, QList<QKeySequence>(), false, Category::View},
298  {FitToPage, "FitToPage", QT_TRANSLATE_NOOP3("KStandardShortcut", "Fit To Page", "@action"), 0, 0, QList<QKeySequence>(), false, Category::View},
299  {FitToWidth, "FitToWidth", QT_TRANSLATE_NOOP3("KStandardShortcut", "Fit To Width", "@action"), 0, 0, QList<QKeySequence>(), false, Category::View},
300  {FitToHeight, "FitToHeight", QT_TRANSLATE_NOOP3("KStandardShortcut", "Fit To Height", "@action"), 0, 0, QList<QKeySequence>(), false, Category::View},
301  {Zoom, "Zoom", QT_TRANSLATE_NOOP3("KStandardShortcut", "Zoom", "@action"), 0, 0, QList<QKeySequence>(), false, Category::View},
302  {Goto, "Goto", QT_TRANSLATE_NOOP3("KStandardShortcut", "Goto", "@action"), 0, 0, QList<QKeySequence>(), false, Category::Navigation},
303  {GotoPage, "GotoPage", QT_TRANSLATE_NOOP3("KStandardShortcut", "Goto Page", "@action"), 0, 0, QList<QKeySequence>(), false, Category::Navigation},
304  {DocumentBack,
305  "DocumentBack",
306  QT_TRANSLATE_NOOP3("KStandardShortcut", "Document Back", "@action"),
307  ALTSHIFT(Left),
308  0,
310  false,
311  Category::Navigation},
313  "DocumentForward",
314  QT_TRANSLATE_NOOP3("KStandardShortcut", "Document Forward", "@action"),
315  ALTSHIFT(Right),
316  0,
318  false,
319  Category::Navigation},
320  {EditBookmarks,
321  "EditBookmarks",
322  QT_TRANSLATE_NOOP3("KStandardShortcut", "Edit Bookmarks", "@action"),
323  0,
324  0,
326  false,
327  Category::Navigation},
328  {Spelling, "Spelling", QT_TRANSLATE_NOOP3("KStandardShortcut", "Spelling", "@action"), 0, 0, QList<QKeySequence>(), false, Category::Edit},
329  {ShowToolbar, "ShowToolbar", QT_TRANSLATE_NOOP3("KStandardShortcut", "Show Toolbar", "@action"), 0, 0, QList<QKeySequence>(), false, Category::View},
330  {ShowStatusbar, "ShowStatusbar", QT_TRANSLATE_NOOP3("KStandardShortcut", "Show Statusbar", "@action"), 0, 0, QList<QKeySequence>(), false, Category::View},
331 #if KCONFIGGUI_BUILD_DEPRECATED_SINCE(5, 39)
332  {SaveOptions, "SaveOptions", QT_TRANSLATE_NOOP3("KStandardShortcut", "Save Options", "@action"), 0, 0, QList<QKeySequence>(), false, Category::Settings},
333 #else
334  // dummy entry
335  {SaveOptions_DEPRECATED_DO_NOT_USE, nullptr, {nullptr, nullptr}, 0, 0, QList<QKeySequence>(), false, Category::InvalidCategory},
336 #endif
337  {KeyBindings, "KeyBindings", QT_TRANSLATE_NOOP3("KStandardShortcut", "Key Bindings", "@action"), CTRLALT(Comma), 0, QList<QKeySequence>(), false, Category::Settings},
338  {Preferences,
339  "Preferences",
340  QT_TRANSLATE_NOOP3("KStandardShortcut", "Configure Application", "@action"),
341  CTRLSHIFT(Comma),
342  0,
344  false,
345  Category::Settings},
347  "ConfigureToolbars",
348  QT_TRANSLATE_NOOP3("KStandardShortcut", "Configure Toolbars", "@action"),
349  0,
350  0,
352  false,
353  Category::Settings},
355  "ConfigureNotifications",
356  QT_TRANSLATE_NOOP3("KStandardShortcut", "Configure Notifications", "@action"),
357  0,
358  0,
360  false,
361  Category::Settings},
362  {TipofDay, "TipofDay", QT_TRANSLATE_NOOP3("KStandardShortcut", "Tip Of Day", "@action"), 0, 0, QList<QKeySequence>(), false, Category::Help},
363  {ReportBug, "ReportBug", QT_TRANSLATE_NOOP3("KStandardShortcut", "Report Bug", "@action"), 0, 0, QList<QKeySequence>(), false, Category::Help},
365  "SwitchApplicationLanguage",
366  QT_TRANSLATE_NOOP3("KStandardShortcut", "Configure Language...", "@action"),
367  0,
368  0,
370  false,
371  Category::Settings},
372  {AboutApp, "AboutApp", QT_TRANSLATE_NOOP3("KStandardShortcut", "About Application", "@action"), 0, 0, QList<QKeySequence>(), false, Category::Help},
373  {AboutKDE, "AboutKDE", QT_TRANSLATE_NOOP3("KStandardShortcut", "About KDE", "@action"), 0, 0, QList<QKeySequence>(), false, Category::Help},
374  // Both "Cut" and "Delete" use Shift+Delete, but this is okay; see
375  // https://commits.kde.org/kxmlgui/8eabbf6725386e716b7536c71a9181dfe5d959f0
376  {DeleteFile, "DeleteFile", QT_TRANSLATE_NOOP3("KStandardShortcut", "Delete", "@action"), SHIFT(Delete), 0, QList<QKeySequence>(), false, Category::File},
377  {RenameFile, "RenameFile", QT_TRANSLATE_NOOP3("KStandardShortcut", "Rename", "@action"), Qt::Key_F2, 0, QList<QKeySequence>(), false, Category::File},
378  {MoveToTrash,
379  "MoveToTrash",
380  QT_TRANSLATE_NOOP3("KStandardShortcut", "Move to Trash", "@action"),
382  0,
384  false,
385  Category::File},
386  {Donate, "Donate", QT_TRANSLATE_NOOP3("KStandardShortcut", "Donate", "@action"), 0, 0, QList<QKeySequence>(), false, Category::Help},
388  "ShowHideHiddenFiles",
389  QT_TRANSLATE_NOOP3("KStandardShortcut", "Show/Hide Hidden Files", "@action"),
390  CTRL(H),
391  ALT(Period),
393  false,
394  Category::View},
395  {CreateFolder,
396  "CreateFolder",
397  QT_TRANSLATE_NOOP3("KStandardShortcut", "Create Folder", "@action"),
398  Qt::Key_F10,
399  0,
401  false,
402  Category::File},
403 
404  // dummy entry to catch simple off-by-one errors. Insert new entries before this line.
405  {AccelNone, nullptr, {nullptr, nullptr}, 0, 0, QList<QKeySequence>(), false, Category::InvalidCategory}};
406 
407 /** Search for the KStandardShortcutInfo object associated with the given @p id.
408  Return a dummy entry with no name and an empty shortcut if @p id is invalid.
409 */
410 static KStandardShortcutInfo *guardedStandardShortcutInfo(StandardShortcut id)
411 {
412  if (id >= static_cast<int>(sizeof(g_infoStandardShortcut) / sizeof(KStandardShortcutInfo)) || id < 0) {
413  qWarning() << "KStandardShortcut: id not found!";
414  return &g_infoStandardShortcut[AccelNone];
415  } else {
416  return &g_infoStandardShortcut[id];
417  }
418 }
419 
420 // Sanitize the list for duplicates. For some reason some
421 // people have kdeglobals entries like
422 // Close=Ctrl+W; Ctrl+Esc; Ctrl+W; Ctrl+Esc;
423 // having the same shortcut more than once in the shortcut
424 // declaration is clearly bogus so fix it
425 static void sanitizeShortcutList(QList<QKeySequence> *list)
426 {
427  for (int i = 0; i < list->size(); ++i) {
428  const QKeySequence &ks = list->at(i);
429  int other = list->indexOf(ks, i + 1);
430  while (other != -1) {
431  list->removeAt(other);
432  other = list->indexOf(ks, other);
433  }
434  }
435 }
436 
437 /** Initialize the accelerator @p id by checking if it is overridden
438  in the configuration file (and if it isn't, use the default).
439  On X11, if QApplication was initialized with GUI disabled,
440  the default will always be used.
441 */
443 {
444  KStandardShortcutInfo *info = guardedStandardShortcutInfo(id);
445 
446  // All three are needed.
447  if (info->id != AccelNone) {
448  Q_ASSERT(info->description.text);
449  Q_ASSERT(info->description.context);
450  Q_ASSERT(info->name);
451  }
452 
453  KConfigGroup cg(KSharedConfig::openConfig(), "Shortcuts");
454 
455  if (cg.hasKey(info->name)) {
456  QString s = cg.readEntry(info->name);
457  if (s != QLatin1String("none")) {
458  info->cut = QKeySequence::listFromString(s);
459  sanitizeShortcutList(&info->cut);
460  } else {
461  info->cut = QList<QKeySequence>();
462  }
463  } else {
464  info->cut = hardcodedDefaultShortcut(id);
465  }
466 
467  info->isInitialized = true;
468 }
469 
471 {
472  KStandardShortcutInfo *info = guardedStandardShortcutInfo(id);
473  // If the action has no standard shortcut associated there is nothing to
474  // save
475  if (info->id == AccelNone) {
476  return;
477  }
478 
479  KConfigGroup cg(KSharedConfig::openConfig(), "Shortcuts");
480 
481  info->cut = newShortcut;
482  bool sameAsDefault = (newShortcut == hardcodedDefaultShortcut(id));
483 
484  if (sameAsDefault) {
485  // If the shortcut is the equal to the hardcoded one we remove it from
486  // kdeglobal if necessary and return.
487  if (cg.hasKey(info->name)) {
489  cg.sync();
490  }
491 
492  return;
493  }
494 
495  // Write the changed shortcut to kdeglobals
496  sanitizeShortcutList(&info->cut);
498  cg.sync();
499 }
500 
502 {
504 }
505 
507 {
508  KStandardShortcutInfo *info = guardedStandardShortcutInfo(id);
509  return QCoreApplication::translate("KStandardShortcut", info->description.text, info->description.context);
510 }
511 
512 // TODO: Add psWhatsThis entry to KStandardShortcutInfo
514 {
515  // KStandardShortcutInfo* info = guardedStandardShortcutInfo( id );
516  // if( info && info->whatsThis )
517  // return i18n(info->whatsThis);
518  // else
519  return QString();
520 }
521 
523 {
524  KStandardShortcutInfo *info = guardedStandardShortcutInfo(id);
525 
526  if (!info->isInitialized) {
527  initialize(id);
528  }
529 
530  return info->cut;
531 }
532 
534 {
535  if (!seq.isEmpty()) {
536  for (const KStandardShortcutInfo &shortcutInfo : g_infoStandardShortcut) {
537  const StandardShortcut id = shortcutInfo.id;
538 #if KCONFIGGUI_BUILD_DEPRECATED_SINCE(5, 39)
539  if (id != AccelNone) {
540 #else
541  if (id != AccelNone && id != SaveOptions_DEPRECATED_DO_NOT_USE) {
542 #endif
543  if (!shortcutInfo.isInitialized) {
544  initialize(id);
545  }
546  if (shortcutInfo.cut.contains(seq)) {
547  return id;
548  }
549  }
550  }
551  }
552  return AccelNone;
553 }
554 
555 #if KCONFIGGUI_BUILD_DEPRECATED_SINCE(5, 71)
556 StandardShortcut find(const char *keyName)
557 {
558  for (const KStandardShortcutInfo &shortcutInfo : g_infoStandardShortcut) {
559  if (qstrcmp(shortcutInfo.name, keyName) == 0) {
560  return shortcutInfo.id;
561  }
562  }
563 
564  return AccelNone;
565 }
566 #endif
567 
569 {
570  for (const KStandardShortcutInfo &shortcutInfo : g_infoStandardShortcut) {
571  if (QString::fromLatin1(shortcutInfo.name) == name) {
572  return shortcutInfo.id;
573  }
574  }
575  return AccelNone;
576 }
577 
579 {
581  KStandardShortcutInfo *info = guardedStandardShortcutInfo(id);
582 
583  if (info->cutDefault != 0) {
584  cut << info->cutDefault;
585  }
586 
587  if (info->cutDefault2 != 0) {
588  if (cut.isEmpty()) {
589  cut << QKeySequence();
590  }
591 
592  cut << info->cutDefault2;
593  }
594 
595  return cut;
596 }
597 
599 {
600  return guardedStandardShortcutInfo(id)->category;
601 }
602 
604 {
605  return shortcut(Open);
606 }
608 {
609  return shortcut(New);
610 }
612 {
613  return shortcut(Close);
614 }
616 {
617  return shortcut(Save);
618 }
620 {
621  return shortcut(Print);
622 }
624 {
625  return shortcut(Quit);
626 }
628 {
629  return shortcut(Cut);
630 }
632 {
633  return shortcut(Copy);
634 }
636 {
637  return shortcut(Paste);
638 }
640 {
641  return shortcut(PasteSelection);
642 }
644 {
645  return shortcut(DeleteWordBack);
646 }
648 {
649  return shortcut(DeleteWordForward);
650 }
652 {
653  return shortcut(Undo);
654 }
656 {
657  return shortcut(Redo);
658 }
660 {
661  return shortcut(Find);
662 }
664 {
665  return shortcut(FindNext);
666 }
668 {
669  return shortcut(FindPrev);
670 }
672 {
673  return shortcut(Replace);
674 }
676 {
677  return shortcut(Home);
678 }
680 {
681  return shortcut(Begin);
682 }
684 {
685  return shortcut(End);
686 }
688 {
689  return shortcut(BeginningOfLine);
690 }
692 {
693  return shortcut(EndOfLine);
694 }
696 {
697  return shortcut(Prior);
698 }
700 {
701  return shortcut(Next);
702 }
704 {
705  return shortcut(BackwardWord);
706 }
708 {
709  return shortcut(ForwardWord);
710 }
712 {
713  return shortcut(GotoLine);
714 }
716 {
717  return shortcut(AddBookmark);
718 }
720 {
721  return shortcut(TabNext);
722 }
724 {
725  return shortcut(TabPrev);
726 }
728 {
729  return shortcut(FullScreen);
730 }
732 {
733  return shortcut(ZoomIn);
734 }
736 {
737  return shortcut(ZoomOut);
738 }
740 {
741  return shortcut(Help);
742 }
744 {
745  return shortcut(TextCompletion);
746 }
748 {
749  return shortcut(PrevCompletion);
750 }
752 {
753  return shortcut(NextCompletion);
754 }
756 {
757  return shortcut(RotateUp);
758 }
760 {
761  return shortcut(RotateDown);
762 }
764 {
766 }
768 {
769  return shortcut(WhatsThis);
770 }
772 {
773  return shortcut(Reload);
774 }
776 {
777  return shortcut(SelectAll);
778 }
780 {
781  return shortcut(Up);
782 }
784 {
785  return shortcut(Back);
786 }
788 {
789  return shortcut(Forward);
790 }
792 {
793  return shortcut(ShowMenubar);
794 }
796 {
797  return shortcut(DeleteFile);
798 }
800 {
801  return shortcut(RenameFile);
802 }
804 {
805  return shortcut(CreateFolder);
806 }
808 {
809  return shortcut(MoveToTrash);
810 }
812 {
813  return shortcut(Preferences);
814 }
815 
817 {
819 }
820 
821 }
@ DeleteWordBack
Delete a word back from mouse/cursor position.
StandardShortcut find(const QKeySequence &seq)
Return the StandardShortcut id of the standard accel action which uses this key sequence,...
const QList< QKeySequence > & tabPrev()
Previous Tab.
const QList< QKeySequence > & back()
Back.
const QList< QKeySequence > & selectAll()
Select all.
const QList< QKeySequence > & pasteSelection()
Paste the selection at mouse/cursor position.
@ TabPrev
Previous Tab.
@ End
Go to end of the document.
const QList< QKeySequence > & zoomOut()
Zoom out.
void saveShortcut(StandardShortcut id, const QList< QKeySequence > &newShortcut)
Saves the new shortcut cut for standard accel id.
static KStandardShortcutInfo * guardedStandardShortcutInfo(StandardShortcut id)
Search for the KStandardShortcutInfo object associated with the given id.
@ Find
Initiate a 'find' request in the current document.
@ PrevCompletion
Iterate through a list when completion returns multiple items.
const QList< QKeySequence > & nextCompletion()
Iterate through a list when completion returns multiple items.
void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags=Normal)
Writes a value to the configuration object.
@ Print
Print current document.
QList< QKeySequence > hardcodedDefaultShortcut(StandardShortcut id)
Returns the hardcoded default shortcut for id.
@ ShowToolbar
Show/Hide the toolbar.
const QList< QKeySequence > & shortcut(StandardShortcut id)
Returns the keybinding for accel.
@ OpenRecent
Open a recently used document.
@ MoveToTrash
Move files or folders to the trash.
const QList< QKeySequence > & renameFile()
Rename files or folders.
const QList< QKeySequence > & gotoLine()
Go to line.
QString translate(const char *context, const char *sourceText, const char *disambiguation, int n)
@ Save
Save current document.
@ DocumentBack
Move back (document style menu).
@ Goto
Jump to some specific location in the document.
@ Paste
Paste contents of clipboard at mouse/cursor position.
StandardShortcut findByName(const QString &name)
Return the StandardShortcut id of the standard accelerator action which has name as its name,...
const QList< QKeySequence > & reload()
Reload.
@ Copy
Copy selected area into the clipboard.
@ DocumentForward
Move forward (document style menu).
@ SaveAs
Save the current document under a different name.
@ AddBookmark
Add current page to bookmarks.
@ PasteSelection
Paste the selection at mouse/cursor position.
@ Persistent
Save this entry when saving the config object.
Definition: kconfigbase.h:38
@ EndOfLine
Go to end of current line.
@ Preferences
Display the preferences/options dialog.
@ DeleteWordForward
Delete a word forward from mouse/cursor position.
const QList< QKeySequence > & undo()
Undo last operation.
@ Replace
Find and replace matches.
const QList< QKeySequence > & close()
Close current document.
@ ShowHideHiddenFiles
Toggle showing or hiding hidden files.
const QList< QKeySequence > & begin()
Go to beginning of the document.
const QList< QKeySequence > & showMenubar()
Show Menu Bar.
const QList< QKeySequence > & forwardWord()
ForwardWord.
@ Notify
Notify remote KConfigWatchers of changes (requires DBus support) Implied persistent.
Definition: kconfigbase.h:51
@ SelectAll
Select all.
@ Global
Save the entry to the global KDE config file instead of the application specific config file.
Definition: kconfigbase.h:42
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.
const QList< QKeySequence > & addBookmark()
Add current page to bookmarks.
@ FitToWidth
Fit the document view to the width of the current window.
void removeAt(int i)
Category
Categories in which the standard shortcuts can be classified.
const QList< QKeySequence > & findNext()
Find the next instance of a stored 'find' Default: F3.
@ Next
Scroll down one page.
const QList< QKeySequence > & substringCompletion()
Find a string within another string or list of strings.
static KStandardShortcutInfo g_infoStandardShortcut[]
Array of predefined KStandardShortcutInfo objects, which cover all the "standard" accelerators.
void initialize(StandardShortcut id)
Initialize the accelerator id by checking if it is overridden in the configuration file (and if it is...
int size() const const
@ ActualSize
View the document at its actual size.
@ NextCompletion
Iterate through a list when completion returns multiple items.
@ Undo
Undo last operation.
const QList< QKeySequence > & help()
Help the user in the current situation.
@ SwitchApplicationLanguage
Display the Switch Application Language dialog.
const QList< QKeySequence > & openNew()
Create a new document (or whatever).
@ TipofDay
Display the "Tip of the Day".
const QList< QKeySequence > & tabNext()
Next Tab.
@ TextCompletion
Complete text in input widgets.
@ AboutKDE
Display the About KDE dialog.
const QList< QKeySequence > & showHideHiddenFiles()
Shows or hides hidden files.
@ PrintPreview
Show a print preview of the current document.
const QList< QKeySequence > & cut()
Cut selected area and store it in the clipboard.
@ RotateUp
Help users iterate through a list of entries.
@ ShowStatusbar
Show/Hide the statusbar.
StandardShortcut
Defines the identifier of all standard accelerators.
@ AboutApp
Display the application's About dialog.
@ FindPrev
Find a previous instance of a stored 'find'.
QList< QKeySequence > listFromString(const QString &str, QKeySequence::SequenceFormat format)
const QList< QKeySequence > & prior()
Scroll up one page.
void deleteEntry(const QString &pKey, WriteConfigFlags pFlags=Normal)
Deletes the entry specified by pKey in the current group.
@ Prior
Scroll up one page.
const T & at(int i) const const
const QList< QKeySequence > & deleteFile()
Permanently delete files or folders.
@ EditBookmarks
Edit the application bookmarks.
@ Begin
Go to beginning of the document.
@ BeginningOfLine
Go to beginning of current line.
const QList< QKeySequence > & replace()
Find and replace matches.
bool isEmpty() const const
@ New
Create a new document.
T readEntry(const QString &key, const T &aDefault) const
Reads the value of an entry specified by pKey in the current group.
Definition: kconfiggroup.h:258
QString whatsThis(StandardShortcut)
What's This button.
@ ConfigureToolbars
Display the toolbar configuration dialog.
@ Cut
Cut selected area and store it in the clipboard.
int indexOf(QStringView str, int from) const const
@ FullScreen
Full Screen mode.
const QList< QKeySequence > & deleteWordBack()
Delete a word back from mouse/cursor position.
@ ShowMenubar
Show Menu Bar.
@ GotoPage
Go to a specific page.
QString label(StandardShortcut id)
Returns a localized label for user-visible display.
@ Clear
Clear the content of the focus widget.
@ ConfigureNotifications
Display the notifications configuration dialog.
@ Home
Go to home page.
const QList< QKeySequence > & prevCompletion()
Iterate through a list when completion returns multiple items.
@ Donate
Open donation page on kde.org.
const QList< QKeySequence > & quit()
Quit the program.
const QList< QKeySequence > & home()
Go to home page.
@ SubstringCompletion
Find a string within another string or list of strings.
@ KeyBindings
Display the configure key bindings dialog.
QString fromLatin1(const char *str, int size)
@ FitToPage
Fit the document view to the size of the current window.
QString name(StandardShortcut id)
Returns a unique name for the given accel.
const QList< QKeySequence > & save()
Save current document.
@ FitToHeight
Fit the document view to the height of the current window.
const QList< QKeySequence > & deleteWordForward()
Delete a word forward from mouse/cursor position.
const QList< QKeySequence > & print()
Print current document.
const QList< QKeySequence > & next()
Scroll down one page.
bool hasKey(const QString &key) const
Checks whether the key has an entry in this group.
const QList< QKeySequence > & up()
Up.
@ GotoLine
Go to line.
const QList< QKeySequence > & backwardWord()
BackwardWord.
QString listToString(const QList< QKeySequence > &list, QKeySequence::SequenceFormat format)
const QList< QKeySequence > & rotateUp()
Help users iterate through a list of entries.
const QList< QKeySequence > & paste()
Paste contents of clipboard at mouse/cursor position.
@ RotateDown
Help users iterate through a list of entries.
const QList< QKeySequence > & forward()
Forward.
const QList< QKeySequence > & rotateDown()
Help users iterate through a list of entries.
bool sync() override
const QList< QKeySequence > & fullScreen()
Full Screen Mode.
@ Zoom
Select the current zoom level.
@ Quit
Quit the program.
@ Help
Help the user in the current situation.
@ Deselect
Deselect any selected elements.
@ ForwardWord
ForwardWord.
@ Close
Close current document.
@ ReportBug
Display the Report Bug dialog.
const QList< QKeySequence > & moveToTrash()
Moves files or folders to the trash.
@ RenameFile
Rename files or folders.
const QList< QKeySequence > & createFolder()
Create a folder.
@ BackwardWord
BackwardWord.
bool isEmpty() const const
const QList< QKeySequence > & zoomIn()
Zoom in.
@ Redo
Redo last operation.
Category category(StandardShortcut id)
Returns the appropriate category for the given StandardShortcut id.
@ Spelling
Pop up the spell checker.
const QList< QKeySequence > & open()
Open file.
const QList< QKeySequence > & findPrev()
Find a previous instance of a stored 'find'.
const QList< QKeySequence > & completion()
Complete text in input widgets.
@ Revert
Revert the current document to the last saved version.
@ WhatsThis
What's This button.
const QList< QKeySequence > & end()
Go to end of the document.
@ CreateFolder
Create a folder.
const QList< QKeySequence > & copy()
Copy selected area into the clipboard.
const QList< QKeySequence > & redo()
Redo last operation.
@ Mail
Send the current document by mail.
const QList< QKeySequence > & preferences()
Opens the app's settings window.
const QList< QKeySequence > & beginningOfLine()
Go to beginning of current line.
const QList< QKeySequence > & endOfLine()
Go to end of current line.
@ FindNext
Find the next instance of a stored 'find'.
@ DeleteFile
Permanently delete files or folders.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Dec 7 2023 04:08:32 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.