Skip to content

Commit

Permalink
Move shortcut creation code to its own helper file
Browse files Browse the repository at this point in the history
  • Loading branch information
pajlada committed Jan 6, 2018
1 parent e5b8e33 commit 8aa459d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
3 changes: 2 additions & 1 deletion chatterino.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
18 changes: 18 additions & 0 deletions src/widgets/helper/shortcut.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include <QShortcut>
#include <QWidget>

namespace chatterino {
namespace widgets {

template <typename WidgetType, typename Func>
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
29 changes: 9 additions & 20 deletions src/widgets/split.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -34,18 +35,6 @@ using namespace chatterino::messages;
namespace chatterino {
namespace widgets {

namespace {

template <typename T>
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)
Expand All @@ -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));
Expand Down

0 comments on commit 8aa459d

Please sign in to comment.