# kdeui Library API Documentation

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

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 12:56:52 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001