From 8aa459d826716d3ecd0185119733768b96bee45f Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sat, 6 Jan 2018 20:24:04 +0100 Subject: [PATCH] Move shortcut creation code to its own helper file --- chatterino.pro | 3 ++- src/widgets/helper/shortcut.hpp | 18 ++++++++++++++++++ src/widgets/split.cpp | 29 +++++++++-------------------- 3 files changed, 29 insertions(+), 21 deletions(-) create mode 100644 src/widgets/helper/shortcut.hpp diff --git a/chatterino.pro b/chatterino.pro index d24cde4ca..e63243da3 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -199,7 +199,8 @@ HEADERS += \ src/messages/highlightphrase.hpp \ src/messages/selection.hpp \ src/singletons/pathmanager.hpp \ - src/widgets/helper/searchpopup.hpp + src/widgets/helper/searchpopup.hpp \ + src/widgets/helper/shortcut.hpp PRECOMPILED_HEADER = diff --git a/src/widgets/helper/shortcut.hpp b/src/widgets/helper/shortcut.hpp new file mode 100644 index 000000000..609633ab9 --- /dev/null +++ b/src/widgets/helper/shortcut.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include +#include + +namespace chatterino { +namespace widgets { + +template +inline void CreateShortcut(WidgetType *w, const char *key, Func func) +{ + auto s = new QShortcut(QKeySequence(key), w); + s->setContext(Qt::WidgetWithChildrenShortcut); + QObject::connect(s, &QShortcut::activated, w, func); +} + +} // namespace widgets +} // namespace chatterino diff --git a/src/widgets/split.cpp b/src/widgets/split.cpp index 4d1797e3d..1667d9cc6 100644 --- a/src/widgets/split.cpp +++ b/src/widgets/split.cpp @@ -6,6 +6,7 @@ #include "twitch/twitchmessagebuilder.hpp" #include "util/urlfetch.hpp" #include "widgets/helper/searchpopup.hpp" +#include "widgets/helper/shortcut.hpp" #include "widgets/qualitypopup.hpp" #include "widgets/splitcontainer.hpp" #include "widgets/textinputdialog.hpp" @@ -34,18 +35,6 @@ using namespace chatterino::messages; namespace chatterino { namespace widgets { -namespace { - -template -inline void ezShortcut(Split *w, const char *key, T t) -{ - auto s = new QShortcut(QKeySequence(key), w); - s->setContext(Qt::WidgetWithChildrenShortcut); - QObject::connect(s, &QShortcut::activated, w, t); -} - -} // namespace - Split::Split(SplitContainer *parent, const std::string &_uuid) : BaseWidget(parent) , uuid(_uuid) @@ -69,22 +58,22 @@ Split::Split(SplitContainer *parent, const std::string &_uuid) // Initialize chat widget-wide hotkeys // CTRL+T: Create new split (Add page) - ezShortcut(this, "CTRL+T", &Split::doAddSplit); + CreateShortcut(this, "CTRL+T", &Split::doAddSplit); // CTRL+W: Close Split - ezShortcut(this, "CTRL+W", &Split::doCloseSplit); + CreateShortcut(this, "CTRL+W", &Split::doCloseSplit); // CTRL+R: Change Channel - ezShortcut(this, "CTRL+R", &Split::doChangeChannel); + CreateShortcut(this, "CTRL+R", &Split::doChangeChannel); // CTRL+F: Search - ezShortcut(this, "CTRL+F", &Split::doSearch); + CreateShortcut(this, "CTRL+F", &Split::doSearch); // xd - // ezShortcut(this, "ALT+SHIFT+RIGHT", &Split::doIncFlexX); - // ezShortcut(this, "ALT+SHIFT+LEFT", &Split::doDecFlexX); - // ezShortcut(this, "ALT+SHIFT+UP", &Split::doIncFlexY); - // ezShortcut(this, "ALT+SHIFT+DOWN", &Split::doDecFlexY); + // CreateShortcut(this, "ALT+SHIFT+RIGHT", &Split::doIncFlexX); + // CreateShortcut(this, "ALT+SHIFT+LEFT", &Split::doDecFlexX); + // CreateShortcut(this, "ALT+SHIFT+UP", &Split::doIncFlexY); + // CreateShortcut(this, "ALT+SHIFT+DOWN", &Split::doDecFlexY); this->channelName.getValueChangedSignal().connect( std::bind(&Split::channelNameUpdated, this, std::placeholders::_1));