本文整理汇总了C++中KAction::shortcut方法的典型用法代码示例。如果您正苦于以下问题:C++ KAction::shortcut方法的具体用法?C++ KAction::shortcut怎么用?C++ KAction::shortcut使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KAction
的用法示例。
在下文中一共展示了KAction::shortcut方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: slotConfigureAccels
void KNotesApp::slotConfigureAccels()
{
KNotesKeyDialog keys( m_globalAccel, this );
QDictIterator<KNote> notes( m_noteList );
if ( !m_noteList.isEmpty() )
keys.insert( (*notes)->actionCollection() );
keys.configure();
m_globalAccel->writeSettings();
updateGlobalAccels();
// update GUI doc for new notes
m_noteGUI.setContent(
KXMLGUIFactory::readConfigFile( instance()->instanceName() + "ui.rc", instance() )
);
if ( m_noteList.isEmpty() )
return;
notes.toFirst();
QValueList<KAction *> list = (*notes)->actionCollection()->actions();
for ( QValueList<KAction *>::iterator it = list.begin(); it != list.end(); ++it )
{
notes.toFirst();
for ( ++notes; *notes; ++notes )
{
KAction *toChange = (*notes)->actionCollection()->action( (*it)->name() );
if ( toChange->shortcut() != (*it)->shortcut() )
toChange->setShortcut( (*it)->shortcut() );
}
}
}
示例2: setupAction
void KMarkNote::setupAction()
{
KStandardAction::openNew(this, SLOT(newNote()), actionCollection());
KStandardAction::close(this, SLOT(close()), actionCollection());
KAction* oneColAction = actionCollection()->addAction("win_onecol", m_view, SLOT(oneColView()));
KAction* twoColAction = actionCollection()->addAction("win_twocol", m_view, SLOT(twoColView()));
KAction* threeColAction = actionCollection()->addAction("win_threecol", m_view, SLOT(threeColView()));
oneColAction->setText(i18n("One Column View"));
twoColAction->setText(i18n("Two Column View"));
threeColAction->setText(i18n("Three Column View"));
oneColAction->setIcon(KIcon("view-split-top-bottom"));
twoColAction->setIcon(KIcon("view-split-left-right"));
threeColAction->setIcon(KIcon("view-file-columns"));
KAction* terminalAction = actionCollection()->addAction("toggle_terminal", m_view, SLOT(toggleTerminal()));
KShortcut terminalShortcut = terminalAction->shortcut();
terminalShortcut.setPrimary(QKeySequence("F4"));
terminalAction->setShortcut(terminalShortcut);
}
示例3: slotShortcutCaptured
void ActionConfigDialog::slotShortcutCaptured(const KShortcut &shortcut)
{
QString shortcutText = shortcut.toString();
QString shortcutText2;
int pos = shortcutText.find(';');
if (pos != -1)
{
shortcutText2 = shortcutText.mid(pos + 1);
shortcutText = shortcutText.left(pos);
}
QString s = shortcutText;
s.replace('+', "\\+");
QRegExp shortcutRx("\\(" + s + "\\)|" + s + "$|" + s + ";");
s = shortcutText2;
s.replace('+', "\\+");
QRegExp shortcutRx2("\\(" + s + "\\)|" + s + "$|" + s + ";");
QString global;
//check for conflicting global shortcuts
QMap<QString, QString>::Iterator it;
for ( it = globalShortcuts.begin(); it != globalShortcuts.end(); ++it )
{
if (it.data().contains(shortcutRx))
{
global = it.key();
break;
}
if (!shortcutText2.isEmpty() && it.data().contains(shortcutRx2))
{
shortcutText = shortcutText2;
global = it.key();
break;
}
}
if (global.isEmpty())
{
QPtrList<KXMLGUIClient> clients = m_mainWindow->guiFactory()->clients();
for( QPtrListIterator<KXMLGUIClient> it( clients ); it.current(); ++it )
{
KActionCollection *ac = (*it)->actionCollection();
for (uint i = 0; i < ac->count(); i++)
{
KAction *action = ac->action(i);
if (action != currentAction && action->shortcut().toString().contains(shortcutRx))
{
global = action->text();
break;
}
if (!shortcutText2.isEmpty() && action != currentAction && action->shortcut().toString().contains(shortcutRx))
{
shortcutText = shortcutText2;
global = action->text();
break;
}
}
if (!global.isEmpty())
break;
}
}
if (global.isEmpty())
{
shortcutKeyButton->setText(shortcutText);
buttonApply->setEnabled(true);
selectedShortcut = shortcut;
} else
{
global.replace('&',"");
QString s = i18n("The '%1' key combination has already been allocated "
"to the \"%2\" action.\n"
"Please choose a unique key combination.").
arg(shortcutText).arg(global);
KMessageBox::sorry( this, s, i18n("Conflicting Shortcuts"));
}
}
示例4: r
ActionConfigDialog::ActionConfigDialog(const QDict<ToolbarEntry> &toolbarList, KMainWindow* parent, const char* name, bool modal, WFlags fl, const QString& defaultAction )
:ActionConfigDialogS( parent, name, modal, fl )
{
m_mainWindow = parent;
m_toolbarList = toolbarList;
buttonOk->setIconSet(SmallIconSet("button_ok"));
buttonCancel->setIconSet(SmallIconSet("button_cancel"));
buttonApply->setIconSet(SmallIconSet("apply"));
//buttonHelp->setIconSet(SmallIconSet("help"));
currentAction = 0L;
m_toolbarItem = 0L;
connect(actionTreeView, SIGNAL(contextMenu(KListView *,QListViewItem *,const QPoint &)),
SLOT(slotContextMenu(KListView *,QListViewItem *,const QPoint &)));
connect(actionTreeView, SIGNAL(selectionChanged(QListViewItem *)),
SLOT(slotSelectionChanged(QListViewItem *)));
connect(shortcutKeyButton, SIGNAL(capturedShortcut(const KShortcut &)),
SLOT(slotShortcutCaptured(const KShortcut &)));
connect(scriptPath, SIGNAL(activated(const QString&)),
SLOT(slotTextChanged(const QString&)));
connect(this, SIGNAL(addToolbar()), m_mainWindow, SLOT(slotAddToolbar()));
connect(this, SIGNAL(removeToolbar(const QString&)), m_mainWindow, SLOT(slotRemoveToolbar(const QString&)));
connect(this, SIGNAL(deleteUserAction(KAction*)), m_mainWindow, SLOT(slotDeleteAction(KAction*)));
connect(this, SIGNAL(configureToolbars(const QString&)), m_mainWindow, SLOT(slotConfigureToolbars(const QString&)));
//fill up the tree view with the toolbars and actions
actionTreeView->setSorting(-1);
allActionsItem = new KListViewItem(actionTreeView, i18n("All"));
actionTreeView->insertItem(allActionsItem);
QListViewItem *item, *oldItem = allActionsItem;
KAction *action;
QString toolbarName;
QString toolbarId;
ToolbarTabWidget *tb = ToolbarTabWidget::ref();
QRegExp r("\\&(?!\\&)");
KActionCollection *ac = m_mainWindow->actionCollection();
for (int i = 0; i < tb->count(); i++)
{
toolbarName = tb->label(i);
toolbarName.replace(r, "");
item = new KListViewItem(actionTreeView, oldItem, i18n(toolbarName.utf8()));
actionTreeView->insertItem(item);
toolbarId = tb->id(i);
QListViewItem *oldActionItem = 0L;
ToolbarEntry *p_toolbar = m_toolbarList[toolbarId];
if (p_toolbar)
{
QDomNode node = p_toolbar->guiClient->domDocument().firstChild().firstChild().firstChild();
while (!node.isNull())
{
if (node.nodeName() == "Action")
{
action = ac->action(node.toElement().attribute("name"));
if (action)
{
oldActionItem = new KListViewItem(item, oldActionItem, action->text().replace(r,""), action->shortcut().toString(), action->name());
oldActionItem->setPixmap(0, SmallIcon(action->icon()) );
}
}
node = node.nextSibling();
}
if (tb->label(tb->currentPageIndex()).replace(r, "") == toolbarName)
{
item->setOpen(true);
if (item->firstChild())
{
if (defaultAction.isEmpty())
{
actionTreeView->setCurrentItem(item->firstChild());
} else
{
QListViewItem *actionItem = item->firstChild();
while (actionItem && actionItem->depth() > 0)
{
if (actionItem->text(0) == defaultAction || actionItem->text(0) == defaultAction + "...")
{
actionTreeView->setCurrentItem(actionItem);
break;
}
actionItem = actionItem->nextSibling();
}
}
}
}
}
oldItem = item;
}
uint acCount = ac->count();
for (uint i = 0; i < acCount; i++)
{
action = ac->action(i);
item = new KListViewItem(allActionsItem, action->text().replace(r, ""), action->shortcut().toString(), action->name());
item->setPixmap(0, SmallIcon(action->icon()) );
}
allActionsItem->sortChildItems(0, true);
treeMenu = new KPopupMenu(actionTreeView);
treeMenu->insertItem(i18n("&Add New Toolbar"), this, SLOT(slotAddToolbar()));
treeMenu->insertItem(i18n("&Remove Toolbar"), this, SLOT(slotRemoveToolbar()));
//.........这里部分代码省略.........
示例5: slotEditToolbar
void ActionConfigDialog::slotEditToolbar()
{
QString toolbarName;
QString toolbarId;
QListViewItem *oldItem;
QListViewItem *item = actionTreeView->currentItem();
if (item->parent())
item = item->parent();
toolbarName = item->text(0);
if ( toolbarName != i18n("All"))
{
emit configureToolbars(toolbarName +" <quanta>");
//update the tree view
KAction *action;
KActionCollection *ac = m_mainWindow->actionCollection();
ToolbarTabWidget *tb = ToolbarTabWidget::ref();
for (int i = 0; i < tb->count(); i++)
{
toolbarName = tb->label(i);
toolbarId = tb->id(i);
ToolbarEntry *p_toolbar = m_toolbarList[toolbarId];
if (p_toolbar)
{
oldItem = actionTreeView->findItem(toolbarName, 0);
item = new KListViewItem(actionTreeView, oldItem, toolbarName);
item->setOpen(oldItem->isOpen());
delete oldItem;
QDomNode node = p_toolbar->guiClient->domDocument().firstChild().firstChild().firstChild();
while (!node.isNull())
{
if (node.nodeName() == "Action")
{
action = ac->action(node.toElement().attribute("name"));
if (action)
{
oldItem = new KListViewItem(item, oldItem, action->text().replace(QRegExp("\\&(?!\\&)"),""), action->shortcut().toString(), action->name());
oldItem->setPixmap(0, SmallIcon(action->icon()));
}
}
node = node.nextSibling();
}
}
}
actionTreeView->setCurrentItem(allActionsItem);
actionTreeView->setSelected(allActionsItem, true);
}
}
示例6: displayAccessKeys
void KKbdAccessExtensions::displayAccessKeys()
{
// Build a list of valid access keys that don't collide with shortcuts.
QString availableAccessKeys = "ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890";
QPtrList<KXMLGUIClient> allClients = d->mainWindow->factory()->clients();
QPtrListIterator<KXMLGUIClient> it( allClients );
KXMLGUIClient *client;
while( (client=it.current()) !=0 )
{
++it;
KActionPtrList actions = client->actionCollection()->actions();
for (int j = 0; j < (int)actions.count(); j++) {
KAction* action = actions[j];
KShortcut sc = action->shortcut();
for (int i = 0; i < (int)sc.count(); i++) {
KKeySequence seq = sc.seq(i);
if (seq.count() == 1) {
QString s = seq.toString();
if (availableAccessKeys.contains(s))
availableAccessKeys.remove(s);
}
}
}
}
// Find all visible, focusable widgets and create a QLabel for each. Don't exceed
// available list of access keys.
QWidgetList* allWidgets = kapp->allWidgets();
QWidget* widget = allWidgets->first();
int accessCount = 0;
int maxAccessCount = availableAccessKeys.length();
int overlap = 20;
QPoint prevGlobalPos = QPoint(-overlap, -overlap);
while (widget && (accessCount < maxAccessCount)) {
if (widget->isVisible() && widget->isFocusEnabled() ) {
QRect r = widget->rect();
QPoint p(r.x(), r.y());
// Don't display an access key if within overlap pixels of previous one.
QPoint globalPos = widget->mapToGlobal(p);
QPoint diffPos = globalPos - prevGlobalPos;
if (diffPos.manhattanLength() > overlap) {
accessCount++;
QLabel* lab=new QLabel(widget, "", widget, 0, Qt::WDestructiveClose);
lab->setPalette(QToolTip::palette());
lab->setLineWidth(2);
lab->setFrameStyle(QFrame::Box | QFrame::Plain);
lab->setMargin(3);
lab->adjustSize();
lab->move(p);
if (!d->accessKeyLabels) {
d->accessKeyLabels = new QPtrList<QLabel>;
d->accessKeyLabels->setAutoDelete(true);
}
d->accessKeyLabels->append(lab);
prevGlobalPos = globalPos;
}
}
widget = allWidgets->next();
}
if (accessCount > 0) {
// Sort the access keys from left to right and down the screen.
QValueList<KSortedLabel> sortedLabels;
for (int i = 0; i < accessCount; i++)
sortedLabels.append(KSortedLabel(d->accessKeyLabels->at(i)));
qHeapSort( sortedLabels );
// Assign access key labels.
for (int i = 0; i < accessCount; i++) {
QLabel* lab = sortedLabels[i].label();
QChar s = availableAccessKeys[i];
lab->setText(s);
lab->adjustSize();
lab->show();
}
}
}
示例7: setupActions
void ViewManager::setupActions()
{
KActionCollection* collection = _actionCollection;
KAction* nextViewAction = new KAction( i18n("Next View") , this );
KAction* previousViewAction = new KAction( i18n("Previous View") , this );
QAction* nextContainerAction = new QAction( i18n("Next View Container") , this);
QAction* moveViewLeftAction = new QAction( i18n("Move View Left") , this );
QAction* moveViewRightAction = new QAction( i18n("Move View Right") , this );
// list of actions that should only be enabled when there are multiple view
// containers open
QList<QAction*> multiViewOnlyActions;
multiViewOnlyActions << nextContainerAction;
if ( collection )
{
KAction* splitLeftRightAction = new KAction( KIcon("view-split-left-right"),
i18nc("@action:inmenu", "Split View Left/Right"),
this );
splitLeftRightAction->setShortcut( QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_L) );
collection->addAction("split-view-left-right",splitLeftRightAction);
connect( splitLeftRightAction , SIGNAL(triggered()) , this , SLOT(splitLeftRight()) );
KAction* splitTopBottomAction = new KAction( KIcon("view-split-top-bottom") ,
i18nc("@action:inmenu", "Split View Top/Bottom"),this);
splitTopBottomAction->setShortcut( QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_T) );
collection->addAction("split-view-top-bottom",splitTopBottomAction);
connect( splitTopBottomAction , SIGNAL(triggered()) , this , SLOT(splitTopBottom()));
KAction* closeActiveAction = new KAction( i18nc("@action:inmenu Close Active View", "Close Active") , this );
closeActiveAction->setIcon(KIcon("view-close"));
closeActiveAction->setShortcut( QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_S) );
closeActiveAction->setEnabled(false);
collection->addAction("close-active-view",closeActiveAction);
connect( closeActiveAction , SIGNAL(triggered()) , this , SLOT(closeActiveView()) );
multiViewOnlyActions << closeActiveAction;
KAction* closeOtherAction = new KAction( i18nc("@action:inmenu Close Other Views", "Close Others") , this );
closeOtherAction->setShortcut( QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_O) );
closeOtherAction->setEnabled(false);
collection->addAction("close-other-views",closeOtherAction);
connect( closeOtherAction , SIGNAL(triggered()) , this , SLOT(closeOtherViews()) );
multiViewOnlyActions << closeOtherAction;
KAction* detachViewAction = collection->addAction("detach-view");
detachViewAction->setIcon( KIcon("tab-detach") );
detachViewAction->setText( i18n("&Detach View") );
// Ctrl+Shift+D is not used as a shortcut by default because it is too close
// to Ctrl+D - which will terminate the session in many cases
detachViewAction->setShortcut( QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_H) );
connect( this , SIGNAL(splitViewToggle(bool)) , this , SLOT(updateDetachViewState()) );
connect( detachViewAction , SIGNAL(triggered()) , this , SLOT(detachActiveView()) );
// Expand & Shrink Active View
KAction* expandActiveAction = new KAction( i18nc("@action:inmenu", "Expand View") , this );
expandActiveAction->setShortcut( QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_BracketRight) );
collection->addAction("expand-active-view",expandActiveAction);
connect( expandActiveAction , SIGNAL(triggered()) , this , SLOT(expandActiveView()) );
multiViewOnlyActions << expandActiveAction;
KAction* shrinkActiveAction = new KAction( i18nc("@action:inmenu", "Shrink View") , this );
shrinkActiveAction->setShortcut( QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_BracketLeft) );
collection->addAction("shrink-active-view",shrinkActiveAction);
connect( shrinkActiveAction , SIGNAL(triggered()) , this , SLOT(shrinkActiveView()) );
multiViewOnlyActions << shrinkActiveAction;
// Next / Previous View , Next Container
collection->addAction("next-view",nextViewAction);
collection->addAction("previous-view",previousViewAction);
collection->addAction("next-container",nextContainerAction);
collection->addAction("move-view-left",moveViewLeftAction);
collection->addAction("move-view-right",moveViewRightAction);
}
QListIterator<QAction*> iter(multiViewOnlyActions);
while ( iter.hasNext() )
{
connect( this , SIGNAL(splitViewToggle(bool)) , iter.next() , SLOT(setEnabled(bool)) );
}
// keyboard shortcut only actions
KShortcut nextViewShortcut = nextViewAction->shortcut();
nextViewShortcut.setPrimary( QKeySequence(Qt::SHIFT+Qt::Key_Right) );
nextViewShortcut.setAlternate( QKeySequence(Qt::CTRL+Qt::Key_PageUp) );
nextViewAction->setShortcut(nextViewShortcut);
connect( nextViewAction, SIGNAL(triggered()) , this , SLOT(nextView()) );
_viewSplitter->addAction(nextViewAction);
KShortcut previousViewShortcut = previousViewAction->shortcut();
previousViewShortcut.setPrimary( QKeySequence(Qt::SHIFT+Qt::Key_Left) );
previousViewShortcut.setAlternate( QKeySequence(Qt::CTRL+Qt::Key_PageDown) );
previousViewAction->setShortcut(previousViewShortcut);
connect( previousViewAction, SIGNAL(triggered()) , this , SLOT(previousView()) );
//.........这里部分代码省略.........
示例8: createActions
void PopupView::createActions()
{
// Remove the Shift+Delete shortcut from the cut action, since it's used for deleting files
KAction *cut = KStandardAction::cut(this, SLOT(cut()), this);
KShortcut cutShortCut = cut->shortcut();
cutShortCut.remove(Qt::SHIFT + Qt::Key_Delete);
cut->setShortcut(cutShortCut);
KAction *copy = KStandardAction::copy(this, SLOT(copy()), this);
KIO::FileUndoManager *manager = KIO::FileUndoManager::self();
KAction *undo = KStandardAction::undo(manager, SLOT(undo()), this);
connect(manager, SIGNAL(undoAvailable(bool)), undo, SLOT(setEnabled(bool)));
connect(manager, SIGNAL(undoTextChanged(QString)), SLOT(undoTextChanged(QString)));
undo->setEnabled(manager->undoAvailable());
KAction *paste = KStandardAction::paste(this, SLOT(paste()), this);
KAction *pasteTo = KStandardAction::paste(this, SLOT(pasteTo()), this);
pasteTo->setEnabled(false); // Only enabled during popupMenu()
QString actionText = KIO::pasteActionText();
if (!actionText.isEmpty()) {
paste->setText(actionText);
} else {
paste->setEnabled(false);
}
KAction *rename = new KAction(KIcon("edit-rename"), i18n("&Rename"), this);
rename->setShortcut(Qt::Key_F2);
connect(rename, SIGNAL(triggered()), SLOT(renameSelectedIcon()));
KAction *trash = new KAction(KIcon("user-trash"), i18n("&Move to Trash"), this);
trash->setShortcut(Qt::Key_Delete);
connect(trash, SIGNAL(triggered(Qt::MouseButtons,Qt::KeyboardModifiers)),
SLOT(moveToTrash(Qt::MouseButtons,Qt::KeyboardModifiers)));
KAction *emptyTrash = new KAction(KIcon("trash-empty"), i18n("&Empty Trash Bin"), this);
KConfig trashConfig("trashrc", KConfig::SimpleConfig);
emptyTrash->setEnabled(!trashConfig.group("Status").readEntry("Empty", true));
connect(emptyTrash, SIGNAL(triggered()), SLOT(emptyTrashBin()));
KAction *del = new KAction(i18n("&Delete"), this);
del->setIcon(KIcon("edit-delete"));
del->setShortcut(Qt::SHIFT + Qt::Key_Delete);
connect(del, SIGNAL(triggered()), SLOT(deleteSelectedIcons()));
// Create the new menu
m_newMenu = new KNewFileMenu(&m_actionCollection, "new_menu", this);
connect(m_newMenu->menu(), SIGNAL(aboutToShow()), this, SLOT(aboutToShowCreateNew()));
m_actionCollection.addAction("undo", undo);
m_actionCollection.addAction("cut", cut);
m_actionCollection.addAction("copy", copy);
m_actionCollection.addAction("paste", paste);
m_actionCollection.addAction("pasteto", pasteTo);
m_actionCollection.addAction("rename", rename);
m_actionCollection.addAction("trash", trash);
m_actionCollection.addAction("del", del);
m_actionCollection.addAction("empty_trash", emptyTrash);
}