diff --git a/src/widgets/notebook.cpp b/src/widgets/notebook.cpp index d1196d9ef..a3b9d74e7 100644 --- a/src/widgets/notebook.cpp +++ b/src/widgets/notebook.cpp @@ -117,6 +117,15 @@ void Notebook::select(SplitContainer *page) this->performLayout(); } +void Notebook::selectIndex(unsigned index) +{ + if (index >= this->pages.size()) { + return; + } + + this->select(this->pages.at(index)); +} + int Notebook::tabCount() { return this->pages.size(); diff --git a/src/widgets/notebook.hpp b/src/widgets/notebook.hpp index b35762e9f..c44567cc7 100644 --- a/src/widgets/notebook.hpp +++ b/src/widgets/notebook.hpp @@ -29,6 +29,7 @@ public: void removePage(SplitContainer *page); void select(SplitContainer *page); + void selectIndex(unsigned index); SplitContainer *getSelectedPage() const { diff --git a/src/widgets/window.cpp b/src/widgets/window.cpp index 24c15fcc3..4a7b25020 100644 --- a/src/widgets/window.cpp +++ b/src/widgets/window.cpp @@ -3,6 +3,7 @@ #include "singletons/channelmanager.hpp" #include "singletons/settingsmanager.hpp" #include "singletons/thememanager.hpp" +#include "widgets/helper/shortcut.hpp" #include "widgets/notebook.hpp" #include "widgets/settingsdialog.hpp" #include "widgets/split.hpp" @@ -55,14 +56,22 @@ Window::Window(const QString &windowName, singletons::ThemeManager &_themeManage this->loadGeometry(); - // Initialize program-wide hotkeys - { - // CTRL+P: Open Settings Dialog - auto shortcut = new QShortcut(QKeySequence("CTRL+P"), this); - connect(shortcut, &QShortcut::activated, []() { - SettingsDialog::showDialog(); // - }); - } + /// Initialize program-wide hotkeys + // CTRL+P: Open Settings Dialog + CreateShortcut(this, "CTRL+P", [] { + SettingsDialog::showDialog(); // + }); + + // CTRL+Number: Switch to n'th tab + CreateShortcut(this, "CTRL+1", [this] { this->notebook.selectIndex(0); }); + CreateShortcut(this, "CTRL+2", [this] { this->notebook.selectIndex(1); }); + CreateShortcut(this, "CTRL+3", [this] { this->notebook.selectIndex(2); }); + CreateShortcut(this, "CTRL+4", [this] { this->notebook.selectIndex(3); }); + CreateShortcut(this, "CTRL+5", [this] { this->notebook.selectIndex(4); }); + CreateShortcut(this, "CTRL+6", [this] { this->notebook.selectIndex(5); }); + CreateShortcut(this, "CTRL+7", [this] { this->notebook.selectIndex(6); }); + CreateShortcut(this, "CTRL+8", [this] { this->notebook.selectIndex(7); }); + CreateShortcut(this, "CTRL+9", [this] { this->notebook.selectIndex(8); }); } void Window::repaintVisibleChatWidgets(Channel *channel) diff --git a/src/widgets/window.hpp b/src/widgets/window.hpp index 6c16075c4..916d17f56 100644 --- a/src/widgets/window.hpp +++ b/src/widgets/window.hpp @@ -44,7 +44,8 @@ class Window : public BaseWidget WindowGeometry windowGeometry; public: - explicit Window(const QString &windowName, singletons::ThemeManager &_themeManager, bool isMainWindow); + explicit Window(const QString &windowName, singletons::ThemeManager &_themeManager, + bool isMainWindow); void repaintVisibleChatWidgets(Channel *channel = nullptr);