kdeui Library API Documentation

kstdaction.cpp

00001 /* This file is part of the KDE libraries
00002    Copyright (C) 1999,2000 Kurt Granroth <granroth@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00016    Boston, MA 02111-1307, USA.
00017 */
00018 
00019 #include "kstdaction.h"
00020 
00021 #include <qtoolbutton.h>
00022 #include <qwhatsthis.h>
00023 
00024 #include <kaboutdata.h>
00025 #include <kaction.h>
00026 #include <kapplication.h>
00027 #include <kdebug.h>
00028 #include <kglobal.h>
00029 #include <kiconloader.h>
00030 #include <klocale.h>
00031 #include <kstdaccel.h>
00032 #include <kmainwindow.h>
00033 #include "kstdaction_p.h"
00034 
00035 namespace KStdAction
00036 {
00037 
00038 QStringList stdNames()
00039 {
00040     return internal_stdNames();
00041 }
00042 
00043 KAction* create( StdAction id, const char *name, const QObject *recvr, const char *slot, KActionCollection* parent )
00044 {
00045     KAction* pAction = 0;
00046     const KStdActionInfo* pInfo = infoPtr( id );
00047     kdDebug(125) << "KStdAction::create( " << id << "=" << (pInfo ? pInfo->psName : (const char*)0) << ", " << parent << ", " << name << " )" << endl; // ellis
00048     if( pInfo ) {
00049         QString sLabel, iconName = pInfo->psIconName;
00050         switch( id ) {
00051          case Back: sLabel = i18n("go back", "&Back");
00052             if (QApplication::reverseLayout() )
00053                 iconName = "forward";
00054             break;
00055 
00056          case Forward: sLabel = i18n("go forward", "&Forward");
00057             if (QApplication::reverseLayout() )
00058                 iconName = "back";
00059             break;
00060 
00061          case Home: sLabel = i18n("beginning (of line)", "&Home"); break;
00062          case Help: sLabel = i18n("show help", "&Help"); break;
00063          case AboutApp: iconName = kapp->miniIconName();
00064          case Preferences:
00065          case HelpContents:
00066             {
00067             const KAboutData *aboutData = KGlobal::instance()->aboutData();
00068             QString appName = (aboutData) ? aboutData->programName() : QString::fromLatin1(qApp->name());
00069             sLabel = i18n(pInfo->psLabel).arg(appName);
00070             }
00071             break;
00072          default: sLabel = i18n(pInfo->psLabel);
00073         }
00074 
00075         if (QApplication::reverseLayout()){
00076             if (id == Prior) iconName = "next";
00077             if (id == Next ) iconName = "previous";
00078         }
00079 
00080         KShortcut cut = KStdAccel::shortcut(pInfo->idAccel);
00081         switch( id ) {
00082          case OpenRecent:
00083             pAction = new KRecentFilesAction( sLabel, pInfo->psIconName, cut,
00084                     recvr, slot,
00085                     parent, (name) ? name : pInfo->psName );
00086             break;
00087          case ShowMenubar:
00088          case ShowToolbar:
00089          case ShowStatusbar:
00090          {
00091             KToggleAction *ret;
00092             ret = new KToggleAction( sLabel, pInfo->psIconName, cut,
00093                     recvr, slot,
00094                     parent, (name) ? name : pInfo->psName );
00095             ret->setChecked( true );
00096             pAction = ret;
00097             break;
00098          }
00099          case FullScreen:
00100          {
00101             KToggleFullScreenAction *ret;
00102             ret = new KToggleFullScreenAction( cut, recvr, slot,
00103                     parent, NULL, (name) ? name : pInfo->psName );
00104             ret->setChecked( false );
00105             pAction = ret;
00106             break;
00107          }
00108          case PasteText:
00109          {
00110             KPasteTextAction *ret;
00111             ret = new KPasteTextAction(sLabel, iconName, cut,
00112                     recvr, slot,
00113                     parent, (name) ? name : pInfo->psName );
00114             pAction = ret;
00115             break;
00116          }
00117          default:
00118             pAction = new KAction( sLabel, iconName, cut,
00119                     recvr, slot,
00120                     parent, (name) ? name : pInfo->psName );
00121             break;
00122         }
00123     }
00124     return pAction;
00125 }
00126 
00127 const char* name( StdAction id )
00128 {
00129     const KStdActionInfo* pInfo = infoPtr( id );
00130     return (pInfo) ? pInfo->psName : 0;
00131 }
00132 
00133 KAction *openNew( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00134     { return KStdAction::create( New, name, recvr, slot, parent ); }
00135 KAction *open( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00136     { return KStdAction::create( Open, name, recvr, slot, parent ); }
00137 KRecentFilesAction *openRecent( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00138     { return (KRecentFilesAction*) KStdAction::create( OpenRecent, name, recvr, slot, parent ); }
00139 KAction *save( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00140     { return KStdAction::create( Save, name, recvr, slot, parent ); }
00141 KAction *saveAs( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00142     { return KStdAction::create( SaveAs, name, recvr, slot, parent ); }
00143 KAction *revert( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00144     { return KStdAction::create( Revert, name, recvr, slot, parent ); }
00145 KAction *print( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00146     { return KStdAction::create( Print, name, recvr, slot, parent ); }
00147 KAction *printPreview( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00148     { return KStdAction::create( PrintPreview, name, recvr, slot, parent ); }
00149 KAction *close( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00150     { return KStdAction::create( Close, name, recvr, slot, parent ); }
00151 KAction *mail( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00152     { return KStdAction::create( Mail, name, recvr, slot, parent ); }
00153 KAction *quit( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00154     { return KStdAction::create( Quit, name, recvr, slot, parent ); }
00155 KAction *undo( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00156     { return KStdAction::create( Undo, name, recvr, slot, parent ); }
00157 KAction *redo( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00158     { return KStdAction::create( Redo, name, recvr, slot, parent ); }
00159 KAction *cut( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00160     { return KStdAction::create( Cut, name, recvr, slot, parent ); }
00161 KAction *copy( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00162     { return KStdAction::create( Copy, name, recvr, slot, parent ); }
00163 KAction *paste( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00164     { return KStdAction::create( Paste, name, recvr, slot, parent ); }
00165 KAction *pasteText( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00166     { return KStdAction::create( PasteText, name, recvr, slot, parent ); }
00167 KAction *clear( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00168     { return KStdAction::create( Clear, name, recvr, slot, parent ); }
00169 KAction *selectAll( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00170     { return KStdAction::create( SelectAll, name, recvr, slot, parent ); }
00171 KAction *deselect( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00172     { return KStdAction::create( Deselect, name, recvr, slot, parent ); }
00173 KAction *find( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00174     { return KStdAction::create( Find, name, recvr, slot, parent ); }
00175 KAction *findNext( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00176     { return KStdAction::create( FindNext, name, recvr, slot, parent ); }
00177 KAction *findPrev( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00178     { return KStdAction::create( FindPrev, name, recvr, slot, parent ); }
00179 KAction *replace( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00180     { return KStdAction::create( Replace, name, recvr, slot, parent ); }
00181 KAction *actualSize( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00182     { return KStdAction::create( ActualSize, name, recvr, slot, parent ); }
00183 KAction *fitToPage( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00184     { return KStdAction::create( FitToPage, name, recvr, slot, parent ); }
00185 KAction *fitToWidth( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00186     { return KStdAction::create( FitToWidth, name, recvr, slot, parent ); }
00187 KAction *fitToHeight( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00188     { return KStdAction::create( FitToHeight, name, recvr, slot, parent ); }
00189 KAction *zoomIn( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00190     { return KStdAction::create( ZoomIn, name, recvr, slot, parent ); }
00191 KAction *zoomOut( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00192     { return KStdAction::create( ZoomOut, name, recvr, slot, parent ); }
00193 KAction *zoom( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00194     { return KStdAction::create( Zoom, name, recvr, slot, parent ); }
00195 KAction *redisplay( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00196     { return KStdAction::create( Redisplay, name, recvr, slot, parent ); }
00197 KAction *up( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00198     { return KStdAction::create( Up, name, recvr, slot, parent ); }
00199 KAction *back( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00200     { return KStdAction::create( Back, name, recvr, slot, parent ); }
00201 KAction *forward( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00202     { return KStdAction::create( Forward, name, recvr, slot, parent ); }
00203 KAction *home( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00204     { return KStdAction::create( Home, name, recvr, slot, parent ); }
00205 KAction *prior( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00206     { return KStdAction::create( Prior, name, recvr, slot, parent ); }
00207 KAction *next( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00208     { return KStdAction::create( Next, name, recvr, slot, parent ); }
00209 KAction *goTo( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00210     { return KStdAction::create( Goto, name, recvr, slot, parent ); }
00211 KAction *gotoPage( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00212     { return KStdAction::create( GotoPage, name, recvr, slot, parent ); }
00213 KAction *gotoLine( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00214     { return KStdAction::create( GotoLine, name, recvr, slot, parent ); }
00215 KAction *firstPage( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00216     { return KStdAction::create( FirstPage, name, recvr, slot, parent ); }
00217 KAction *lastPage( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00218     { return KStdAction::create( LastPage, name, recvr, slot, parent ); }
00219 KAction *addBookmark( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00220     { return KStdAction::create( AddBookmark, name, recvr, slot, parent ); }
00221 KAction *editBookmarks( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00222     { return KStdAction::create( EditBookmarks, name, recvr, slot, parent ); }
00223 KAction *spelling( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00224     { return KStdAction::create( Spelling, name, recvr, slot, parent ); }
00225 
00226 KToggleAction *showMenubar( const QObject *recvr, const char *slot, KActionCollection* parent, const char *_name )
00227 {
00228     KToggleAction *ret;
00229     ret = new KToggleAction(i18n("Show &Menubar"), "showmenu", KStdAccel::shortcut(KStdAccel::ShowMenubar), recvr, slot,
00230                             parent, _name ? _name : name(ShowMenubar));
00231     ret->setWhatsThis( i18n( "Show Menubar<p>"
00232                              "Shows the menubar again after it has been hidden" ) );
00233     KGuiItem guiItem( i18n("Hide &Menubar"), 0 /*same icon*/, QString::null,
00234                       i18n( "Hide Menubar<p>"
00235                             "Hide the menubar. You can usually get it back using the right mouse button inside the window itself." ) );
00236     ret->setCheckedState( guiItem );
00237     ret->setChecked(true);
00238     return ret;
00239 }
00240 
00241 // obsolete
00242 KToggleAction *showToolbar( const QObject *recvr, const char *slot, KActionCollection* parent, const char *_name )
00243 {
00244     KToggleAction *ret;
00245     ret = new KToggleAction(i18n("Show &Toolbar"), 0, recvr, slot, parent,
00246                             _name ? _name : name(ShowToolbar));
00247     ret->setChecked(true);
00248     return ret;
00249 
00250 }
00251 
00252 // obsolete
00253 KToggleToolBarAction *showToolbar( const char* toolBarName, KActionCollection* parent, const char *_name )
00254 {
00255     KToggleToolBarAction *ret;
00256     ret = new KToggleToolBarAction(toolBarName, i18n("Show &Toolbar"), parent,
00257                             _name ? _name : name(ShowToolbar));
00258     return ret;
00259 }
00260 
00261 KToggleAction *showStatusbar( const QObject *recvr, const char *slot,
00262                                          KActionCollection* parent, const char *_name )
00263 {
00264     KToggleAction *ret;
00265     ret = new KToggleAction(i18n("Show St&atusbar"), 0, recvr, slot, parent,
00266                             _name ? _name : name(ShowStatusbar));
00267     ret->setWhatsThis( i18n( "Show Statusbar<p>"
00268                              "Shows the statusbar, which is the bar at the bottom of the window used for status information." ) );
00269     KGuiItem guiItem( i18n("Hide St&atusbar"), QString::null, QString::null,
00270                       i18n( "Hide Statusbar<p>"
00271                             "Hides the statusbar, which is the bar at the bottom of the window used for status information." ) );
00272     ret->setCheckedState( guiItem );
00273 
00274     ret->setChecked(true);
00275     return ret;
00276 }
00277 
00278 KToggleFullScreenAction *fullScreen( const QObject *recvr, const char *slot, KActionCollection* parent,
00279     QWidget* window, const char *name )
00280 {
00281     KToggleFullScreenAction *ret;
00282     ret = static_cast< KToggleFullScreenAction* >( KStdAction::create( FullScreen, name, recvr, slot, parent ));
00283     ret->setWindow( window );
00284     return ret;
00285 }
00286 
00287 KAction *saveOptions( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00288     { return KStdAction::create( SaveOptions, name, recvr, slot, parent ); }
00289 KAction *keyBindings( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00290     { return KStdAction::create( KeyBindings, name, recvr, slot, parent ); }
00291 KAction *preferences( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00292     { return KStdAction::create( Preferences, name, recvr, slot, parent ); }
00293 KAction *configureToolbars( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00294     { return KStdAction::create( ConfigureToolbars, name, recvr, slot, parent ); }
00295 KAction *configureNotifications( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00296     { return KStdAction::create( ConfigureNotifications, name, recvr, slot, parent ); }
00297 KAction *help( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00298     { return KStdAction::create( Help, name, recvr, slot, parent ); }
00299 KAction *helpContents( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00300     { return KStdAction::create( HelpContents, name, recvr, slot, parent ); }
00301 KAction *whatsThis( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00302     { return KStdAction::create( WhatsThis, name, recvr, slot, parent ); }
00303 KAction *tipOfDay( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00304     { return KStdAction::create( TipofDay, name, recvr, slot, parent ); }
00305 KAction *reportBug( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00306     { return KStdAction::create( ReportBug, name, recvr, slot, parent ); }
00307 KAction *aboutApp( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00308     { return KStdAction::create( AboutApp, name, recvr, slot, parent ); }
00309 KAction *aboutKDE( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00310     { return KStdAction::create( AboutKDE, name, recvr, slot, parent ); }
00311 
00312 }
KDE Logo
This file is part of the documentation for kdeui Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Jul 22 10:16:47 2005 by doxygen 1.3.6 written by Dimitri van Heesch, © 1997-2003