2018-06-26 14:39:22 +02:00
|
|
|
#include "widgets/splits/SplitInput.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
|
|
|
|
#include "Application.hpp"
|
2021-11-21 18:46:21 +01:00
|
|
|
#include "common/QLogging.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "controllers/commands/CommandController.hpp"
|
2021-11-21 18:46:21 +01:00
|
|
|
#include "controllers/hotkeys/HotkeyController.hpp"
|
2018-08-11 22:23:06 +02:00
|
|
|
#include "messages/Link.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "providers/twitch/TwitchChannel.hpp"
|
2019-09-15 13:02:02 +02:00
|
|
|
#include "providers/twitch/TwitchIrcServer.hpp"
|
2018-06-28 19:46:45 +02:00
|
|
|
#include "singletons/Settings.hpp"
|
2018-06-28 20:03:04 +02:00
|
|
|
#include "singletons/Theme.hpp"
|
2020-08-15 18:59:17 +02:00
|
|
|
#include "util/Clamp.hpp"
|
2021-07-24 12:01:50 +02:00
|
|
|
#include "util/Helpers.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "util/LayoutCreator.hpp"
|
2018-08-11 22:23:06 +02:00
|
|
|
#include "widgets/dialogs/EmotePopup.hpp"
|
|
|
|
#include "widgets/helper/ChannelView.hpp"
|
|
|
|
#include "widgets/helper/EffectLabel.hpp"
|
|
|
|
#include "widgets/helper/ResizingTextEdit.hpp"
|
Sort and force grouping of includes (#4172)
This change enforces strict include grouping using IncludeCategories
In addition to adding this to the .clang-format file and applying it in the tests/src and src directories, I also did the following small changes:
In ChatterSet.hpp, I changed lrucache to a <>include
In Irc2.hpp, I change common/SignalVector.hpp to a "project-include"
In AttachedWindow.cpp, NativeMessaging.cpp, WindowsHelper.hpp, BaseWindow.cpp, and StreamerMode.cpp, I disabled clang-format for the windows-includes
In WindowDescriptors.hpp, I added the missing vector include. It was previously not needed because the include was handled by another file that was previously included first.
clang-format minimum version has been bumped, so Ubuntu version used in the check-formatting job has been bumped to 22.04 (which is the latest LTS)
2022-11-27 19:32:53 +01:00
|
|
|
#include "widgets/Notebook.hpp"
|
|
|
|
#include "widgets/Scrollbar.hpp"
|
2021-06-19 18:29:17 +02:00
|
|
|
#include "widgets/splits/InputCompletionPopup.hpp"
|
2018-06-26 14:39:22 +02:00
|
|
|
#include "widgets/splits/Split.hpp"
|
|
|
|
#include "widgets/splits/SplitContainer.hpp"
|
2018-08-11 22:23:06 +02:00
|
|
|
#include "widgets/splits/SplitInput.hpp"
|
2017-01-01 02:30:42 +01:00
|
|
|
|
2017-01-31 10:41:05 +01:00
|
|
|
#include <QCompleter>
|
2017-01-18 04:52:47 +01:00
|
|
|
#include <QPainter>
|
|
|
|
|
Sort and force grouping of includes (#4172)
This change enforces strict include grouping using IncludeCategories
In addition to adding this to the .clang-format file and applying it in the tests/src and src directories, I also did the following small changes:
In ChatterSet.hpp, I changed lrucache to a <>include
In Irc2.hpp, I change common/SignalVector.hpp to a "project-include"
In AttachedWindow.cpp, NativeMessaging.cpp, WindowsHelper.hpp, BaseWindow.cpp, and StreamerMode.cpp, I disabled clang-format for the windows-includes
In WindowDescriptors.hpp, I added the missing vector include. It was previously not needed because the include was handled by another file that was previously included first.
clang-format minimum version has been bumped, so Ubuntu version used in the check-formatting job has been bumped to 22.04 (which is the latest LTS)
2022-11-27 19:32:53 +01:00
|
|
|
#include <functional>
|
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
2017-01-18 21:30:23 +01:00
|
|
|
|
2022-07-31 12:45:25 +02:00
|
|
|
SplitInput::SplitInput(Split *_chatWidget, bool enableInlineReplying)
|
|
|
|
: SplitInput(_chatWidget, _chatWidget, enableInlineReplying)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SplitInput::SplitInput(QWidget *parent, Split *_chatWidget,
|
|
|
|
bool enableInlineReplying)
|
|
|
|
: BaseWidget(parent)
|
2018-06-06 18:57:22 +02:00
|
|
|
, split_(_chatWidget)
|
2022-07-31 12:45:25 +02:00
|
|
|
, enableInlineReplying_(enableInlineReplying)
|
2017-01-01 02:30:42 +01:00
|
|
|
{
|
2021-11-21 18:46:21 +01:00
|
|
|
this->installEventFilter(this);
|
2018-01-25 20:49:49 +01:00
|
|
|
this->initLayout();
|
2017-01-22 05:58:23 +01:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
auto completer =
|
|
|
|
new QCompleter(&this->split_->getChannel().get()->completionModel);
|
2018-06-06 18:57:22 +02:00
|
|
|
this->ui_.textEdit->setCompleter(completer);
|
2018-01-25 20:49:49 +01:00
|
|
|
|
2022-06-14 15:46:52 +02:00
|
|
|
this->signalHolder_.managedConnect(this->split_->channelChanged, [this] {
|
|
|
|
auto channel = this->split_->getChannel();
|
|
|
|
auto completer = new QCompleter(&channel->completionModel);
|
2018-06-06 18:57:22 +02:00
|
|
|
this->ui_.textEdit->setCompleter(completer);
|
2018-03-24 12:02:07 +01:00
|
|
|
});
|
|
|
|
|
2018-01-25 20:49:49 +01:00
|
|
|
// misc
|
|
|
|
this->installKeyPressedEvent();
|
2021-11-21 18:46:21 +01:00
|
|
|
this->addShortcuts();
|
2020-11-08 12:02:19 +01:00
|
|
|
this->ui_.textEdit->focusLost.connect([this] {
|
2021-06-19 18:29:17 +02:00
|
|
|
this->hideCompletionPopup();
|
2020-11-08 12:02:19 +01:00
|
|
|
});
|
2018-11-21 21:37:41 +01:00
|
|
|
this->scaleChangedEvent(this->scale());
|
2021-11-21 18:46:21 +01:00
|
|
|
this->signalHolder_.managedConnect(getApp()->hotkeys->onItemsUpdated,
|
|
|
|
[this]() {
|
|
|
|
this->clearShortcuts();
|
|
|
|
this->addShortcuts();
|
|
|
|
});
|
2018-01-25 20:49:49 +01:00
|
|
|
}
|
2017-01-22 05:58:23 +01:00
|
|
|
|
2018-01-25 20:49:49 +01:00
|
|
|
void SplitInput::initLayout()
|
|
|
|
{
|
2018-04-27 22:11:19 +02:00
|
|
|
auto app = getApp();
|
2018-06-26 17:06:17 +02:00
|
|
|
LayoutCreator<SplitInput> layoutCreator(this);
|
2017-10-27 21:04:27 +02:00
|
|
|
|
2018-06-06 18:57:22 +02:00
|
|
|
auto layout =
|
2022-07-31 12:45:25 +02:00
|
|
|
layoutCreator.setLayoutType<QVBoxLayout>().withoutMargin().assign(
|
|
|
|
&this->ui_.vbox);
|
|
|
|
|
|
|
|
// reply label stuff
|
|
|
|
auto replyWrapper =
|
|
|
|
layout.emplace<QWidget>().assign(&this->ui_.replyWrapper);
|
|
|
|
this->ui_.replyWrapper->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
|
|
|
auto replyHbox = replyWrapper.emplace<QHBoxLayout>().withoutMargin().assign(
|
|
|
|
&this->ui_.replyHbox);
|
|
|
|
|
|
|
|
auto replyLabel = replyHbox.emplace<QLabel>().assign(&this->ui_.replyLabel);
|
|
|
|
replyLabel->setAlignment(Qt::AlignLeft);
|
|
|
|
replyLabel->setFont(
|
|
|
|
app->fonts->getFont(FontStyle::ChatMedium, this->scale()));
|
|
|
|
|
|
|
|
replyHbox->addStretch(1);
|
|
|
|
|
|
|
|
auto replyCancelButton = replyHbox.emplace<EffectLabel>(nullptr, 4)
|
|
|
|
.assign(&this->ui_.cancelReplyButton);
|
|
|
|
replyCancelButton->getLabel().setTextFormat(Qt::RichText);
|
|
|
|
|
|
|
|
replyCancelButton->hide();
|
|
|
|
replyLabel->hide();
|
|
|
|
|
|
|
|
// hbox for input, right box
|
|
|
|
auto hboxLayout =
|
|
|
|
layout.emplace<QHBoxLayout>().withoutMargin().assign(&this->ui_.hbox);
|
2017-10-27 20:34:23 +02:00
|
|
|
|
2018-01-25 20:49:49 +01:00
|
|
|
// input
|
2018-08-06 21:17:03 +02:00
|
|
|
auto textEdit =
|
2022-07-31 12:45:25 +02:00
|
|
|
hboxLayout.emplace<ResizingTextEdit>().assign(&this->ui_.textEdit);
|
2018-01-25 20:49:49 +01:00
|
|
|
connect(textEdit.getElement(), &ResizingTextEdit::textChanged, this,
|
|
|
|
&SplitInput::editTextChanged);
|
2017-06-11 11:36:42 +02:00
|
|
|
|
2018-01-25 20:49:49 +01:00
|
|
|
// right box
|
2022-07-31 12:45:25 +02:00
|
|
|
auto box = hboxLayout.emplace<QVBoxLayout>().withoutMargin();
|
2018-01-25 20:49:49 +01:00
|
|
|
box->setSpacing(0);
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
auto textEditLength =
|
|
|
|
box.emplace<QLabel>().assign(&this->ui_.textEditLength);
|
2018-01-25 20:49:49 +01:00
|
|
|
textEditLength->setAlignment(Qt::AlignRight);
|
2017-09-15 17:23:49 +02:00
|
|
|
|
2018-01-25 20:49:49 +01:00
|
|
|
box->addStretch(1);
|
2018-08-08 15:35:54 +02:00
|
|
|
box.emplace<EffectLabel>().assign(&this->ui_.emoteButton);
|
2018-01-25 20:49:49 +01:00
|
|
|
}
|
|
|
|
|
2018-06-06 18:57:22 +02:00
|
|
|
this->ui_.emoteButton->getLabel().setTextFormat(Qt::RichText);
|
2017-06-11 11:36:42 +02:00
|
|
|
|
2018-01-25 20:49:49 +01:00
|
|
|
// ---- misc
|
2017-06-11 11:36:42 +02:00
|
|
|
|
2018-01-25 20:49:49 +01:00
|
|
|
// set edit font
|
2018-08-06 21:17:03 +02:00
|
|
|
this->ui_.textEdit->setFont(
|
2018-11-21 21:37:41 +01:00
|
|
|
app->fonts->getFont(FontStyle::ChatMedium, this->scale()));
|
2020-08-15 18:59:17 +02:00
|
|
|
QObject::connect(this->ui_.textEdit, &QTextEdit::cursorPositionChanged,
|
|
|
|
this, &SplitInput::onCursorPositionChanged);
|
2021-05-15 16:24:46 +02:00
|
|
|
QObject::connect(this->ui_.textEdit, &QTextEdit::textChanged, this,
|
|
|
|
&SplitInput::onTextChanged);
|
2017-01-22 05:58:23 +01:00
|
|
|
|
2021-12-19 15:57:56 +01:00
|
|
|
this->managedConnections_.managedConnect(app->fonts->fontChanged, [=]() {
|
2018-08-06 21:17:03 +02:00
|
|
|
this->ui_.textEdit->setFont(
|
2018-11-21 21:37:41 +01:00
|
|
|
app->fonts->getFont(FontStyle::ChatMedium, this->scale()));
|
2022-07-31 12:45:25 +02:00
|
|
|
this->ui_.replyLabel->setFont(
|
|
|
|
app->fonts->getFont(FontStyle::ChatMediumBold, this->scale()));
|
2021-12-19 15:57:56 +01:00
|
|
|
});
|
2018-01-25 20:49:49 +01:00
|
|
|
|
|
|
|
// open emote popup
|
2020-11-08 12:02:19 +01:00
|
|
|
QObject::connect(this->ui_.emoteButton, &EffectLabel::leftClicked, [=] {
|
|
|
|
this->openEmotePopup();
|
|
|
|
});
|
2017-09-15 17:23:49 +02:00
|
|
|
|
2022-07-31 12:45:25 +02:00
|
|
|
// clear input and remove reply thread
|
|
|
|
QObject::connect(this->ui_.cancelReplyButton, &EffectLabel::leftClicked,
|
|
|
|
[=] {
|
|
|
|
this->clearInput();
|
|
|
|
});
|
|
|
|
|
2018-01-25 20:49:49 +01:00
|
|
|
// clear channelview selection when selecting in the input
|
2018-08-06 21:17:03 +02:00
|
|
|
QObject::connect(this->ui_.textEdit, &QTextEdit::copyAvailable,
|
|
|
|
[this](bool available) {
|
2018-10-21 13:43:02 +02:00
|
|
|
if (available)
|
|
|
|
{
|
2018-08-11 22:23:06 +02:00
|
|
|
this->split_->view_->clearSelection();
|
2018-08-06 21:17:03 +02:00
|
|
|
}
|
|
|
|
});
|
2017-01-22 12:46:35 +01:00
|
|
|
|
2018-01-25 20:49:49 +01:00
|
|
|
// textEditLength visibility
|
2018-08-12 12:56:28 +02:00
|
|
|
getSettings()->showMessageLength.connect(
|
2018-08-06 21:17:03 +02:00
|
|
|
[this](const bool &value, auto) {
|
2018-10-20 19:15:15 +02:00
|
|
|
// this->ui_.textEditLength->setHidden(!value);
|
|
|
|
this->editTextChanged();
|
2018-08-06 21:17:03 +02:00
|
|
|
},
|
2018-06-06 18:57:22 +02:00
|
|
|
this->managedConnections_);
|
2018-01-25 20:49:49 +01:00
|
|
|
}
|
2017-01-22 12:46:35 +01:00
|
|
|
|
2018-01-25 20:49:49 +01:00
|
|
|
void SplitInput::scaleChangedEvent(float scale)
|
|
|
|
{
|
2022-07-31 12:45:25 +02:00
|
|
|
auto app = getApp();
|
|
|
|
// update the icon size of the buttons
|
2018-06-07 17:43:21 +02:00
|
|
|
this->updateEmoteButton();
|
2022-07-31 12:45:25 +02:00
|
|
|
this->updateCancelReplyButton();
|
2018-01-25 20:49:49 +01:00
|
|
|
|
|
|
|
// set maximum height
|
2022-06-26 18:53:09 +02:00
|
|
|
if (!this->hidden)
|
|
|
|
{
|
|
|
|
this->setMaximumHeight(this->scaledMaxHeight());
|
|
|
|
}
|
2018-08-06 21:17:03 +02:00
|
|
|
this->ui_.textEdit->setFont(
|
2022-07-31 12:45:25 +02:00
|
|
|
app->fonts->getFont(FontStyle::ChatMedium, this->scale()));
|
2021-12-26 00:43:03 +01:00
|
|
|
this->ui_.textEditLength->setFont(
|
2022-07-31 12:45:25 +02:00
|
|
|
app->fonts->getFont(FontStyle::ChatMedium, this->scale()));
|
|
|
|
this->ui_.replyLabel->setFont(
|
|
|
|
app->fonts->getFont(FontStyle::ChatMediumBold, this->scale()));
|
2018-01-25 20:49:49 +01:00
|
|
|
}
|
|
|
|
|
2018-07-06 17:11:37 +02:00
|
|
|
void SplitInput::themeChangedEvent()
|
2018-01-25 20:49:49 +01:00
|
|
|
{
|
2020-12-13 12:16:08 +01:00
|
|
|
QPalette palette, placeholderPalette;
|
2018-01-25 20:49:49 +01:00
|
|
|
|
2020-12-13 12:16:08 +01:00
|
|
|
palette.setColor(QPalette::WindowText, this->theme->splits.input.text);
|
2021-08-07 12:37:02 +02:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
|
2020-12-13 12:16:08 +01:00
|
|
|
placeholderPalette.setColor(
|
|
|
|
QPalette::PlaceholderText,
|
|
|
|
this->theme->messages.textColors.chatPlaceholder);
|
2021-08-07 12:37:02 +02:00
|
|
|
#endif
|
2017-01-31 10:41:05 +01:00
|
|
|
|
2018-06-07 17:43:21 +02:00
|
|
|
this->updateEmoteButton();
|
2022-07-31 12:45:25 +02:00
|
|
|
this->updateCancelReplyButton();
|
2018-06-06 18:57:22 +02:00
|
|
|
this->ui_.textEditLength->setPalette(palette);
|
2018-01-25 20:49:49 +01:00
|
|
|
|
2022-03-12 11:40:51 +01:00
|
|
|
this->ui_.textEdit->setStyleSheet(this->theme->splits.input.styleSheet);
|
2021-08-07 12:37:02 +02:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
|
2020-12-13 12:16:08 +01:00
|
|
|
this->ui_.textEdit->setPalette(placeholderPalette);
|
2021-08-07 12:37:02 +02:00
|
|
|
#endif
|
2022-11-10 20:11:40 +01:00
|
|
|
auto marginPx = (this->theme->isLightTheme() ? 4 : 2) * this->scale();
|
|
|
|
this->ui_.vbox->setContentsMargins(marginPx, marginPx, marginPx, marginPx);
|
2018-06-07 17:43:21 +02:00
|
|
|
|
|
|
|
this->ui_.emoteButton->getLabel().setStyleSheet("color: #000");
|
2022-07-31 12:45:25 +02:00
|
|
|
|
|
|
|
if (this->theme->isLightTheme())
|
|
|
|
{
|
|
|
|
this->ui_.replyLabel->setStyleSheet("color: #333");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->ui_.replyLabel->setStyleSheet("color: #ccc");
|
|
|
|
}
|
2018-06-07 17:43:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SplitInput::updateEmoteButton()
|
|
|
|
{
|
2018-11-21 21:37:41 +01:00
|
|
|
float scale = this->scale();
|
2018-06-07 17:43:21 +02:00
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
QString text = "<img src=':/buttons/emote.svg' width='xD' height='xD' />";
|
2018-06-07 17:43:21 +02:00
|
|
|
text.replace("xD", QString::number(int(12 * scale)));
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->theme->isLightTheme())
|
|
|
|
{
|
2018-09-21 20:18:52 +02:00
|
|
|
text.replace("emote", "emoteDark");
|
2018-06-07 17:43:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
this->ui_.emoteButton->getLabel().setText(text);
|
|
|
|
this->ui_.emoteButton->setFixedHeight(int(18 * scale));
|
2018-01-25 20:49:49 +01:00
|
|
|
}
|
2017-01-31 10:41:05 +01:00
|
|
|
|
2022-07-31 12:45:25 +02:00
|
|
|
void SplitInput::updateCancelReplyButton()
|
|
|
|
{
|
|
|
|
float scale = this->scale();
|
|
|
|
|
|
|
|
QString text =
|
|
|
|
QStringLiteral(
|
|
|
|
"<img src=':/buttons/cancel.svg' width='%1' height='%1' />")
|
|
|
|
.arg(QString::number(int(12 * scale)));
|
|
|
|
|
|
|
|
if (this->theme->isLightTheme())
|
|
|
|
{
|
|
|
|
text.replace("cancel", "cancelDark");
|
|
|
|
}
|
|
|
|
|
|
|
|
this->ui_.cancelReplyButton->getLabel().setText(text);
|
|
|
|
this->ui_.cancelReplyButton->setFixedHeight(int(12 * scale));
|
|
|
|
}
|
|
|
|
|
2018-08-27 14:36:01 +02:00
|
|
|
void SplitInput::openEmotePopup()
|
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
if (!this->emotePopup_)
|
|
|
|
{
|
2019-08-13 16:39:22 +02:00
|
|
|
this->emotePopup_ = new EmotePopup(this);
|
|
|
|
this->emotePopup_->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
|
2018-08-27 14:36:01 +02:00
|
|
|
this->emotePopup_->linkClicked.connect([this](const Link &link) {
|
2018-10-21 13:43:02 +02:00
|
|
|
if (link.type == Link::InsertText)
|
|
|
|
{
|
2018-09-19 20:14:01 +02:00
|
|
|
QTextCursor cursor = this->ui_.textEdit->textCursor();
|
|
|
|
QString textToInsert(link.value + " ");
|
|
|
|
|
|
|
|
// If symbol before cursor isn't space or empty
|
|
|
|
// Then insert space before emote.
|
2018-09-21 22:01:21 +02:00
|
|
|
if (cursor.position() > 0 &&
|
2018-10-21 13:43:02 +02:00
|
|
|
!this->getInputText()[cursor.position() - 1].isSpace())
|
|
|
|
{
|
2018-09-19 20:14:01 +02:00
|
|
|
textToInsert = " " + textToInsert;
|
|
|
|
}
|
|
|
|
this->insertText(textToInsert);
|
2018-08-27 14:36:01 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-11-21 21:37:41 +01:00
|
|
|
this->emotePopup_->resize(int(300 * this->emotePopup_->scale()),
|
|
|
|
int(500 * this->emotePopup_->scale()));
|
2018-08-27 14:36:01 +02:00
|
|
|
this->emotePopup_->loadChannel(this->split_->getChannel());
|
|
|
|
this->emotePopup_->show();
|
2022-05-07 16:31:14 +02:00
|
|
|
this->emotePopup_->raise();
|
2018-09-25 13:37:24 +02:00
|
|
|
this->emotePopup_->activateWindow();
|
2018-08-27 14:36:01 +02:00
|
|
|
}
|
|
|
|
|
2022-07-31 12:45:25 +02:00
|
|
|
QString SplitInput::handleSendMessage(std::vector<QString> &arguments)
|
|
|
|
{
|
|
|
|
auto c = this->split_->getChannel();
|
|
|
|
if (c == nullptr)
|
|
|
|
return "";
|
|
|
|
|
|
|
|
if (!c->isTwitchChannel() || this->replyThread_ == nullptr)
|
|
|
|
{
|
|
|
|
// standard message send behavior
|
|
|
|
QString message = ui_.textEdit->toPlainText();
|
|
|
|
|
|
|
|
message = message.replace('\n', ' ');
|
|
|
|
QString sendMessage =
|
|
|
|
getApp()->commands->execCommand(message, c, false);
|
|
|
|
|
|
|
|
c->sendMessage(sendMessage);
|
|
|
|
|
|
|
|
this->postMessageSend(message, arguments);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Reply to message
|
|
|
|
auto tc = dynamic_cast<TwitchChannel *>(c.get());
|
|
|
|
if (!tc)
|
|
|
|
{
|
|
|
|
// this should not fail
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
QString message = this->ui_.textEdit->toPlainText();
|
|
|
|
|
|
|
|
if (this->enableInlineReplying_)
|
|
|
|
{
|
|
|
|
// Remove @username prefix that is inserted when doing inline replies
|
|
|
|
message.remove(0, this->replyThread_->root()->displayName.length() +
|
|
|
|
1); // remove "@username"
|
|
|
|
|
|
|
|
if (!message.isEmpty() && message.at(0) == ' ')
|
|
|
|
{
|
|
|
|
message.remove(0, 1); // remove possible space
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
message = message.replace('\n', ' ');
|
|
|
|
QString sendMessage =
|
|
|
|
getApp()->commands->execCommand(message, c, false);
|
|
|
|
|
|
|
|
// Reply within TwitchChannel
|
|
|
|
tc->sendReply(sendMessage, this->replyThread_->rootId());
|
|
|
|
|
|
|
|
this->postMessageSend(message, arguments);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SplitInput::postMessageSend(const QString &message,
|
|
|
|
const std::vector<QString> &arguments)
|
|
|
|
{
|
|
|
|
// don't add duplicate messages and empty message to message history
|
|
|
|
if ((this->prevMsg_.isEmpty() || !this->prevMsg_.endsWith(message)) &&
|
|
|
|
!message.trimmed().isEmpty())
|
|
|
|
{
|
|
|
|
this->prevMsg_.append(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arguments.empty() || arguments.at(0) != "keepInput")
|
|
|
|
{
|
|
|
|
this->clearInput();
|
|
|
|
}
|
|
|
|
this->prevIndex_ = this->prevMsg_.size();
|
|
|
|
}
|
|
|
|
|
2022-06-26 18:53:09 +02:00
|
|
|
int SplitInput::scaledMaxHeight() const
|
|
|
|
{
|
|
|
|
return int(150 * this->scale());
|
|
|
|
}
|
|
|
|
|
2021-11-21 18:46:21 +01:00
|
|
|
void SplitInput::addShortcuts()
|
2018-01-25 20:49:49 +01:00
|
|
|
{
|
2021-11-21 18:46:21 +01:00
|
|
|
HotkeyController::HotkeyMap actions{
|
|
|
|
{"cursorToStart",
|
|
|
|
[this](std::vector<QString> arguments) -> QString {
|
|
|
|
if (arguments.size() != 1)
|
|
|
|
{
|
|
|
|
qCWarning(chatterinoHotkeys)
|
|
|
|
<< "Invalid cursorToStart arguments. Argument 0: select "
|
|
|
|
"(\"withSelection\" or \"withoutSelection\")";
|
|
|
|
return "Invalid cursorToStart arguments. Argument 0: select "
|
|
|
|
"(\"withSelection\" or \"withoutSelection\")";
|
|
|
|
}
|
|
|
|
QTextCursor cursor = this->ui_.textEdit->textCursor();
|
|
|
|
auto place = QTextCursor::Start;
|
|
|
|
auto stringTakeSelection = arguments.at(0);
|
|
|
|
bool select;
|
|
|
|
if (stringTakeSelection == "withSelection")
|
|
|
|
{
|
|
|
|
select = true;
|
|
|
|
}
|
|
|
|
else if (stringTakeSelection == "withoutSelection")
|
|
|
|
{
|
|
|
|
select = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qCWarning(chatterinoHotkeys)
|
|
|
|
<< "Invalid cursorToStart select argument (0)!";
|
|
|
|
return "Invalid cursorToStart select argument (0)!";
|
|
|
|
}
|
|
|
|
|
|
|
|
cursor.movePosition(place,
|
|
|
|
select ? QTextCursor::MoveMode::KeepAnchor
|
|
|
|
: QTextCursor::MoveMode::MoveAnchor);
|
|
|
|
this->ui_.textEdit->setTextCursor(cursor);
|
|
|
|
return "";
|
|
|
|
}},
|
|
|
|
{"cursorToEnd",
|
|
|
|
[this](std::vector<QString> arguments) -> QString {
|
|
|
|
if (arguments.size() != 1)
|
|
|
|
{
|
|
|
|
qCWarning(chatterinoHotkeys)
|
|
|
|
<< "Invalid cursorToEnd arguments. Argument 0: select "
|
|
|
|
"(\"withSelection\" or \"withoutSelection\")";
|
|
|
|
return "Invalid cursorToEnd arguments. Argument 0: select "
|
|
|
|
"(\"withSelection\" or \"withoutSelection\")";
|
|
|
|
}
|
|
|
|
QTextCursor cursor = this->ui_.textEdit->textCursor();
|
|
|
|
auto place = QTextCursor::End;
|
|
|
|
auto stringTakeSelection = arguments.at(0);
|
|
|
|
bool select;
|
|
|
|
if (stringTakeSelection == "withSelection")
|
|
|
|
{
|
|
|
|
select = true;
|
|
|
|
}
|
|
|
|
else if (stringTakeSelection == "withoutSelection")
|
|
|
|
{
|
|
|
|
select = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qCWarning(chatterinoHotkeys)
|
|
|
|
<< "Invalid cursorToEnd select argument (0)!";
|
|
|
|
return "Invalid cursorToEnd select argument (0)!";
|
|
|
|
}
|
|
|
|
|
|
|
|
cursor.movePosition(place,
|
|
|
|
select ? QTextCursor::MoveMode::KeepAnchor
|
|
|
|
: QTextCursor::MoveMode::MoveAnchor);
|
|
|
|
this->ui_.textEdit->setTextCursor(cursor);
|
|
|
|
return "";
|
|
|
|
}},
|
|
|
|
{"openEmotesPopup",
|
|
|
|
[this](std::vector<QString>) -> QString {
|
|
|
|
this->openEmotePopup();
|
|
|
|
return "";
|
|
|
|
}},
|
|
|
|
{"sendMessage",
|
|
|
|
[this](std::vector<QString> arguments) -> QString {
|
2022-07-31 12:45:25 +02:00
|
|
|
return this->handleSendMessage(arguments);
|
2021-11-21 18:46:21 +01:00
|
|
|
}},
|
|
|
|
{"previousMessage",
|
|
|
|
[this](std::vector<QString>) -> QString {
|
|
|
|
if (this->prevMsg_.size() && this->prevIndex_)
|
|
|
|
{
|
|
|
|
if (this->prevIndex_ == (this->prevMsg_.size()))
|
|
|
|
{
|
|
|
|
this->currMsg_ = ui_.textEdit->toPlainText();
|
|
|
|
}
|
|
|
|
|
|
|
|
this->prevIndex_--;
|
|
|
|
this->ui_.textEdit->setPlainText(
|
|
|
|
this->prevMsg_.at(this->prevIndex_));
|
2022-10-22 11:42:46 +02:00
|
|
|
this->ui_.textEdit->resetCompletion();
|
2021-11-21 18:46:21 +01:00
|
|
|
|
|
|
|
QTextCursor cursor = this->ui_.textEdit->textCursor();
|
|
|
|
cursor.movePosition(QTextCursor::End);
|
|
|
|
this->ui_.textEdit->setTextCursor(cursor);
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}},
|
|
|
|
{"nextMessage",
|
|
|
|
[this](std::vector<QString>) -> QString {
|
|
|
|
// If user did not write anything before then just do nothing.
|
|
|
|
if (this->prevMsg_.isEmpty())
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
bool cursorToEnd = true;
|
|
|
|
QString message = ui_.textEdit->toPlainText();
|
|
|
|
|
|
|
|
if (this->prevIndex_ != (this->prevMsg_.size() - 1) &&
|
|
|
|
this->prevIndex_ != this->prevMsg_.size())
|
|
|
|
{
|
|
|
|
this->prevIndex_++;
|
|
|
|
this->ui_.textEdit->setPlainText(
|
|
|
|
this->prevMsg_.at(this->prevIndex_));
|
2022-10-22 11:42:46 +02:00
|
|
|
this->ui_.textEdit->resetCompletion();
|
2021-11-21 18:46:21 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->prevIndex_ = this->prevMsg_.size();
|
|
|
|
if (message == this->prevMsg_.at(this->prevIndex_ - 1))
|
|
|
|
{
|
|
|
|
// If user has just come from a message history
|
|
|
|
// Then simply get currMsg_.
|
|
|
|
this->ui_.textEdit->setPlainText(this->currMsg_);
|
2022-10-22 11:42:46 +02:00
|
|
|
this->ui_.textEdit->resetCompletion();
|
2021-11-21 18:46:21 +01:00
|
|
|
}
|
|
|
|
else if (message != this->currMsg_)
|
|
|
|
{
|
|
|
|
// If user are already in current message
|
|
|
|
// And type something new
|
|
|
|
// Then replace currMsg_ with new one.
|
|
|
|
this->currMsg_ = message;
|
|
|
|
}
|
|
|
|
// If user is already in current message
|
|
|
|
// Then don't touch cursos.
|
|
|
|
cursorToEnd =
|
|
|
|
(message == this->prevMsg_.at(this->prevIndex_ - 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cursorToEnd)
|
|
|
|
{
|
|
|
|
QTextCursor cursor = this->ui_.textEdit->textCursor();
|
|
|
|
cursor.movePosition(QTextCursor::End);
|
|
|
|
this->ui_.textEdit->setTextCursor(cursor);
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}},
|
|
|
|
{"undo",
|
|
|
|
[this](std::vector<QString>) -> QString {
|
|
|
|
this->ui_.textEdit->undo();
|
|
|
|
return "";
|
|
|
|
}},
|
|
|
|
{"redo",
|
|
|
|
[this](std::vector<QString>) -> QString {
|
|
|
|
this->ui_.textEdit->redo();
|
|
|
|
return "";
|
|
|
|
}},
|
|
|
|
{"copy",
|
|
|
|
[this](std::vector<QString> arguments) -> QString {
|
|
|
|
// XXX: this action is unused at the moment, a qt standard shortcut is used instead
|
|
|
|
if (arguments.size() == 0)
|
|
|
|
{
|
|
|
|
return "copy action takes only one argument: the source "
|
|
|
|
"of the copy \"split\", \"input\" or "
|
|
|
|
"\"auto\". If the source is \"split\", only text "
|
|
|
|
"from the chat will be copied. If it is "
|
|
|
|
"\"splitInput\", text from the input box will be "
|
|
|
|
"copied. Automatic will pick whichever has a "
|
|
|
|
"selection";
|
|
|
|
}
|
|
|
|
bool copyFromSplit = false;
|
|
|
|
auto mode = arguments.at(0);
|
|
|
|
if (mode == "split")
|
|
|
|
{
|
|
|
|
copyFromSplit = true;
|
|
|
|
}
|
|
|
|
else if (mode == "splitInput")
|
|
|
|
{
|
|
|
|
copyFromSplit = false;
|
|
|
|
}
|
|
|
|
else if (mode == "auto")
|
|
|
|
{
|
|
|
|
const auto &cursor = this->ui_.textEdit->textCursor();
|
|
|
|
copyFromSplit = !cursor.hasSelection();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (copyFromSplit)
|
|
|
|
{
|
|
|
|
this->split_->copyToClipboard();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->ui_.textEdit->copy();
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}},
|
|
|
|
{"paste",
|
|
|
|
[this](std::vector<QString>) -> QString {
|
|
|
|
this->ui_.textEdit->paste();
|
|
|
|
return "";
|
|
|
|
}},
|
|
|
|
{"clear",
|
|
|
|
[this](std::vector<QString>) -> QString {
|
2022-07-31 12:45:25 +02:00
|
|
|
this->clearInput();
|
2021-11-21 18:46:21 +01:00
|
|
|
return "";
|
|
|
|
}},
|
|
|
|
{"selectAll",
|
|
|
|
[this](std::vector<QString>) -> QString {
|
|
|
|
this->ui_.textEdit->selectAll();
|
|
|
|
return "";
|
|
|
|
}},
|
2022-03-27 13:33:44 +02:00
|
|
|
{"selectWord",
|
|
|
|
[this](std::vector<QString>) -> QString {
|
|
|
|
auto cursor = this->ui_.textEdit->textCursor();
|
|
|
|
cursor.select(QTextCursor::WordUnderCursor);
|
|
|
|
this->ui_.textEdit->setTextCursor(cursor);
|
|
|
|
return "";
|
|
|
|
}},
|
2021-11-21 18:46:21 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
this->shortcuts_ = getApp()->hotkeys->shortcutsForCategory(
|
2021-11-27 13:47:31 +01:00
|
|
|
HotkeyCategory::SplitInput, actions, this->parentWidget());
|
2021-11-21 18:46:21 +01:00
|
|
|
}
|
2018-04-27 22:11:19 +02:00
|
|
|
|
2021-11-21 18:46:21 +01:00
|
|
|
bool SplitInput::eventFilter(QObject *obj, QEvent *event)
|
|
|
|
{
|
|
|
|
if (event->type() == QEvent::ShortcutOverride ||
|
|
|
|
event->type() == QEvent::Shortcut)
|
|
|
|
{
|
2021-06-19 18:29:17 +02:00
|
|
|
if (auto popup = this->inputCompletionPopup_.get())
|
2020-08-15 18:59:17 +02:00
|
|
|
{
|
|
|
|
if (popup->isVisible())
|
|
|
|
{
|
2021-11-21 18:46:21 +01:00
|
|
|
// Stop shortcut from triggering by saying we will handle it ourselves
|
|
|
|
event->accept();
|
2019-06-21 22:15:17 +02:00
|
|
|
|
2021-11-21 18:46:21 +01:00
|
|
|
// Return false means the underlying event isn't stopped, it will continue to propagate
|
|
|
|
return false;
|
2017-07-24 13:48:34 +02:00
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
2021-11-21 18:46:21 +01:00
|
|
|
}
|
2019-03-02 09:28:54 +01:00
|
|
|
|
2021-11-21 18:46:21 +01:00
|
|
|
return BaseWidget::eventFilter(obj, event);
|
|
|
|
}
|
2019-03-02 09:28:54 +01:00
|
|
|
|
2021-11-21 18:46:21 +01:00
|
|
|
void SplitInput::installKeyPressedEvent()
|
|
|
|
{
|
|
|
|
this->ui_.textEdit->keyPressed.disconnectAll();
|
|
|
|
this->ui_.textEdit->keyPressed.connect([this](QKeyEvent *event) {
|
|
|
|
if (auto popup = this->inputCompletionPopup_.get())
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2021-11-21 18:46:21 +01:00
|
|
|
if (popup->isVisible())
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2021-11-21 18:46:21 +01:00
|
|
|
if (popup->eventFilter(nullptr, event))
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2021-11-21 18:46:21 +01:00
|
|
|
event->accept();
|
2018-08-27 20:12:38 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-07-24 13:48:34 +02:00
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
2021-11-21 18:46:21 +01:00
|
|
|
|
|
|
|
// One of the last remaining of it's kind, the copy shortcut.
|
|
|
|
// For some bizarre reason Qt doesn't want this key be rebound.
|
|
|
|
// TODO(Mm2PL): Revisit in Qt6, maybe something changed?
|
|
|
|
if ((event->key() == Qt::Key_C || event->key() == Qt::Key_Insert) &&
|
|
|
|
event->modifiers() == Qt::ControlModifier)
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
|
|
|
if (this->split_->view_->hasSelection())
|
|
|
|
{
|
2018-08-02 14:23:27 +02:00
|
|
|
this->split_->copyToClipboard();
|
2017-09-21 02:20:02 +02:00
|
|
|
event->accept();
|
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
2017-01-29 13:23:22 +01:00
|
|
|
});
|
2017-01-22 12:46:35 +01:00
|
|
|
}
|
|
|
|
|
2022-11-21 19:27:56 +01:00
|
|
|
void SplitInput::mousePressEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (this->hidden)
|
|
|
|
{
|
|
|
|
BaseWidget::mousePressEvent(event);
|
|
|
|
}
|
|
|
|
// else, don't call QWidget::mousePressEvent,
|
|
|
|
// which will call event->ignore()
|
|
|
|
}
|
|
|
|
|
2021-05-15 16:24:46 +02:00
|
|
|
void SplitInput::onTextChanged()
|
|
|
|
{
|
2021-06-19 18:29:17 +02:00
|
|
|
this->updateCompletionPopup();
|
2021-05-15 16:24:46 +02:00
|
|
|
}
|
|
|
|
|
2020-08-15 18:59:17 +02:00
|
|
|
void SplitInput::onCursorPositionChanged()
|
|
|
|
{
|
2021-06-19 18:29:17 +02:00
|
|
|
this->updateCompletionPopup();
|
2020-08-15 18:59:17 +02:00
|
|
|
}
|
|
|
|
|
2021-06-19 18:29:17 +02:00
|
|
|
void SplitInput::updateCompletionPopup()
|
2020-08-15 18:59:17 +02:00
|
|
|
{
|
2020-10-17 15:59:15 +02:00
|
|
|
auto channel = this->split_->getChannel().get();
|
2021-06-19 18:29:17 +02:00
|
|
|
auto tc = dynamic_cast<TwitchChannel *>(channel);
|
2022-09-30 22:59:52 +02:00
|
|
|
bool showEmoteCompletion = getSettings()->emoteCompletionWithColon;
|
2021-06-19 18:29:17 +02:00
|
|
|
bool showUsernameCompletion =
|
|
|
|
tc && getSettings()->showUsernameCompletionMenu;
|
|
|
|
if (!showEmoteCompletion && !showUsernameCompletion)
|
2020-08-15 18:59:17 +02:00
|
|
|
{
|
2021-06-19 18:29:17 +02:00
|
|
|
this->hideCompletionPopup();
|
2020-08-23 11:28:22 +02:00
|
|
|
return;
|
2020-08-15 18:59:17 +02:00
|
|
|
}
|
|
|
|
|
2021-06-19 18:29:17 +02:00
|
|
|
// check if in completion prefix
|
2020-08-15 18:59:17 +02:00
|
|
|
auto &edit = *this->ui_.textEdit;
|
|
|
|
|
|
|
|
auto text = edit.toPlainText();
|
2020-08-23 09:17:19 +02:00
|
|
|
auto position = edit.textCursor().position() - 1;
|
2020-08-15 18:59:17 +02:00
|
|
|
|
2021-06-27 14:47:14 +02:00
|
|
|
if (text.length() == 0 || position == -1)
|
2020-08-15 18:59:17 +02:00
|
|
|
{
|
2021-06-19 18:29:17 +02:00
|
|
|
this->hideCompletionPopup();
|
2020-08-15 18:59:17 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = clamp(position, 0, text.length() - 1); i >= 0; i--)
|
|
|
|
{
|
|
|
|
if (text[i] == ' ')
|
|
|
|
{
|
2021-06-19 18:29:17 +02:00
|
|
|
this->hideCompletionPopup();
|
2020-08-15 18:59:17 +02:00
|
|
|
return;
|
|
|
|
}
|
2021-06-19 18:29:17 +02:00
|
|
|
else if (text[i] == ':' && showEmoteCompletion)
|
2020-08-15 18:59:17 +02:00
|
|
|
{
|
2020-08-22 12:34:19 +02:00
|
|
|
if (i == 0 || text[i - 1].isSpace())
|
2021-06-19 18:29:17 +02:00
|
|
|
this->showCompletionPopup(text.mid(i, position - i + 1).mid(1),
|
|
|
|
true);
|
2020-08-22 12:34:19 +02:00
|
|
|
else
|
2021-06-19 18:29:17 +02:00
|
|
|
this->hideCompletionPopup();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (text[i] == '@' && showUsernameCompletion)
|
|
|
|
{
|
|
|
|
if (i == 0 || text[i - 1].isSpace())
|
|
|
|
this->showCompletionPopup(text.mid(i, position - i + 1).mid(1),
|
|
|
|
false);
|
|
|
|
else
|
|
|
|
this->hideCompletionPopup();
|
2020-08-15 18:59:17 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-19 18:29:17 +02:00
|
|
|
this->hideCompletionPopup();
|
2020-08-15 18:59:17 +02:00
|
|
|
}
|
|
|
|
|
2021-06-19 18:29:17 +02:00
|
|
|
void SplitInput::showCompletionPopup(const QString &text, bool emoteCompletion)
|
2020-08-15 18:59:17 +02:00
|
|
|
{
|
2021-06-19 18:29:17 +02:00
|
|
|
if (!this->inputCompletionPopup_.get())
|
2020-08-15 18:59:17 +02:00
|
|
|
{
|
2021-06-19 18:29:17 +02:00
|
|
|
this->inputCompletionPopup_ = new InputCompletionPopup(this);
|
|
|
|
this->inputCompletionPopup_->setInputAction(
|
2020-08-15 18:59:17 +02:00
|
|
|
[that = QObjectRef(this)](const QString &text) mutable {
|
|
|
|
if (auto this2 = that.get())
|
|
|
|
{
|
2021-06-19 18:29:17 +02:00
|
|
|
this2->insertCompletionText(text);
|
|
|
|
this2->hideCompletionPopup();
|
2020-08-15 18:59:17 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-06-19 18:29:17 +02:00
|
|
|
auto popup = this->inputCompletionPopup_.get();
|
2020-08-15 18:59:17 +02:00
|
|
|
assert(popup);
|
|
|
|
|
2021-06-19 18:29:17 +02:00
|
|
|
if (emoteCompletion) // autocomplete emotes
|
|
|
|
popup->updateEmotes(text, this->split_->getChannel());
|
|
|
|
else // autocomplete usernames
|
|
|
|
popup->updateUsers(text, this->split_->getChannel());
|
2020-08-15 18:59:17 +02:00
|
|
|
|
|
|
|
auto pos = this->mapToGlobal({0, 0}) - QPoint(0, popup->height()) +
|
|
|
|
QPoint((this->width() - popup->width()) / 2, 0);
|
|
|
|
|
|
|
|
popup->move(pos);
|
|
|
|
popup->show();
|
|
|
|
}
|
|
|
|
|
2021-06-19 18:29:17 +02:00
|
|
|
void SplitInput::hideCompletionPopup()
|
2020-08-15 18:59:17 +02:00
|
|
|
{
|
2021-06-19 18:29:17 +02:00
|
|
|
if (auto popup = this->inputCompletionPopup_.get())
|
2020-08-15 18:59:17 +02:00
|
|
|
popup->hide();
|
|
|
|
}
|
|
|
|
|
2021-06-19 18:29:17 +02:00
|
|
|
void SplitInput::insertCompletionText(const QString &input_)
|
2020-08-15 18:59:17 +02:00
|
|
|
{
|
|
|
|
auto &edit = *this->ui_.textEdit;
|
2020-08-22 12:34:19 +02:00
|
|
|
auto input = input_ + ' ';
|
2020-08-15 18:59:17 +02:00
|
|
|
|
|
|
|
auto text = edit.toPlainText();
|
2021-09-11 12:09:14 +02:00
|
|
|
auto position = edit.textCursor().position() - 1;
|
2020-08-15 18:59:17 +02:00
|
|
|
|
|
|
|
for (int i = clamp(position, 0, text.length() - 1); i >= 0; i--)
|
|
|
|
{
|
2021-06-19 18:29:17 +02:00
|
|
|
bool done = false;
|
2020-08-15 18:59:17 +02:00
|
|
|
if (text[i] == ':')
|
|
|
|
{
|
2021-06-19 18:29:17 +02:00
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
else if (text[i] == '@')
|
|
|
|
{
|
2021-07-24 12:01:50 +02:00
|
|
|
const auto userMention =
|
|
|
|
formatUserMention(input_, edit.isFirstWord(),
|
|
|
|
getSettings()->mentionUsersWithComma);
|
|
|
|
input = "@" + userMention + " ";
|
2021-06-19 18:29:17 +02:00
|
|
|
done = true;
|
|
|
|
}
|
2020-08-15 18:59:17 +02:00
|
|
|
|
2021-06-19 18:29:17 +02:00
|
|
|
if (done)
|
|
|
|
{
|
|
|
|
auto cursor = edit.textCursor();
|
2022-05-30 13:09:38 +02:00
|
|
|
edit.setPlainText(
|
|
|
|
text.remove(i, position - i + 1).insert(i, input));
|
2020-08-15 18:59:17 +02:00
|
|
|
|
|
|
|
cursor.setPosition(i + input.size());
|
|
|
|
edit.setTextCursor(cursor);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-27 20:39:53 +01:00
|
|
|
bool SplitInput::hasSelection() const
|
2017-09-21 02:20:02 +02:00
|
|
|
{
|
2022-11-27 20:39:53 +01:00
|
|
|
return this->ui_.textEdit->textCursor().hasSelection();
|
|
|
|
}
|
2017-09-21 02:20:02 +02:00
|
|
|
|
2022-11-27 20:39:53 +01:00
|
|
|
void SplitInput::clearSelection() const
|
|
|
|
{
|
|
|
|
auto cursor = this->ui_.textEdit->textCursor();
|
|
|
|
cursor.clearSelection();
|
|
|
|
this->ui_.textEdit->setTextCursor(cursor);
|
2017-09-21 02:20:02 +02:00
|
|
|
}
|
|
|
|
|
2021-07-24 12:01:50 +02:00
|
|
|
bool SplitInput::isEditFirstWord() const
|
|
|
|
{
|
|
|
|
return this->ui_.textEdit->isFirstWord();
|
|
|
|
}
|
|
|
|
|
2017-12-17 16:19:16 +01:00
|
|
|
QString SplitInput::getInputText() const
|
|
|
|
{
|
2018-06-06 18:57:22 +02:00
|
|
|
return this->ui_.textEdit->toPlainText();
|
2017-12-17 16:19:16 +01:00
|
|
|
}
|
|
|
|
|
2018-01-24 20:58:53 +01:00
|
|
|
void SplitInput::insertText(const QString &text)
|
|
|
|
{
|
2018-06-06 18:57:22 +02:00
|
|
|
this->ui_.textEdit->insertPlainText(text);
|
2017-01-01 02:30:42 +01:00
|
|
|
}
|
|
|
|
|
2022-06-26 18:53:09 +02:00
|
|
|
void SplitInput::hide()
|
|
|
|
{
|
|
|
|
if (this->isHidden())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->hidden = true;
|
|
|
|
this->setMaximumHeight(0);
|
|
|
|
this->updateGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SplitInput::show()
|
|
|
|
{
|
|
|
|
if (!this->isHidden())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->hidden = false;
|
|
|
|
this->setMaximumHeight(this->scaledMaxHeight());
|
|
|
|
this->updateGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SplitInput::isHidden() const
|
|
|
|
{
|
|
|
|
return this->hidden;
|
|
|
|
}
|
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void SplitInput::editTextChanged()
|
2017-01-29 13:23:22 +01:00
|
|
|
{
|
2018-04-27 22:11:19 +02:00
|
|
|
auto app = getApp();
|
|
|
|
|
2018-01-25 20:49:49 +01:00
|
|
|
// set textLengthLabel value
|
2018-06-06 18:57:22 +02:00
|
|
|
QString text = this->ui_.textEdit->toPlainText();
|
2017-12-17 02:40:05 +01:00
|
|
|
|
2022-11-13 12:47:46 +01:00
|
|
|
if (this->shouldPreventInput(text))
|
|
|
|
{
|
|
|
|
this->ui_.textEdit->setPlainText(text.left(TWITCH_MESSAGE_LIMIT));
|
|
|
|
this->ui_.textEdit->moveCursor(QTextCursor::EndOfBlock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-06 10:46:23 +02:00
|
|
|
if (text.startsWith("/r ", Qt::CaseInsensitive) &&
|
2020-11-08 12:02:19 +01:00
|
|
|
this->split_->getChannel()->isTwitchChannel())
|
2018-05-25 13:53:55 +02:00
|
|
|
{
|
2022-03-19 12:02:29 +01:00
|
|
|
QString lastUser = app->twitch->lastUserThatWhisperedMe.get();
|
2018-10-21 13:43:02 +02:00
|
|
|
if (!lastUser.isEmpty())
|
|
|
|
{
|
2018-06-06 18:57:22 +02:00
|
|
|
this->ui_.textEdit->setPlainText("/w " + lastUser + text.mid(2));
|
|
|
|
this->ui_.textEdit->moveCursor(QTextCursor::EndOfBlock);
|
2018-05-25 13:53:55 +02:00
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-05-25 13:53:55 +02:00
|
|
|
this->textChanged.invoke(text);
|
2017-12-17 16:19:16 +01:00
|
|
|
|
2018-05-25 13:53:55 +02:00
|
|
|
text = text.trimmed();
|
2018-08-06 21:17:03 +02:00
|
|
|
text =
|
|
|
|
app->commands->execCommand(text, this->split_->getChannel(), true);
|
2018-05-25 13:53:55 +02:00
|
|
|
}
|
2018-01-04 04:03:51 +01:00
|
|
|
|
2022-11-13 12:47:46 +01:00
|
|
|
if (getSettings()->messageOverflow.getValue() == MessageOverflow::Highlight)
|
|
|
|
{
|
|
|
|
if (text.length() > TWITCH_MESSAGE_LIMIT &&
|
|
|
|
text.length() > this->lastOverflowLength)
|
|
|
|
{
|
|
|
|
QTextCharFormat format;
|
|
|
|
format.setForeground(Qt::red);
|
|
|
|
|
|
|
|
QTextCursor cursor = this->ui_.textEdit->textCursor();
|
|
|
|
cursor.setPosition(lastOverflowLength, QTextCursor::MoveAnchor);
|
|
|
|
cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
|
|
|
|
|
|
|
|
this->lastOverflowLength = text.length();
|
|
|
|
|
|
|
|
cursor.setCharFormat(format);
|
|
|
|
}
|
|
|
|
else if (this->lastOverflowLength != TWITCH_MESSAGE_LIMIT)
|
|
|
|
{
|
|
|
|
this->lastOverflowLength = TWITCH_MESSAGE_LIMIT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-17 02:40:05 +01:00
|
|
|
QString labelText;
|
|
|
|
|
2018-10-24 10:33:35 +02:00
|
|
|
if (text.length() > 0 && getSettings()->showMessageLength)
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2018-11-21 21:37:41 +01:00
|
|
|
labelText = QString::number(text.length());
|
2021-05-01 16:42:08 +02:00
|
|
|
if (text.length() > TWITCH_MESSAGE_LIMIT)
|
|
|
|
{
|
|
|
|
this->ui_.textEditLength->setStyleSheet("color: red");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->ui_.textEditLength->setStyleSheet("");
|
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-24 10:33:35 +02:00
|
|
|
labelText = "";
|
2017-12-17 02:40:05 +01:00
|
|
|
}
|
|
|
|
|
2018-06-06 18:57:22 +02:00
|
|
|
this->ui_.textEditLength->setText(labelText);
|
2022-07-31 12:45:25 +02:00
|
|
|
|
|
|
|
bool hasReply = false;
|
|
|
|
if (this->enableInlineReplying_)
|
|
|
|
{
|
|
|
|
if (this->replyThread_ != nullptr)
|
|
|
|
{
|
|
|
|
// Check if the input still starts with @username. If not, don't reply.
|
|
|
|
//
|
|
|
|
// We need to verify that
|
|
|
|
// 1. the @username prefix exists and
|
|
|
|
// 2. if a character exists after the @username, it is a space
|
|
|
|
QString replyPrefix = "@" + this->replyThread_->root()->displayName;
|
|
|
|
if (!text.startsWith(replyPrefix) ||
|
|
|
|
(text.length() > replyPrefix.length() &&
|
|
|
|
text.at(replyPrefix.length()) != ' '))
|
|
|
|
{
|
|
|
|
this->replyThread_ = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show/hide reply label if inline replies are possible
|
|
|
|
hasReply = this->replyThread_ != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->ui_.replyWrapper->setVisible(hasReply);
|
|
|
|
this->ui_.replyLabel->setVisible(hasReply);
|
|
|
|
this->ui_.cancelReplyButton->setVisible(hasReply);
|
2017-01-29 13:23:22 +01:00
|
|
|
}
|
|
|
|
|
2022-06-26 18:53:09 +02:00
|
|
|
void SplitInput::paintEvent(QPaintEvent * /*event*/)
|
2017-01-01 02:30:42 +01:00
|
|
|
{
|
|
|
|
QPainter painter(this);
|
|
|
|
|
2022-07-31 12:45:25 +02:00
|
|
|
int s;
|
|
|
|
QColor borderColor;
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->theme->isLightTheme())
|
|
|
|
{
|
2022-07-31 12:45:25 +02:00
|
|
|
s = int(3 * this->scale());
|
|
|
|
borderColor = QColor("#ccc");
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-07-31 12:45:25 +02:00
|
|
|
s = int(1 * this->scale());
|
|
|
|
borderColor = QColor("#333");
|
|
|
|
}
|
2018-05-23 04:22:17 +02:00
|
|
|
|
2022-07-31 12:45:25 +02:00
|
|
|
QMargins removeMargins(s - 1, s - 1, s, s);
|
|
|
|
QRect baseRect = this->rect();
|
2018-05-23 04:22:17 +02:00
|
|
|
|
2022-07-31 12:45:25 +02:00
|
|
|
// completeAreaRect includes the reply label
|
|
|
|
QRect completeAreaRect = baseRect.marginsRemoved(removeMargins);
|
|
|
|
painter.fillRect(completeAreaRect, this->theme->splits.input.background);
|
|
|
|
painter.setPen(borderColor);
|
|
|
|
painter.drawRect(completeAreaRect);
|
|
|
|
|
|
|
|
if (this->enableInlineReplying_ && this->replyThread_ != nullptr)
|
|
|
|
{
|
|
|
|
// Move top of rect down to not include reply label
|
|
|
|
baseRect.setTop(baseRect.top() + this->ui_.replyWrapper->height());
|
2018-06-06 13:35:06 +02:00
|
|
|
|
2022-07-31 12:45:25 +02:00
|
|
|
QRect onlyInputRect = baseRect.marginsRemoved(removeMargins);
|
|
|
|
painter.setPen(borderColor);
|
|
|
|
painter.drawRect(onlyInputRect);
|
|
|
|
}
|
2017-01-01 02:30:42 +01:00
|
|
|
}
|
2017-01-22 05:58:23 +01:00
|
|
|
|
2017-11-12 17:21:50 +01:00
|
|
|
void SplitInput::resizeEvent(QResizeEvent *)
|
2017-01-22 05:58:23 +01:00
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->height() == this->maximumHeight())
|
|
|
|
{
|
2018-06-06 18:57:22 +02:00
|
|
|
this->ui_.textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-06-06 18:57:22 +02:00
|
|
|
this->ui_.textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
2017-01-22 05:58:23 +01:00
|
|
|
}
|
|
|
|
}
|
2017-06-07 10:09:24 +02:00
|
|
|
|
2022-07-31 12:45:25 +02:00
|
|
|
void SplitInput::giveFocus(Qt::FocusReason reason)
|
|
|
|
{
|
|
|
|
this->ui_.textEdit->setFocus(reason);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SplitInput::setReply(std::shared_ptr<MessageThread> reply,
|
|
|
|
bool showReplyingLabel)
|
|
|
|
{
|
|
|
|
this->replyThread_ = std::move(reply);
|
|
|
|
|
|
|
|
if (this->enableInlineReplying_)
|
|
|
|
{
|
|
|
|
// Only enable reply label if inline replying
|
2022-10-03 20:05:42 +02:00
|
|
|
auto replyPrefix = "@" + this->replyThread_->root()->displayName;
|
2022-09-14 12:55:52 +02:00
|
|
|
auto plainText = this->ui_.textEdit->toPlainText().trimmed();
|
|
|
|
if (!plainText.startsWith(replyPrefix))
|
|
|
|
{
|
2022-10-03 20:05:42 +02:00
|
|
|
if (!plainText.isEmpty())
|
|
|
|
{
|
|
|
|
replyPrefix.append(' ');
|
|
|
|
}
|
2022-09-14 12:55:52 +02:00
|
|
|
this->ui_.textEdit->setPlainText(replyPrefix + plainText + " ");
|
|
|
|
this->ui_.textEdit->moveCursor(QTextCursor::EndOfBlock);
|
2022-10-22 11:42:46 +02:00
|
|
|
this->ui_.textEdit->resetCompletion();
|
2022-09-14 12:55:52 +02:00
|
|
|
}
|
2022-07-31 12:45:25 +02:00
|
|
|
this->ui_.replyLabel->setText("Replying to @" +
|
|
|
|
this->replyThread_->root()->displayName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SplitInput::setPlaceholderText(const QString &text)
|
|
|
|
{
|
|
|
|
this->ui_.textEdit->setPlaceholderText(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SplitInput::clearInput()
|
|
|
|
{
|
|
|
|
this->currMsg_ = "";
|
|
|
|
this->ui_.textEdit->setText("");
|
|
|
|
this->ui_.textEdit->moveCursor(QTextCursor::Start);
|
|
|
|
if (this->enableInlineReplying_)
|
|
|
|
{
|
|
|
|
this->replyThread_ = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-13 12:47:46 +01:00
|
|
|
bool SplitInput::shouldPreventInput(const QString &text) const
|
|
|
|
{
|
|
|
|
if (getSettings()->messageOverflow.getValue() != MessageOverflow::Prevent)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto channel = this->split_->getChannel();
|
|
|
|
|
|
|
|
if (channel == nullptr)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!channel->isTwitchChannel())
|
|
|
|
{
|
|
|
|
// Don't respect this setting for IRC channels as the limits might be server-specific
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return text.length() > TWITCH_MESSAGE_LIMIT;
|
|
|
|
}
|
|
|
|
|
2017-06-07 10:09:24 +02:00
|
|
|
} // namespace chatterino
|