Skip to content

Commit

Permalink
Implement CTRL+1 to CTRL+9 hotkeys for switching tabs
Browse files Browse the repository at this point in the history
Progress on #21
  • Loading branch information
pajlada committed Jan 6, 2018
1 parent 8aa459d commit b8e268f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
9 changes: 9 additions & 0 deletions src/widgets/notebook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/widgets/notebook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Notebook : public BaseWidget

void removePage(SplitContainer *page);
void select(SplitContainer *page);
void selectIndex(unsigned index);

SplitContainer *getSelectedPage() const
{
Expand Down
25 changes: 17 additions & 8 deletions src/widgets/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/widgets/window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit b8e268f

Please sign in to comment.