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
46// clang-format off
47
48static constexpr KStandardActionInfo g_rgActionInfo[] = {
49 { New, KStandardShortcut::New, "file_new", QT_TRANSLATE_NOOP("KStandardActions", "&New"), QT_TRANSLATE_NOOP("KStandardActions", "Create new document"), "document-new" },
50 { Open, KStandardShortcut::Open, "file_open", QT_TRANSLATE_NOOP("KStandardActions", "&Open…"), QT_TRANSLATE_NOOP("KStandardActions", "Open an existing document"), "document-open" },
51 { 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" },
52 { Save, KStandardShortcut::Save, "file_save", QT_TRANSLATE_NOOP("KStandardActions", "&Save"), QT_TRANSLATE_NOOP("KStandardActions", "Save document"), "document-save" },
53 { 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" },
54 { Revert, KStandardShortcut::Revert, "file_revert", QT_TRANSLATE_NOOP("KStandardActions", "Re&vert"), QT_TRANSLATE_NOOP("KStandardActions", "Revert unsaved changes made to document"), "document-revert" },
55 { Close, KStandardShortcut::Close, "file_close", QT_TRANSLATE_NOOP("KStandardActions", "&Close"), QT_TRANSLATE_NOOP("KStandardActions", "Close document"), "document-close" },
56 { Print, KStandardShortcut::Print, "file_print", QT_TRANSLATE_NOOP("KStandardActions", "&Print…"), QT_TRANSLATE_NOOP("KStandardActions", "Print document"), "document-print" },
57 { 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" },
58 { Mail, KStandardShortcut::Mail, "file_mail", QT_TRANSLATE_NOOP("KStandardActions", "&Mail…"), QT_TRANSLATE_NOOP("KStandardActions", "Send document by mail"), "mail-send" },
59 { Quit, KStandardShortcut::Quit, "file_quit", QT_TRANSLATE_NOOP("KStandardActions", "&Quit"), QT_TRANSLATE_NOOP("KStandardActions", "Quit application"), "application-exit" },
60
61 { Undo, KStandardShortcut::Undo, "edit_undo", QT_TRANSLATE_NOOP("KStandardActions", "&Undo"), QT_TRANSLATE_NOOP("KStandardActions", "Undo last action"), "edit-undo" },
62 { Redo, KStandardShortcut::Redo, "edit_redo", QT_TRANSLATE_NOOP("KStandardActions", "Re&do"), QT_TRANSLATE_NOOP("KStandardActions", "Redo last undone action"), "edit-redo" },
63 { Cut, KStandardShortcut::Cut, "edit_cut", QT_TRANSLATE_NOOP("KStandardActions", "Cu&t"), QT_TRANSLATE_NOOP("KStandardActions", "Cut selection to clipboard"), "edit-cut" },
64 { Copy, KStandardShortcut::Copy, "edit_copy", QT_TRANSLATE_NOOP("KStandardActions", "&Copy"), QT_TRANSLATE_NOOP("KStandardActions", "Copy selection to clipboard"), "edit-copy" },
65 { Paste, KStandardShortcut::Paste, "edit_paste", QT_TRANSLATE_NOOP("KStandardActions", "&Paste"), QT_TRANSLATE_NOOP("KStandardActions", "Paste clipboard content"), "edit-paste" },
66 { Clear, KStandardShortcut::Clear, "edit_clear", QT_TRANSLATE_NOOP("KStandardActions", "C&lear"), {}, "edit-clear" },
67 { SelectAll, KStandardShortcut::SelectAll, "edit_select_all", QT_TRANSLATE_NOOP("KStandardActions", "Select &All"), {}, "edit-select-all" },
68 { Deselect, KStandardShortcut::Deselect, "edit_deselect", QT_TRANSLATE_NOOP("KStandardActions", "Dese&lect"), {}, "edit-select-none" },
69 { Find, KStandardShortcut::Find, "edit_find", QT_TRANSLATE_NOOP("KStandardActions", "&Find…"), {}, "edit-find" },
70 { FindNext, KStandardShortcut::FindNext, "edit_find_next", QT_TRANSLATE_NOOP("KStandardActions", "Find &Next"), {}, "go-down-search" },
71 { FindPrev, KStandardShortcut::FindPrev, "edit_find_prev", QT_TRANSLATE_NOOP("KStandardActions", "Find Pre&vious"), {}, "go-up-search" },
72 { Replace, KStandardShortcut::Replace, "edit_replace", QT_TRANSLATE_NOOP("KStandardActions", "&Replace…"), {}, "edit-find-replace" },
73
74 { 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" },
75 { 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" },
76 { 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" },
77 { 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" },
78 { ZoomIn, KStandardShortcut::ZoomIn, "view_zoom_in", QT_TRANSLATE_NOOP("KStandardActions", "Zoom &In"), {}, "zoom-in" },
79 { ZoomOut, KStandardShortcut::ZoomOut, "view_zoom_out", QT_TRANSLATE_NOOP("KStandardActions", "Zoom &Out"), {}, "zoom-out" },
80 { Zoom, KStandardShortcut::Zoom, "view_zoom", QT_TRANSLATE_NOOP("KStandardActions", "&Zoom…"), QT_TRANSLATE_NOOP("KStandardActions", "Select zoom level"), "zoom" },
81 { Redisplay, KStandardShortcut::Reload, "view_redisplay", QT_TRANSLATE_NOOP("KStandardActions", "&Refresh"), QT_TRANSLATE_NOOP("KStandardActions", "Refresh document"), "view-refresh" },
82
83 { Up, KStandardShortcut::Up, "go_up", QT_TRANSLATE_NOOP("KStandardActions", "&Up"), QT_TRANSLATE_NOOP("KStandardActions", "Go up"), "go-up" },
84 // The following three have special i18n() needs for sLabel
85 { Back, KStandardShortcut::Back, "go_back", {}, {}, "go-previous" },
86 { Forward, KStandardShortcut::Forward, "go_forward", {}, {}, "go-next" },
87 { Home, KStandardShortcut::Home, "go_home", {}, {}, "go-home" },
88 { Prior, KStandardShortcut::Prior, "go_previous", QT_TRANSLATE_NOOP("KStandardActions", "&Previous Page"), QT_TRANSLATE_NOOP("KStandardActions", "Go to previous page"), "go-previous-view-page" },
89 { Next, KStandardShortcut::Next, "go_next", QT_TRANSLATE_NOOP("KStandardActions", "&Next Page"), QT_TRANSLATE_NOOP("KStandardActions", "Go to next page"), "go-next-view-page" },
90 { Goto, KStandardShortcut::Goto, "go_goto", QT_TRANSLATE_NOOP("KStandardActions", "&Go To…"), {}, {} },
91 { GotoPage, KStandardShortcut::GotoPage, "go_goto_page", QT_TRANSLATE_NOOP("KStandardActions", "&Go to Page…"), {}, "go-jump" },
92 { GotoLine, KStandardShortcut::GotoLine, "go_goto_line", QT_TRANSLATE_NOOP("KStandardActions", "&Go to Line…"), {}, {} },
93 { FirstPage, KStandardShortcut::Begin, "go_first", QT_TRANSLATE_NOOP("KStandardActions", "&First Page"), QT_TRANSLATE_NOOP("KStandardActions", "Go to first page"), "go-first-view-page" },
94 { LastPage, KStandardShortcut::End, "go_last", QT_TRANSLATE_NOOP("KStandardActions", "&Last Page"), QT_TRANSLATE_NOOP("KStandardActions", "Go to last page"), "go-last-view-page" },
95 { DocumentBack, KStandardShortcut::DocumentBack, "go_document_back", QT_TRANSLATE_NOOP("KStandardActions", "&Back"), QT_TRANSLATE_NOOP("KStandardActions", "Go back in document"), "go-previous" },
96 { DocumentForward, KStandardShortcut::DocumentForward, "go_document_forward", QT_TRANSLATE_NOOP("KStandardActions", "&Forward"), QT_TRANSLATE_NOOP("KStandardActions", "Go forward in document"), "go-next" },
97
98 { AddBookmark, KStandardShortcut::AddBookmark, "bookmark_add", QT_TRANSLATE_NOOP("KStandardActions", "&Add Bookmark"), {}, "bookmark-new" },
99 { EditBookmarks, KStandardShortcut::EditBookmarks, "bookmark_edit", QT_TRANSLATE_NOOP("KStandardActions", "&Edit Bookmarks…"), {}, "bookmarks-organize" },
100
101 { Spelling, KStandardShortcut::Spelling, "tools_spelling", QT_TRANSLATE_NOOP("KStandardActions", "&Spelling…"), QT_TRANSLATE_NOOP("KStandardActions", "Check spelling in document"), "tools-check-spelling" },
102
103 { ShowMenubar, KStandardShortcut::ShowMenubar, "options_show_menubar", QT_TRANSLATE_NOOP("KStandardActions", "Show &Menubar"), QT_TRANSLATE_NOOP("KStandardActions", "Show or hide menubar"), "show-men" },
104 { ShowToolbar, KStandardShortcut::ShowToolbar, "options_show_toolbar", QT_TRANSLATE_NOOP("KStandardActions", "Show &Toolbar"), QT_TRANSLATE_NOOP("KStandardActions", "Show or hide toolbar"), {} },
105 { ShowStatusbar, KStandardShortcut::ShowStatusbar, "options_show_statusbar", QT_TRANSLATE_NOOP("KStandardActions", "Show St&atusbar"), QT_TRANSLATE_NOOP("KStandardActions", "Show or hide statusbar"), {} },
106 { FullScreen, KStandardShortcut::FullScreen, "fullscreen", QT_TRANSLATE_NOOP("KStandardActions", "F&ull Screen Mode"), {}, "view-fullscreen" },
107 { KeyBindings, KStandardShortcut::KeyBindings, "options_configure_keybinding", QT_TRANSLATE_NOOP("KStandardActions", "Configure Keyboard S&hortcuts…"), {}, "configure-shortcuts" },
108 { Preferences, KStandardShortcut::Preferences, "options_configure", QT_TRANSLATE_NOOP("KStandardActions", "&Configure Krita..."), {}, "configure" },
109 { ConfigureToolbars, KStandardShortcut::ConfigureToolbars, "options_configure_toolbars", QT_TRANSLATE_NOOP("KStandardActions", "Configure Tool&bars…"), {}, "configure-toolbars" },
110 { ConfigureNotifications, KStandardShortcut::ConfigureNotifications, "options_configure_notifications", QT_TRANSLATE_NOOP("KStandardActions", "Configure &Notifications…"), {}, "preferences-desktop-notification" },
111
112 // the idea here is that Contents is used in menus, and Help in dialogs, so both share the same
113 // shortcut
114 { HelpContents, KStandardShortcut::Help, "help_contents", QT_TRANSLATE_NOOP("KStandardActions", "Krita &Handbook"), {}, "help-contents" },
115 { WhatsThis, KStandardShortcut::WhatsThis, "help_whats_this", QT_TRANSLATE_NOOP("KStandardActions", "What's &This?"), {}, "help-contextual" },
116 { ReportBug, KStandardShortcut::ReportBug, "help_report_bug", QT_TRANSLATE_NOOP("KStandardActions", "&Report Bug..."), {}, "tools-report-bug" },
117 { SwitchApplicationLanguage, KStandardShortcut::SwitchApplicationLanguage, "switch_application_language", QT_TRANSLATE_NOOP("KStandardActions", "Switch Application &Language..."), {}, "preferences-desktop-locale" },
118 { AboutApp, KStandardShortcut::AccelNone, "help_about_app", QT_TRANSLATE_NOOP("KStandardActions", "&About Krita"), {}, nullptr },
119 { AboutKDE, KStandardShortcut::AccelNone, "help_about_kde", QT_TRANSLATE_NOOP("KStandardActions", "About &KDE"), {}, "kde" },
120 { ActionNone, KStandardShortcut::AccelNone, {}, {}, {}, {} },
121 };
122
123
124// clang-format on
125
127{
128 for (uint i = 0; g_rgActionInfo[i].id != ActionNone; i++) {
129 if (g_rgActionInfo[i].id == id) {
130 return &g_rgActionInfo[i];
131 }
132 }
133
134 return 0;
135}
136
138{
139 QStringList result;
140
141 for (uint i = 0; g_rgActionInfo[i].id != ActionNone; i++)
142 if (g_rgActionInfo[i].psLabel) {
143 if (QByteArray(g_rgActionInfo[i].psLabel).contains("%1"))
144 // Prevents i18n from complaining about unsubstituted placeholder.
145 {
146 result.append(i18n(g_rgActionInfo[i].psLabel, QString()));
147 } else {
148 result.append(i18n(g_rgActionInfo[i].psLabel));
149 }
150 }
151
152 return result;
153}
154
155class AutomaticAction : public QAction
156{
157 Q_OBJECT
158
159public:
160 AutomaticAction(const QIcon &icon, const QString &text, const QList<QKeySequence> &shortcut, const char *slot,
161 QObject *parent);
162public Q_SLOTS:
163 inline void cut()
164 {
165 invokeEditSlot("cut");
166 }
167 inline void copy()
168 {
169 invokeEditSlot("copy");
170 }
171 inline void paste()
172 {
173 invokeEditSlot("paste");
174 }
175 inline void clear()
176 {
177 invokeEditSlot("clear");
178 }
179 inline void selectAll()
180 {
181 invokeEditSlot("selectAll");
182 }
183
184 void invokeEditSlot(const char *slot)
185 {
186 if (qApp->focusWidget()) {
187 QMetaObject::invokeMethod(qApp->focusWidget(), slot);
188 }
189 }
190
191};
192
193}
194
195#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