00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "kstandardaction.h"
00020 #include "kstandardaction_p.h"
00021 #include "kstandardaction_p.moc"
00022
00023 #include <QtCore/QMutableStringListIterator>
00024 #include <QtGui/QToolButton>
00025
00026 #include <kaboutdata.h>
00027 #include <kaction.h>
00028 #include <QtGui/QApplication>
00029 #include <kcomponentdata.h>
00030 #include <kdebug.h>
00031 #include <kglobal.h>
00032 #include <kguiitem.h>
00033 #include <kiconloader.h>
00034 #include <klocale.h>
00035 #include <kstandardshortcut.h>
00036 #include <kmainwindow.h>
00037 #include <kicon.h>
00038
00039 #include "krecentfilesaction.h"
00040 #include "ktogglefullscreenaction.h"
00041 #include "kpastetextaction.h"
00042 #include "kactioncollection.h"
00043
00044 namespace KStandardAction
00045 {
00046 AutomaticAction::AutomaticAction(const KIcon &icon, const QString &text, const KShortcut &shortcut, const char *slot,
00047 QObject *parent)
00048 : KAction(parent)
00049 {
00050 setText(text);
00051 setIcon(icon);
00052 setShortcut(shortcut);
00053 connect(this, SIGNAL(triggered()), this, slot);
00054 }
00055
00056 QStringList stdNames()
00057 {
00058 return internal_stdNames();
00059 }
00060
00061 KAction *create(StandardAction id, const QObject *recvr, const char *slot, QObject *parent)
00062 {
00063 KAction *pAction = 0;
00064 const KStandardActionInfo* pInfo = infoPtr(id);
00065
00066 kDebug(125) << "KStandardAction::create( " << id << "=" << (pInfo ? pInfo->psName : (const char*)0) << ", " << parent << " )";
00067
00068 if ( pInfo ) {
00069 QString sLabel, iconName = pInfo->psIconName;
00070 switch( id ) {
00071 case Back:
00072 sLabel = i18nc( "go back", "&Back");
00073 if ( QApplication::isRightToLeft() )
00074 iconName = "go-next";
00075 break;
00076
00077 case Forward:
00078 sLabel = i18nc( "go forward", "&Forward" );
00079 if ( QApplication::isRightToLeft() )
00080 iconName = "go-previous";
00081 break;
00082
00083 case Home:
00084 sLabel = i18nc( "home page", "&Home" );
00085 break;
00086 case Help:
00087 sLabel = i18nc( "show help", "&Help" );
00088 break;
00089 case Preferences:
00090 case AboutApp:
00091 case HelpContents:
00092 {
00093 const KAboutData *aboutData = KGlobal::mainComponent().aboutData();
00094
00095
00096
00097
00098
00099
00100
00101 QString appName = (aboutData) ? aboutData->programName() : qApp->applicationName();
00102 sLabel = i18n( pInfo->psLabel, appName );
00103 }
00104 break;
00105 default:
00106 sLabel = i18n( pInfo->psLabel );
00107 }
00108
00109 if ( QApplication::isRightToLeft() ) {
00110 switch ( id ) {
00111 case Prior: iconName = "go-next-page"; break;
00112 case Next: iconName = "go-previous-page"; break;
00113 case FirstPage: iconName = "go-last-page"; break;
00114 case LastPage: iconName = "go-first-page"; break;
00115 case DocumentBack: iconName = "go-next"; break;
00116 case DocumentForward: iconName = "go-previous"; break;
00117 default: break;
00118 }
00119 }
00120
00121 QIcon icon = iconName.isEmpty() ? KIcon() : KIcon(iconName);
00122
00123 switch ( id ) {
00124 case OpenRecent:
00125 pAction = new KRecentFilesAction(parent);
00126 break;
00127 case ShowMenubar:
00128 case ShowToolbar:
00129 case ShowStatusbar:
00130 pAction = new KAction(parent);
00131 pAction->setCheckable(true);
00132 pAction->setChecked(true);
00133 break;
00134 case FullScreen:
00135 pAction = new KToggleFullScreenAction(parent);
00136 pAction->setCheckable(true);
00137 break;
00138 case PasteText:
00139 pAction = new KPasteTextAction(parent);
00140 break;
00141
00142 case AboutApp:
00143 pAction = new KAction(parent);
00144 icon = qApp->windowIcon();
00145 break;
00146
00147 default:
00148 pAction = new KAction(parent);
00149 break;
00150 }
00151
00152 switch ( id ) {
00153 case Quit:
00154 pAction->setMenuRole(QAction::QuitRole);
00155 break;
00156
00157 case Preferences:
00158 pAction->setMenuRole(QAction::PreferencesRole);
00159 break;
00160
00161 case AboutApp:
00162 pAction->setMenuRole(QAction::AboutRole);
00163 break;
00164
00165 default:
00166 pAction->setMenuRole(QAction::NoRole);
00167 break;
00168 }
00169
00170 pAction->setText(sLabel);
00171 pAction->setIcon(icon);
00172
00173 KShortcut cut = KStandardShortcut::shortcut(pInfo->idAccel);
00174 if (!cut.isEmpty())
00175 pAction->setShortcut(cut);
00176
00177 pAction->setObjectName(pInfo->psName);
00178 }
00179
00180 if (recvr && slot) {
00181 if (id != OpenRecent)
00182 QObject::connect(pAction, SIGNAL(triggered(bool)), recvr, slot);
00183 else
00184
00185
00186 QObject::connect(pAction, SIGNAL(urlSelected(const KUrl &)), recvr, slot);
00187 }
00188
00189 KActionCollection *collection = qobject_cast<KActionCollection *>(parent);
00190 if (pAction && collection)
00191 collection->addAction(pAction->objectName(), pAction);
00192
00193 return pAction;
00194 }
00195
00196 const char* name( StandardAction id )
00197 {
00198 const KStandardActionInfo* pInfo = infoPtr( id );
00199 return (pInfo) ? pInfo->psName : 0;
00200 }
00201
00202 KAction *openNew(const QObject *recvr, const char *slot, QObject *parent)
00203 {
00204 return KStandardAction::create(New, recvr, slot, parent);
00205 }
00206
00207 KAction *open(const QObject *recvr, const char *slot, QObject *parent)
00208 {
00209 return KStandardAction::create(Open, recvr, slot, parent);
00210 }
00211
00212 KRecentFilesAction *openRecent(const QObject *recvr, const char *slot, QObject *parent)
00213 {
00214 return (KRecentFilesAction*) KStandardAction::create( OpenRecent, recvr, slot, parent );
00215 }
00216
00217 KAction *save(const QObject *recvr, const char *slot, QObject *parent)
00218 {
00219 return KStandardAction::create(Save, recvr, slot, parent);
00220 }
00221
00222 KAction *saveAs(const QObject *recvr, const char *slot, QObject *parent)
00223 {
00224 return KStandardAction::create(SaveAs, recvr, slot, parent);
00225 }
00226
00227 KAction *revert(const QObject *recvr, const char *slot, QObject *parent)
00228 {
00229 return KStandardAction::create(Revert, recvr, slot, parent);
00230 }
00231
00232 KAction *print(const QObject *recvr, const char *slot, QObject *parent)
00233 {
00234 return KStandardAction::create(Print, recvr, slot, parent);
00235 }
00236
00237 KAction *printPreview( const QObject *recvr, const char *slot, QObject *parent )
00238 {
00239 return KStandardAction::create( PrintPreview, recvr, slot, parent );
00240 }
00241
00242 KAction *close( const QObject *recvr, const char *slot, QObject *parent )
00243 {
00244 return KStandardAction::create( Close, recvr, slot, parent );
00245 }
00246
00247 KAction *mail( const QObject *recvr, const char *slot, QObject *parent )
00248 {
00249 return KStandardAction::create( Mail, recvr, slot, parent );
00250 }
00251
00252 KAction *quit( const QObject *recvr, const char *slot, QObject *parent )
00253 {
00254 return KStandardAction::create( Quit, recvr, slot, parent );
00255 }
00256
00257 KAction *undo( const QObject *recvr, const char *slot, QObject *parent )
00258 {
00259 return KStandardAction::create( Undo, recvr, slot, parent );
00260 }
00261
00262 KAction *redo( const QObject *recvr, const char *slot, QObject *parent )
00263 {
00264 return KStandardAction::create( Redo, recvr, slot, parent );
00265 }
00266
00267 KAction *cut( const QObject *recvr, const char *slot, QObject *parent )
00268 {
00269 return KStandardAction::create( Cut, recvr, slot, parent );
00270 }
00271
00272 KAction *copy( const QObject *recvr, const char *slot, QObject *parent )
00273 {
00274 return KStandardAction::create( Copy, recvr, slot, parent );
00275 }
00276
00277 KAction *paste( const QObject *recvr, const char *slot, QObject *parent )
00278 {
00279 return KStandardAction::create( Paste, recvr, slot, parent );
00280 }
00281
00282 KAction *pasteText( const QObject *recvr, const char *slot, QObject *parent )
00283 {
00284 return KStandardAction::create( PasteText, recvr, slot, parent );
00285 }
00286
00287 KAction *clear( const QObject *recvr, const char *slot, QObject *parent )
00288 {
00289 return KStandardAction::create( Clear, recvr, slot, parent );
00290 }
00291
00292 KAction *selectAll( const QObject *recvr, const char *slot, QObject *parent )
00293 {
00294 return KStandardAction::create( SelectAll, recvr, slot, parent );
00295 }
00296
00297 KAction *deselect( const QObject *recvr, const char *slot, QObject *parent )
00298 {
00299 return KStandardAction::create( Deselect, recvr, slot, parent );
00300 }
00301
00302 KAction *find( const QObject *recvr, const char *slot, QObject *parent )
00303 {
00304 return KStandardAction::create( Find, recvr, slot, parent );
00305 }
00306
00307 KAction *findNext( const QObject *recvr, const char *slot, QObject *parent )
00308 {
00309 return KStandardAction::create( FindNext, recvr, slot, parent );
00310 }
00311
00312 KAction *findPrev( const QObject *recvr, const char *slot, QObject *parent )
00313 {
00314 return KStandardAction::create( FindPrev, recvr, slot, parent );
00315 }
00316
00317 KAction *replace( const QObject *recvr, const char *slot, QObject *parent )
00318 {
00319 return KStandardAction::create( Replace, recvr, slot, parent );
00320 }
00321
00322 KAction *actualSize( const QObject *recvr, const char *slot, QObject *parent )
00323 {
00324 return KStandardAction::create( ActualSize, recvr, slot, parent );
00325 }
00326
00327 KAction *fitToPage( const QObject *recvr, const char *slot, QObject *parent )
00328 {
00329 return KStandardAction::create( FitToPage, recvr, slot, parent );
00330 }
00331
00332 KAction *fitToWidth( const QObject *recvr, const char *slot, QObject *parent )
00333 {
00334 return KStandardAction::create( FitToWidth, recvr, slot, parent );
00335 }
00336
00337 KAction *fitToHeight( const QObject *recvr, const char *slot, QObject *parent )
00338 {
00339 return KStandardAction::create( FitToHeight, recvr, slot, parent );
00340 }
00341
00342 KAction *zoomIn( const QObject *recvr, const char *slot, QObject *parent )
00343 {
00344 return KStandardAction::create( ZoomIn, recvr, slot, parent );
00345 }
00346
00347 KAction *zoomOut( const QObject *recvr, const char *slot, QObject *parent )
00348 {
00349 return KStandardAction::create( ZoomOut, recvr, slot, parent );
00350 }
00351
00352 KAction *zoom( const QObject *recvr, const char *slot, QObject *parent )
00353 {
00354 return KStandardAction::create( Zoom, recvr, slot, parent );
00355 }
00356
00357 KAction *redisplay( const QObject *recvr, const char *slot, QObject *parent )
00358 {
00359 return KStandardAction::create( Redisplay, recvr, slot, parent );
00360 }
00361
00362 KAction *up( const QObject *recvr, const char *slot, QObject *parent )
00363 {
00364 return KStandardAction::create( Up, recvr, slot, parent );
00365 }
00366
00367 KAction *back( const QObject *recvr, const char *slot, QObject *parent )
00368 {
00369 return KStandardAction::create( Back, recvr, slot, parent );
00370 }
00371
00372 KAction *forward( const QObject *recvr, const char *slot, QObject *parent )
00373 {
00374 return KStandardAction::create( Forward, recvr, slot, parent );
00375 }
00376
00377 KAction *home( const QObject *recvr, const char *slot, QObject *parent )
00378 {
00379 return KStandardAction::create( Home, recvr, slot, parent );
00380 }
00381
00382 KAction *prior( const QObject *recvr, const char *slot, QObject *parent )
00383 {
00384 return KStandardAction::create( Prior, recvr, slot, parent );
00385 }
00386
00387 KAction *next( const QObject *recvr, const char *slot, QObject *parent )
00388 {
00389 return KStandardAction::create( Next, recvr, slot, parent );
00390 }
00391
00392 KAction *goTo( const QObject *recvr, const char *slot, QObject *parent )
00393 {
00394 return KStandardAction::create( Goto, recvr, slot, parent );
00395 }
00396
00397 KAction *gotoPage( const QObject *recvr, const char *slot, QObject *parent )
00398 {
00399 return KStandardAction::create( GotoPage, recvr, slot, parent );
00400 }
00401
00402 KAction *gotoLine( const QObject *recvr, const char *slot, QObject *parent )
00403 {
00404 return KStandardAction::create( GotoLine, recvr, slot, parent );
00405 }
00406
00407 KAction *firstPage( const QObject *recvr, const char *slot, QObject *parent )
00408 {
00409 return KStandardAction::create( FirstPage, recvr, slot, parent );
00410 }
00411
00412 KAction *lastPage( const QObject *recvr, const char *slot, QObject *parent )
00413 {
00414 return KStandardAction::create( LastPage, recvr, slot, parent );
00415 }
00416
00417 KAction *documentBack( const QObject *recvr, const char *slot, QObject *parent )
00418 {
00419 return KStandardAction::create( DocumentBack, recvr, slot, parent );
00420 }
00421
00422 KAction *documentForward( const QObject *recvr, const char *slot, QObject *parent )
00423 {
00424 return KStandardAction::create( DocumentForward, recvr, slot, parent );
00425 }
00426
00427 KAction *addBookmark( const QObject *recvr, const char *slot, QObject *parent )
00428 {
00429 return KStandardAction::create( AddBookmark, recvr, slot, parent );
00430 }
00431
00432 KAction *editBookmarks( const QObject *recvr, const char *slot, QObject *parent )
00433 {
00434 return KStandardAction::create( EditBookmarks, recvr, slot, parent );
00435 }
00436
00437 KAction *spelling( const QObject *recvr, const char *slot, QObject *parent )
00438 {
00439 return KStandardAction::create( Spelling, recvr, slot, parent );
00440 }
00441
00442 static KAction *buildAutomaticAction( QObject* parent, StandardAction id, const char* slot )
00443 {
00444 const KStandardActionInfo* p = infoPtr( id );
00445 if ( !p )
00446 return 0;
00447
00448 AutomaticAction *action = new AutomaticAction( KIcon( p->psIconName ), p->psLabel,
00449 KStandardShortcut::shortcut( p->idAccel ), slot, parent);
00450
00451 action->setObjectName(p->psName);
00452 action->setWhatsThis( p->psWhatsThis );
00453
00454 KActionCollection *collection = qobject_cast<KActionCollection *>(parent);
00455 if (collection)
00456 collection->addAction(action->objectName(), action);
00457
00458 return action;
00459 }
00460
00461 KAction *cut( QObject* parent )
00462 {
00463 return buildAutomaticAction( parent, Cut, SLOT( cut() ) );
00464 }
00465
00466 KAction *copy( QObject* parent )
00467 {
00468 return buildAutomaticAction( parent, Copy, SLOT( copy() ) );
00469 }
00470
00471 KAction *paste( QObject* parent )
00472 {
00473 return buildAutomaticAction( parent, Paste, SLOT( paste() ) );
00474 }
00475
00476 KAction *clear( QObject* parent )
00477 {
00478 return buildAutomaticAction( parent, Clear, SLOT( clear() ) );
00479 }
00480
00481 KAction *selectAll( QObject* parent )
00482 {
00483 return buildAutomaticAction( parent, SelectAll, SLOT( selectAll() ) );
00484 }
00485
00486 KToggleAction *showMenubar(const QObject *recvr, const char *slot, QObject *parent)
00487 {
00488 KToggleAction *ret = new KToggleAction(i18n( "Show &Menubar" ), parent);
00489 ret->setObjectName(name(ShowMenubar));
00490 ret->setIcon( KIcon( "show-menu" ) );
00491
00492 ret->setShortcut( KStandardShortcut::shortcut( KStandardShortcut::ShowMenubar ) );
00493
00494 ret->setWhatsThis( i18n( "Show Menubar<p>"
00495 "Shows the menubar again after it has been hidden</p>" ) );
00496
00497 ret->setChecked( true );
00498
00499 if ( recvr && slot )
00500 QObject::connect( ret, SIGNAL( triggered( bool ) ), recvr, slot );
00501
00502 KActionCollection *collection = qobject_cast<KActionCollection *>(parent);
00503 if (collection)
00504 collection->addAction(ret->objectName(), ret);
00505
00506 return ret;
00507 }
00508
00509 KToggleAction *showStatusbar(const QObject *recvr, const char *slot, QObject *parent)
00510 {
00511 KToggleAction *ret = new KToggleAction(i18n( "Show St&atusbar" ), parent);
00512 ret->setObjectName(name(ShowStatusbar));
00513
00514 ret->setWhatsThis( i18n( "Show Statusbar<br /><br />"
00515 "Shows the statusbar, which is the bar at the bottom of the window used for status information." ) );
00516
00517 ret->setChecked( true );
00518
00519 if ( recvr && slot )
00520 QObject::connect( ret, SIGNAL( triggered( bool ) ), recvr, slot );
00521
00522 KActionCollection *collection = qobject_cast<KActionCollection *>(parent);
00523 if (collection)
00524 collection->addAction(ret->objectName(), ret);
00525
00526 return ret;
00527 }
00528
00529 KToggleFullScreenAction *fullScreen(const QObject *recvr, const char *slot, QWidget* window, QObject *parent)
00530 {
00531 KToggleFullScreenAction *ret;
00532 ret = static_cast< KToggleFullScreenAction* >( KStandardAction::create( FullScreen, recvr, slot, parent ) );
00533 ret->setWindow( window );
00534
00535 return ret;
00536 }
00537
00538 KAction *saveOptions( const QObject *recvr, const char *slot, QObject *parent )
00539 {
00540 return KStandardAction::create( SaveOptions, recvr, slot, parent );
00541 }
00542
00543 KAction *keyBindings( const QObject *recvr, const char *slot, QObject *parent )
00544 {
00545 return KStandardAction::create( KeyBindings, recvr, slot, parent );
00546 }
00547
00548 KAction *preferences( const QObject *recvr, const char *slot, QObject *parent )
00549 {
00550 return KStandardAction::create( Preferences, recvr, slot, parent );
00551 }
00552
00553 KAction *configureToolbars( const QObject *recvr, const char *slot, QObject *parent )
00554 {
00555 return KStandardAction::create( ConfigureToolbars, recvr, slot, parent );
00556 }
00557
00558 KAction *configureNotifications( const QObject *recvr, const char *slot, QObject *parent )
00559 {
00560 return KStandardAction::create( ConfigureNotifications, recvr, slot, parent );
00561 }
00562
00563 KAction *help( const QObject *recvr, const char *slot, QObject *parent )
00564 {
00565 return KStandardAction::create( Help, recvr, slot, parent );
00566 }
00567
00568 KAction *helpContents( const QObject *recvr, const char *slot, QObject *parent )
00569 {
00570 return KStandardAction::create( HelpContents, recvr, slot, parent );
00571 }
00572
00573 KAction *whatsThis( const QObject *recvr, const char *slot, QObject *parent )
00574 {
00575 return KStandardAction::create( WhatsThis, recvr, slot, parent );
00576 }
00577
00578 KAction *tipOfDay( const QObject *recvr, const char *slot, QObject *parent )
00579 {
00580 return KStandardAction::create( TipofDay, recvr, slot, parent );
00581 }
00582
00583 KAction *reportBug( const QObject *recvr, const char *slot, QObject *parent )
00584 {
00585 return KStandardAction::create( ReportBug, recvr, slot, parent );
00586 }
00587
00588 KAction *switchApplicationLanguage( const QObject *recvr, const char *slot, QObject *parent )
00589 {
00590 return KStandardAction::create( SwitchApplicationLanguage, recvr, slot, parent );
00591 }
00592
00593 KAction *aboutApp( const QObject *recvr, const char *slot, QObject *parent )
00594 {
00595 return KStandardAction::create( AboutApp, recvr, slot, parent );
00596 }
00597
00598 KAction *aboutKDE( const QObject *recvr, const char *slot, QObject *parent )
00599 {
00600 return KStandardAction::create( AboutKDE, recvr, slot, parent );
00601 }
00602
00603 }
00604