KToggleFullScreenAction *fullScreen(const QObject *recvr, const char *slot, KActionCollection *parent, QWidget *window, const char *name) { KToggleFullScreenAction *ret; ret = static_cast< KToggleFullScreenAction * >(KStdAction::create(FullScreen, name, recvr, slot, parent)); ret->setWindow(window); return ret; }
KAction *create(StdAction id, const char *name, const QObject *recvr, const char *slot, KActionCollection *parent) { KAction *pAction = 0; const KStdActionInfo *pInfo = infoPtr(id); kdDebug(125) << "KStdAction::create( " << id << "=" << (pInfo ? pInfo->psName : (const char *)0) << ", " << parent << ", " << name << " )" << endl; // ellis if(pInfo) { QString sLabel, iconName = pInfo->psIconName; switch(id) { case Back: sLabel = i18n("go back", "&Back"); if(QApplication::reverseLayout()) iconName = "forward"; break; case Forward: sLabel = i18n("go forward", "&Forward"); if(QApplication::reverseLayout()) iconName = "back"; break; case Home: sLabel = i18n("beginning (of line)", "&Home"); break; case Help: sLabel = i18n("show help", "&Help"); break; case AboutApp: iconName = kapp->miniIconName(); case Preferences: case HelpContents: { const KAboutData *aboutData = KGlobal::instance()->aboutData(); /* TODO KDE4 const KAboutData *aboutData; if ( parent ) aboutData = parent->instance()->aboutData(); else aboutData = KGlobal::instance()->aboutData(); */ QString appName = (aboutData) ? aboutData->programName() : QString::fromLatin1(qApp->name()); sLabel = i18n(pInfo->psLabel).arg(appName); } break; default: sLabel = i18n(pInfo->psLabel); } if(QApplication::reverseLayout()) { if(id == Prior) iconName = "forward"; if(id == Next) iconName = "back"; if(id == FirstPage) iconName = "finish"; if(id == LastPage) iconName = "start"; } KShortcut cut = KStdAccel::shortcut(pInfo->idAccel); switch(id) { case OpenRecent: pAction = new KRecentFilesAction(sLabel, pInfo->psIconName, cut, recvr, slot, parent, (name) ? name : pInfo->psName); break; case ShowMenubar: case ShowToolbar: case ShowStatusbar: { KToggleAction *ret; ret = new KToggleAction(sLabel, pInfo->psIconName, cut, recvr, slot, parent, (name) ? name : pInfo->psName); ret->setChecked(true); pAction = ret; break; } case FullScreen: { KToggleFullScreenAction *ret; ret = new KToggleFullScreenAction(cut, recvr, slot, parent, NULL, (name) ? name : pInfo->psName); ret->setChecked(false); pAction = ret; break; } case PasteText: { KPasteTextAction *ret; ret = new KPasteTextAction(sLabel, iconName, cut, recvr, slot, parent, (name) ? name : pInfo->psName); pAction = ret; break; } default: pAction = new KAction(sLabel, iconName, cut, recvr, slot, parent, (name) ? name : pInfo->psName); break; } } return pAction; }
void MainWindow::setupActions() { KActionCollection* collection = actionCollection(); // File Menu KAction* newTabAction = collection->addAction("new-tab"); newTabAction->setIcon( KIcon("tab-new") ); newTabAction->setText( i18n("New &Tab") ); newTabAction->setShortcut( QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_N) ); connect( newTabAction , SIGNAL(triggered()) , this , SLOT(newTab()) ); KAction* newWindowAction = collection->addAction("new-window"); newWindowAction->setIcon( KIcon("window-new") ); newWindowAction->setText( i18n("New &Window") ); newWindowAction->setShortcut( QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_M) ); connect( newWindowAction , SIGNAL(triggered()) , this , SLOT(newWindow()) ); KAction* remoteConnectionAction = collection->addAction("remote-connection"); remoteConnectionAction->setText( i18n("Remote Connection...") ); remoteConnectionAction->setIcon( KIcon("network-connect") ); remoteConnectionAction->setShortcut( QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_R) ); connect( remoteConnectionAction , SIGNAL(triggered()) , this , SLOT(showRemoteConnectionDialog()) ); KAction* quitAction = KStandardAction::quit( this , SLOT(close()) , collection ); // the default shortcut for quit is typically Ctrl+[Some Letter, usually Q] but that is reserved for // use by terminal applications quitAction->setShortcut(Qt::CTRL+Qt::SHIFT+Qt::Key_Q); // Bookmark Menu KActionMenu* bookmarkMenu = new KActionMenu(i18n("&Bookmarks") , collection ); _bookmarkHandler = new BookmarkHandler( collection , bookmarkMenu->menu() , true , this ); collection->addAction("bookmark" , bookmarkMenu); connect( _bookmarkHandler , SIGNAL(openUrls(QList<KUrl>)) , this , SLOT(openUrls(QList<KUrl>)) ); //TODO - The 'Add Bookmark' menu action currently has a Ctrl+B shortcut by // default which cannot be overridden // View Menu _toggleMenuBarAction = new KToggleAction(this); _toggleMenuBarAction->setText( i18n("Show Menu Bar") ); _toggleMenuBarAction->setIcon( KIcon("show-menu") ); _toggleMenuBarAction->setChecked( !menuBar()->isHidden() ); connect( _toggleMenuBarAction , SIGNAL(toggled(bool)) , menuBar() , SLOT(setVisible(bool)) ); collection->addAction("show-menubar",_toggleMenuBarAction); // Hide the Show/Hide menubar item if the menu bar is a MacOS-style menu bar if ( menuBar()->isTopLevelMenu() ) _toggleMenuBarAction->setVisible(false); // Full Screen KToggleFullScreenAction* fullScreenAction = new KToggleFullScreenAction(this); fullScreenAction->setWindow(this); fullScreenAction->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_F11 ); collection->addAction("view-full-screen",fullScreenAction); connect( fullScreenAction , SIGNAL(toggled(bool)) , this , SLOT(viewFullScreen(bool)) ); // Settings Menu KStandardAction::configureNotifications( this , SLOT(configureNotifications()) , collection ); KStandardAction::keyBindings( this , SLOT(showShortcutsDialog()) , collection ); KAction* manageProfilesAction = collection->addAction("manage-profiles"); manageProfilesAction->setText( i18n("Manage Profiles...") ); manageProfilesAction->setIcon( KIcon("configure") ); connect( manageProfilesAction , SIGNAL(triggered()) , this , SLOT(showManageProfilesDialog()) ); }