• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDEUI

  • kdeui
  • widgets
khelpmenu.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the KDE Libraries
3 * Copyright (C) 1999-2000 Espen Sand (espen@kde.org)
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 *
20 */
21
22// I (espen) prefer that header files are included alphabetically
23
24#include "khelpmenu.h"
25
26#include <QtCore/QTimer>
27#include <QtGui/QLabel>
28#include <QtGui/QWidget>
29#include <QtGui/QWhatsThis>
30
31#include <kaboutapplicationdialog.h>
32#include <kaboutdata.h>
33#include <kaboutkdedialog_p.h>
34#include <kaction.h>
35#include <kactioncollection.h>
36#include <kapplication.h>
37#include <kauthorized.h>
38#include <kbugreport.h>
39#include <kdialog.h>
40#include <kguiitem.h>
41#include <khbox.h>
42#include <kiconloader.h>
43#include <klocale.h>
44#include <kmenu.h>
45#include <kstandardshortcut.h>
46#include <kstandardaction.h>
47#include <kstandardguiitem.h>
48#include <kswitchlanguagedialog_p.h>
49#include <ktoolinvocation.h>
50#include <kstandarddirs.h>
51
52#include <config.h>
53#ifdef Q_WS_X11
54#include <QX11EmbedWidget>
55#endif
56
57using namespace KDEPrivate;
58
59class KHelpMenuPrivate
60{
61public:
62 KHelpMenuPrivate()
63 : mSwitchApplicationLanguage(0),
64 mActionsCreated(false),
65 mSwitchApplicationLanguageAction(0)
66 {
67 mMenu = 0;
68 mAboutApp = 0;
69 mAboutKDE = 0;
70 mBugReport = 0;
71 mHandBookAction = 0;
72 mWhatsThisAction = 0;
73 mReportBugAction = 0;
74 mAboutAppAction = 0;
75 mAboutKDEAction = 0;
76 }
77 ~KHelpMenuPrivate()
78 {
79 delete mMenu;
80 delete mAboutApp;
81 delete mAboutKDE;
82 delete mBugReport;
83 delete mSwitchApplicationLanguage;
84 }
85
86 void createActions(KHelpMenu* q);
87
88 KMenu *mMenu;
89 KDialog *mAboutApp;
90 KAboutKdeDialog *mAboutKDE;
91 KBugReport *mBugReport;
92 KSwitchLanguageDialog *mSwitchApplicationLanguage;
93
94// TODO evaluate if we use static_cast<QWidget*>(parent()) instead of mParent to win that bit of memory
95 QWidget *mParent;
96 QString mAboutAppText;
97
98 bool mShowWhatsThis;
99 bool mActionsCreated;
100
101 KAction *mHandBookAction, *mWhatsThisAction;
102 QAction *mReportBugAction, *mSwitchApplicationLanguageAction, *mAboutAppAction, *mAboutKDEAction;
103
104 const KAboutData *mAboutData;
105};
106
107KHelpMenu::KHelpMenu( QWidget *parent, const QString &aboutAppText,
108 bool showWhatsThis )
109 : QObject(parent), d(new KHelpMenuPrivate)
110{
111 d->mAboutAppText = aboutAppText;
112 d->mShowWhatsThis = showWhatsThis;
113 d->mParent = parent;
114 d->mAboutData = 0;
115}
116
117KHelpMenu::KHelpMenu( QWidget *parent, const KAboutData *aboutData,
118 bool showWhatsThis, KActionCollection *actions )
119 : QObject(parent), d(new KHelpMenuPrivate)
120{
121 d->mShowWhatsThis = showWhatsThis;
122 d->mParent = parent;
123 d->mAboutData = aboutData;
124
125 if (actions) {
126 d->createActions(this);
127 if (d->mHandBookAction)
128 actions->addAction(d->mHandBookAction->objectName(), d->mHandBookAction);
129 if (d->mWhatsThisAction)
130 actions->addAction(d->mWhatsThisAction->objectName(), d->mWhatsThisAction);
131 if (d->mReportBugAction)
132 actions->addAction(d->mReportBugAction->objectName(), d->mReportBugAction);
133 if (d->mSwitchApplicationLanguageAction)
134 actions->addAction(d->mSwitchApplicationLanguageAction->objectName(), d->mSwitchApplicationLanguageAction);
135 if (d->mAboutAppAction)
136 actions->addAction(d->mAboutAppAction->objectName(), d->mAboutAppAction);
137 if (d->mAboutKDEAction)
138 actions->addAction(d->mAboutKDEAction->objectName(), d->mAboutKDEAction);
139 }
140}
141
142KHelpMenu::~KHelpMenu()
143{
144 delete d;
145}
146
147void KHelpMenuPrivate::createActions(KHelpMenu* q)
148{
149 if (mActionsCreated)
150 return;
151 mActionsCreated = true;
152
153 if (KAuthorized::authorizeKAction("help_contents")) {
154 mHandBookAction = KStandardAction::helpContents(q, SLOT(appHelpActivated()), q);
155 }
156 if (mShowWhatsThis && KAuthorized::authorizeKAction("help_whats_this")) {
157 mWhatsThisAction = KStandardAction::whatsThis(q, SLOT(contextHelpActivated()), q);
158 }
159
160 const KAboutData *aboutData = mAboutData ? mAboutData : KGlobal::mainComponent().aboutData();
161 if (KAuthorized::authorizeKAction("help_report_bug") && aboutData && !aboutData->bugAddress().isEmpty()) {
162 mReportBugAction = KStandardAction::reportBug(q, SLOT(reportBug()), q);
163 }
164
165 if (KAuthorized::authorizeKAction("switch_application_language")) {
166 if((KGlobal::dirs()->findAllResources("locale", QString::fromLatin1("*/entry.desktop"))).count() > 0) {
167 mSwitchApplicationLanguageAction = KStandardAction::create(KStandardAction::SwitchApplicationLanguage, q, SLOT(switchApplicationLanguage()), q);
168 }
169 }
170
171 if (KAuthorized::authorizeKAction("help_about_app")) {
172 mAboutAppAction = KStandardAction::aboutApp(q, SLOT(aboutApplication()), q);
173 }
174
175 if (KAuthorized::authorizeKAction("help_about_kde")) {
176 mAboutKDEAction = KStandardAction::aboutKDE(q, SLOT(aboutKDE()), q);
177 }
178}
179
180// Used in the non-xml-gui case, like kfind or ksnapshot's help button.
181KMenu* KHelpMenu::menu()
182{
183 if( !d->mMenu )
184 {
185 d->mMenu = new KMenu();
186 connect( d->mMenu, SIGNAL(destroyed()), this, SLOT(menuDestroyed()));
187
188 d->mMenu->setTitle(i18n("&Help"));
189
190 d->createActions(this);
191
192 bool need_separator = false;
193 if (d->mHandBookAction) {
194 d->mMenu->addAction(d->mHandBookAction);
195 need_separator = true;
196 }
197
198 if (d->mWhatsThisAction) {
199 d->mMenu->addAction(d->mWhatsThisAction);
200 need_separator = true;
201 }
202
203 if (d->mReportBugAction) {
204 if (need_separator)
205 d->mMenu->addSeparator();
206 d->mMenu->addAction(d->mReportBugAction);
207 need_separator = true;
208 }
209
210 if (d->mSwitchApplicationLanguageAction) {
211 if (need_separator)
212 d->mMenu->addSeparator();
213 d->mMenu->addAction(d->mSwitchApplicationLanguageAction);
214 need_separator = true;
215 }
216
217 if (need_separator)
218 d->mMenu->addSeparator();
219
220 if (d->mAboutAppAction) {
221 d->mMenu->addAction(d->mAboutAppAction);
222 }
223
224 if (d->mAboutKDEAction) {
225 d->mMenu->addAction(d->mAboutKDEAction);
226 }
227 }
228
229 return d->mMenu;
230}
231
232QAction *KHelpMenu::action( MenuId id ) const
233{
234 switch (id)
235 {
236 case menuHelpContents:
237 return d->mHandBookAction;
238 break;
239
240 case menuWhatsThis:
241 return d->mWhatsThisAction;
242 break;
243
244 case menuReportBug:
245 return d->mReportBugAction;
246 break;
247
248 case menuSwitchLanguage:
249 return d->mSwitchApplicationLanguageAction;
250 break;
251
252 case menuAboutApp:
253 return d->mAboutAppAction;
254 break;
255
256 case menuAboutKDE:
257 return d->mAboutKDEAction;
258 break;
259 }
260
261 return 0;
262}
263
264void KHelpMenu::appHelpActivated()
265{
266 KToolInvocation::invokeHelp();
267}
268
269
270void KHelpMenu::aboutApplication()
271{
272 if (receivers(SIGNAL(showAboutApplication())) > 0)
273 {
274 emit showAboutApplication();
275 }
276 else if (d->mAboutData)
277 {
278 if( !d->mAboutApp )
279 {
280 d->mAboutApp = new KAboutApplicationDialog( d->mAboutData, d->mParent );
281 connect( d->mAboutApp, SIGNAL(finished()), this, SLOT(dialogFinished()) );
282 }
283 d->mAboutApp->show();
284 }
285 else
286 {
287 if( !d->mAboutApp )
288 {
289 d->mAboutApp = new KDialog( d->mParent, Qt::Dialog );
290 d->mAboutApp->setCaption( i18n("About %1", KGlobal::caption() ) );
291 d->mAboutApp->setButtons( KDialog::Yes );
292 d->mAboutApp->setObjectName( "about" );
293 d->mAboutApp->setButtonText( KDialog::Yes, KStandardGuiItem::ok().text() );
294 d->mAboutApp->setDefaultButton( KDialog::Yes );
295 d->mAboutApp->setEscapeButton( KDialog::Yes );
296 connect( d->mAboutApp, SIGNAL(finished()), this, SLOT(dialogFinished()) );
297
298 KHBox *hbox = new KHBox( d->mAboutApp );
299 d->mAboutApp->setMainWidget( hbox );
300 hbox->setSpacing(KDialog::spacingHint()*3);
301 hbox->setMargin(KDialog::marginHint()*1);
302
303 QLabel *label1 = new QLabel(hbox);
304
305 int size = IconSize(KIconLoader::Dialog);
306 label1->setPixmap( qApp->windowIcon().pixmap(size,size) );
307 QLabel *label2 = new QLabel(hbox);
308 label2->setText( d->mAboutAppText );
309 }
310 d->mAboutApp->show();
311 }
312}
313
314
315void KHelpMenu::aboutKDE()
316{
317 if( !d->mAboutKDE )
318 {
319 d->mAboutKDE = new KAboutKdeDialog( d->mParent );
320 connect( d->mAboutKDE, SIGNAL(finished()), this, SLOT(dialogFinished()) );
321 }
322 d->mAboutKDE->show();
323}
324
325
326void KHelpMenu::reportBug()
327{
328 if( !d->mBugReport )
329 {
330 d->mBugReport = new KBugReport( d->mParent, false, d->mAboutData );
331 connect( d->mBugReport, SIGNAL(finished()),this,SLOT(dialogFinished()) );
332 }
333 d->mBugReport->show();
334}
335
336
337void KHelpMenu::switchApplicationLanguage()
338{
339 if ( !d->mSwitchApplicationLanguage )
340 {
341 d->mSwitchApplicationLanguage = new KSwitchLanguageDialog( d->mParent );
342 connect( d->mSwitchApplicationLanguage, SIGNAL(finished()), this, SLOT(dialogFinished()) );
343 }
344 d->mSwitchApplicationLanguage->show();
345}
346
347
348void KHelpMenu::dialogFinished()
349{
350 QTimer::singleShot( 0, this, SLOT(timerExpired()) );
351}
352
353
354void KHelpMenu::timerExpired()
355{
356 if( d->mAboutKDE && !d->mAboutKDE->isVisible() )
357 {
358 delete d->mAboutKDE; d->mAboutKDE = 0;
359 }
360
361 if( d->mBugReport && !d->mBugReport->isVisible() )
362 {
363 delete d->mBugReport; d->mBugReport = 0;
364 }
365
366 if ( d->mSwitchApplicationLanguage && !d->mSwitchApplicationLanguage->isVisible() )
367 {
368 delete d->mSwitchApplicationLanguage; d->mSwitchApplicationLanguage = 0;
369 }
370
371 if( d->mAboutApp && !d->mAboutApp->isVisible() )
372 {
373 delete d->mAboutApp; d->mAboutApp = 0;
374 }
375}
376
377
378void KHelpMenu::menuDestroyed()
379{
380 d->mMenu = 0;
381}
382
383
384void KHelpMenu::contextHelpActivated()
385{
386 QWhatsThis::enterWhatsThisMode();
387 QWidget* w = QApplication::widgetAt( QCursor::pos() );
388#ifdef Q_WS_X11
389 while ( w && !w->isTopLevel() && !qobject_cast<QX11EmbedWidget*>(w) )
390 w = w->parentWidget();
391#ifdef __GNUC__
392#warning how to enter whats this mode for a QX11EmbedWidget?
393#endif
394// if ( w && qobject_cast<QX11EmbedWidget*>(w) )
395// (( QX11EmbedWidget*) w )->enterWhatsThisMode();
396#endif
397}
398
399
400#include "khelpmenu.moc"
KAboutApplicationDialog
Standard "About Application" dialog box.
Definition: kaboutapplicationdialog.h:49
KAboutData
KAboutData::bugAddress
QString bugAddress() const
KActionCollection
A container for a set of QAction objects.
Definition: kactioncollection.h:57
KActionCollection::addAction
QAction * addAction(const QString &name, QAction *action)
Add an action under the given name to the collection.
Definition: kactioncollection.cpp:217
KAction
Class to encapsulate user-driven action or event.
Definition: kaction.h:217
KBugReport
A dialog box for sending bug reports.
Definition: kbugreport.h:41
KComponentData::aboutData
const KAboutData * aboutData() const
KDialog
A dialog base class with standard buttons and predefined layouts.
Definition: kdialog.h:129
KDialog::marginHint
static int marginHint()
Returns the number of pixels that should be used between a dialog edge and the outermost widget(s) ac...
Definition: kdialog.cpp:427
KDialog::spacingHint
static int spacingHint()
Returns the number of pixels that should be used between widgets inside a dialog according to the KDE...
Definition: kdialog.cpp:432
KDialog::Yes
@ Yes
Show Yes button. (this button closes the dialog and sets the result to KDialog::Yes)
Definition: kdialog.h:147
KHBox
A container widget which arranges its children horizontally.
Definition: khbox.h:41
KHBox::setMargin
void setMargin(int margin)
Sets the margin of the hbox.
Definition: khbox.cpp:108
KHBox::setSpacing
void setSpacing(int space)
Sets the spacing between the child widgets to space.
Definition: khbox.cpp:98
KHelpMenu
Standard KDE help menu with dialog boxes.
Definition: khelpmenu.h:111
KHelpMenu::action
QAction * action(MenuId id) const
Returns the QAction * associated with the given parameter Will return NULL pointers if menu() has not...
Definition: khelpmenu.cpp:232
KHelpMenu::showAboutApplication
void showAboutApplication()
This signal is emitted from aboutApplication() if no "about application" string has been defined.
KHelpMenu::appHelpActivated
void appHelpActivated()
Opens the help page for the application.
Definition: khelpmenu.cpp:264
KHelpMenu::contextHelpActivated
void contextHelpActivated()
Activates What's This help for the application.
Definition: khelpmenu.cpp:384
KHelpMenu::MenuId
MenuId
Definition: khelpmenu.h:169
KHelpMenu::menuReportBug
@ menuReportBug
Definition: khelpmenu.h:174
KHelpMenu::menuSwitchLanguage
@ menuSwitchLanguage
Definition: khelpmenu.h:175
KHelpMenu::menuAboutApp
@ menuAboutApp
Definition: khelpmenu.h:172
KHelpMenu::menuWhatsThis
@ menuWhatsThis
Definition: khelpmenu.h:171
KHelpMenu::menuAboutKDE
@ menuAboutKDE
Definition: khelpmenu.h:173
KHelpMenu::menuHelpContents
@ menuHelpContents
Definition: khelpmenu.h:170
KHelpMenu::aboutKDE
void aboutKDE()
Opens the standard "About KDE" dialog box.
Definition: khelpmenu.cpp:315
KHelpMenu::~KHelpMenu
~KHelpMenu()
Destructor.
Definition: khelpmenu.cpp:142
KHelpMenu::menu
KMenu * menu()
Returns a popup menu you can use in the menu bar or where you need it.
Definition: khelpmenu.cpp:181
KHelpMenu::switchApplicationLanguage
void switchApplicationLanguage()
Opens the changing default application language dialog box.
Definition: khelpmenu.cpp:337
KHelpMenu::reportBug
void reportBug()
Opens the standard "Report Bugs" dialog box.
Definition: khelpmenu.cpp:326
KHelpMenu::KHelpMenu
KHelpMenu(QWidget *parent=0, const QString &aboutAppText=QString(), bool showWhatsThis=true)
Constructor.
Definition: khelpmenu.cpp:107
KHelpMenu::aboutApplication
void aboutApplication()
Opens an application specific dialog box.
Definition: khelpmenu.cpp:270
KIconLoader::Dialog
@ Dialog
Icons for use in dialog titles, page lists, etc.
Definition: kiconloader.h:143
KMenu
A menu with keyboard searching.
Definition: kmenu.h:42
KToolInvocation::invokeHelp
static void invokeHelp(const QString &anchor=QString(), const QString &appname=QString(), const QByteArray &startup_id=QByteArray())
QAction
QLabel
QObject
QWidget
kaboutapplicationdialog.h
kaboutdata.h
kaction.h
kactioncollection.h
kapplication.h
kauthorized.h
kbugreport.h
kdialog.h
kguiitem.h
khbox.h
khelpmenu.h
IconSize
int IconSize(KIconLoader::Group group)
Definition: kiconloader.cpp:1598
kiconloader.h
klocale.h
i18n
QString i18n(const char *text)
kmenu.h
kstandardaction.h
kstandarddirs.h
kstandardguiitem.h
kstandardshortcut.h
ktoolinvocation.h
KAuthorized::authorizeKAction
bool authorizeKAction(const QString &action)
KDEPrivate
Definition: kcolorchoosermode.cpp:24
KGlobal::mainComponent
const KComponentData & mainComponent()
KGlobal::dirs
KStandardDirs * dirs()
KGlobal::caption
QString caption()
KStandardAction::whatsThis
KAction * whatsThis(const QObject *recvr, const char *slot, QObject *parent)
Trigger the What's This cursor.
Definition: kstandardaction.cpp:606
KStandardAction::helpContents
KAction * helpContents(const QObject *recvr, const char *slot, QObject *parent)
Display the help contents.
Definition: kstandardaction.cpp:601
KStandardAction::create
KAction * create(StandardAction id, const QObject *recvr, const char *slot, QObject *parent)
Creates an action corresponding to one of the KStandardAction::StandardAction actions,...
Definition: kstandardaction.cpp:82
KStandardAction::SwitchApplicationLanguage
@ SwitchApplicationLanguage
Definition: kstandardaction.h:164
KStandardAction::aboutApp
KAction * aboutApp(const QObject *recvr, const char *slot, QObject *parent)
Display the application's About box.
Definition: kstandardaction.cpp:626
KStandardAction::reportBug
KAction * reportBug(const QObject *recvr, const char *slot, QObject *parent)
Open up the Report Bug dialog.
Definition: kstandardaction.cpp:616
KStandardAction::aboutKDE
KAction * aboutKDE(const QObject *recvr, const char *slot, QObject *parent)
Display the About KDE dialog.
Definition: kstandardaction.cpp:631
KStandardAction::switchApplicationLanguage
KAction * switchApplicationLanguage(const QObject *recvr, const char *slot, QObject *parent)
Definition: kstandardaction.cpp:621
KStandardGuiItem::ok
KGuiItem ok()
Returns the 'Ok' gui item.
Definition: kstandardguiitem.cpp:107
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal