diff --git a/lib/appbase/common/ChatterinoSetting.hpp b/lib/appbase/common/ChatterinoSetting.hpp index cebcb33f2..d77648414 100644 --- a/lib/appbase/common/ChatterinoSetting.hpp +++ b/lib/appbase/common/ChatterinoSetting.hpp @@ -51,4 +51,38 @@ using IntSetting = ChatterinoSetting; using StringSetting = ChatterinoSetting; using QStringSetting = ChatterinoSetting; +template +class EnumSetting + : public ChatterinoSetting::type> +{ + using Underlying = typename std::underlying_type::type; + +public: + using ChatterinoSetting::ChatterinoSetting; + + EnumSetting(const std::string &path, const Enum &defaultValue) + : ChatterinoSetting(path, Underlying(defaultValue)) + { + _registerSetting(this->getData()); + } + + template + EnumSetting &operator=(Enum newValue) + { + this->setValue(Underlying(newValue)); + + return *this; + } + + operator Enum() + { + return Enum(this->getValue()); + } + + Enum getEnum() + { + return Enum(this->getValue()); + } +}; + } // namespace AB_NAMESPACE diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index c4f6bac0e..cd6925d36 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -103,6 +103,8 @@ public: "/behaviour/autocompletion/prefixOnlyCompletion", true}; BoolSetting pauseChatOnHover = {"/behaviour/pauseChatHover", false}; + EnumSetting pauseChatModifier = { + "/behaviour/pauseChatModifier", Qt::KeyboardModifier::NoModifier}; BoolSetting autorun = {"/behaviour/autorun", false}; BoolSetting mentionUsersWithComma = {"/behaviour/mentionUsersWithComma", true}; diff --git a/src/widgets/helper/ChannelView.hpp b/src/widgets/helper/ChannelView.hpp index 0ea042e13..6e5893319 100644 --- a/src/widgets/helper/ChannelView.hpp +++ b/src/widgets/helper/ChannelView.hpp @@ -44,6 +44,7 @@ enum class PauseReason { Mouse, Selection, DoubleClick, + KeyboardModifier, }; using SteadyClock = std::chrono::steady_clock; diff --git a/src/widgets/settingspages/GeneralPage.cpp b/src/widgets/settingspages/GeneralPage.cpp index 87ef4172e..7c957e90a 100644 --- a/src/widgets/settingspages/GeneralPage.cpp +++ b/src/widgets/settingspages/GeneralPage.cpp @@ -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 &setting) + { + layout.addDropdown( + 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()) diff --git a/src/widgets/splits/Split.cpp b/src/widgets/splits/Split.cpp index 4e8a41719..134dd094e 100644 --- a/src/widgets/splits/Split.cpp +++ b/src/widgets/splits/Split.cpp @@ -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(