kdeui Library API Documentation

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 #if defined Q_WS_X11 && ! defined K_WS_QTONLY
00047 #include <qxembed.h>
00048 #endif
00049 
00050 class KHelpMenuPrivate
00051 {
00052 public:
00053     KHelpMenuPrivate()
00054     {
00055     }
00056     ~KHelpMenuPrivate()
00057     {
00058     }
00059 
00060     const KAboutData *mAboutData;
00061 };
00062 
00063 KHelpMenu::KHelpMenu( QWidget *parent, const QString &aboutAppText,
00064               bool showWhatsThis )
00065   : QObject(parent), mMenu(0), mAboutApp(0), mAboutKDE(0), mBugReport(0),
00066     d(new KHelpMenuPrivate)
00067 {
00068   mParent = parent;
00069   mAboutAppText = aboutAppText;
00070   mShowWhatsThis = showWhatsThis;
00071   d->mAboutData = 0;
00072 }
00073 
00074 KHelpMenu::KHelpMenu( QWidget *parent, const KAboutData *aboutData,
00075               bool showWhatsThis, KActionCollection *actions )
00076   : QObject(parent), mMenu(0), mAboutApp(0), mAboutKDE(0), mBugReport(0),
00077     d(new KHelpMenuPrivate)
00078 {
00079   mParent = parent;
00080   mShowWhatsThis = showWhatsThis;
00081 
00082   d->mAboutData = aboutData;
00083 
00084   if (!aboutData)
00085     mAboutAppText = QString::null;
00086 
00087   if (actions)
00088   {
00089     KStdAction::helpContents(this, SLOT(appHelpActivated()), actions);
00090     if (showWhatsThis)
00091       KStdAction::whatsThis(this, SLOT(contextHelpActivated()), actions);
00092     KStdAction::reportBug(this, SLOT(reportBug()), actions);
00093     KStdAction::aboutApp(this, SLOT(aboutApplication()), actions);
00094     KStdAction::aboutKDE(this, SLOT(aboutKDE()), actions);
00095   }
00096 }
00097 
00098 KHelpMenu::~KHelpMenu()
00099 {
00100   delete mMenu;
00101   delete mAboutApp;
00102   delete mAboutKDE;
00103   delete mBugReport;
00104   delete d;
00105 }
00106 
00107 
00108 KPopupMenu* KHelpMenu::menu()
00109 {
00110   if( mMenu == 0 )
00111   {
00112     //
00113     // 1999-12-02 Espen Sand:
00114     // I use hardcoded menu id's here. Reason is to stay backward
00115     // compatible.
00116     //
00117     const KAboutData *aboutData = d->mAboutData ? d->mAboutData : KGlobal::instance()->aboutData();
00118     QString appName = (aboutData)? aboutData->programName() : QString::fromLatin1(qApp->name());
00119 
00120     mMenu = new KPopupMenu();
00121     connect( mMenu, SIGNAL(destroyed()), this, SLOT(menuDestroyed()));
00122 
00123     bool need_separator = false;
00124     if (kapp->authorizeKAction("help_contents"))
00125     {
00126       mMenu->insertItem( BarIcon( "contents", KIcon::SizeSmall),
00127                      i18n( "%1 &Handbook" ).arg( appName) ,menuHelpContents );
00128       mMenu->connectItem( menuHelpContents, this, SLOT(appHelpActivated()) );
00129       mMenu->setAccel( KStdAccel::shortcut(KStdAccel::Help), menuHelpContents );
00130       need_separator = true;
00131     }
00132 
00133     if( (mShowWhatsThis == true) && kapp->authorizeKAction("help_whats_this") )
00134     {
00135       QToolButton* wtb = QWhatsThis::whatsThisButton(0);
00136       mMenu->insertItem( wtb->iconSet(),i18n( "What's &This" ), menuWhatsThis);
00137       mMenu->connectItem( menuWhatsThis, this, SLOT(contextHelpActivated()) );
00138       delete wtb;
00139       mMenu->setAccel( SHIFT + Key_F1, menuWhatsThis );
00140       need_separator = true;
00141     }
00142 
00143     if (kapp->authorizeKAction("help_report_bug") && aboutData && !aboutData->bugAddress().isEmpty() )
00144     {
00145       if (need_separator)
00146         mMenu->insertSeparator();
00147       mMenu->insertItem( i18n( "&Report Bug..." ), menuReportBug );
00148       mMenu->connectItem( menuReportBug, this, SLOT(reportBug()) );
00149       need_separator = true;
00150     }
00151 
00152     if (need_separator)
00153       mMenu->insertSeparator();
00154 
00155     if (kapp->authorizeKAction("help_about_app"))
00156     {
00157       mMenu->insertItem( kapp->miniIcon(),
00158         i18n( "&About %1" ).arg(appName), menuAboutApp );
00159       mMenu->connectItem( menuAboutApp, this, SLOT( aboutApplication() ) );
00160     }
00161     
00162     if (kapp->authorizeKAction("help_about_kde"))
00163     {
00164       mMenu->insertItem( SmallIcon("about_kde"), i18n( "About &KDE" ), menuAboutKDE );
00165       mMenu->connectItem( menuAboutKDE, this, SLOT( aboutKDE() ) );
00166     }
00167   }
00168 
00169   return( mMenu );
00170 }
00171 
00172 
00173 
00174 void KHelpMenu::appHelpActivated()
00175 {
00176   kapp->invokeHelp();
00177 }
00178 
00179 
00180 void KHelpMenu::aboutApplication()
00181 {
00182   if (d->mAboutData)
00183   {
00184     if( mAboutApp == 0 )
00185     {
00186       mAboutApp = new KAboutApplication( d->mAboutData, mParent, "about", false );
00187       connect( mAboutApp, SIGNAL(finished()), this, SLOT( dialogFinished()) );
00188     }
00189     mAboutApp->show();
00190   }
00191   else if( mAboutAppText.isEmpty() )
00192   {
00193     emit showAboutApplication();
00194   }
00195   else
00196   {
00197     if( mAboutApp == 0 )
00198     {
00199       mAboutApp = new KDialogBase( QString::null, // Caption is defined below
00200                    KDialogBase::Yes, KDialogBase::Yes,
00201                    KDialogBase::Yes, mParent, "about",
00202                    false, true, i18n("&OK") );
00203       connect( mAboutApp, SIGNAL(finished()), this, SLOT( dialogFinished()) );
00204 
00205       QHBox *hbox = new QHBox( mAboutApp );
00206       mAboutApp->setMainWidget( hbox );
00207       hbox->setSpacing(KDialog::spacingHint()*3);
00208       hbox->setMargin(KDialog::marginHint()*1);
00209 
00210       QLabel *label1 = new QLabel(hbox);
00211       label1->setPixmap( kapp->icon() );
00212       QLabel *label2 = new QLabel(hbox);
00213       label2->setText( mAboutAppText );
00214 
00215       mAboutApp->setPlainCaption( i18n("About %1").arg(kapp->caption()) );
00216       mAboutApp->disableResize();
00217     }
00218 
00219     mAboutApp->show();
00220   }
00221 }
00222 
00223 
00224 void KHelpMenu::aboutKDE()
00225 {
00226   if( mAboutKDE == 0 )
00227   {
00228     mAboutKDE = new KAboutKDE( mParent, "aboutkde", false );
00229     connect( mAboutKDE, SIGNAL(finished()), this, SLOT( dialogFinished()) );
00230   }
00231   mAboutKDE->show();
00232 }
00233 
00234 
00235 void KHelpMenu::reportBug()
00236 {
00237   if( mBugReport == 0 )
00238   {
00239     mBugReport = new KBugReport( mParent, false, d->mAboutData );
00240     connect( mBugReport, SIGNAL(finished()),this,SLOT( dialogFinished()) );
00241   }
00242   mBugReport->show();
00243 }
00244 
00245 
00246 void KHelpMenu::dialogFinished()
00247 {
00248   QTimer::singleShot( 0, this, SLOT(timerExpired()) );
00249 }
00250 
00251 
00252 void KHelpMenu::timerExpired()
00253 {
00254   if( mAboutKDE != 0 && mAboutKDE->isVisible() == false )
00255   {
00256     delete mAboutKDE; mAboutKDE = 0;
00257   }
00258 
00259   if( mBugReport != 0 && mBugReport->isVisible() == false )
00260   {
00261     delete mBugReport; mBugReport = 0;
00262   }
00263 
00264   if( mAboutApp != 0 && mAboutApp->isVisible() == false )
00265   {
00266     delete mAboutApp; mAboutApp = 0;
00267   }
00268 }
00269 
00270 
00271 void KHelpMenu::menuDestroyed()
00272 {
00273   mMenu = 0;
00274 }
00275 
00276 
00277 void KHelpMenu::contextHelpActivated()
00278 {
00279   QWhatsThis::enterWhatsThisMode();
00280   QWidget* w = QApplication::widgetAt( QCursor::pos(), true );
00281   while ( w && !w->isTopLevel() && !w->inherits("QXEmbed")  )
00282       w = w->parentWidget();
00283 #if defined Q_WS_X11 && ! defined K_WS_QTONLY
00284    if ( w && w->inherits("QXEmbed") )
00285       (( QXEmbed*) w )->enterWhatsThisMode();
00286 #endif
00287 }
00288 
00289 void KHelpMenu::virtual_hook( int, void* )
00290 { /*BASE::virtual_hook( id, data );*/ }
00291 
00292 
00293 #include "khelpmenu.moc"
KDE Logo
This file is part of the documentation for kdeui Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Feb 14 09:16:33 2006 by doxygen 1.3.6 written by Dimitri van Heesch, © 1997-2003