khelpmenu.cpp
/*
* This file is part of the KDE Libraries
* Copyright (C) 1999-2000 Espen Sand (espen@kde.org)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
// I (espen) prefer that header files are included alphabetically
#include <qhbox.h>
#include <qlabel.h>
#include <qtimer.h>
#include <qtoolbutton.h>
#include <qwhatsthis.h>
#include <qwidget.h>
#include <kaboutapplication.h>
#include <kaboutdata.h>
#include <kaboutkde.h>
#include <kaction.h>
#include <kapplication.h>
#include <kbugreport.h>
#include <kdialogbase.h>
#include <khelpmenu.h>
#include <kiconloader.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kpopupmenu.h>
#include <kstdaccel.h>
#include <kstdaction.h>
#include "kswitchlanguagedialog.h"
#include "config.h"
#include <qxembed.h>
class KHelpMenuPrivate
{
public:
KHelpMenuPrivate():mSwitchApplicationLanguage(NULL)
{
}
~KHelpMenuPrivate()
{
delete mSwitchApplicationLanguage;
}
const KAboutData *mAboutData;
KSwitchLanguageDialog *mSwitchApplicationLanguage;
};
KHelpMenu::KHelpMenu( QWidget *parent, const QString &aboutAppText,
bool showWhatsThis )
: QObject(parent), mMenu(0), mAboutApp(0), mAboutKDE(0), mBugReport(0),
d(new KHelpMenuPrivate)
{
mParent = parent;
mAboutAppText = aboutAppText;
mShowWhatsThis = showWhatsThis;
d->mAboutData = 0;
}
KHelpMenu::KHelpMenu( QWidget *parent, const KAboutData *aboutData,
bool showWhatsThis, KActionCollection *actions )
: QObject(parent), mMenu(0), mAboutApp(0), mAboutKDE(0), mBugReport(0),
d(new KHelpMenuPrivate)
{
mParent = parent;
mShowWhatsThis = showWhatsThis;
d->mAboutData = aboutData;
if (!aboutData)
mAboutAppText = QString::null;
if (actions)
{
KStdAction::helpContents(this, SLOT(appHelpActivated()), actions);
if (showWhatsThis)
KStdAction::whatsThis(this, SLOT(contextHelpActivated()), actions);
KStdAction::reportBug(this, SLOT(reportBug()), actions);
KStdAction::aboutApp(this, SLOT(aboutApplication()), actions);
KStdAction::aboutKDE(this, SLOT(aboutKDE()), actions);
KStdAction::switchApplicationLanguage(this, SLOT(switchApplicationLanguage()), actions);
}
}
KHelpMenu::~KHelpMenu()
{
delete mMenu;
delete mAboutApp;
delete mAboutKDE;
delete mBugReport;
delete d;
}
KPopupMenu* KHelpMenu::menu()
{
if( !mMenu )
{
//
// 1999-12-02 Espen Sand:
// I use hardcoded menu id's here. Reason is to stay backward
// compatible.
//
const KAboutData *aboutData = d->mAboutData ? d->mAboutData : KGlobal::instance()->aboutData();
QString appName = (aboutData)? aboutData->programName() : QString::fromLatin1(qApp->name());
mMenu = new KPopupMenu();
connect( mMenu, SIGNAL(destroyed()), this, SLOT(menuDestroyed()));
bool need_separator = false;
if (kapp->authorizeKAction("help_contents"))
{
mMenu->insertItem( BarIcon( "contents", KIcon::SizeSmall),
i18n( "%1 &Handbook" ).arg( appName) ,menuHelpContents );
mMenu->connectItem( menuHelpContents, this, SLOT(appHelpActivated()) );
mMenu->setAccel( KStdAccel::shortcut(KStdAccel::Help), menuHelpContents );
need_separator = true;
}
if( mShowWhatsThis && kapp->authorizeKAction("help_whats_this") )
{
QToolButton* wtb = QWhatsThis::whatsThisButton(0);
mMenu->insertItem( wtb->iconSet(),i18n( "What's &This" ), menuWhatsThis);
mMenu->connectItem( menuWhatsThis, this, SLOT(contextHelpActivated()) );
delete wtb;
mMenu->setAccel( SHIFT + Key_F1, menuWhatsThis );
need_separator = true;
}
if (kapp->authorizeKAction("help_report_bug") && aboutData && !aboutData->bugAddress().isEmpty() )
{
if (need_separator)
mMenu->insertSeparator();
mMenu->insertItem( i18n( "&Report Bug..." ), menuReportBug );
mMenu->connectItem( menuReportBug, this, SLOT(reportBug()) );
need_separator = true;
}
if (kapp->authorizeKAction("switch_application_language"))
{
if (need_separator)
mMenu->insertSeparator();
mMenu->insertItem( i18n( "Switch application &language..." ), menuSwitchLanguage );
mMenu->connectItem( menuSwitchLanguage, this, SLOT(switchApplicationLanguage()) );
need_separator = true;
}
if (need_separator)
mMenu->insertSeparator();
if (kapp->authorizeKAction("help_about_app"))
{
mMenu->insertItem( kapp->miniIcon(),
i18n( "&About %1" ).arg(appName), menuAboutApp );
mMenu->connectItem( menuAboutApp, this, SLOT( aboutApplication() ) );
}
if (kapp->authorizeKAction("help_about_kde"))
{
mMenu->insertItem( SmallIcon("about_kde"), i18n( "About &KDE" ), menuAboutKDE );
mMenu->connectItem( menuAboutKDE, this, SLOT( aboutKDE() ) );
}
}
return mMenu;
}
void KHelpMenu::appHelpActivated()
{
kapp->invokeHelp();
}
void KHelpMenu::aboutApplication()
{
if (d->mAboutData)
{
if( !mAboutApp )
{
mAboutApp = new KAboutApplication( d->mAboutData, mParent, "about", false );
connect( mAboutApp, SIGNAL(finished()), this, SLOT( dialogFinished()) );
}
mAboutApp->show();
}
else if( mAboutAppText.isEmpty() )
{
emit showAboutApplication();
}
else
{
if( !mAboutApp )
{
mAboutApp = new KDialogBase( QString::null, // Caption is defined below
KDialogBase::Yes, KDialogBase::Yes,
KDialogBase::Yes, mParent, "about",
false, true, KStdGuiItem::ok() );
connect( mAboutApp, SIGNAL(finished()), this, SLOT( dialogFinished()) );
QHBox *hbox = new QHBox( mAboutApp );
mAboutApp->setMainWidget( hbox );
hbox->setSpacing(KDialog::spacingHint()*3);
hbox->setMargin(KDialog::marginHint()*1);
QLabel *label1 = new QLabel(hbox);
label1->setPixmap( kapp->icon() );
QLabel *label2 = new QLabel(hbox);
label2->setText( mAboutAppText );
mAboutApp->setPlainCaption( i18n("About %1").arg(kapp->caption()) );
mAboutApp->disableResize();
}
mAboutApp->show();
}
}
void KHelpMenu::aboutKDE()
{
if( !mAboutKDE )
{
mAboutKDE = new KAboutKDE( mParent, "aboutkde", false );
connect( mAboutKDE, SIGNAL(finished()), this, SLOT( dialogFinished()) );
}
mAboutKDE->show();
}
void KHelpMenu::reportBug()
{
if( !mBugReport )
{
mBugReport = new KBugReport( mParent, false, d->mAboutData );
connect( mBugReport, SIGNAL(finished()),this,SLOT( dialogFinished()) );
}
mBugReport->show();
}
void KHelpMenu::switchApplicationLanguage()
{
if ( !d->mSwitchApplicationLanguage )
{
d->mSwitchApplicationLanguage = new KSwitchLanguageDialog( mParent, "switchlanguagedialog", false );
connect( d->mSwitchApplicationLanguage, SIGNAL(finished()), this, SLOT( dialogFinished()) );
}
d->mSwitchApplicationLanguage->show();
}
void KHelpMenu::dialogFinished()
{
QTimer::singleShot( 0, this, SLOT(timerExpired()) );
}
void KHelpMenu::timerExpired()
{
if( mAboutKDE && !mAboutKDE->isVisible() )
{
delete mAboutKDE; mAboutKDE = 0;
}
if( mBugReport && !mBugReport->isVisible() )
{
delete mBugReport; mBugReport = 0;
}
if( mAboutApp && !mAboutApp->isVisible() )
{
delete mAboutApp; mAboutApp = 0;
}
if (d->mSwitchApplicationLanguage && !d->mSwitchApplicationLanguage->isVisible())
{
delete d->mSwitchApplicationLanguage; d->mSwitchApplicationLanguage = 0;
}
}
void KHelpMenu::menuDestroyed()
{
mMenu = 0;
}
void KHelpMenu::contextHelpActivated()
{
QWhatsThis::enterWhatsThisMode();
QWidget* w = QApplication::widgetAt( QCursor::pos(), true );
while ( w && !w->isTopLevel() && !w->inherits("QXEmbed") )
w = w->parentWidget();
#ifdef Q_WS_X11
if ( w && w->inherits("QXEmbed") )
(( QXEmbed*) w )->enterWhatsThisMode();
#endif
}
void KHelpMenu::virtual_hook( int, void* )
{ /*BASE::virtual_hook( id, data );*/ }
#include "khelpmenu.moc"
KDialog::marginHint
static int marginHint()
Return the number of pixels you shall use between a dialog edge and the outermost widget(s) according...
Definition: kdialog.cpp:97
KActionCollection
A managed set of KAction objects.
Definition: kactioncollection.h:78
KStdAccel::shortcut
const KShortcut & shortcut(StdAccel id)
KStdAction::whatsThis
KAction * whatsThis(const QObject *recvr, const char *slot, KActionCollection *parent, const char *name)
Trigger the What's This cursor.
Definition: kstdaction.cpp:310
KAboutKDE
Standard "About KDE" dialog box,.
Definition: kaboutkde.h:40
KStdAction::reportBug
KAction * reportBug(const QObject *recvr, const char *slot, KActionCollection *parent, const char *name)
Open up the Report Bug dialog.
Definition: kstdaction.cpp:314
KDialogBase::disableResize
void disableResize()
Convenience method.
Definition: kdialogbase.cpp:531
KStdAction::helpContents
KAction * helpContents(const QObject *recvr, const char *slot, KActionCollection *parent, const char *name)
Display the help contents.
Definition: kstdaction.cpp:308
klocale.h
KDialogBase
A dialog base class with standard buttons and predefined layouts.
Definition: kdialogbase.h:191
KAboutData::bugAddress
QString bugAddress() const
KBugReport
A dialog box for sending bug reports.
Definition: kbugreport.h:42
KIcon::SizeSmall
KDialog::spacingHint
static int spacingHint()
Return the number of pixels you shall use between widgets inside a dialog according to the KDE standa...
Definition: kdialog.cpp:103
KAboutApplication
Standard "About Application" dialog box.
Definition: kaboutapplication.h:44
KAboutData
KSwitchLanguageDialog
Standard "switch application language" dialog box.
Definition: kswitchlanguagedialog.h:38
KGlobal::instance
static KInstance * instance()
KAboutData::programName
QString programName() const
KStdAction::aboutKDE
KAction * aboutKDE(const QObject *recvr, const char *slot, KActionCollection *parent, const char *name)
Display the About KDE dialog.
Definition: kstdaction.cpp:320
KAboutDialog::show
virtual void show(void)
Makes a modeless (modal = false in constructor) dialog visible.
Definition: kaboutdialog.cpp:1549
KDialogBase::setMainWidget
void setMainWidget(QWidget *widget)
Sets the main user definable widget.
Definition: kdialogbase.cpp:1431
KStdAction::switchApplicationLanguage
KAction * switchApplicationLanguage(const QObject *recvr, const char *slot, KActionCollection *parent, const char *name)
Display "Switch application language" dialog.
Definition: kstdaction.cpp:316
KDialog::setPlainCaption
virtual void setPlainCaption(const QString &caption)
Make a plain caption without any modifications.
Definition: kdialog.cpp:122
KStdAction::aboutApp
KAction * aboutApp(const QObject *recvr, const char *slot, KActionCollection *parent, const char *name)
Display the application's About box.
Definition: kstdaction.cpp:318
KDialogBase::Yes
Show Yes button.
Definition: kdialogbase.h:210

KDE Home | KDE Accessibility Home | Description of Access Keys