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 // Set the text before setting the MenuRole, as on OS X setText will do some heuristic role guessing.
113 // This ensures user menu items get the intended role out of the list below.
114 pAction->setText(sLabel);
115
116 switch (id) {
117 case Quit:
119 break;
120
121 case Preferences:
123 break;
124
125 case AboutApp:
127 break;
128
129 default:
131 break;
132 }
133
134 if (!QCoreApplication::translate("KStandardActions", pInfo->psToolTip).isEmpty()) {
135 pAction->setToolTip(QCoreApplication::translate("KStandardActions", pInfo->psToolTip));
136 }
137 pAction->setIcon(icon);
138
140 if (!cut.isEmpty()) {
141 // emulate KActionCollection::setDefaultShortcuts to allow the use of "configure shortcuts"
142 pAction->setShortcuts(cut);
143 pAction->setProperty("defaultShortcuts", QVariant::fromValue(cut));
144 }
147 pAction,
148 [pAction, shortcut = pInfo->idAccel](KStandardShortcut::StandardShortcut id, const QList<QKeySequence> &newShortcut) {
149 if (id != shortcut) {
150 return;
151 }
152 pAction->setShortcuts(newShortcut);
153 pAction->setProperty("defaultShortcuts", QVariant::fromValue(newShortcut));
154 });
155
156 pAction->setObjectName(pInfo->psName.toString());
157 }
158
159 if (pAction && parent && parent->inherits("KActionCollection")) {
160 QMetaObject::invokeMethod(parent, "addAction", Q_ARG(QString, pAction->objectName()), Q_ARG(QAction *, pAction));
161 }
162
163 return pAction;
164}
165
167{
168 const KStandardActionsInfo *pInfo = infoPtr(id);
169 return (pInfo) ? pInfo->psName.toString() : QString();
170}
171}
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 Fri Jul 26 2024 11:52:48 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.