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