KConfig

kstandardactions.h
1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 1999, 2000 Kurt Granroth <granroth@kde.org>
4 SPDX-FileCopyrightText: 2001, 2002 Ellis Whitehead <ellis@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-only
7*/
8#ifndef KGUISTANDARDACTION_H
9#define KGUISTANDARDACTION_H
10
11#include <QAction>
12#include <QList>
13#include <QStringList>
14
15#include <KStandardShortcut>
16#include <kconfiggui_export.h>
17
18#include <optional>
19#include <type_traits>
20
21class QObject;
22class QAction;
23
24/**
25 * Convenience methods to access all standard KDE actions.
26 *
27 * These actions should be used instead of hardcoding menubar and
28 * toolbar items. Using these actions helps your application easily
29 * conform to the <a href="https://develop.kde.org/hig/">KDE Human Interface Guidelines</a>.
30 *
31 * All of the documentation for QAction holds for KStandardActions
32 * also. When in doubt on how things work, check the QAction
33 * documentation first.
34 * Please note that calling any of these methods automatically adds the action
35 * to the actionCollection() of the QObject given by the 'parent' parameter.
36 *
37 * <b>Simple Example:</b>\n
38 *
39 * In general, using standard actions should be a drop in replacement
40 * for regular actions. For example, if you previously had:
41 * @code
42 * QAction *newAct = new QAction(QIcon::fromTheme("document-new"),
43 * i18n("&New"),
44 * this);
45 * newAct->setShortcut(KStandardShortcut::shortcut(KStandardShortcut::New).constFirst());
46 * connect(newAct, &QAction::triggered, this, &ClassFoo::fileNew);
47 * @endcode
48 *
49 * You can replace it with:
50 * @code
51 * QAction *newAct = KStandardActions::openNew(this, &ClassFoo::fileNew, this);
52 * @endcode
53 *
54 * Alternatively you can instantiate the action using the StandardAction enums
55 * provided. This author can't think of a reason why you would want to, but, hey,
56 * if you do, here's how:
57 *
58 * \code
59 * QAction *newAct = KStandardActions::create(KStandardActions::New, this, &ClassFoo::fileNew, this);
60 * \endcode
61 *
62 * <b>Relationship with KActionCollection from KXMLGui</b>\n
63 *
64 * If a KActionCollection is passed as the parent then the action will be
65 * automatically added to that collection:
66 * \code
67 * QAction *cut = KStandardActions::cut(this, &ClassFoo::editCut, actionCollection());
68 * \endcode
69 *
70 * Each action has a unique internal name which can be queried using the
71 * name method. For example KStandardActions::name(KStandardActions::Cut)
72 * would return 'edit_cut'. This name can be used as a unique identifier
73 * for the actions. So if you wanted to add an existing standard action
74 * to an action collection you can do so like this:
75 * \code
76 * QAction *cut = KStandardActions::cut(this, &ClassFoo::editCut, this);
77 * actionCollection()->addAction(KStandardActions::name(KStandardActions::Cut), cut);
78 * \endcode
79 *
80 * You can then get a pointer to the action using
81 * \code
82 * QAction *cutPtr = actionCollection()->action(KStandardActions::name(KStandardActions::Cut));
83 * \endcode
84 *
85 * @author Kurt Granroth <granroth@kde.org>
86 * @since 6.3
87 */
88namespace KStandardActions
89{
90/**
91 * The standard menubar and toolbar actions.
92 */
94 ActionNone,
95 // File Menu
96 New, ///< Create a new document or window.
97 Open, ///< Open an existing file.
98 OpenRecent, ///< Open a recently used document.
99 Save, ///< Save the current document.
100 SaveAs, ///< Save the current document under a different name.
101 Revert, ///< Revert the current document to the last saved version.
102 Close, ///< Close the current document.
103 Print, ///< Print the current document.
104 PrintPreview, ///< Show a print preview of the current document.
105 Mail, ///< Send the current document by mail.
106 Quit, ///< Quit the program.
107 // Edit Menu
108 Undo, ///< Undo the last operation.
109 Redo, ///< Redo the last operation.
110 Cut, ///< Cut selected area and store it in the clipboard.
111 Copy, ///< Copy selected area and store it in the clipboard.
112 Paste, ///< Paste the contents of clipboard at the current mouse or cursor.
113 SelectAll, ///< Select all elements in the current document.
114 Deselect, ///< Deselect any selected elements in the current document.
115 Find, ///< Initiate a 'find' request in the current document.
116 FindNext, ///< Find the next instance of a stored 'find'
117 FindPrev, ///< Find a previous instance of a stored 'find'.
118 Replace, ///< Find and replace matches.
119 // View Menu
120 ActualSize, ///< View the document at its actual size.
121 FitToPage, ///< Fit the document view to the size of the current window.
122 FitToWidth, ///< Fit the document view to the width of the current window.
123 FitToHeight, ///< Fit the document view to the height of the current window.
124 ZoomIn, ///< Zoom in the current document.
125 ZoomOut, ///< Zoom out the current document.
126 Zoom, ///< Select the current zoom level.
127 Redisplay, ///< Redisplay or redraw the document.
128 // Go Menu
129 Up, ///< Move up (web style menu).
130 Back, ///< Move back (web style menu).
131 Forward, ///< Move forward (web style menu).
132 Home, ///< Go to the "Home" position or document.
133 Prior, ///< Scroll up one page.
134 Next, ///< Scroll down one page.
135 Goto, ///< Jump to some specific location in the document.
136 GotoPage, ///< Go to a specific page.
137 GotoLine, ///< Go to a specific line.
138 FirstPage, ///< Jump to the first page.
139 LastPage, ///< Jump to the last page.
140 DocumentBack, ///< Move back (document style menu).
141 DocumentForward, ///< Move forward (document style menu).
142 // Bookmarks Menu
143 AddBookmark, ///< Add the current page to the bookmarks tree.
144 EditBookmarks, ///< Edit the application bookmarks.
145 // Tools Menu
146 Spelling, ///< Pop up the spell checker.
147 // Settings Menu
148 ShowMenubar, ///< Show/Hide the menubar.
149 ShowToolbar, ///< Show/Hide the toolbar.
150 ShowStatusbar, ///< Show/Hide the statusbar.
151 KeyBindings, ///< Display the configure key bindings dialog.
152 Preferences, ///< Display the preferences/options dialog.
153 ConfigureToolbars, ///< Display the toolbar configuration dialog.
154 // Help Menu
155 HelpContents, ///< Display the handbook of the application.
156 WhatsThis, ///< Trigger the What's This cursor.
157 ReportBug, ///< Open up the Report Bug dialog.
158 AboutApp, ///< Display the application's About box.
159 AboutKDE, ///< Display the About KDE dialog.
160 // Other standard actions
161 ConfigureNotifications, ///< Display the notifications configuration dialog.
162 FullScreen, ///< Switch to/from full screen mode.
163 Clear, ///< Clear the content of the focus widget.
164 SwitchApplicationLanguage, ///< Display the Switch Application Language dialog.
165 DeleteFile, ///< Permanently deletes files or folders.
166 RenameFile, ///< Renames files or folders.
167 MoveToTrash, ///< Moves files or folders to the trash.
168 Donate, ///< Open donation page on kde.org.
169 HamburgerMenu ///< Opens a menu that substitutes the menubar.
170 // To keep in sync with KConfigWidgets::KStandardAction
172
173/**
174 * @internal
175 */
176KCONFIGGUI_EXPORT QAction *_kgui_createInternal(StandardAction id, QObject *parent);
177
178/**
179 * Creates an action corresponding to one of the
180 * KStandardActions::StandardAction actions, which is connected to the given
181 * object and @p slot, and is owned by @p parent.
182 *
183 * If not explicitly specified, @p connectionType will be AutoConnection for all actions
184 * except for ConfigureToolbars it will be QueuedConnection.
185 *
186 * @see create(StandardAction, const QObject *, const char *, QObject *)
187 */
188template<class Receiver, class Func>
189inline QAction *create(StandardAction id, const Receiver *recvr, Func slot, QObject *parent, std::optional<Qt::ConnectionType> connectionType = std::nullopt)
190{
191 QAction *action = _kgui_createInternal(id, parent);
192 // ConfigureToolbars is special because of bug #200815
193 const Qt::ConnectionType defaultConnectionType = (id == ConfigureToolbars) ? Qt::QueuedConnection : Qt::AutoConnection;
194 QObject::connect(action, &QAction::triggered, recvr, slot, connectionType.value_or(defaultConnectionType));
195 return action;
196}
197
198/**
199 * This will return the internal name of a given standard action.
200 */
201KCONFIGGUI_EXPORT QString name(StandardAction id);
202
203/**
204 * Returns a list of all actionIds.
205 */
206KCONFIGGUI_EXPORT QList<StandardAction> actionIds();
207
208/**
209 * Returns the standardshortcut associated with @a actionId.
210 *
211 * @param id The identifier whose associated shortcut is wanted.
212 */
214
215// clang-format off
216#define KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(name, enumValue) \
217 template<class Receiver, class Func> \
218 inline QAction *name(const Receiver *recvr, Func slot, QObject *parent) \
219 { return create(enumValue, recvr, slot, parent); }
220// clang-format on
221
222/**
223 * Create a new document or window.
224 */
225KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(openNew, New)
226
227/**
228 * Open an existing file.
229 */
230KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(open, Open)
231
232/**
233 * Save the current document.
234 */
235KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(save, Save)
236
237/**
238 * Save the current document under a different name.
239 */
240KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(saveAs, SaveAs)
241
242/**
243 * Revert the current document to the last saved version
244 * (essentially will undo all changes).
245 */
246KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(revert, Revert)
247
248/**
249 * Close the current document.
250 */
251KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(close, Close)
252
253/**
254 * Print the current document.
255 */
256KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(print, Print)
257
258/**
259 * Show a print preview of the current document.
260 */
261KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(printPreview, PrintPreview)
262
263/**
264 * Mail this document.
265 */
266KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(mail, Mail)
267
268/**
269 * Quit the program.
270 *
271 * Note that you probably want to connect this action to either QWidget::close()
272 * or QApplication::closeAllWindows(), but not QApplication::quit(), so that
273 * KMainWindow::queryClose() is called on any open window (to warn the user
274 * about unsaved changes for example).
275 */
276KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(quit, Quit)
277
278/**
279 * Undo the last operation.
280 */
281KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(undo, Undo)
282
283/**
284 * Redo the last operation.
285 */
286KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(redo, Redo)
287
288/**
289 * Cut selected area and store it in the clipboard.
290 */
291KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(cut, Cut)
292
293/**
294 * Copy the selected area into the clipboard.
295 */
296KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(copy, Copy)
297
298/**
299 * Paste the contents of clipboard at the current mouse or cursor
300 * position.
301 */
302KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(paste, Paste)
303
304/**
305 * Clear the content of the focus widget
306 */
307KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(clear, Clear)
308
309/**
310 * Select all elements in the current document.
311 */
312KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(selectAll, SelectAll)
313
314/**
315 * Deselect any selected elements in the current document.
316 */
317KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(deselect, Deselect)
318
319/**
320 * Initiate a 'find' request in the current document.
321 */
322KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(find, Find)
323
324/**
325 * Find the next instance of a stored 'find'.
326 */
327KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(findNext, FindNext)
328
329/**
330 * Find a previous instance of a stored 'find'.
331 */
332KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(findPrev, FindPrev)
333
334/**
335 * Find and replace matches.
336 */
337KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(replace, Replace)
338
339/**
340 * View the document at its actual size.
341 */
342KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(actualSize, ActualSize)
343
344/**
345 * Fit the document view to the size of the current window.
346 */
347KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(fitToPage, FitToPage)
348
349/**
350 * Fit the document view to the width of the current window.
351 */
352KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(fitToWidth, FitToWidth)
353
354/**
355 * Fit the document view to the height of the current window.
356 */
357KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(fitToHeight, FitToHeight)
358
359/**
360 * Zoom in the current document view.
361 */
362KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(zoomIn, ZoomIn)
363
364/**
365 * Zoom out the current document view.
366 */
367KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(zoomOut, ZoomOut)
368
369/**
370 * Select the current zoom level.
371 */
372KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(zoom, Zoom)
373
374/**
375 * Redisplay or redraw the document.
376 */
377KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(redisplay, Redisplay)
378
379/**
380 * Move up (web style menu).
381 */
382KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(up, Up)
383
384/**
385 * Move back (web style menu).
386 */
387KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(back, Back)
388
389/**
390 * Move forward (web style menu).
391 */
392KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(forward, Forward)
393
394/**
395 * Go to the "Home" position or document.
396 */
397KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(home, Home)
398
399/**
400 * Scroll up one page.
401 */
402KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(prior, Prior)
403
404/**
405 * Scroll down one page.
406 */
407KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(next, Next)
408
409/**
410 * Jump to some specific location in the document.
411 */
412KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(goTo, Goto)
413
414/**
415 * Go to a specific page.
416 */
417KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(gotoPage, GotoPage)
418
419/**
420 * Go to a specific line.
421 */
422KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(gotoLine, GotoLine)
423
424/**
425 * Jump to the first page.
426 */
427KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(firstPage, FirstPage)
428
429/**
430 * Jump to the last page.
431 */
432KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(lastPage, LastPage)
433
434/**
435 * Move back (document style menu).
436 */
437KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(documentBack, DocumentBack)
438
439/**
440 * Move forward (document style menu).
441 */
442KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(documentForward, DocumentForward)
443
444/**
445 * Add the current page to the bookmarks tree.
446 */
447KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(addBookmark, AddBookmark)
448
449/**
450 * Edit the application bookmarks.
451 */
452KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(editBookmarks, EditBookmarks)
453
454/**
455 * Pop up the spell checker.
456 */
457KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(spelling, Spelling)
458
459/**
460 * Display the configure key bindings dialog.
461 *
462 * Note that you might be able to use the pre-built KXMLGUIFactory's function:
463 * @code
464 * KStandardActions::keyBindings(guiFactory(), &KXMLGUIFactory::showConfigureShortcutsDialog, actionCollection());
465 * @endcode
466 */
467KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(keyBindings, KeyBindings)
468
469/**
470 * Display the preferences/options dialog.
471 */
472KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(preferences, Preferences)
473
474/**
475 * Display the toolbar configuration dialog.
476 */
477KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(configureToolbars, ConfigureToolbars)
478
479/**
480 * Display the notifications configuration dialog.
481 */
482KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(configureNotifications, ConfigureNotifications)
483
484/**
485 * Display the Switch Application Language dialog.
486 */
487KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(switchApplicationLanguage, SwitchApplicationLanguage)
488
489/**
490 * Display the handbook of the application.
491 */
492KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(helpContents, HelpContents)
493
494/**
495 * Trigger the What's This cursor.
496 */
497KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(whatsThis, WhatsThis)
498
499/**
500 * Open up the Report Bug dialog.
501 */
502KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(reportBug, ReportBug)
503
504/**
505 * Display the application's About box.
506 */
507KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(aboutApp, AboutApp)
508
509/**
510 * Display the About KDE dialog.
511 */
512KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(aboutKDE, AboutKDE)
513
514/**
515 * Permanently deletes files or folders.
516 */
517KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(deleteFile, DeleteFile)
518
519/**
520 * Renames files or folders.
521 */
522KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(renameFile, RenameFile)
523
524/**
525 * Moves files or folders to the trash.
526 */
527KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(moveToTrash, MoveToTrash)
528
529/**
530 * Open donation page on kde.org.
531 */
532KGUISTANDARDACTION_WITH_NEW_STYLE_CONNECT(donate, Donate)
533}
534
535#endif // KSTDACTION_H
Convenience methods to access all standard KDE actions.
KStandardShortcut::StandardShortcut shortcutForActionId(StandardAction id)
Returns the standardshortcut associated with actionId.
QString name(StandardAction id)
This will return the internal name of a given standard action.
QAction * _kgui_createInternal(StandardAction id, QObject *parent)
StandardAction
The standard menubar and toolbar actions.
@ SaveAs
Save the current document under a different name.
@ Revert
Revert the current document to the last saved version.
@ AboutKDE
Display the About KDE dialog.
@ GotoPage
Go to a specific page.
@ Mail
Send the current document by mail.
@ OpenRecent
Open a recently used document.
@ GotoLine
Go to a specific line.
@ Goto
Jump to some specific location in the document.
@ Deselect
Deselect any selected elements in the current document.
@ ZoomIn
Zoom in the current document.
@ FitToHeight
Fit the document view to the height of the current window.
@ FullScreen
Switch to/from full screen mode.
@ Clear
Clear the content of the focus widget.
@ Open
Open an existing file.
@ Save
Save the current document.
@ HamburgerMenu
Opens a menu that substitutes the menubar.
@ ShowToolbar
Show/Hide the toolbar.
@ ReportBug
Open up the Report Bug dialog.
@ Next
Scroll down one page.
@ WhatsThis
Trigger the What's This cursor.
@ Home
Go to the "Home" position or document.
@ RenameFile
Renames files or folders.
@ Spelling
Pop up the spell checker.
@ Prior
Scroll up one page.
@ SwitchApplicationLanguage
Display the Switch Application Language dialog.
@ FitToWidth
Fit the document view to the width of the current window.
@ New
Create a new document or window.
@ ConfigureToolbars
Display the toolbar configuration dialog.
@ ConfigureNotifications
Display the notifications configuration dialog.
@ SelectAll
Select all elements in the current document.
@ FindNext
Find the next instance of a stored 'find'.
@ Undo
Undo the last operation.
@ Donate
Open donation page on kde.org.
@ Print
Print the current document.
@ Up
Move up (web style menu).
@ AddBookmark
Add the current page to the bookmarks tree.
@ Replace
Find and replace matches.
@ LastPage
Jump to the last page.
@ Cut
Cut selected area and store it in the clipboard.
@ KeyBindings
Display the configure key bindings dialog.
@ FindPrev
Find a previous instance of a stored 'find'.
@ Redo
Redo the last operation.
@ Copy
Copy selected area and store it in the clipboard.
@ ShowMenubar
Show/Hide the menubar.
@ DocumentForward
Move forward (document style menu).
@ Back
Move back (web style menu).
@ ZoomOut
Zoom out the current document.
@ PrintPreview
Show a print preview of the current document.
@ Zoom
Select the current zoom level.
@ ActualSize
View the document at its actual size.
@ Forward
Move forward (web style menu).
@ Close
Close the current document.
@ DeleteFile
Permanently deletes files or folders.
@ EditBookmarks
Edit the application bookmarks.
@ FitToPage
Fit the document view to the size of the current window.
@ FirstPage
Jump to the first page.
@ AboutApp
Display the application's About box.
@ DocumentBack
Move back (document style menu).
@ MoveToTrash
Moves files or folders to the trash.
@ HelpContents
Display the handbook of the application.
@ Quit
Quit the program.
@ ShowStatusbar
Show/Hide the statusbar.
@ Preferences
Display the preferences/options dialog.
@ Find
Initiate a 'find' request in the current document.
@ Paste
Paste the contents of clipboard at the current mouse or cursor.
@ Redisplay
Redisplay or redraw the document.
QAction * create(StandardAction id, const Receiver *recvr, Func slot, QObject *parent, std::optional< Qt::ConnectionType > connectionType=std::nullopt)
Creates an action corresponding to one of the KStandardActions::StandardAction actions,...
QList< StandardAction > actionIds()
Returns a list of all actionIds.
StandardShortcut
Defines the identifier of all standard accelerators.
void triggered(bool checked)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
ConnectionType
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:18:27 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.