Assign some keyboard shortcuts.

This commit is contained in:
Felix Geyer 2012-05-15 18:16:04 +02:00
parent b90807c4d3
commit 56ac80f475
2 changed files with 18 additions and 0 deletions

View File

@ -35,6 +35,12 @@ MainWindow::MainWindow()
setWindowIcon(dataPath()->applicationIcon());
m_ui->toolBar->toggleViewAction()->setText(tr("Show toolbar"));
setShortcut(m_ui->actionDatabaseOpen, QKeySequence::Open, Qt::CTRL + Qt::Key_O);
setShortcut(m_ui->actionDatabaseSave, QKeySequence::Save, Qt::CTRL + Qt::Key_S);
setShortcut(m_ui->actionDatabaseSaveAs, QKeySequence::SaveAs);
setShortcut(m_ui->actionDatabaseClose, QKeySequence::Close, Qt::CTRL + Qt::Key_W);
setShortcut(m_ui->actionQuit, QKeySequence::Quit, Qt::CTRL + Qt::Key_Q);
connect(m_ui->tabWidget, SIGNAL(entrySelectionChanged(bool)),
SLOT(setMenuActionState()));
connect(m_ui->tabWidget, SIGNAL(currentWidgetModeChanged(DatabaseWidget::Mode)),
@ -196,3 +202,13 @@ void MainWindow::closeEvent(QCloseEvent* event) {
event->accept();
}
}
void MainWindow::setShortcut(QAction* action, QKeySequence::StandardKey standard, int fallback)
{
if (!QKeySequence::keyBindings(standard).isEmpty()) {
action->setShortcuts(standard);
}
else if (fallback != 0) {
action->setShortcut(QKeySequence(fallback));
}
}

View File

@ -44,6 +44,8 @@ private Q_SLOTS:
void showAboutDialog();
private:
static void setShortcut(QAction* action, QKeySequence::StandardKey standard, int fallback = 0);
static const QString BaseWindowTitle;
const QScopedPointer<Ui::MainWindow> m_ui;