From d9f87c08245f55e9b2cd1f4bcdf73b63449ca1f9 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 13 Aug 2017 15:24:41 +0200 Subject: [PATCH] Implement Ctrl+Tab (Move to next tab) and Ctrl+Shift+Tab (Move to previous tab) --- src/widgets/chatwidgetinput.cpp | 17 +++++++++++++++++ src/widgets/notebook.cpp | 26 ++++++++++++++++++++++++++ src/widgets/notebook.hpp | 3 +++ 3 files changed, 46 insertions(+) diff --git a/src/widgets/chatwidgetinput.cpp b/src/widgets/chatwidgetinput.cpp index 948b253c..075e7f3d 100644 --- a/src/widgets/chatwidgetinput.cpp +++ b/src/widgets/chatwidgetinput.cpp @@ -3,6 +3,7 @@ #include "colorscheme.hpp" #include "completionmanager.hpp" #include "ircmanager.hpp" +#include "notebook.hpp" #include "notebookpage.hpp" #include "settingsmanager.hpp" @@ -128,6 +129,22 @@ ChatWidgetInput::ChatWidgetInput(ChatWidget *_chatWidget) page->requestFocus(reqX, reqY); } + } else if (event->key() == Qt::Key_Tab) { + if (event->modifiers() == Qt::ControlModifier) { + NotebookPage *page = static_cast(this->chatWidget->parentWidget()); + + Notebook *notebook = static_cast(page->parentWidget()); + + notebook->nextTab(); + } + } else if (event->key() == Qt::Key_Backtab) { + if (event->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) { + NotebookPage *page = static_cast(this->chatWidget->parentWidget()); + + Notebook *notebook = static_cast(page->parentWidget()); + + notebook->previousTab(); + } } }); diff --git a/src/widgets/notebook.cpp b/src/widgets/notebook.cpp index fa81ec10..de14444d 100644 --- a/src/widgets/notebook.cpp +++ b/src/widgets/notebook.cpp @@ -134,6 +134,32 @@ void Notebook::rearrangePage(NotebookPage *page, int index) performLayout(); } +void Notebook::nextTab() +{ + if (this->pages.size() <= 1) { + return; + } + + int index = (this->pages.indexOf(this->selectedPage) + 1) % this->pages.size(); + + this->select(this->pages[index]); +} + +void Notebook::previousTab() +{ + if (this->pages.size() <= 1) { + return; + } + + int index = (this->pages.indexOf(this->selectedPage) - 1); + + if (index < 0) { + index += this->pages.size(); + } + + this->select(this->pages[index]); +} + void Notebook::performLayout(bool animated) { int x = 0, y = 0; diff --git a/src/widgets/notebook.hpp b/src/widgets/notebook.hpp index 2b608533..1719edc6 100644 --- a/src/widgets/notebook.hpp +++ b/src/widgets/notebook.hpp @@ -42,6 +42,9 @@ public: NotebookPage *tabAt(QPoint point, int &index); void rearrangePage(NotebookPage *page, int index); + void nextTab(); + void previousTab(); + protected: void resizeEvent(QResizeEvent *);