diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index dc7d3210f..3f5006a5c 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -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)); + } +} diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index d21e1ad3e..e6504c5db 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -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 m_ui;