refactor: Fix a bunch of minor things (#5094)

This commit is contained in:
pajlada
2024-01-17 21:05:44 +01:00
committed by GitHub
parent 718696db53
commit 9eeea8f203
11 changed files with 194 additions and 137 deletions
+102 -88
View File
@@ -213,16 +213,17 @@ void SplitInput::scaleChangedEvent(float scale)
this->setMaximumHeight(this->scaledMaxHeight());
}
this->ui_.textEdit->setFont(
app->fonts->getFont(FontStyle::ChatMedium, this->scale()));
app->fonts->getFont(FontStyle::ChatMedium, scale));
this->ui_.textEditLength->setFont(
app->fonts->getFont(FontStyle::ChatMedium, this->scale()));
app->fonts->getFont(FontStyle::ChatMedium, scale));
this->ui_.replyLabel->setFont(
app->fonts->getFont(FontStyle::ChatMediumBold, this->scale()));
app->fonts->getFont(FontStyle::ChatMediumBold, scale));
}
void SplitInput::themeChangedEvent()
{
QPalette palette, placeholderPalette;
QPalette palette;
QPalette placeholderPalette;
palette.setColor(QPalette::WindowText, this->theme->splits.input.text);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
@@ -256,15 +257,12 @@ void SplitInput::themeChangedEvent()
void SplitInput::updateEmoteButton()
{
float scale = this->scale();
auto scale = this->scale();
QString text = "<img src=':/buttons/emote.svg' width='xD' height='xD' />";
text.replace("xD", QString::number(int(12 * scale)));
if (this->theme->isLightTheme())
{
text.replace("emote", "emoteDark");
}
auto text =
QStringLiteral("<img src=':/buttons/%1.svg' width='%2' height='%2' />")
.arg(this->theme->isLightTheme() ? "emoteDark" : "emote")
.arg(int(12 * scale));
this->ui_.emoteButton->getLabel().setText(text);
this->ui_.emoteButton->setFixedHeight(int(18 * scale));
@@ -274,15 +272,10 @@ 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");
}
auto text =
QStringLiteral("<img src=':/buttons/%1.svg' width='%2' height='%2' />")
.arg(this->theme->isLightTheme() ? "cancelDark" : "cancel")
.arg(int(12 * scale));
this->ui_.cancelReplyButton->getLabel().setText(text);
this->ui_.cancelReplyButton->setFixedHeight(int(12 * scale));
@@ -324,7 +317,7 @@ void SplitInput::openEmotePopup()
this->emotePopup_->activateWindow();
}
QString SplitInput::handleSendMessage(std::vector<QString> &arguments)
QString SplitInput::handleSendMessage(const std::vector<QString> &arguments)
{
auto c = this->split_->getChannel();
if (c == nullptr)
@@ -346,40 +339,37 @@ QString SplitInput::handleSendMessage(std::vector<QString> &arguments)
this->postMessageSend(message, arguments);
return "";
}
else
// Reply to message
auto *tc = dynamic_cast<TwitchChannel *>(c.get());
if (!tc)
{
// 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_->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_->id);
this->postMessageSend(message, arguments);
// 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_->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_->id);
this->postMessageSend(message, arguments);
return "";
}
void SplitInput::postMessageSend(const QString &message,
@@ -408,7 +398,7 @@ void SplitInput::addShortcuts()
{
HotkeyController::HotkeyMap actions{
{"cursorToStart",
[this](std::vector<QString> arguments) -> QString {
[this](const std::vector<QString> &arguments) -> QString {
if (arguments.size() != 1)
{
qCWarning(chatterinoHotkeys)
@@ -419,8 +409,8 @@ void SplitInput::addShortcuts()
}
QTextCursor cursor = this->ui_.textEdit->textCursor();
auto place = QTextCursor::Start;
auto stringTakeSelection = arguments.at(0);
bool select;
const auto &stringTakeSelection = arguments.at(0);
bool select{};
if (stringTakeSelection == "withSelection")
{
select = true;
@@ -443,7 +433,7 @@ void SplitInput::addShortcuts()
return "";
}},
{"cursorToEnd",
[this](std::vector<QString> arguments) -> QString {
[this](const std::vector<QString> &arguments) -> QString {
if (arguments.size() != 1)
{
qCWarning(chatterinoHotkeys)
@@ -454,8 +444,8 @@ void SplitInput::addShortcuts()
}
QTextCursor cursor = this->ui_.textEdit->textCursor();
auto place = QTextCursor::End;
auto stringTakeSelection = arguments.at(0);
bool select;
const auto &stringTakeSelection = arguments.at(0);
bool select{};
if (stringTakeSelection == "withSelection")
{
select = true;
@@ -478,36 +468,45 @@ void SplitInput::addShortcuts()
return "";
}},
{"openEmotesPopup",
[this](std::vector<QString>) -> QString {
[this](const std::vector<QString> &arguments) -> QString {
(void)arguments;
this->openEmotePopup();
return "";
}},
{"sendMessage",
[this](std::vector<QString> arguments) -> QString {
[this](const std::vector<QString> &arguments) -> QString {
return this->handleSendMessage(arguments);
}},
{"previousMessage",
[this](std::vector<QString>) -> QString {
if (this->prevMsg_.size() && this->prevIndex_)
[this](const std::vector<QString> &arguments) -> QString {
(void)arguments;
if (this->prevMsg_.isEmpty() || this->prevIndex_ == 0)
{
if (this->prevIndex_ == (this->prevMsg_.size()))
{
this->currMsg_ = ui_.textEdit->toPlainText();
}
this->prevIndex_--;
this->ui_.textEdit->setPlainText(
this->prevMsg_.at(this->prevIndex_));
this->ui_.textEdit->resetCompletion();
QTextCursor cursor = this->ui_.textEdit->textCursor();
cursor.movePosition(QTextCursor::End);
this->ui_.textEdit->setTextCursor(cursor);
return "";
}
if (this->prevIndex_ == (this->prevMsg_.size()))
{
this->currMsg_ = ui_.textEdit->toPlainText();
}
this->prevIndex_--;
this->ui_.textEdit->setPlainText(
this->prevMsg_.at(this->prevIndex_));
this->ui_.textEdit->resetCompletion();
QTextCursor cursor = this->ui_.textEdit->textCursor();
cursor.movePosition(QTextCursor::End);
this->ui_.textEdit->setTextCursor(cursor);
return "";
}},
{"nextMessage",
[this](std::vector<QString>) -> QString {
[this](const std::vector<QString> &arguments) -> QString {
(void)arguments;
// If user did not write anything before then just do nothing.
if (this->prevMsg_.isEmpty())
{
@@ -556,19 +555,23 @@ void SplitInput::addShortcuts()
return "";
}},
{"undo",
[this](std::vector<QString>) -> QString {
[this](const std::vector<QString> &arguments) -> QString {
(void)arguments;
this->ui_.textEdit->undo();
return "";
}},
{"redo",
[this](std::vector<QString>) -> QString {
[this](const std::vector<QString> &arguments) -> QString {
(void)arguments;
this->ui_.textEdit->redo();
return "";
}},
{"copy",
[this](std::vector<QString> arguments) -> QString {
[this](const std::vector<QString> &arguments) -> QString {
// XXX: this action is unused at the moment, a qt standard shortcut is used instead
if (arguments.size() == 0)
if (arguments.empty())
{
return "copy action takes only one argument: the source "
"of the copy \"split\", \"input\" or "
@@ -578,8 +581,9 @@ void SplitInput::addShortcuts()
"copied. Automatic will pick whichever has a "
"selection";
}
bool copyFromSplit = false;
auto mode = arguments.at(0);
const auto &mode = arguments.at(0);
if (mode == "split")
{
copyFromSplit = true;
@@ -605,22 +609,30 @@ void SplitInput::addShortcuts()
return "";
}},
{"paste",
[this](std::vector<QString>) -> QString {
[this](const std::vector<QString> &arguments) -> QString {
(void)arguments;
this->ui_.textEdit->paste();
return "";
}},
{"clear",
[this](std::vector<QString>) -> QString {
[this](const std::vector<QString> &arguments) -> QString {
(void)arguments;
this->clearInput();
return "";
}},
{"selectAll",
[this](std::vector<QString>) -> QString {
[this](const std::vector<QString> &arguments) -> QString {
(void)arguments;
this->ui_.textEdit->selectAll();
return "";
}},
{"selectWord",
[this](std::vector<QString>) -> QString {
[this](const std::vector<QString> &arguments) -> QString {
(void)arguments;
auto cursor = this->ui_.textEdit->textCursor();
cursor.select(QTextCursor::WordUnderCursor);
this->ui_.textEdit->setTextCursor(cursor);
@@ -1018,7 +1030,7 @@ void SplitInput::paintEvent(QPaintEvent * /*event*/)
{
QPainter painter(this);
int s;
int s{};
QColor borderColor;
if (this->theme->isLightTheme())
@@ -1052,8 +1064,10 @@ void SplitInput::paintEvent(QPaintEvent * /*event*/)
}
}
void SplitInput::resizeEvent(QResizeEvent *)
void SplitInput::resizeEvent(QResizeEvent *event)
{
(void)event;
if (this->height() == this->maximumHeight())
{
this->ui_.textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);