mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Move shortcut creation code to its own helper file
This commit is contained in:
parent
e5b8e33eb3
commit
8aa459d826
3 changed files with 29 additions and 21 deletions
|
@ -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 =
|
||||
|
|
18
src/widgets/helper/shortcut.hpp
Normal file
18
src/widgets/helper/shortcut.hpp
Normal file
|
@ -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
|
|
@ -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 <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)
|
||||
|
@ -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));
|
||||
|
|
Loading…
Reference in a new issue