Skip to content

Commit

Permalink
fix: word wrap
Browse files Browse the repository at this point in the history
  • Loading branch information
8thony authored Jan 11, 2025
1 parent b0e8556 commit 0e04b8b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Minor: Remove incognito browser support for `opera/launcher` (this should no longer be a thing). (#5805)
- Minor: Remove incognito browser support for `iexplore`, because internet explorer is EOL. (#5810)
- Bugfix: Fixed a crash relating to Lua HTTP. (#5800)
- Bugfix: Fixed missing word wrap in update popup. (#5811)
- Dev: Updated Conan dependencies. (#5776)

## 2.5.2
Expand Down
21 changes: 20 additions & 1 deletion src/widgets/Label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ void Label::setHasOffset(bool hasOffset)
this->hasOffset_ = hasOffset;
this->updateSize();
}

bool Label::getWordWrap() const
{
return this->wordWrap_;
}

void Label::setWordWrap(bool wrap)
{
this->wordWrap_ = wrap;
this->update();
}

void Label::setFontStyle(FontStyle style)
{
this->fontStyle_ = style;
Expand Down Expand Up @@ -107,7 +119,14 @@ void Label::paintEvent(QPaintEvent *)
painter.setBrush(this->palette().windowText());

QTextOption option(alignment);
option.setWrapMode(QTextOption::NoWrap);
if (this->wordWrap_)
{
option.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
}
else
{
option.setWrapMode(QTextOption::NoWrap);
}
painter.drawText(textRect, this->text_, option);

#if 0
Expand Down
4 changes: 4 additions & 0 deletions src/widgets/Label.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class Label : public BaseWidget
bool getHasOffset() const;
void setHasOffset(bool hasOffset);

bool getWordWrap() const;
void setWordWrap(bool wrap);

protected:
void scaleChangedEvent(float scale_) override;
void paintEvent(QPaintEvent *) override;
Expand All @@ -43,6 +46,7 @@ class Label : public BaseWidget
QSize preferedSize_;
bool centered_ = false;
bool hasOffset_ = true;
bool wordWrap_ = false;

pajlada::Signals::SignalHolder connections_;
};
Expand Down
9 changes: 5 additions & 4 deletions src/widgets/dialogs/UpdateDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ UpdateDialog::UpdateDialog()
LayoutCreator<UpdateDialog>(this).setLayoutType<QVBoxLayout>();

layout.emplace<Label>("You shouldn't be seeing this dialog.")
.assign(&this->ui_.label);
.assign(&this->ui_.label)
->setWordWrap(true);

auto buttons = layout.emplace<QDialogButtonBox>();
auto *install = buttons->addButton("Install", QDialogButtonBox::AcceptRole);
Expand Down Expand Up @@ -55,9 +56,9 @@ void UpdateDialog::updateStatusChanged(Updates::Status status)
this->ui_.label->setText((
getApp()->getUpdates().isDowngrade()
? QString(
"The version online (%1) seems to be\nlower than the "
"The version online (%1) seems to be lower than the "
"current (%2).\nEither a version was reverted or "
"you are\nrunning a newer build.\n\nDo you want to "
"you are running a newer build.\n\nDo you want to "
"download and install it?")
.arg(getApp()->getUpdates().getOnlineVersion(),
getApp()->getUpdates().getCurrentVersion())
Expand All @@ -76,7 +77,7 @@ void UpdateDialog::updateStatusChanged(Updates::Status status)
case Updates::Downloading: {
this->ui_.label->setText(
"Downloading updates.\n\nChatterino will restart "
"automatically\nwhen the download is done.");
"automatically when the download is done.");
}
break;

Expand Down

0 comments on commit 0e04b8b

Please sign in to comment.