Skip to content

Commit

Permalink
fix: restore input layout (almost) (#5519)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerixyz committed Jul 20, 2024
1 parent 0495fbc commit 44abb19
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 24 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
- Minor: Improve appearance of reply button. (#5491)
- Minor: Introduce HTTP API for plugins. (#5383, #5492, #5494)
- Minor: Support more Firefox variants for incognito link opening. (#5503)
- Minor: Replying to a message will now display the message being replied to. (#4350)
- Minor: Replying to a message will now display the message being replied to. (#4350, #5519)
- Minor: Links can now have prefixes and suffixes such as parentheses. (#5486)
- Bugfix: Fixed tab move animation occasionally failing to start after closing a tab. (#5426)
- Bugfix: If a network request errors with 200 OK, Qt's error code is now reported instead of the HTTP status. (#5378)
Expand Down
55 changes: 32 additions & 23 deletions src/widgets/splits/SplitInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,26 @@ void SplitInput::initLayout()
layoutCreator.setLayoutType<QVBoxLayout>().withoutMargin().assign(
&this->ui_.vbox);
layout->setSpacing(0);
auto marginPx = this->marginForTheme();
layout->setContentsMargins(marginPx, marginPx, marginPx, marginPx);
this->applyOuterMargin();

// reply label stuff
auto replyWrapper =
layout.emplace<QWidget>().assign(&this->ui_.replyWrapper);
replyWrapper->setContentsMargins(0, 0, 0, 0);
replyWrapper->setContentsMargins(0, 0, 1, 1);

auto replyVbox =
replyWrapper.setLayoutType<QVBoxLayout>().withoutMargin().assign(
&this->ui_.replyVbox);
replyVbox->setSpacing(0);
replyVbox->setSpacing(1);

auto replyHbox =
replyVbox.emplace<QHBoxLayout>().assign(&this->ui_.replyHbox);

auto messageVbox = layoutCreator.setLayoutType<QVBoxLayout>();
this->ui_.replyMessage = new MessageView();
messageVbox->addWidget(this->ui_.replyMessage, 1, Qt::AlignLeft);
messageVbox->addWidget(this->ui_.replyMessage, 0, Qt::AlignLeft);
messageVbox->setContentsMargins(10, 0, 0, 0);
replyVbox->addLayout(messageVbox->layout(), 1);
replyVbox->addLayout(messageVbox->layout(), 0);

auto replyLabel = replyHbox.emplace<QLabel>().assign(&this->ui_.replyLabel);
replyLabel->setAlignment(Qt::AlignLeft);
Expand All @@ -122,7 +121,7 @@ void SplitInput::initLayout()

auto inputWrapper =
layout.emplace<QWidget>().assign(&this->ui_.inputWrapper);
inputWrapper->setContentsMargins(0, 0, 0, 0);
inputWrapper->setContentsMargins(1, 1, 1, 1);

// hbox for input, right box
auto hboxLayout =
Expand Down Expand Up @@ -231,7 +230,7 @@ void SplitInput::scaleChangedEvent(float scale)
this->setMaximumHeight(this->scaledMaxHeight());
if (this->replyTarget_ != nullptr)
{
this->ui_.vbox->setSpacing(this->marginForTheme() * 2);
this->ui_.vbox->setSpacing(this->marginForTheme());
}
}
this->ui_.textEdit->setFont(
Expand Down Expand Up @@ -271,11 +270,10 @@ void SplitInput::themeChangedEvent()
}

// update vbox
auto marginPx = this->marginForTheme();
this->ui_.vbox->setContentsMargins(marginPx, marginPx, marginPx, marginPx);
this->applyOuterMargin();
if (this->replyTarget_ != nullptr)
{
this->ui_.vbox->setSpacing(this->marginForTheme() * 2);
this->ui_.vbox->setSpacing(this->marginForTheme());
}
}

Expand Down Expand Up @@ -1095,26 +1093,26 @@ void SplitInput::paintEvent(QPaintEvent * /*event*/)
{
QPainter painter(this);

int s = this->marginForTheme();
QColor borderColor =
this->theme->isLightTheme() ? QColor("#ccc") : QColor("#333");

QRect baseRect = this->rect();
QRect inputBoxRect = this->ui_.inputWrapper->geometry();
inputBoxRect.setX(baseRect.x());
inputBoxRect.setWidth(baseRect.width());
baseRect.setWidth(baseRect.width() - 1);

painter.fillRect(inputBoxRect, this->theme->splits.input.background);
auto *inputWrap = this->ui_.inputWrapper;
auto inputBoxRect = inputWrap->geometry();
inputBoxRect.setSize(inputBoxRect.size() - QSize{1, 1});

painter.setBrush({this->theme->splits.input.background});
painter.setPen(borderColor);
painter.drawRect(inputBoxRect);

if (this->enableInlineReplying_ && this->replyTarget_ != nullptr)
{
QRect replyRect = this->ui_.replyWrapper->geometry();
replyRect.setX(baseRect.x());
replyRect.setWidth(baseRect.width());
auto replyRect = this->ui_.replyWrapper->geometry();
replyRect.setSize(replyRect.size() - QSize{1, 1});

painter.fillRect(replyRect, this->theme->splits.input.background);
painter.setBrush(this->theme->splits.input.background);
painter.setPen(borderColor);
painter.drawRect(replyRect);

Expand All @@ -1140,7 +1138,7 @@ void SplitInput::resizeEvent(QResizeEvent *event)
this->ui_.textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}

this->ui_.replyMessage->setWidth(this->width());
this->ui_.replyMessage->setWidth(this->replyMessageWidth());
}

void SplitInput::giveFocus(Qt::FocusReason reason)
Expand Down Expand Up @@ -1170,11 +1168,11 @@ void SplitInput::setReply(MessagePtr target)

if (this->enableInlineReplying_)
{
this->ui_.replyMessage->setWidth(this->replyMessageWidth());
this->ui_.replyMessage->setMessage(this->replyTarget_);
this->ui_.replyMessage->setWidth(this->width());

// add spacing between reply box and input box
this->ui_.vbox->setSpacing(this->marginForTheme() * 2);
this->ui_.vbox->setSpacing(this->marginForTheme());
if (!this->isHidden())
{
// update maximum height to give space for message
Expand Down Expand Up @@ -1274,4 +1272,15 @@ int SplitInput::marginForTheme() const
}
}

void SplitInput::applyOuterMargin()
{
auto margin = std::max(this->marginForTheme() - 1, 0);
this->ui_.vbox->setContentsMargins(margin, margin, margin, margin);
}

int SplitInput::replyMessageWidth() const
{
return this->ui_.inputWrapper->width() - 1 - 10;
}

} // namespace chatterino
4 changes: 4 additions & 0 deletions src/widgets/splits/SplitInput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ class SplitInput : public BaseWidget

int marginForTheme() const;

void applyOuterMargin();

int replyMessageWidth() const;

Split *const split_;
ChannelView *const channelView_;
QPointer<EmotePopup> emotePopup_;
Expand Down

0 comments on commit 44abb19

Please sign in to comment.