Krita Source Code Documentation
Loading...
Searching...
No Matches
khelpmenu.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the KDE Libraries
3 * SPDX-FileCopyrightText: 1999-2000 Espen Sand (espen@kde.org)
4 *
5 * SPDX-License-Identifier: LGPL-2.0-or-later
6 *
7 */
8
9// I (espen) prefer that header files are included alphabetically
10
11#include "khelpmenu.h"
12#include "config-xmlgui.h"
13#include <QTimer>
14#include <QAction>
15#include <QApplication>
16#include <QDialogButtonBox>
17#include <QMenu>
18#include <QStyle>
19#include <QWidget>
20#include <QWhatsThis>
21#include <QFile>
22#include <QDir>
23#include <QUrl>
24#include <QBoxLayout>
25#include <QStandardPaths>
26#include <QDesktopServices>
27#include <QDebug>
28
29#include "kaboutkdedialog_p.h"
30#include "kbugreport.h"
32
33#include <kaboutdata.h>
34#include <klocalizedstring.h>
35#include <kstandardaction.h>
36
37#include <kritaversion.h>
38
39using namespace KDEPrivate;
40
42{
43public:
45 : mAboutData(KAboutData::applicationData())
46 {
47 }
49 {
50 delete mMenu;
51 delete mAboutApp;
52 delete mAboutKDE;
53 delete mBugReport;
55 }
56
58
59 QMenu *mMenu {nullptr};
60 QDialog *mAboutApp {nullptr};
64 // TODO evaluate if we use static_cast<QWidget*>(parent()) instead of mParent to win that bit of memory
65 QWidget *mParent {nullptr};
67
68 bool mShowWhatsThis {false};
69 bool mActionsCreated {false};
70
71 QAction *mHandBookAction {nullptr};
72 QAction *mWhatsThisAction {nullptr};
73 QAction *mReportBugAction {nullptr};
75 QAction *mAboutAppAction {nullptr};
76 QAction *mAboutKDEAction {nullptr};
77
78 KAboutData mAboutData;
79};
80
81KisKHelpMenu::KisKHelpMenu(QWidget *parent, const QString &aboutAppText,
82 bool showWhatsThis)
83 : QObject(parent), d(new KisKHelpMenuPrivate)
84{
85 d->mAboutAppText = aboutAppText;
86 d->mShowWhatsThis = showWhatsThis;
87 d->mParent = parent;
88 d->createActions(this);
89}
90
91KisKHelpMenu::KisKHelpMenu(QWidget *parent, const KAboutData &aboutData,
92 bool showWhatsThis)
93 : QObject(parent), d(new KisKHelpMenuPrivate)
94{
95 d->mShowWhatsThis = showWhatsThis;
96 d->mParent = parent;
97 d->mAboutData = aboutData;
98 d->createActions(this);
99}
100
102{
103 delete d;
104}
105
107{
108 if (mActionsCreated) {
109 return;
110 }
111 mActionsCreated = true;
112 mHandBookAction = KStandardAction::helpContents(q, SLOT(appHelpActivated()), q);
113 if (mShowWhatsThis) {
114 mWhatsThisAction = KStandardAction::whatsThis(q, SLOT(contextHelpActivated()), q);
115 }
116
117 if (!mAboutData.bugAddress().isEmpty()) {
118 mReportBugAction = KStandardAction::reportBug(q, SLOT(reportBug()), q);
119 }
120
122 mAboutAppAction = KStandardAction::aboutApp(q, SLOT(aboutApplication()), q);
123 mAboutKDEAction = KStandardAction::aboutKDE(q, SLOT(aboutKDE()), q);
124}
125
126// Used in the non-xml-gui case, like kfind or ksnapshot's help button.
128{
129 if (!d->mMenu) {
130 d->mMenu = new QMenu();
131 connect(d->mMenu, SIGNAL(destroyed()), this, SLOT(menuDestroyed()));
132
133 d->mMenu->setTitle(i18n("&Help"));
134
135 d->createActions(this);
136
137 bool need_separator = false;
138 if (d->mHandBookAction) {
139 d->mMenu->addAction(d->mHandBookAction);
140 need_separator = true;
141 }
142
143 if (d->mWhatsThisAction) {
144 d->mMenu->addAction(d->mWhatsThisAction);
145 need_separator = true;
146 }
147
148 if (d->mReportBugAction) {
149 if (need_separator) {
150 d->mMenu->addSeparator();
151 }
152 d->mMenu->addAction(d->mReportBugAction);
153 need_separator = true;
154 }
155
157 if (need_separator) {
158 d->mMenu->addSeparator();
159 }
161 need_separator = true;
162 }
163
164 if (need_separator) {
165 d->mMenu->addSeparator();
166 }
167
168 if (d->mAboutAppAction) {
169 d->mMenu->addAction(d->mAboutAppAction);
170 }
171
172 if (d->mAboutKDEAction) {
173 d->mMenu->addAction(d->mAboutKDEAction);
174 }
175 }
176
177 return d->mMenu;
178}
179
180QAction *KisKHelpMenu::action(MenuId id) const
181{
182 switch (id) {
183 case menuHelpContents:
184 return d->mHandBookAction;
185 break;
186
187 case menuWhatsThis:
188 return d->mWhatsThisAction;
189 break;
190
191 case menuReportBug:
192 return d->mReportBugAction;
193 break;
194
197 break;
198
199 case menuAboutApp:
200 return d->mAboutAppAction;
201 break;
202
203 case menuAboutKDE:
204 return d->mAboutKDEAction;
205 break;
206 }
207
208 return 0;
209}
210
212{
213 QDesktopServices::openUrl(QUrl(QStringLiteral("help:/")));
214}
215
217{
218 if (receivers(SIGNAL(showAboutApplication())) > 0) {
219 Q_EMIT showAboutApplication();
220 }
221}
222
224{
225 if (!d->mAboutKDE) {
227 connect(d->mAboutKDE, SIGNAL(finished(int)), this, SLOT(dialogFinished()));
228 }
229 d->mAboutKDE->show();
230}
231
233{
234#ifdef KRITA_STABLE
235 QDesktopServices::openUrl(QUrl("https://docs.krita.org/en/untranslatable_pages/reporting_bugs.html"));
236#else
237 if (!d->mBugReport) {
239 connect(d->mBugReport, SIGNAL(finished(int)), this, SLOT(dialogFinished()));
240 }
241 d->mBugReport->show();
242#endif
243}
244
253
255{
256 QTimer::singleShot(0, this, SLOT(timerExpired()));
257}
258
260{
261 if (d->mAboutKDE && !d->mAboutKDE->isVisible()) {
262 delete d->mAboutKDE; d->mAboutKDE = 0;
263 }
264
265 if (d->mBugReport && !d->mBugReport->isVisible()) {
266 delete d->mBugReport; d->mBugReport = 0;
267 }
270 }
271 if (d->mAboutApp && !d->mAboutApp->isVisible()) {
272 delete d->mAboutApp; d->mAboutApp = 0;
273 }
274}
275
277{
278 d->mMenu = 0;
279}
280
282{
283 QWhatsThis::enterWhatsThisMode();
284}
285
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
Standard "About KDE" dialog box.
Standard "switch application language" dialog box.
A dialog box for sending bug reports.
Definition kbugreport.h:29
QAction * mAboutAppAction
Definition khelpmenu.cpp:75
QAction * mAboutKDEAction
Definition khelpmenu.cpp:76
void createActions(KisKHelpMenu *q)
KisKBugReport * mBugReport
Definition khelpmenu.cpp:62
QAction * mHandBookAction
Definition khelpmenu.cpp:71
KAboutData mAboutData
Definition khelpmenu.cpp:78
QAction * mSwitchApplicationLanguageAction
Definition khelpmenu.cpp:74
QAction * mWhatsThisAction
Definition khelpmenu.cpp:72
KisKSwitchLanguageDialog * mSwitchApplicationLanguage
Definition khelpmenu.cpp:63
QAction * mReportBugAction
Definition khelpmenu.cpp:73
KisKAboutKdeDialog * mAboutKDE
Definition khelpmenu.cpp:61
Standard KDE help menu with dialog boxes.
Definition khelpmenu.h:106
void contextHelpActivated()
KisKHelpMenu(QWidget *parent=0, const QString &aboutAppText=QString(), bool showWhatsThis=true)
Definition khelpmenu.cpp:81
void appHelpActivated()
void timerExpired()
void showAboutApplication()
void aboutApplication()
~KisKHelpMenu() override
KisKHelpMenuPrivate *const d
Definition khelpmenu.h:248
QAction * action(MenuId id) const
void reportBug()
void dialogFinished()
void aboutKDE()
void switchApplicationLanguage()
QMenu * menu()
void menuDestroyed()
QAction * aboutKDE(const QObject *recvr, const char *slot, QObject *parent)
QAction * whatsThis(const QObject *recvr, const char *slot, QObject *parent)
QAction * helpContents(const QObject *recvr, const char *slot, QObject *parent)
QAction * reportBug(const QObject *recvr, const char *slot, QObject *parent)
QAction * aboutApp(const QObject *recvr, const char *slot, QObject *parent)
QAction * create(StandardAction id, const QObject *recvr, const char *slot, QObject *parent)