diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index f1b833a9..f742893c 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -221,6 +221,28 @@ void MainWindow::init() closeSqlTab(ui->tabSqlAreas->currentIndex()); }); + // Shortcuts for advancing and going back in the SQL Execution area tabs, independently of the widget which has focus. + // This emulates the shortcuts provided by QTabWidget. + QShortcut* shortcutNextTab = new QShortcut(QKeySequence(tr("Ctrl+Tab")), ui->tabSqlAreas, nullptr, nullptr, Qt::WidgetWithChildrenShortcut); + connect(shortcutNextTab, &QShortcut::activated, this, [this]() { + if(ui->tabSqlAreas->currentIndex() == ui->tabSqlAreas->count() - 1) + ui->tabSqlAreas->setCurrentIndex(0); + else + ui->tabSqlAreas->setCurrentIndex(ui->tabSqlAreas->currentIndex() + 1); + SqlExecutionArea* sqlWidget = qobject_cast(ui->tabSqlAreas->currentWidget()); + sqlWidget->getEditor()->setFocus(); + }); + + QShortcut* shortcutPreviousTab = new QShortcut(QKeySequence(tr("Ctrl+Shift+Tab")), ui->tabSqlAreas, nullptr, nullptr, Qt::WidgetWithChildrenShortcut); + connect(shortcutPreviousTab, &QShortcut::activated, this, [this]() { + if(ui->tabSqlAreas->currentIndex() == 0) + ui->tabSqlAreas->setCurrentIndex(ui->tabSqlAreas->count() - 1); + else + ui->tabSqlAreas->setCurrentIndex(ui->tabSqlAreas->currentIndex() - 1); + SqlExecutionArea* sqlWidget = qobject_cast(ui->tabSqlAreas->currentWidget()); + sqlWidget->getEditor()->setFocus(); + }); + // Create the actions for the recently opened dbs list for(int i = 0; i < MaxRecentFiles; ++i) { recentFileActs[i] = new QAction(this); diff --git a/src/sqltextedit.cpp b/src/sqltextedit.cpp index eabf43fc..4f3dedfe 100644 --- a/src/sqltextedit.cpp +++ b/src/sqltextedit.cpp @@ -41,6 +41,9 @@ SqlTextEdit::SqlTextEdit(QWidget* parent) : QShortcut* shortcutToggleComment = new QShortcut(QKeySequence(tr("Ctrl+/")), this, nullptr, nullptr, Qt::WidgetShortcut); connect(shortcutToggleComment, &QShortcut::activated, this, &SqlTextEdit::toggleBlockComment); + QShortcut* shortcutFocusOut = new QShortcut(QKeySequence(tr("Ctrl+PgDown")), this, nullptr, nullptr, Qt::WidgetShortcut); + connect(shortcutFocusOut, &QShortcut::activated, this, &SqlTextEdit::transferFocus); + // Do rest of initialisation reloadSettings(); } @@ -133,3 +136,9 @@ void SqlTextEdit::toggleBlockComment() } endUndoAction(); } + +void SqlTextEdit::transferFocus() +{ + // We need two jumps to get to the Table Results widget + nextInFocusChain()->nextInFocusChain()->setFocus(); +} diff --git a/src/sqltextedit.h b/src/sqltextedit.h index ffcd6cf8..b20af62e 100644 --- a/src/sqltextedit.h +++ b/src/sqltextedit.h @@ -18,6 +18,9 @@ public: static SqlUiLexer* sqlLexer; +private: + void transferFocus(); + public slots: void reloadSettings(); void toggleBlockComment();