# kdeui Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# khelpmenu.cpp

    00001 /*
    00002  * This file is part of the KDE Libraries
    00003  * Copyright (C) 1999-2000 Espen Sand (espen@kde.org)
    00004  *
    00005  * This library is free software; you can redistribute it and/or
    00006  * modify it under the terms of the GNU Library General Public
    00007  * License as published by the Free Software Foundation; either
    00008  * version 2 of the License, or (at your option) any later version.
    00009  *
    00010  * This library is distributed in the hope that it will be useful,
    00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013  * Library General Public License for more details.
    00014  *
    00015  * You should have received a copy of the GNU Library General Public License
    00016  * along with this library; see the file COPYING.LIB.  If not, write to
    00017  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00018  * Boston, MA 02111-1307, USA.
    00019  *
    00020  */
    00021
    00022 // I (espen) prefer that header files are included alphabetically
    00023 #include <qhbox.h>
    00024 #include <qlabel.h>
    00025 #include <qtimer.h>
    00026 #include <qtoolbutton.h>
    00027 #include <qwhatsthis.h>
    00028 #include <qwidget.h>
    00029
    00030 #include <kaboutapplication.h>
    00031 #include <kaboutdata.h>
    00032 #include <kaboutkde.h>
    00033 #include <kaction.h>
    00034 #include <kapplication.h>
    00035 #include <kbugreport.h>
    00036 #include <kdialogbase.h>
    00037 #include <khelpmenu.h>
    00038 #include <kiconloader.h>
    00039 #include <klocale.h>
    00040 #include <kmessagebox.h>
    00041 #include <kpopupmenu.h>
    00042 #include <kstdaccel.h>
    00043 #include <kstdaction.h>
    00044
    00045 #include "config.h"
    00046 #include <qxembed.h>
    00047
    00048 class KHelpMenuPrivate
    00049 {
    00050 public:
    00051     KHelpMenuPrivate()
    00052     {
    00053     }
    00054     ~KHelpMenuPrivate()
    00055     {
    00056     }
    00057
    00058     const KAboutData *mAboutData;
    00059 };
    00060
    00061 KHelpMenu::KHelpMenu( QWidget *parent, const QString &aboutAppText,
    00062               bool showWhatsThis )
    00063   : QObject(parent), mMenu(0), mAboutApp(0), mAboutKDE(0), mBugReport(0),
    00064     d(new KHelpMenuPrivate)
    00065 {
    00066   mParent = parent;
    00067   mAboutAppText = aboutAppText;
    00068   mShowWhatsThis = showWhatsThis;
    00069   d->mAboutData = 0;
    00070 }
    00071
    00072 KHelpMenu::KHelpMenu( QWidget *parent, const KAboutData *aboutData,
    00073               bool showWhatsThis, KActionCollection *actions )
    00074   : QObject(parent), mMenu(0), mAboutApp(0), mAboutKDE(0), mBugReport(0),
    00075     d(new KHelpMenuPrivate)
    00076 {
    00077   mParent = parent;
    00078   mShowWhatsThis = showWhatsThis;
    00079
    00080   d->mAboutData = aboutData;
    00081
    00082   if (!aboutData)
    00083     mAboutAppText = QString::null;
    00084
    00085   if (actions)
    00086   {
    00087     KStdAction::helpContents(this, SLOT(appHelpActivated()), actions);
    00088     if (showWhatsThis)
    00089       KStdAction::whatsThis(this, SLOT(contextHelpActivated()), actions);
    00090     KStdAction::reportBug(this, SLOT(reportBug()), actions);
    00091     KStdAction::aboutApp(this, SLOT(aboutApplication()), actions);
    00092     KStdAction::aboutKDE(this, SLOT(aboutKDE()), actions);
    00093   }
    00094 }
    00095
    00096 KHelpMenu::~KHelpMenu()
    00097 {
    00098   delete mMenu;
    00099   delete mAboutApp;
    00100   delete mAboutKDE;
    00101   delete mBugReport;
    00102   delete d;
    00103 }
    00104
    00105
    00106 KPopupMenu* KHelpMenu::menu()
    00107 {
    00108   if( !mMenu )
    00109   {
    00110     //
    00111     // 1999-12-02 Espen Sand:
    00112     // I use hardcoded menu id's here. Reason is to stay backward
    00113     // compatible.
    00114     //
    00115     const KAboutData *aboutData = d->mAboutData ? d->mAboutData : KGlobal::instance()->aboutData();
    00116     QString appName = (aboutData)? aboutData->programName() : QString::fromLatin1(qApp->name());
    00117
    00118     mMenu = new KPopupMenu();
    00119     connect( mMenu, SIGNAL(destroyed()), this, SLOT(menuDestroyed()));
    00120
    00121     bool need_separator = false;
    00122     if (kapp->authorizeKAction("help_contents"))
    00123     {
    00124       mMenu->insertItem( BarIcon( "contents", KIcon::SizeSmall),
    00125                      i18n( "%1 &Handbook" ).arg( appName) ,menuHelpContents );
    00126       mMenu->connectItem( menuHelpContents, this, SLOT(appHelpActivated()) );
    00127       mMenu->setAccel( KStdAccel::shortcut(KStdAccel::Help), menuHelpContents );
    00128       need_separator = true;
    00129     }
    00130
    00131     if( mShowWhatsThis && kapp->authorizeKAction("help_whats_this") )
    00132     {
    00133       QToolButton* wtb = QWhatsThis::whatsThisButton(0);
    00134       mMenu->insertItem( wtb->iconSet(),i18n( "What's &This" ), menuWhatsThis);
    00135       mMenu->connectItem( menuWhatsThis, this, SLOT(contextHelpActivated()) );
    00136       delete wtb;
    00137       mMenu->setAccel( SHIFT + Key_F1, menuWhatsThis );
    00138       need_separator = true;
    00139     }
    00140
    00141     if (kapp->authorizeKAction("help_report_bug") && aboutData && !aboutData->bugAddress().isEmpty() )
    00142     {
    00143       if (need_separator)
    00144         mMenu->insertSeparator();
    00145       mMenu->insertItem( i18n( "&Report Bug..." ), menuReportBug );
    00146       mMenu->connectItem( menuReportBug, this, SLOT(reportBug()) );
    00147       need_separator = true;
    00148     }
    00149
    00150     if (need_separator)
    00151       mMenu->insertSeparator();
    00152
    00153     if (kapp->authorizeKAction("help_about_app"))
    00154     {
    00155       mMenu->insertItem( kapp->miniIcon(),
    00156         i18n( "&About %1" ).arg(appName), menuAboutApp );
    00157       mMenu->connectItem( menuAboutApp, this, SLOT( aboutApplication() ) );
    00158     }
    00159
    00160     if (kapp->authorizeKAction("help_about_kde"))
    00161     {
    00162       mMenu->insertItem( SmallIcon("about_kde"), i18n( "About &KDE" ), menuAboutKDE );
    00163       mMenu->connectItem( menuAboutKDE, this, SLOT( aboutKDE() ) );
    00164     }
    00165   }
    00166
    00167   return mMenu;
    00168 }
    00169
    00170
    00171
    00172 void KHelpMenu::appHelpActivated()
    00173 {
    00174   kapp->invokeHelp();
    00175 }
    00176
    00177
    00178 void KHelpMenu::aboutApplication()
    00179 {
    00180   if (d->mAboutData)
    00181   {
    00182     if( !mAboutApp )
    00183     {
    00184       mAboutApp = new KAboutApplication( d->mAboutData, mParent, "about", false );
    00185       connect( mAboutApp, SIGNAL(finished()), this, SLOT( dialogFinished()) );
    00186     }
    00187     mAboutApp->show();
    00188   }
    00189   else if( mAboutAppText.isEmpty() )
    00190   {
    00191     emit showAboutApplication();
    00192   }
    00193   else
    00194   {
    00195     if( !mAboutApp )
    00196     {
    00197       mAboutApp = new KDialogBase( QString::null, // Caption is defined below
    00198                    KDialogBase::Yes, KDialogBase::Yes,
    00199                    KDialogBase::Yes, mParent, "about",
    00200                    false, true, KStdGuiItem::ok() );
    00201       connect( mAboutApp, SIGNAL(finished()), this, SLOT( dialogFinished()) );
    00202
    00203       QHBox *hbox = new QHBox( mAboutApp );
    00204       mAboutApp->setMainWidget( hbox );
    00205       hbox->setSpacing(KDialog::spacingHint()*3);
    00206       hbox->setMargin(KDialog::marginHint()*1);
    00207
    00208       QLabel *label1 = new QLabel(hbox);
    00209       label1->setPixmap( kapp->icon() );
    00210       QLabel *label2 = new QLabel(hbox);
    00211       label2->setText( mAboutAppText );
    00212
    00213       mAboutApp->setPlainCaption( i18n("About %1").arg(kapp->caption()) );
    00214       mAboutApp->disableResize();
    00215     }
    00216
    00217     mAboutApp->show();
    00218   }
    00219 }
    00220
    00221
    00222 void KHelpMenu::aboutKDE()
    00223 {
    00224   if( !mAboutKDE )
    00225   {
    00226     mAboutKDE = new KAboutKDE( mParent, "aboutkde", false );
    00227     connect( mAboutKDE, SIGNAL(finished()), this, SLOT( dialogFinished()) );
    00228   }
    00229   mAboutKDE->show();
    00230 }
    00231
    00232
    00233 void KHelpMenu::reportBug()
    00234 {
    00235   if( !mBugReport )
    00236   {
    00237     mBugReport = new KBugReport( mParent, false, d->mAboutData );
    00238     connect( mBugReport, SIGNAL(finished()),this,SLOT( dialogFinished()) );
    00239   }
    00240   mBugReport->show();
    00241 }
    00242
    00243
    00244 void KHelpMenu::dialogFinished()
    00245 {
    00246   QTimer::singleShot( 0, this, SLOT(timerExpired()) );
    00247 }
    00248
    00249
    00250 void KHelpMenu::timerExpired()
    00251 {
    00252   if( mAboutKDE && !mAboutKDE->isVisible() )
    00253   {
    00254     delete mAboutKDE; mAboutKDE = 0;
    00255   }
    00256
    00257   if( mBugReport && !mBugReport->isVisible() )
    00258   {
    00259     delete mBugReport; mBugReport = 0;
    00260   }
    00261
    00262   if( mAboutApp && !mAboutApp->isVisible() )
    00263   {
    00264     delete mAboutApp; mAboutApp = 0;
    00265   }
    00266 }
    00267
    00268
    00269 void KHelpMenu::menuDestroyed()
    00270 {
    00271   mMenu = 0;
    00272 }
    00273
    00274
    00275 void KHelpMenu::contextHelpActivated()
    00276 {
    00277   QWhatsThis::enterWhatsThisMode();
    00278   QWidget* w = QApplication::widgetAt( QCursor::pos(), true );
    00279   while ( w && !w->isTopLevel() && !w->inherits("QXEmbed")  )
    00280       w = w->parentWidget();
    00281 #ifdef Q_WS_X11
    00282    if ( w && w->inherits("QXEmbed") )
    00283       (( QXEmbed*) w )->enterWhatsThisMode();
    00284 #endif
    00285 }
    00286
    00287 void KHelpMenu::virtual_hook( int, void* )
    00288 { /*BASE::virtual_hook( id, data );*/ }
    00289
    00290
    00291 #include "khelpmenu.moc"

This file is part of the documentation for kdeui Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:20:17 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003