# kdeui Library API Documentation

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

# 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             /* TODO KDE4
    00069             const KAboutData *aboutData;
    00070             if ( parent )
    00071                 aboutData = parent->instance()->aboutData();
    00072             else
    00073                 aboutData = KGlobal::instance()->aboutData();
    00074             */
    00075             QString appName = (aboutData) ? aboutData->programName() : QString::fromLatin1(qApp->name());
    00076             sLabel = i18n(pInfo->psLabel).arg(appName);
    00077             }
    00078             break;
    00079          default: sLabel = i18n(pInfo->psLabel);
    00080         }
    00081
    00082         if (QApplication::reverseLayout()){
    00083             if (id == Prior) iconName = "next";
    00084             if (id == Next ) iconName = "previous";
    00085         }
    00086
    00087         KShortcut cut = KStdAccel::shortcut(pInfo->idAccel);
    00088         switch( id ) {
    00089          case OpenRecent:
    00090             pAction = new KRecentFilesAction( sLabel, pInfo->psIconName, cut,
    00091                     recvr, slot,
    00092                     parent, (name) ? name : pInfo->psName );
    00093             break;
    00094          case ShowMenubar:
    00095          case ShowToolbar:
    00096          case ShowStatusbar:
    00097          {
    00098             KToggleAction *ret;
    00099             ret = new KToggleAction( sLabel, pInfo->psIconName, cut,
    00100                     recvr, slot,
    00101                     parent, (name) ? name : pInfo->psName );
    00102             ret->setChecked( true );
    00103             pAction = ret;
    00104             break;
    00105          }
    00106          case FullScreen:
    00107          {
    00108             KToggleFullScreenAction *ret;
    00109             ret = new KToggleFullScreenAction( cut, recvr, slot,
    00110                     parent, NULL, (name) ? name : pInfo->psName );
    00111             ret->setChecked( false );
    00112             pAction = ret;
    00113             break;
    00114          }
    00115          case PasteText:
    00116          {
    00117             KPasteTextAction *ret;
    00118             ret = new KPasteTextAction(sLabel, iconName, cut,
    00119                     recvr, slot,
    00120                     parent, (name) ? name : pInfo->psName );
    00121             pAction = ret;
    00122             break;
    00123          }
    00124          default:
    00125             pAction = new KAction( sLabel, iconName, cut,
    00126                     recvr, slot,
    00127                     parent, (name) ? name : pInfo->psName );
    00128             break;
    00129         }
    00130     }
    00131     return pAction;
    00132 }
    00133
    00134 const char* name( StdAction id )
    00135 {
    00136     const KStdActionInfo* pInfo = infoPtr( id );
    00137     return (pInfo) ? pInfo->psName : 0;
    00138 }
    00139
    00140 KAction *openNew( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00141     { return KStdAction::create( New, name, recvr, slot, parent ); }
    00142 KAction *open( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00143     { return KStdAction::create( Open, name, recvr, slot, parent ); }
    00144 KRecentFilesAction *openRecent( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00145     { return (KRecentFilesAction*) KStdAction::create( OpenRecent, name, recvr, slot, parent ); }
    00146 KAction *save( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00147     { return KStdAction::create( Save, name, recvr, slot, parent ); }
    00148 KAction *saveAs( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00149     { return KStdAction::create( SaveAs, name, recvr, slot, parent ); }
    00150 KAction *revert( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00151     { return KStdAction::create( Revert, name, recvr, slot, parent ); }
    00152 KAction *print( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00153     { return KStdAction::create( Print, name, recvr, slot, parent ); }
    00154 KAction *printPreview( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00155     { return KStdAction::create( PrintPreview, name, recvr, slot, parent ); }
    00156 KAction *close( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00157     { return KStdAction::create( Close, name, recvr, slot, parent ); }
    00158 KAction *mail( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00159     { return KStdAction::create( Mail, name, recvr, slot, parent ); }
    00160 KAction *quit( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00161     { return KStdAction::create( Quit, name, recvr, slot, parent ); }
    00162 KAction *undo( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00163     { return KStdAction::create( Undo, name, recvr, slot, parent ); }
    00164 KAction *redo( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00165     { return KStdAction::create( Redo, name, recvr, slot, parent ); }
    00166 KAction *cut( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00167     { return KStdAction::create( Cut, name, recvr, slot, parent ); }
    00168 KAction *copy( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00169     { return KStdAction::create( Copy, name, recvr, slot, parent ); }
    00170 KAction *paste( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00171     { return KStdAction::create( Paste, name, recvr, slot, parent ); }
    00172 KAction *pasteText( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00173     { return KStdAction::create( PasteText, name, recvr, slot, parent ); }
    00174 KAction *clear( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00175     { return KStdAction::create( Clear, name, recvr, slot, parent ); }
    00176 KAction *selectAll( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00177     { return KStdAction::create( SelectAll, name, recvr, slot, parent ); }
    00178 KAction *deselect( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00179     { return KStdAction::create( Deselect, name, recvr, slot, parent ); }
    00180 KAction *find( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00181     { return KStdAction::create( Find, name, recvr, slot, parent ); }
    00182 KAction *findNext( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00183     { return KStdAction::create( FindNext, name, recvr, slot, parent ); }
    00184 KAction *findPrev( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00185     { return KStdAction::create( FindPrev, name, recvr, slot, parent ); }
    00186 KAction *replace( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00187     { return KStdAction::create( Replace, name, recvr, slot, parent ); }
    00188 KAction *actualSize( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00189     { return KStdAction::create( ActualSize, name, recvr, slot, parent ); }
    00190 KAction *fitToPage( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00191     { return KStdAction::create( FitToPage, name, recvr, slot, parent ); }
    00192 KAction *fitToWidth( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00193     { return KStdAction::create( FitToWidth, name, recvr, slot, parent ); }
    00194 KAction *fitToHeight( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00195     { return KStdAction::create( FitToHeight, name, recvr, slot, parent ); }
    00196 KAction *zoomIn( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00197     { return KStdAction::create( ZoomIn, name, recvr, slot, parent ); }
    00198 KAction *zoomOut( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00199     { return KStdAction::create( ZoomOut, name, recvr, slot, parent ); }
    00200 KAction *zoom( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00201     { return KStdAction::create( Zoom, name, recvr, slot, parent ); }
    00202 KAction *redisplay( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00203     { return KStdAction::create( Redisplay, name, recvr, slot, parent ); }
    00204 KAction *up( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00205     { return KStdAction::create( Up, name, recvr, slot, parent ); }
    00206 KAction *back( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00207     { return KStdAction::create( Back, name, recvr, slot, parent ); }
    00208 KAction *forward( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00209     { return KStdAction::create( Forward, name, recvr, slot, parent ); }
    00210 KAction *home( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00211     { return KStdAction::create( Home, name, recvr, slot, parent ); }
    00212 KAction *prior( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00213     { return KStdAction::create( Prior, name, recvr, slot, parent ); }
    00214 KAction *next( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00215     { return KStdAction::create( Next, name, recvr, slot, parent ); }
    00216 KAction *goTo( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00217     { return KStdAction::create( Goto, name, recvr, slot, parent ); }
    00218 KAction *gotoPage( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00219     { return KStdAction::create( GotoPage, name, recvr, slot, parent ); }
    00220 KAction *gotoLine( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00221     { return KStdAction::create( GotoLine, name, recvr, slot, parent ); }
    00222 KAction *firstPage( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00223     { return KStdAction::create( FirstPage, name, recvr, slot, parent ); }
    00224 KAction *lastPage( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00225     { return KStdAction::create( LastPage, name, recvr, slot, parent ); }
    00226 KAction *addBookmark( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00227     { return KStdAction::create( AddBookmark, name, recvr, slot, parent ); }
    00228 KAction *editBookmarks( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00229     { return KStdAction::create( EditBookmarks, name, recvr, slot, parent ); }
    00230 KAction *spelling( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00231     { return KStdAction::create( Spelling, name, recvr, slot, parent ); }
    00232
    00233 KToggleAction *showMenubar( const QObject *recvr, const char *slot, KActionCollection* parent, const char *_name )
    00234 {
    00235     KToggleAction *ret;
    00236     ret = new KToggleAction(i18n("Show &Menubar"), "showmenu", KStdAccel::shortcut(KStdAccel::ShowMenubar), recvr, slot,
    00237                             parent, _name ? _name : name(ShowMenubar));
    00238     ret->setWhatsThis( i18n( "Show Menubar<p>"
    00239                              "Shows the menubar again after it has been hidden" ) );
    00240     KGuiItem guiItem( i18n("Hide &Menubar"), 0 /*same icon*/, QString::null,
    00241                       i18n( "Hide Menubar<p>"
    00242                             "Hide the menubar. You can usually get it back using the right mouse button inside the window itself." ) );
    00243     ret->setCheckedState( guiItem );
    00244     ret->setChecked(true);
    00245     return ret;
    00246 }
    00247
    00248 // obsolete
    00249 KToggleAction *showToolbar( const QObject *recvr, const char *slot, KActionCollection* parent, const char *_name )
    00250 {
    00251     KToggleAction *ret;
    00252     ret = new KToggleAction(i18n("Show &Toolbar"), 0, recvr, slot, parent,
    00253                             _name ? _name : name(ShowToolbar));
    00254     ret->setChecked(true);
    00255     return ret;
    00256
    00257 }
    00258
    00259 // obsolete
    00260 KToggleToolBarAction *showToolbar( const char* toolBarName, KActionCollection* parent, const char *_name )
    00261 {
    00262     KToggleToolBarAction *ret;
    00263     ret = new KToggleToolBarAction(toolBarName, i18n("Show &Toolbar"), parent,
    00264                             _name ? _name : name(ShowToolbar));
    00265     return ret;
    00266 }
    00267
    00268 KToggleAction *showStatusbar( const QObject *recvr, const char *slot,
    00269                                          KActionCollection* parent, const char *_name )
    00270 {
    00271     KToggleAction *ret;
    00272     ret = new KToggleAction(i18n("Show St&atusbar"), 0, recvr, slot, parent,
    00273                             _name ? _name : name(ShowStatusbar));
    00274     ret->setWhatsThis( i18n( "Show Statusbar<p>"
    00275                              "Shows the statusbar, which is the bar at the bottom of the window used for status information." ) );
    00276     KGuiItem guiItem( i18n("Hide St&atusbar"), QString::null, QString::null,
    00277                       i18n( "Hide Statusbar<p>"
    00278                             "Hides the statusbar, which is the bar at the bottom of the window used for status information." ) );
    00279     ret->setCheckedState( guiItem );
    00280
    00281     ret->setChecked(true);
    00282     return ret;
    00283 }
    00284
    00285 KToggleFullScreenAction *fullScreen( const QObject *recvr, const char *slot, KActionCollection* parent,
    00286     QWidget* window, const char *name )
    00287 {
    00288     KToggleFullScreenAction *ret;
    00289     ret = static_cast< KToggleFullScreenAction* >( KStdAction::create( FullScreen, name, recvr, slot, parent ));
    00290     ret->setWindow( window );
    00291     return ret;
    00292 }
    00293
    00294 KAction *saveOptions( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00295     { return KStdAction::create( SaveOptions, name, recvr, slot, parent ); }
    00296 KAction *keyBindings( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00297     { return KStdAction::create( KeyBindings, name, recvr, slot, parent ); }
    00298 KAction *preferences( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00299     { return KStdAction::create( Preferences, name, recvr, slot, parent ); }
    00300 KAction *configureToolbars( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00301     { return KStdAction::create( ConfigureToolbars, name, recvr, slot, parent ); }
    00302 KAction *configureNotifications( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00303     { return KStdAction::create( ConfigureNotifications, name, recvr, slot, parent ); }
    00304 KAction *help( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00305     { return KStdAction::create( Help, name, recvr, slot, parent ); }
    00306 KAction *helpContents( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00307     { return KStdAction::create( HelpContents, name, recvr, slot, parent ); }
    00308 KAction *whatsThis( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00309     { return KStdAction::create( WhatsThis, name, recvr, slot, parent ); }
    00310 KAction *tipOfDay( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00311     { return KStdAction::create( TipofDay, name, recvr, slot, parent ); }
    00312 KAction *reportBug( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00313     { return KStdAction::create( ReportBug, name, recvr, slot, parent ); }
    00314 KAction *aboutApp( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00315     { return KStdAction::create( AboutApp, name, recvr, slot, parent ); }
    00316 KAction *aboutKDE( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
    00317     { return KStdAction::create( AboutKDE, name, recvr, slot, parent ); }
    00318
    00319 }

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:23 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003