Fixed drawing of long window titles on macOS.
This commit is contained in:
parent
113b289f7f
commit
22ceaae4ed
3 changed files with 20 additions and 1 deletions
|
|
@ -320,6 +320,7 @@ WindowHelper::WindowHelper(not_null<RpWidget*> window)
|
|||
updateCustomTitleVisibility();
|
||||
}
|
||||
init();
|
||||
_title->setControlsRect(_private->controlsRect());
|
||||
}
|
||||
|
||||
WindowHelper::~WindowHelper() {
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ public:
|
|||
|
||||
void setText(const QString &text);
|
||||
void setStyle(const style::WindowTitle &st);
|
||||
void setControlsRect(const QRect &rect);
|
||||
[[nodiscard]] QString text() const;
|
||||
[[nodiscard]] bool shouldBeHidden() const;
|
||||
|
||||
|
|
@ -44,6 +45,8 @@ private:
|
|||
not_null<const style::WindowTitle*> _st;
|
||||
object_ptr<Ui::PlainShadow> _shadow;
|
||||
QString _text;
|
||||
int _textWidth = 0;
|
||||
int _controlsRight = 0;
|
||||
QFont _font;
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ TitleWidget::TitleWidget(not_null<RpWidget*> parent, int height)
|
|||
void TitleWidget::setText(const QString &text) {
|
||||
if (_text != text) {
|
||||
_text = text;
|
||||
_textWidth = QFontMetrics(_font).horizontalAdvance(_text);
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
|
@ -39,6 +40,10 @@ void TitleWidget::setStyle(const style::WindowTitle &st) {
|
|||
update();
|
||||
}
|
||||
|
||||
void TitleWidget::setControlsRect(const QRect &rect) {
|
||||
_controlsRight = rect.left() * 2 + rect.width();
|
||||
}
|
||||
|
||||
bool TitleWidget::shouldBeHidden() const {
|
||||
return !_st->height;
|
||||
}
|
||||
|
|
@ -94,7 +99,17 @@ void TitleWidget::paintEvent(QPaintEvent *e) {
|
|||
|
||||
p.setFont(_font);
|
||||
p.setPen(active ? _st->fgActive : _st->fg);
|
||||
p.drawText(rect(), _text, style::al_center);
|
||||
|
||||
if ((width() - _controlsRight * 2) < _textWidth) {
|
||||
const auto elided = QFontMetrics(_font).elidedText(
|
||||
_text,
|
||||
Qt::ElideRight,
|
||||
width() - _controlsRight);
|
||||
const auto padding = QMargins(_controlsRight, 0, 0, 0);
|
||||
p.drawText(rect() - padding, elided, style::al_left);
|
||||
} else {
|
||||
p.drawText(rect(), _text, style::al_center);
|
||||
}
|
||||
}
|
||||
|
||||
void TitleWidget::resizeEvent(QResizeEvent *e) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue