KConfig

kstandardactions.cpp
1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 1999, 2000 Kurt Granroth <granroth@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-only
6*/
7
8#include "kstandardactions.h"
9#include "kstandardactions_p.h"
10#include "moc_kstandardactions_p.cpp"
11
12#include <KStandardShortcutWatcher>
13#include <QGuiApplication>
14
16{
17
19{
21
22 for (uint i = 0; g_rgActionInfo[i].id != ActionNone; i++) {
23 result.append(g_rgActionInfo[i].id);
24 }
25
26 return result;
27}
28
30{
31 const KStandardActionsInfo *pInfo = infoPtr(id);
32 return (pInfo) ? pInfo->idAccel : KStandardShortcut::AccelNone;
33}
34
36{
37 QAction *pAction = new QAction(parent);
38 const KStandardActionsInfo *pInfo = infoPtr(id);
39
40 // qCDebug(KCONFIG_WIDGETS_LOG) << "KStandardActions::create( " << id << "=" << (pInfo ? pInfo->psName : (const char*)0) << ", " << parent << " )"; //
41 // ellis
42
43 if (pInfo) {
44 QString sLabel;
45 QString iconName = pInfo->psIconName.toString();
46
47 switch (id) {
48 case Back:
49 sLabel = QCoreApplication::translate("go back", "&Back");
51 iconName = QStringLiteral("go-next");
52 }
53 break;
54
55 case Forward:
56 sLabel = QCoreApplication::translate("go forward", "&Forward");
58 iconName = QStringLiteral("go-previous");
59 }
60 break;
61
62 case Home:
63 sLabel = QCoreApplication::translate("home page", "&Home");
64 break;
65 case Preferences:
66 case AboutApp:
67 case HelpContents: {
69 if (appDisplayName.isEmpty()) {
70 appDisplayName = QCoreApplication::applicationName();
71 }
72 sLabel = QCoreApplication::translate("KStandardActions", pInfo->psLabel).arg(appDisplayName);
73 } break;
74 default:
75 sLabel = QCoreApplication::translate("KStandardActions", pInfo->psLabel);
76 }
77
79 switch (id) {
80 case Prior:
81 iconName = QStringLiteral("go-next-view-page");
82 break;
83 case Next:
84 iconName = QStringLiteral("go-previous-view-page");
85 break;
86 case FirstPage:
87 iconName = QStringLiteral("go-last-view-page");
88 break;
89 case LastPage:
90 iconName = QStringLiteral("go-first-view-page");
91 break;
92 case DocumentBack:
93 iconName = QStringLiteral("go-next");
94 break;
95 case DocumentForward:
96 iconName = QStringLiteral("go-previous");
97 break;
98 default:
99 break;
100 }
101 }
102
103 if (id == Donate) {
105 if (!currencyCode.isEmpty()) {
106 iconName = QStringLiteral("help-donate-%1").arg(currencyCode);
107 }
108 }
109
110 QIcon icon = iconName.isEmpty() ? QIcon() : QIcon::fromTheme(iconName);
111
112 if (id == AboutApp) {
113 icon = qGuiApp->windowIcon();
114 }
115
116 // Set the text before setting the MenuRole, as on OS X setText will do some heuristic role guessing.
117 // This ensures user menu items get the intended role out of the list below.
118 pAction->setText(sLabel);
119
120 switch (id) {
121 case Quit:
123 break;
124
125 case Preferences:
127 break;
128
129 case AboutApp:
131 break;
132
133 default:
135 break;
136 }
137
138 if (!QCoreApplication::translate("KStandardActions", pInfo->psToolTip).isEmpty()) {
139 pAction->setToolTip(QCoreApplication::translate("KStandardActions", pInfo->psToolTip));
140 }
141 pAction->setIcon(icon);
142
144 if (!cut.isEmpty()) {
145 // emulate KActionCollection::setDefaultShortcuts to allow the use of "configure shortcuts"
146 pAction->setShortcuts(cut);
147 pAction->setProperty("defaultShortcuts", QVariant::fromValue(cut));
148 }
151 pAction,
152 [pAction, shortcut = pInfo->idAccel](KStandardShortcut::StandardShortcut id, const QList<QKeySequence> &newShortcut) {
153 if (id != shortcut) {
154 return;
155 }
156 pAction->setShortcuts(newShortcut);
157 pAction->setProperty("defaultShortcuts", QVariant::fromValue(newShortcut));
158 });
159
160 pAction->setObjectName(pInfo->psName.toString());
161 }
162
163 if (pAction && parent && parent->inherits("KActionCollection")) {
164 QMetaObject::invokeMethod(parent, "addAction", Q_ARG(QString, pAction->objectName()), Q_ARG(QAction *, pAction));
165 }
166
167 return pAction;
168}
169
171{
172 const KStandardActionsInfo *pInfo = infoPtr(id);
173 return (pInfo) ? pInfo->psName.toString() : QString();
174}
175}
void shortcutChanged(KStandardShortcut::StandardShortcut id, const QList< QKeySequence > &shortcut)
The standardshortcut id was changed to shortcut.
Convenience methods to access all standard KDE actions.
KStandardShortcut::StandardShortcut shortcutForActionId(StandardAction id)
Returns the standardshortcut associated with actionId.
QAction * _kgui_createInternal(StandardAction id, QObject *parent)
StandardAction
The standard menubar and toolbar actions.
@ Next
Scroll down one page.
@ Home
Go to the "Home" position or document.
@ Prior
Scroll up one page.
@ Donate
Open donation page on kde.org.
@ LastPage
Jump to the last page.
@ DocumentForward
Move forward (document style menu).
@ Back
Move back (web style menu).
@ Forward
Move forward (web style menu).
@ FirstPage
Jump to the first page.
@ AboutApp
Display the application's About box.
@ DocumentBack
Move back (document style menu).
@ HelpContents
Display the handbook of the application.
@ Quit
Quit the program.
@ Preferences
Display the preferences/options dialog.
QList< StandardAction > actionIds()
Returns a list of all actionIds.
StandardShortcutWatcher * shortcutWatcher()
Returns the global KStandardShortcutWatcher instance of this program.
const QList< QKeySequence > & shortcut(StandardShortcut id)
Returns the keybinding for accel.
StandardShortcut
Defines the identifier of all standard accelerators.
void setIcon(const QIcon &icon)
void setMenuRole(MenuRole menuRole)
void setShortcuts(QKeySequence::StandardKey key)
void setText(const QString &text)
void setToolTip(const QString &tip)
QString translate(const char *context, const char *sourceText, const char *disambiguation, int n)
bool isRightToLeft()
QIcon fromTheme(const QString &name)
void append(QList< T > &&value)
QString currencySymbol(CurrencySymbolFormat format) const const
bool invokeMethod(QObject *context, Functor &&function, FunctorReturnType *ret)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void setObjectName(QAnyStringView name)
bool setProperty(const char *name, QVariant &&value)
QString arg(Args &&... args) const const
bool isEmpty() const const
QString toLower() const const
QVariant fromValue(T &&value)
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.