fix: restore input layout (almost) (#5519)

This commit is contained in:
nerix 2024-07-21 00:49:46 +02:00 committed by GitHub
parent 0495fbca43
commit 44abb1901f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 37 additions and 24 deletions

View file

@ -21,7 +21,7 @@
- Minor: Improve appearance of reply button. (#5491) - Minor: Improve appearance of reply button. (#5491)
- Minor: Introduce HTTP API for plugins. (#5383, #5492, #5494) - Minor: Introduce HTTP API for plugins. (#5383, #5492, #5494)
- Minor: Support more Firefox variants for incognito link opening. (#5503) - 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) - 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: 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) - Bugfix: If a network request errors with 200 OK, Qt's error code is now reported instead of the HTTP status. (#5378)

View file

@ -84,27 +84,26 @@ void SplitInput::initLayout()
layoutCreator.setLayoutType<QVBoxLayout>().withoutMargin().assign( layoutCreator.setLayoutType<QVBoxLayout>().withoutMargin().assign(
&this->ui_.vbox); &this->ui_.vbox);
layout->setSpacing(0); layout->setSpacing(0);
auto marginPx = this->marginForTheme(); this->applyOuterMargin();
layout->setContentsMargins(marginPx, marginPx, marginPx, marginPx);
// reply label stuff // reply label stuff
auto replyWrapper = auto replyWrapper =
layout.emplace<QWidget>().assign(&this->ui_.replyWrapper); layout.emplace<QWidget>().assign(&this->ui_.replyWrapper);
replyWrapper->setContentsMargins(0, 0, 0, 0); replyWrapper->setContentsMargins(0, 0, 1, 1);
auto replyVbox = auto replyVbox =
replyWrapper.setLayoutType<QVBoxLayout>().withoutMargin().assign( replyWrapper.setLayoutType<QVBoxLayout>().withoutMargin().assign(
&this->ui_.replyVbox); &this->ui_.replyVbox);
replyVbox->setSpacing(0); replyVbox->setSpacing(1);
auto replyHbox = auto replyHbox =
replyVbox.emplace<QHBoxLayout>().assign(&this->ui_.replyHbox); replyVbox.emplace<QHBoxLayout>().assign(&this->ui_.replyHbox);
auto messageVbox = layoutCreator.setLayoutType<QVBoxLayout>(); auto messageVbox = layoutCreator.setLayoutType<QVBoxLayout>();
this->ui_.replyMessage = new MessageView(); 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); 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); auto replyLabel = replyHbox.emplace<QLabel>().assign(&this->ui_.replyLabel);
replyLabel->setAlignment(Qt::AlignLeft); replyLabel->setAlignment(Qt::AlignLeft);
@ -122,7 +121,7 @@ void SplitInput::initLayout()
auto inputWrapper = auto inputWrapper =
layout.emplace<QWidget>().assign(&this->ui_.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 // hbox for input, right box
auto hboxLayout = auto hboxLayout =
@ -231,7 +230,7 @@ void SplitInput::scaleChangedEvent(float scale)
this->setMaximumHeight(this->scaledMaxHeight()); this->setMaximumHeight(this->scaledMaxHeight());
if (this->replyTarget_ != nullptr) if (this->replyTarget_ != nullptr)
{ {
this->ui_.vbox->setSpacing(this->marginForTheme() * 2); this->ui_.vbox->setSpacing(this->marginForTheme());
} }
} }
this->ui_.textEdit->setFont( this->ui_.textEdit->setFont(
@ -271,11 +270,10 @@ void SplitInput::themeChangedEvent()
} }
// update vbox // update vbox
auto marginPx = this->marginForTheme(); this->applyOuterMargin();
this->ui_.vbox->setContentsMargins(marginPx, marginPx, marginPx, marginPx);
if (this->replyTarget_ != nullptr) if (this->replyTarget_ != nullptr)
{ {
this->ui_.vbox->setSpacing(this->marginForTheme() * 2); this->ui_.vbox->setSpacing(this->marginForTheme());
} }
} }
@ -1095,26 +1093,26 @@ void SplitInput::paintEvent(QPaintEvent * /*event*/)
{ {
QPainter painter(this); QPainter painter(this);
int s = this->marginForTheme();
QColor borderColor = QColor borderColor =
this->theme->isLightTheme() ? QColor("#ccc") : QColor("#333"); this->theme->isLightTheme() ? QColor("#ccc") : QColor("#333");
QRect baseRect = this->rect(); QRect baseRect = this->rect();
QRect inputBoxRect = this->ui_.inputWrapper->geometry(); baseRect.setWidth(baseRect.width() - 1);
inputBoxRect.setX(baseRect.x());
inputBoxRect.setWidth(baseRect.width());
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.setPen(borderColor);
painter.drawRect(inputBoxRect); painter.drawRect(inputBoxRect);
if (this->enableInlineReplying_ && this->replyTarget_ != nullptr) if (this->enableInlineReplying_ && this->replyTarget_ != nullptr)
{ {
QRect replyRect = this->ui_.replyWrapper->geometry(); auto replyRect = this->ui_.replyWrapper->geometry();
replyRect.setX(baseRect.x()); replyRect.setSize(replyRect.size() - QSize{1, 1});
replyRect.setWidth(baseRect.width());
painter.fillRect(replyRect, this->theme->splits.input.background); painter.setBrush(this->theme->splits.input.background);
painter.setPen(borderColor); painter.setPen(borderColor);
painter.drawRect(replyRect); painter.drawRect(replyRect);
@ -1140,7 +1138,7 @@ void SplitInput::resizeEvent(QResizeEvent *event)
this->ui_.textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); this->ui_.textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
} }
this->ui_.replyMessage->setWidth(this->width()); this->ui_.replyMessage->setWidth(this->replyMessageWidth());
} }
void SplitInput::giveFocus(Qt::FocusReason reason) void SplitInput::giveFocus(Qt::FocusReason reason)
@ -1170,11 +1168,11 @@ void SplitInput::setReply(MessagePtr target)
if (this->enableInlineReplying_) if (this->enableInlineReplying_)
{ {
this->ui_.replyMessage->setWidth(this->replyMessageWidth());
this->ui_.replyMessage->setMessage(this->replyTarget_); this->ui_.replyMessage->setMessage(this->replyTarget_);
this->ui_.replyMessage->setWidth(this->width());
// add spacing between reply box and input box // add spacing between reply box and input box
this->ui_.vbox->setSpacing(this->marginForTheme() * 2); this->ui_.vbox->setSpacing(this->marginForTheme());
if (!this->isHidden()) if (!this->isHidden())
{ {
// update maximum height to give space for message // update maximum height to give space for message
@ -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 } // namespace chatterino

View file

@ -124,6 +124,10 @@ protected:
int marginForTheme() const; int marginForTheme() const;
void applyOuterMargin();
int replyMessageWidth() const;
Split *const split_; Split *const split_;
ChannelView *const channelView_; ChannelView *const channelView_;
QPointer<EmotePopup> emotePopup_; QPointer<EmotePopup> emotePopup_;