diff --git a/Telegram/SourceFiles/boxes/peer_list_box.cpp b/Telegram/SourceFiles/boxes/peer_list_box.cpp index 859688c9a..9d739724b 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_box.cpp @@ -330,7 +330,7 @@ bool PeerListRow::checked() const { } void PeerListRow::setCustomStatus(const QString &status) { - _status = status; + setStatusText(status); _statusType = StatusType::Custom; } @@ -345,7 +345,7 @@ void PeerListRow::refreshStatus() { } if (auto user = peer()->asUser()) { auto time = unixtime(); - _status = App::onlineText(user, time); + setStatusText(App::onlineText(user, time)); _statusType = App::onlineColorUse(user, time) ? StatusType::Online : StatusType::LastSeen; } } @@ -365,10 +365,11 @@ void PeerListRow::invalidatePixmapsCache() { } } -void PeerListRow::paintStatusText(Painter &p, int x, int y, int outerWidth, bool selected) { +void PeerListRow::paintStatusText(Painter &p, int x, int y, int availableWidth, int outerWidth, bool selected) { auto statusHasOnlineColor = (_statusType == PeerListRow::StatusType::Online); + p.setFont(st::contactsStatusFont); p.setPen(statusHasOnlineColor ? st::contactsStatusFgOnline : (selected ? st::contactsStatusFgOver : st::contactsStatusFg)); - p.drawTextLeft(x, y, outerWidth, _status); + p.drawTextLeft(x, y, outerWidth, (_statusWidth <= availableWidth) ? _status : st::contactsStatusFont->elided(_status, availableWidth)); } template @@ -442,6 +443,11 @@ void PeerListRow::paintDisabledCheckUserpic(Painter &p, int x, int y, int outerW st::contactsPhotoCheckbox.check.check.paint(p, iconEllipse.topLeft(), outerWidth); } +void PeerListRow::setStatusText(const QString &text) { + _status = text; + _statusWidth = st::contactsStatusFont->width(_status); +} + float64 PeerListRow::checkedRatio() { return _checkbox ? _checkbox->checkedAnimationRatio() : 0.; } @@ -828,6 +834,7 @@ void PeerListBox::Inner::paintRow(Painter &p, TimeMs ms, RowIndex index) { if (!actionSize.isEmpty()) { namew -= actionMargins.left() + actionSize.width() + actionMargins.right(); } + auto statusw = namew; if (row->needsVerifiedIcon()) { auto icon = &st::dialogsVerifiedIcon; namew -= icon->width(); @@ -845,7 +852,7 @@ void PeerListBox::Inner::paintRow(Painter &p, TimeMs ms, RowIndex index) { p.setFont(st::contactsStatusFont); if (row->isSearchResult() && !_mentionHighlight.isEmpty() && peer->userName().startsWith(_mentionHighlight, Qt::CaseInsensitive)) { auto username = peer->userName(); - auto availableWidth = width() - namex - st::contactsPadding.right(); + auto availableWidth = statusw; auto highlightedPart = '@' + username.mid(0, _mentionHighlight.size()); auto grayedPart = username.mid(_mentionHighlight.size()); auto highlightedWidth = st::contactsStatusFont->width(highlightedPart); @@ -864,7 +871,7 @@ void PeerListBox::Inner::paintRow(Painter &p, TimeMs ms, RowIndex index) { p.drawTextLeft(namex + highlightedWidth, st::contactsPadding.top() + st::contactsStatusTop, width(), grayedPart); } } else { - row->paintStatusText(p, namex, st::contactsPadding.top() + st::contactsStatusTop, width(), selected); + row->paintStatusText(p, namex, st::contactsPadding.top() + st::contactsStatusTop, statusw, width(), selected); } } diff --git a/Telegram/SourceFiles/boxes/peer_list_box.h b/Telegram/SourceFiles/boxes/peer_list_box.h index 980735ef1..f6ae1c7ab 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.h +++ b/Telegram/SourceFiles/boxes/peer_list_box.h @@ -134,7 +134,7 @@ public: } virtual void lazyInitialize(); - virtual void paintStatusText(Painter &p, int x, int y, int outerWidth, bool selected); + virtual void paintStatusText(Painter &p, int x, int y, int availableWidth, int outerWidth, bool selected); protected: bool isInitialized() const { @@ -145,6 +145,7 @@ private: void createCheckbox(base::lambda updateCallback); void setCheckedInternal(bool checked, SetStyle style); void paintDisabledCheckUserpic(Painter &p, int x, int y, int outerWidth) const; + void setStatusText(const QString &text); PeerListRowId _id = 0; gsl::not_null _peer; @@ -152,6 +153,7 @@ private: std::unique_ptr _checkbox; Text _name; QString _status; + int _statusWidth = 0; StatusType _statusType = StatusType::Online; OrderedSet _nameFirstChars; int _absoluteIndex = -1; diff --git a/Telegram/SourceFiles/calls/calls_box_controller.cpp b/Telegram/SourceFiles/calls/calls_box_controller.cpp index f17aea6e5..168a502f6 100644 --- a/Telegram/SourceFiles/calls/calls_box_controller.cpp +++ b/Telegram/SourceFiles/calls/calls_box_controller.cpp @@ -77,7 +77,7 @@ public: return _items.front()->id; } - void paintStatusText(Painter &p, int x, int y, int outerWidth, bool selected) override; + void paintStatusText(Painter &p, int x, int y, int availableWidth, int outerWidth, bool selected) override; void addActionRipple(QPoint point, base::lambda updateCallback) override; void stopLastActionRipple() override; @@ -111,7 +111,7 @@ BoxController::Row::Row(HistoryItem *item) : PeerListRow(item->history()->peer, refreshStatus(); } -void BoxController::Row::paintStatusText(Painter &p, int x, int y, int outerWidth, bool selected) { +void BoxController::Row::paintStatusText(Painter &p, int x, int y, int availableWidth, int outerWidth, bool selected) { auto icon = ([this] { switch (_type) { case Type::In: return &st::callArrowIn; @@ -121,9 +121,11 @@ void BoxController::Row::paintStatusText(Painter &p, int x, int y, int outerWidt Unexpected("_type in Calls::BoxController::Row::paintStatusText()."); })(); icon->paint(p, x + st::callArrowPosition.x(), y + st::callArrowPosition.y(), outerWidth); - x += + st::callArrowPosition.x() + icon->width() + st::callArrowSkip; + auto shift = st::callArrowPosition.x() + icon->width() + st::callArrowSkip; + x += shift; + availableWidth -= shift; - PeerListRow::paintStatusText(p, x, y, outerWidth, selected); + PeerListRow::paintStatusText(p, x, y, availableWidth, outerWidth, selected); } void BoxController::Row::paintAction(Painter &p, TimeMs ms, int x, int y, int outerWidth, bool actionSelected) {