Krita Source Code Documentation
Loading...
Searching...
No Matches
kstandardaction_p.h
Go to the documentation of this file.
1/* This file is part of the KDE libraries
2 SPDX-FileCopyrightText: 1999, 2000 Kurt Granroth <granroth@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-only
5*/
6
7#ifndef KSTANDARDACTION_PRIVATE_H
8#define KSTANDARDACTION_PRIVATE_H
9
10#include <QAction>
11#include <QApplication>
12#include <QWidget>
13
14#include <klocalizedstring.h>
15#include <kstandardshortcut.h>
16
17namespace KStandardAction
18{
19
22 KStandardShortcut::StandardShortcut idAccel;
23 const char *psName;
24 const char *psLabel;
25 const char *psToolTip;
26 const char *psIconName;
27};
28
29
30// clang-format off
31
32static constexpr KStandardActionInfo g_rgActionInfo[] = {
33 { New, KStandardShortcut::New, "file_new", QT_TRANSLATE_NOOP("KStandardActions", "&New"), QT_TRANSLATE_NOOP("KStandardActions", "Create new document"), "document-new" },
34 { Open, KStandardShortcut::Open, "file_open", QT_TRANSLATE_NOOP("KStandardActions", "&Open…"), QT_TRANSLATE_NOOP("KStandardActions", "Open an existing document"), "document-open" },
35 { OpenRecent, KStandardShortcut::AccelNone, "file_open_recent", QT_TRANSLATE_NOOP("KStandardActions", "Open &Recent"), QT_TRANSLATE_NOOP("KStandardActions", "Open a document which was recently opened"), "document-open-recent" },
36 { Save, KStandardShortcut::Save, "file_save", QT_TRANSLATE_NOOP("KStandardActions", "&Save"), QT_TRANSLATE_NOOP("KStandardActions", "Save document"), "document-save" },
37 { SaveAs, KStandardShortcut::SaveAs, "file_save_as", QT_TRANSLATE_NOOP("KStandardActions", "Save &As…"), QT_TRANSLATE_NOOP("KStandardActions", "Save document under a new name"), "document-save-as" },
38 { Revert, KStandardShortcut::Revert, "file_revert", QT_TRANSLATE_NOOP("KStandardActions", "Re&vert"), QT_TRANSLATE_NOOP("KStandardActions", "Revert unsaved changes made to document"), "document-revert" },
39 { Close, KStandardShortcut::Close, "file_close", QT_TRANSLATE_NOOP("KStandardActions", "&Close"), QT_TRANSLATE_NOOP("KStandardActions", "Close document"), "document-close" },
40 { Print, KStandardShortcut::Print, "file_print", QT_TRANSLATE_NOOP("KStandardActions", "&Print…"), QT_TRANSLATE_NOOP("KStandardActions", "Print document"), "document-print" },
41 { PrintPreview, KStandardShortcut::PrintPreview, "file_print_preview", QT_TRANSLATE_NOOP("KStandardActions", "Print Previe&w"), QT_TRANSLATE_NOOP("KStandardActions", "Show a print preview of document"), "document-print-preview" },
42 { Mail, KStandardShortcut::Mail, "file_mail", QT_TRANSLATE_NOOP("KStandardActions", "&Mail…"), QT_TRANSLATE_NOOP("KStandardActions", "Send document by mail"), "mail-send" },
43 { Quit, KStandardShortcut::Quit, "file_quit", QT_TRANSLATE_NOOP("KStandardActions", "&Quit"), QT_TRANSLATE_NOOP("KStandardActions", "Quit application"), "application-exit" },
44
45 { Undo, KStandardShortcut::Undo, "edit_undo", QT_TRANSLATE_NOOP("KStandardActions", "&Undo"), QT_TRANSLATE_NOOP("KStandardActions", "Undo last action"), "edit-undo" },
46 { Redo, KStandardShortcut::Redo, "edit_redo", QT_TRANSLATE_NOOP("KStandardActions", "Re&do"), QT_TRANSLATE_NOOP("KStandardActions", "Redo last undone action"), "edit-redo" },
47 { Cut, KStandardShortcut::Cut, "edit_cut", QT_TRANSLATE_NOOP("KStandardActions", "Cu&t"), QT_TRANSLATE_NOOP("KStandardActions", "Cut selection to clipboard"), "edit-cut" },
48 { Copy, KStandardShortcut::Copy, "edit_copy", QT_TRANSLATE_NOOP("KStandardActions", "&Copy"), QT_TRANSLATE_NOOP("KStandardActions", "Copy selection to clipboard"), "edit-copy" },
49 { Paste, KStandardShortcut::Paste, "edit_paste", QT_TRANSLATE_NOOP("KStandardActions", "&Paste"), QT_TRANSLATE_NOOP("KStandardActions", "Paste clipboard content"), "edit-paste" },
50 { Clear, KStandardShortcut::Clear, "edit_clear", QT_TRANSLATE_NOOP("KStandardActions", "C&lear"), {}, "edit-clear" },
51 { SelectAll, KStandardShortcut::SelectAll, "edit_select_all", QT_TRANSLATE_NOOP("KStandardActions", "Select &All"), {}, "edit-select-all" },
52 { Deselect, KStandardShortcut::Deselect, "edit_deselect", QT_TRANSLATE_NOOP("KStandardActions", "Dese&lect"), {}, "edit-select-none" },
53 { Find, KStandardShortcut::Find, "edit_find", QT_TRANSLATE_NOOP("KStandardActions", "&Find…"), {}, "edit-find" },
54 { FindNext, KStandardShortcut::FindNext, "edit_find_next", QT_TRANSLATE_NOOP("KStandardActions", "Find &Next"), {}, "go-down-search" },
55 { FindPrev, KStandardShortcut::FindPrev, "edit_find_prev", QT_TRANSLATE_NOOP("KStandardActions", "Find Pre&vious"), {}, "go-up-search" },
56 { Replace, KStandardShortcut::Replace, "edit_replace", QT_TRANSLATE_NOOP("KStandardActions", "&Replace…"), {}, "edit-find-replace" },
57
58 { ActualSize, KStandardShortcut::ActualSize, "view_actual_size", QT_TRANSLATE_NOOP("KStandardActions", "Zoom to &Actual Size"), QT_TRANSLATE_NOOP("KStandardActions", "View document at its actual size"), "zoom-original" },
59 { FitToPage, KStandardShortcut::FitToPage, "view_fit_to_page", QT_TRANSLATE_NOOP("KStandardActions", "&Fit to Page"), QT_TRANSLATE_NOOP("KStandardActions", "Zoom to fit page in window"), "zoom-fit-page" },
60 { FitToWidth, KStandardShortcut::FitToWidth, "view_fit_to_width", QT_TRANSLATE_NOOP("KStandardActions", "Fit to Page &Width"), QT_TRANSLATE_NOOP("KStandardActions", "Zoom to fit page width in window"), "zoom-fit-width" },
61 { FitToHeight, KStandardShortcut::FitToHeight, "view_fit_to_height", QT_TRANSLATE_NOOP("KStandardActions", "Fit to Page &Height"), QT_TRANSLATE_NOOP("KStandardActions", "Zoom to fit page height in window"), "zoom-fit-height" },
62 { ZoomIn, KStandardShortcut::ZoomIn, "view_zoom_in", QT_TRANSLATE_NOOP("KStandardActions", "Zoom &In"), {}, "zoom-in" },
63 { ZoomOut, KStandardShortcut::ZoomOut, "view_zoom_out", QT_TRANSLATE_NOOP("KStandardActions", "Zoom &Out"), {}, "zoom-out" },
64 { Zoom, KStandardShortcut::Zoom, "view_zoom", QT_TRANSLATE_NOOP("KStandardActions", "&Zoom…"), QT_TRANSLATE_NOOP("KStandardActions", "Select zoom level"), "zoom" },
65 { Redisplay, KStandardShortcut::Reload, "view_redisplay", QT_TRANSLATE_NOOP("KStandardActions", "&Refresh"), QT_TRANSLATE_NOOP("KStandardActions", "Refresh document"), "view-refresh" },
66
67 { Up, KStandardShortcut::Up, "go_up", QT_TRANSLATE_NOOP("KStandardActions", "&Up"), QT_TRANSLATE_NOOP("KStandardActions", "Go up"), "go-up" },
68 // The following three have special i18n() needs for sLabel
69 { Back, KStandardShortcut::Back, "go_back", {}, {}, "go-previous" },
70 { Forward, KStandardShortcut::Forward, "go_forward", {}, {}, "go-next" },
71 { Home, KStandardShortcut::Home, "go_home", {}, {}, "go-home" },
72 { Prior, KStandardShortcut::Prior, "go_previous", QT_TRANSLATE_NOOP("KStandardActions", "&Previous Page"), QT_TRANSLATE_NOOP("KStandardActions", "Go to previous page"), "go-previous-view-page" },
73 { Next, KStandardShortcut::Next, "go_next", QT_TRANSLATE_NOOP("KStandardActions", "&Next Page"), QT_TRANSLATE_NOOP("KStandardActions", "Go to next page"), "go-next-view-page" },
74 { Goto, KStandardShortcut::Goto, "go_goto", QT_TRANSLATE_NOOP("KStandardActions", "&Go To…"), {}, {} },
75 { GotoPage, KStandardShortcut::GotoPage, "go_goto_page", QT_TRANSLATE_NOOP("KStandardActions", "&Go to Page…"), {}, "go-jump" },
76 { GotoLine, KStandardShortcut::GotoLine, "go_goto_line", QT_TRANSLATE_NOOP("KStandardActions", "&Go to Line…"), {}, {} },
77 { FirstPage, KStandardShortcut::Begin, "go_first", QT_TRANSLATE_NOOP("KStandardActions", "&First Page"), QT_TRANSLATE_NOOP("KStandardActions", "Go to first page"), "go-first-view-page" },
78 { LastPage, KStandardShortcut::End, "go_last", QT_TRANSLATE_NOOP("KStandardActions", "&Last Page"), QT_TRANSLATE_NOOP("KStandardActions", "Go to last page"), "go-last-view-page" },
79 { DocumentBack, KStandardShortcut::DocumentBack, "go_document_back", QT_TRANSLATE_NOOP("KStandardActions", "&Back"), QT_TRANSLATE_NOOP("KStandardActions", "Go back in document"), "go-previous" },
80 { DocumentForward, KStandardShortcut::DocumentForward, "go_document_forward", QT_TRANSLATE_NOOP("KStandardActions", "&Forward"), QT_TRANSLATE_NOOP("KStandardActions", "Go forward in document"), "go-next" },
81
82 { AddBookmark, KStandardShortcut::AddBookmark, "bookmark_add", QT_TRANSLATE_NOOP("KStandardActions", "&Add Bookmark"), {}, "bookmark-new" },
83 { EditBookmarks, KStandardShortcut::EditBookmarks, "bookmark_edit", QT_TRANSLATE_NOOP("KStandardActions", "&Edit Bookmarks…"), {}, "bookmarks-organize" },
84
85 { Spelling, KStandardShortcut::Spelling, "tools_spelling", QT_TRANSLATE_NOOP("KStandardActions", "&Spelling…"), QT_TRANSLATE_NOOP("KStandardActions", "Check spelling in document"), "tools-check-spelling" },
86
87 { ShowMenubar, KStandardShortcut::ShowMenubar, "options_show_menubar", QT_TRANSLATE_NOOP("KStandardActions", "Show &Menubar"), QT_TRANSLATE_NOOP("KStandardActions", "Show or hide menubar"), "show-men" },
88 { ShowToolbar, KStandardShortcut::ShowToolbar, "options_show_toolbar", QT_TRANSLATE_NOOP("KStandardActions", "Show &Toolbar"), QT_TRANSLATE_NOOP("KStandardActions", "Show or hide toolbar"), {} },
89 { ShowStatusbar, KStandardShortcut::ShowStatusbar, "options_show_statusbar", QT_TRANSLATE_NOOP("KStandardActions", "Show St&atusbar"), QT_TRANSLATE_NOOP("KStandardActions", "Show or hide statusbar"), {} },
90 { FullScreen, KStandardShortcut::FullScreen, "fullscreen", QT_TRANSLATE_NOOP("KStandardActions", "F&ull Screen Mode"), {}, "view-fullscreen" },
91 { KeyBindings, KStandardShortcut::KeyBindings, "options_configure_keybinding", QT_TRANSLATE_NOOP("KStandardActions", "Configure Keyboard S&hortcuts…"), {}, "configure-shortcuts" },
92 { Preferences, KStandardShortcut::Preferences, "options_configure", QT_TRANSLATE_NOOP("KStandardActions", "&Configure %1…"), {}, "configure" },
93 { ConfigureToolbars, KStandardShortcut::ConfigureToolbars, "options_configure_toolbars", QT_TRANSLATE_NOOP("KStandardActions", "Configure Tool&bars…"), {}, "configure-toolbars" },
94 { ConfigureNotifications, KStandardShortcut::ConfigureNotifications, "options_configure_notifications", QT_TRANSLATE_NOOP("KStandardActions", "Configure &Notifications…"), {}, "preferences-desktop-notification" },
95
96 // the idea here is that Contents is used in menus, and Help in dialogs, so both share the same
97 // shortcut
98 { HelpContents, KStandardShortcut::Help, "help_contents", QT_TRANSLATE_NOOP("KStandardActions", "%1 &Handbook"), {}, "help-contents" },
99 { WhatsThis, KStandardShortcut::WhatsThis, "help_whats_this", QT_TRANSLATE_NOOP("KStandardActions", "What's &This?"), {}, "help-contextual" },
100 { ReportBug, KStandardShortcut::ReportBug, "help_report_bug", QT_TRANSLATE_NOOP("KStandardActions", "&Report Bug…"), {}, "tools-report-bug" },
101 { SwitchApplicationLanguage, KStandardShortcut::SwitchApplicationLanguage, "switch_application_language", QT_TRANSLATE_NOOP("KStandardActions", "Configure &Language…"), {}, "preferences-desktop-locale" },
102 { AboutApp, KStandardShortcut::AccelNone, "help_about_app", QT_TRANSLATE_NOOP("KStandardActions", "&About %1"), {}, nullptr },
103 { AboutKDE, KStandardShortcut::AccelNone, "help_about_kde", QT_TRANSLATE_NOOP("KStandardActions", "About &KDE"), {}, "kde" },
104 { ActionNone, KStandardShortcut::AccelNone, {}, {}, {}, {} },
105 };
106
107
108// clang-format on
109
111{
112 for (uint i = 0; g_rgActionInfo[i].id != ActionNone; i++) {
113 if (g_rgActionInfo[i].id == id) {
114 return &g_rgActionInfo[i];
115 }
116 }
117
118 return 0;
119}
120
122{
123 QStringList result;
124
125 for (uint i = 0; g_rgActionInfo[i].id != ActionNone; i++)
126 if (g_rgActionInfo[i].psLabel) {
127 if (QByteArray(g_rgActionInfo[i].psLabel).contains("%1"))
128 // Prevents i18n from complaining about unsubstituted placeholder.
129 {
130 result.append(i18n(g_rgActionInfo[i].psLabel, QString()));
131 } else {
132 result.append(i18n(g_rgActionInfo[i].psLabel));
133 }
134 }
135
136 return result;
137}
138
139class AutomaticAction : public QAction
140{
141 Q_OBJECT
142
143public:
144 AutomaticAction(const QIcon &icon, const QString &text, const QList<QKeySequence> &shortcut, const char *slot,
145 QObject *parent);
146public Q_SLOTS:
147 inline void cut()
148 {
149 invokeEditSlot("cut");
150 }
151 inline void copy()
152 {
153 invokeEditSlot("copy");
154 }
155 inline void paste()
156 {
157 invokeEditSlot("paste");
158 }
159 inline void clear()
160 {
161 invokeEditSlot("clear");
162 }
163 inline void selectAll()
164 {
165 invokeEditSlot("selectAll");
166 }
167
168 void invokeEditSlot(const char *slot)
169 {
170 if (qApp->focusWidget()) {
171 QMetaObject::invokeMethod(qApp->focusWidget(), slot);
172 }
173 }
174
175};
176
177}
178
179#endif
unsigned int uint
AutomaticAction(const QIcon &icon, const QString &text, const QList< QKeySequence > &shortcut, const char *slot, QObject *parent)
void invokeEditSlot(const char *slot)
static QStringList internal_stdNames()
const KStandardActionInfo * infoPtr(StandardAction id)
static constexpr KStandardActionInfo g_rgActionInfo[]
KStandardShortcut::StandardShortcut idAccel