• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kdeui

khelpmenu.cpp

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

kdeui

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

API Reference

Skip menu "API Reference"
  • dcop
  • DNSSD
  • interfaces
  • Kate
  • kconf_update
  • KDECore
  • KDED
  • kdefx
  • KDEsu
  • kdeui
  • KDocTools
  • KHTML
  • KImgIO
  • KInit
  • kio
  • kioslave
  • KJS
  • KNewStuff
  • KParts
  • KUtils
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal