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