本文整理汇总了C++中KActionCollection::setDefaultShortcuts方法的典型用法代码示例。如果您正苦于以下问题:C++ KActionCollection::setDefaultShortcuts方法的具体用法?C++ KActionCollection::setDefaultShortcuts怎么用?C++ KActionCollection::setDefaultShortcuts使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KActionCollection
的用法示例。
在下文中一共展示了KActionCollection::setDefaultShortcuts方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: group
KrViewer::KrViewer(QWidget *parent) :
KParts::MainWindow(parent, (Qt::WindowFlags)KDE_DEFAULT_WINDOWFLAGS), manager(this, this), tabBar(this),
reservedKeys(), reservedKeyActions(), sizeX(-1), sizeY(-1)
{
//setWFlags(Qt::WType_TopLevel | WDestructiveClose);
setXMLFile("krviewer.rc"); // kpart-related xml file
setHelpMenuEnabled(false);
connect(&manager, SIGNAL(activePartChanged(KParts::Part*)),
this, SLOT(createGUI(KParts::Part*)));
connect(&tabBar, &QTabWidget::currentChanged, this, &KrViewer::tabChanged);
connect(&tabBar, SIGNAL(tabCloseRequested(int)), this, SLOT(tabCloseRequest(int)));
tabBar.setDocumentMode(true);
tabBar.setMovable(true);
setCentralWidget(&tabBar);
printAction = KStandardAction::print(this, SLOT(print()), 0);
copyAction = KStandardAction::copy(this, SLOT(copy()), 0);
viewerMenu = new QMenu(this);
QAction *tempAction;
KActionCollection *ac = actionCollection();
#define addCustomMenuAction(name, text, slot, shortcut)\
tempAction = ac->addAction(name, this, slot);\
tempAction->setText(text);\
ac->setDefaultShortcut(tempAction, shortcut);\
viewerMenu->addAction(tempAction);
addCustomMenuAction("genericViewer", i18n("&Generic Viewer"), SLOT(viewGeneric()), Qt::CTRL + Qt::SHIFT + Qt::Key_G);
addCustomMenuAction("textViewer", i18n("&Text Viewer"), SLOT(viewText()), Qt::CTRL + Qt::SHIFT + Qt::Key_T);
addCustomMenuAction("hexViewer", i18n("&Hex Viewer"), SLOT(viewHex()), Qt::CTRL + Qt::SHIFT + Qt::Key_H);
addCustomMenuAction("lister", i18n("&Lister"), SLOT(viewLister()), Qt::CTRL + Qt::SHIFT + Qt::Key_L);
viewerMenu->addSeparator();
addCustomMenuAction("textEditor", i18n("Text &Editor"), SLOT(editText()), Qt::CTRL + Qt::SHIFT + Qt::Key_E);
viewerMenu->addSeparator();
QList<QAction *> actList = menuBar()->actions();
bool hasPrint = false, hasCopy = false;
foreach(QAction *a, actList) {
if (a->shortcut().matches(printAction->shortcut()) != QKeySequence::NoMatch)
hasPrint = true;
if (a->shortcut().matches(copyAction->shortcut()) != QKeySequence::NoMatch)
hasCopy = true;
}
QAction *printAct = viewerMenu->addAction(printAction->icon(), printAction->text(), this, SLOT(print()));
if (hasPrint)
printAct->setShortcut(printAction->shortcut());
QAction *copyAct = viewerMenu->addAction(copyAction->icon(), copyAction->text(), this, SLOT(copy()));
if (hasCopy)
copyAct->setShortcut(copyAction->shortcut());
viewerMenu->addSeparator();
configKeysAction = ac->addAction(KStandardAction::KeyBindings, this, SLOT(configureShortcuts()));
viewerMenu->addAction(configKeysAction);
viewerMenu->addSeparator();
detachAction = ac->addAction("detachTab", this, SLOT(detachTab()));
detachAction->setText(i18n("&Detach Tab"));
//no point in detaching only one tab..
detachAction->setEnabled(false);
ac->setDefaultShortcut(detachAction, Qt::META + Qt::Key_D);
viewerMenu->addAction(detachAction);
quitAction = ac->addAction(KStandardAction::Quit, this, SLOT(close()));
viewerMenu->addAction(quitAction);
tabCloseAction = ac->addAction("closeTab", this, SLOT(tabCloseRequest()));
tabCloseAction->setText(i18n("&Close Current Tab"));
QList<QKeySequence> shortcuts = KStandardShortcut::close();
shortcuts.append(Qt::Key_Escape);
ac->setDefaultShortcuts(tabCloseAction, shortcuts);
tabNextAction = ac->addAction("nextTab", this, SLOT(nextTab()));
tabNextAction->setText(i18n("&Next Tab"));
ac->setDefaultShortcuts(tabNextAction, KStandardShortcut::tabNext());
tabPrevAction = ac->addAction("prevTab", this, SLOT(prevTab()));
tabPrevAction->setText(i18n("&Previous Tab"));
ac->setDefaultShortcuts(tabPrevAction, KStandardShortcut::tabPrev());
tabBar.setTabsClosable(true);
checkModified();
KConfigGroup group(krConfig, "KrViewerWindow");
int sx = group.readEntry("Window Width", -1);
int sy = group.readEntry("Window Height", -1);
if (sx != -1 && sy != -1)
resize(sx, sy);
else
resize(900, 700);
if (group.readEntry("Window Maximized", false)) {
setWindowState(windowState() | Qt::WindowMaximized);
}
//.........这里部分代码省略.........