added pause while key is down

This commit is contained in:
fourtf 2019-09-16 10:40:02 +02:00
parent b06918eb47
commit 63126899ec
5 changed files with 96 additions and 0 deletions

View file

@ -51,4 +51,38 @@ using IntSetting = ChatterinoSetting<int>;
using StringSetting = ChatterinoSetting<std::string>;
using QStringSetting = ChatterinoSetting<QString>;
template <typename Enum>
class EnumSetting
: public ChatterinoSetting<typename std::underlying_type<Enum>::type>
{
using Underlying = typename std::underlying_type<Enum>::type;
public:
using ChatterinoSetting<Underlying>::ChatterinoSetting;
EnumSetting(const std::string &path, const Enum &defaultValue)
: ChatterinoSetting<Underlying>(path, Underlying(defaultValue))
{
_registerSetting(this->getData());
}
template <typename T2>
EnumSetting<Enum> &operator=(Enum newValue)
{
this->setValue(Underlying(newValue));
return *this;
}
operator Enum()
{
return Enum(this->getValue());
}
Enum getEnum()
{
return Enum(this->getValue());
}
};
} // namespace AB_NAMESPACE

View file

@ -103,6 +103,8 @@ public:
"/behaviour/autocompletion/prefixOnlyCompletion", true};
BoolSetting pauseChatOnHover = {"/behaviour/pauseChatHover", false};
EnumSetting<Qt::KeyboardModifier> pauseChatModifier = {
"/behaviour/pauseChatModifier", Qt::KeyboardModifier::NoModifier};
BoolSetting autorun = {"/behaviour/autorun", false};
BoolSetting mentionUsersWithComma = {"/behaviour/mentionUsersWithComma",
true};

View file

@ -44,6 +44,7 @@ enum class PauseReason {
Mouse,
Selection,
DoubleClick,
KeyboardModifier,
};
using SteadyClock = std::chrono::steady_clock;

View file

@ -21,9 +21,56 @@
#define FIREFOX_EXTENSION_LINK \
"https://addons.mozilla.org/en-US/firefox/addon/chatterino-native-host/"
// define to highlight sections in editor
#define addTitle addTitle
#ifdef Q_OS_WIN
# define META_KEY "Windows"
#else
# define META_KEY "Meta"
#endif
namespace chatterino {
namespace {
void addKeyboardModifierSetting(SettingsLayout &layout,
const QString &title,
EnumSetting<Qt::KeyboardModifier> &setting)
{
layout.addDropdown<int>(
title, {"None", "Shift", "Control", "Alt", META_KEY}, setting,
[](int index) {
switch (index)
{
case Qt::ShiftModifier:
return 1;
case Qt::ControlModifier:
return 2;
case Qt::AltModifier:
return 3;
case Qt::MetaModifier:
return 4;
default:
return 0;
}
},
[](DropdownArgs args) {
switch (args.index)
{
case 1:
return Qt::ShiftModifier;
case 2:
return Qt::ControlModifier;
case 3:
return Qt::AltModifier;
case 4:
return Qt::MetaModifier;
default:
return Qt::NoModifier;
}
},
false);
}
} // namespace
TitleLabel *SettingsLayout::addTitle(const QString &title)
{
@ -273,6 +320,8 @@ void GeneralPage::initLayout(SettingsLayout &layout)
layout.addCheckbox("Smooth scrolling on new messages",
s.enableSmoothScrollingNewMessages);
layout.addCheckbox("Pause on hover", s.pauseChatOnHover);
addKeyboardModifierSetting(layout, "Pause while holding a key",
s.pauseChatModifier);
layout.addCheckbox("Show input when it's empty", s.showEmptyInput);
layout.addCheckbox("Show message length while typing", s.showMessageLength);
if (!BaseWindow::supportsCustomWindowFrame())

View file

@ -188,6 +188,16 @@ Split::Split(QWidget *parent)
{
this->overlay_->hide();
}
if (getSettings()->pauseChatModifier.getEnum() != Qt::NoModifier &&
status == getSettings()->pauseChatModifier.getEnum())
{
this->view_->pause(PauseReason::KeyboardModifier);
}
else
{
this->view_->unpause(PauseReason::KeyboardModifier);
}
});
this->input_->ui_.textEdit->focused.connect(