From caa0220ce647f92ab42e7628dd833bf8339e22c5 Mon Sep 17 00:00:00 2001 From: pajlada Date: Sun, 7 May 2023 15:18:07 +0200 Subject: [PATCH] Add a Send button that can be used to send messages (#4607) This button is disabled by default, and can be enabled with the "Show send message button" setting. --- CHANGELOG.md | 1 + src/CMakeLists.txt | 2 ++ src/common/ChatterSet.hpp | 1 + src/common/enums/MessageOverflow.hpp | 18 ++++++++++++++++++ src/providers/colors/ColorProvider.cpp | 3 ++- src/singletons/Settings.hpp | 4 +++- src/singletons/Updates.cpp | 1 + src/widgets/settingspages/GeneralPage.cpp | 5 +++++ src/widgets/splits/SplitInput.cpp | 23 +++++++++++++++++++++++ src/widgets/splits/SplitInput.hpp | 14 +------------- 10 files changed, 57 insertions(+), 15 deletions(-) create mode 100644 src/common/enums/MessageOverflow.hpp diff --git a/CHANGELOG.md b/CHANGELOG.md index 143f12620..fb27834a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unversioned +- Minor: Added a Send button in the input box so you can click to send a message. This is disabled by default and can be enabled with the "Show send message button" setting. (#4607) - Minor: Improved error messages when the updater fails a download. (#4594) - Minor: Added `/shield` and `/shieldoff` commands to toggle shield mode. (#4580) - Bugfix: Fixed the menu warping on macOS on Qt6. (#4595) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 753c8ce04..0fa8d9073 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -51,6 +51,8 @@ set(SOURCE_FILES common/WindowDescriptors.cpp common/WindowDescriptors.hpp + common/enums/MessageOverflow.hpp + controllers/accounts/Account.cpp controllers/accounts/Account.hpp controllers/accounts/AccountController.cpp diff --git a/src/common/ChatterSet.hpp b/src/common/ChatterSet.hpp index 1d0b28180..7483aa692 100644 --- a/src/common/ChatterSet.hpp +++ b/src/common/ChatterSet.hpp @@ -9,6 +9,7 @@ #include #include #include +#include namespace chatterino { diff --git a/src/common/enums/MessageOverflow.hpp b/src/common/enums/MessageOverflow.hpp new file mode 100644 index 000000000..28dbd800c --- /dev/null +++ b/src/common/enums/MessageOverflow.hpp @@ -0,0 +1,18 @@ +#pragma once + +namespace chatterino { + +// MessageOverflow is used for controlling how to guide the user into not +// sending a message that will be discarded by Twitch +enum MessageOverflow { + // Allow overflowing characters to be inserted into the input box, but highlight them in red + Highlight, + + // Prevent more characters from being inserted into the input box + Prevent, + + // Do nothing + Allow, +}; + +} // namespace chatterino diff --git a/src/providers/colors/ColorProvider.cpp b/src/providers/colors/ColorProvider.cpp index 5f47c2f68..fbda9c6ee 100644 --- a/src/providers/colors/ColorProvider.cpp +++ b/src/providers/colors/ColorProvider.cpp @@ -2,7 +2,8 @@ #include "controllers/highlights/HighlightPhrase.hpp" #include "singletons/Settings.hpp" -#include "singletons/Theme.hpp" + +#include namespace chatterino { diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index 3ac503886..4ff10a071 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -2,13 +2,13 @@ #include "BaseSettings.hpp" #include "common/Channel.hpp" +#include "common/enums/MessageOverflow.hpp" #include "common/SignalVector.hpp" #include "controllers/logging/ChannelLog.hpp" #include "singletons/Toasts.hpp" #include "util/RapidJsonSerializeQString.hpp" #include "util/StreamerMode.hpp" #include "widgets/Notebook.hpp" -#include "widgets/splits/SplitInput.hpp" #include #include @@ -509,6 +509,8 @@ public: IntSetting lastSelectChannelTab = {"/ui/lastSelectChannelTab", 0}; IntSetting lastSelectIrcConn = {"/ui/lastSelectIrcConn", 0}; + BoolSetting showSendButton = {"/ui/showSendButton", false}; + // Similarity BoolSetting similarityEnabled = {"/similarity/similarityEnabled", false}; BoolSetting colorSimilarDisabled = {"/similarity/colorSimilarDisabled", diff --git a/src/singletons/Updates.cpp b/src/singletons/Updates.cpp index 00bc2a6e4..c54d63e7b 100644 --- a/src/singletons/Updates.cpp +++ b/src/singletons/Updates.cpp @@ -11,6 +11,7 @@ #include "util/CombinePath.hpp" #include "util/PostToThread.hpp" +#include #include #include #include diff --git a/src/widgets/settingspages/GeneralPage.cpp b/src/widgets/settingspages/GeneralPage.cpp index 4054870a1..d8234e9fb 100644 --- a/src/widgets/settingspages/GeneralPage.cpp +++ b/src/widgets/settingspages/GeneralPage.cpp @@ -1014,6 +1014,11 @@ void GeneralPage::initLayout(GeneralPageView &layout) helixTimegateModerators->setMinimumWidth( helixTimegateModerators->minimumSizeHint().width()); + layout.addCheckbox( + "Show send message button", s.showSendButton, false, + "Show a Send button next to each split input that can be " + "clicked to send the message"); + layout.addStretch(); // invisible element for width diff --git a/src/widgets/splits/SplitInput.cpp b/src/widgets/splits/SplitInput.cpp index 252b308f9..56af3e5d5 100644 --- a/src/widgets/splits/SplitInput.cpp +++ b/src/widgets/splits/SplitInput.cpp @@ -1,6 +1,7 @@ #include "widgets/splits/SplitInput.hpp" #include "Application.hpp" +#include "common/enums/MessageOverflow.hpp" #include "common/QLogging.hpp" #include "controllers/commands/CommandController.hpp" #include "controllers/hotkeys/HotkeyController.hpp" @@ -114,6 +115,28 @@ void SplitInput::initLayout() connect(textEdit.getElement(), &ResizingTextEdit::textChanged, this, &SplitInput::editTextChanged); + hboxLayout.emplace().assign(&this->ui_.sendButton); + this->ui_.sendButton->getLabel().setText("SEND"); + this->ui_.sendButton->hide(); + + QObject::connect(this->ui_.sendButton, &EffectLabel::leftClicked, [this] { + std::vector arguments; + this->handleSendMessage(arguments); + }); + + getSettings()->showSendButton.connect( + [this](const bool value, auto) { + if (value) + { + this->ui_.sendButton->show(); + } + else + { + this->ui_.sendButton->hide(); + } + }, + this->managedConnections_); + // right box auto box = hboxLayout.emplace().withoutMargin(); box->setSpacing(0); diff --git a/src/widgets/splits/SplitInput.hpp b/src/widgets/splits/SplitInput.hpp index a0ec5eb52..2199f855d 100644 --- a/src/widgets/splits/SplitInput.hpp +++ b/src/widgets/splits/SplitInput.hpp @@ -23,19 +23,6 @@ class MessageThread; class ResizingTextEdit; class ChannelView; -// MessageOverflow is used for controlling how to guide the user into not -// sending a message that will be discarded by Twitch -enum MessageOverflow { - // Allow overflowing characters to be inserted into the input box, but highlight them in red - Highlight, - - // Prevent more characters from being inserted into the input box - Prevent, - - // Do nothing - Allow, -}; - class SplitInput : public BaseWidget { Q_OBJECT @@ -132,6 +119,7 @@ protected: struct { ResizingTextEdit *textEdit; QLabel *textEditLength; + EffectLabel *sendButton; EffectLabel *emoteButton; QHBoxLayout *hbox;