# HG changeset patch # User František Kučera # Date 1591048580 -7200 # Node ID 50461b01e30dec0abb67a8b441ec99db1c50f057 # Parent 334a114407cd89fc4dd934bfeb883b180168ad4a basic keyboard shortcuts: Ctrl+PgDown, Ctrl+PgUp, Ctrl+Q diff -r 334a114407cd -r 50461b01e30d src/RelpipeChartMainWindow.cpp --- a/src/RelpipeChartMainWindow.cpp Fri Jan 31 23:34:52 2020 +0100 +++ b/src/RelpipeChartMainWindow.cpp Mon Jun 01 23:56:20 2020 +0200 @@ -18,6 +18,7 @@ #include #include +#include #include "RelpipeChartMainWindow.h" @@ -31,11 +32,39 @@ tabs->setTabIcon(optionsIndex, QIcon::fromTheme("configure")); statusBar()->addWidget(status); setCentralWidget(tabs); + setupKeyboardShortcuts(); } +void RelpipeChartMainWindow::setupKeyboardShortcuts() { + // TODO: less boilerplate code + QAction* nextTabAction = new QAction(this); + nextTabAction->setShortcut(Qt::Key_PageDown | Qt::CTRL); + connect(nextTabAction, &QAction::triggered, this, &RelpipeChartMainWindow::selectNextTab); + this->addAction(nextTabAction); + + QAction* previousTabAction = new QAction(this); + previousTabAction->setShortcut(Qt::Key_PageUp | Qt::CTRL); + connect(previousTabAction, &QAction::triggered, this, &RelpipeChartMainWindow::selectPreviousTab); + this->addAction(previousTabAction); + + QAction* quitAction = new QAction(this); + quitAction->setShortcut(Qt::Key_Q | Qt::CTRL); + connect(quitAction, &QAction::triggered, this, &RelpipeChartMainWindow::close); + this->addAction(quitAction); +} + + RelpipeChartMainWindow::~RelpipeChartMainWindow() { } +void RelpipeChartMainWindow::selectNextTab() { + tabs->setCurrentIndex((tabs->currentIndex() + 1) % tabs->count()); +} + +void RelpipeChartMainWindow::selectPreviousTab() { + tabs->setCurrentIndex((tabs->count() + tabs->currentIndex() - 1) % tabs->count()); +} + void RelpipeChartMainWindow::startRelation(const string_t name, std::vector attributes) { setStatusMessage(L"Reading relation: " + name); diff -r 334a114407cd -r 50461b01e30d src/RelpipeChartMainWindow.h --- a/src/RelpipeChartMainWindow.h Fri Jan 31 23:34:52 2020 +0100 +++ b/src/RelpipeChartMainWindow.h Mon Jun 01 23:56:20 2020 +0200 @@ -43,6 +43,8 @@ void attribute(const string_t value); void endOfPipe(); void setStatusMessage(string_t message); + void selectNextTab(); + void selectPreviousTab(); private: Ui::RelpipeChartMainWindow widget; QTabWidget* tabs = new QTabWidget(this); @@ -50,4 +52,5 @@ RelpipeTableModel* currentModel; RelpipeChartWidget* currentChartWidget; QLabel* status = new QLabel(); + void setupKeyboardShortcuts(); };