From 1dd461b24a1226f3cbf2141b48f0f2aa65b92869 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 22 May 2019 11:57:25 +0300 Subject: [PATCH] Moved left elision of counters to Dialogs::Layout::paintUnreadCount. --- Telegram/SourceFiles/dialogs/dialogs_layout.cpp | 14 ++++++++------ Telegram/SourceFiles/dialogs/dialogs_layout.h | 5 +++-- Telegram/SourceFiles/ui/special_buttons.cpp | 5 +---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Telegram/SourceFiles/dialogs/dialogs_layout.cpp b/Telegram/SourceFiles/dialogs/dialogs_layout.cpp index f16fc404f9..35e425dfcf 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_layout.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_layout.cpp @@ -79,9 +79,6 @@ void PaintNarrowCounter( ? QString::number(unreadCount) : QString(); const auto allowDigits = displayMentionBadge ? 1 : 3; - if (counter.size() > allowDigits + 1) { - counter = qsl("..") + counter.mid(counter.size() - allowDigits); - } auto unreadRight = st::dialogsPadding.x() + st::dialogsPhotoSize; auto unreadTop = st::dialogsPadding.y() + st::dialogsPhotoSize - st::dialogsUnreadHeight; auto unreadWidth = 0; @@ -89,7 +86,7 @@ void PaintNarrowCounter( UnreadBadgeStyle st; st.active = active; st.muted = unreadMuted; - paintUnreadCount(p, counter, unreadRight, unreadTop, st, &unreadWidth); + paintUnreadCount(p, counter, unreadRight, unreadTop, st, &unreadWidth, allowDigits); skipBeforeMention += unreadWidth + st.padding; } if (displayMentionBadge) { @@ -553,11 +550,16 @@ UnreadBadgeStyle::UnreadBadgeStyle() void paintUnreadCount( Painter &p, - const QString &text, + const QString &unreadCount, int x, int y, const UnreadBadgeStyle &st, - int *outUnreadWidth) { + int *outUnreadWidth, + int allowDigits) { + const auto text = (allowDigits > 0) && (unreadCount.size() > allowDigits + 1) + ? qsl("..") + unreadCount.mid(unreadCount.size() - allowDigits) + : unreadCount; + int unreadWidth = st.font->width(text); int unreadRectWidth = unreadWidth + 2 * st.padding; int unreadRectHeight = st.size; diff --git a/Telegram/SourceFiles/dialogs/dialogs_layout.h b/Telegram/SourceFiles/dialogs/dialogs_layout.h index adc67808f0..e5ac51c9b9 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_layout.h +++ b/Telegram/SourceFiles/dialogs/dialogs_layout.h @@ -81,11 +81,12 @@ struct UnreadBadgeStyle { }; void paintUnreadCount( Painter &p, - const QString &text, + const QString &t, int x, int y, const UnreadBadgeStyle &st, - int *outUnreadWidth = nullptr); + int *outUnreadWidth = nullptr, + int allowDigits = 0); void clearUnreadBadgesCache(); diff --git a/Telegram/SourceFiles/ui/special_buttons.cpp b/Telegram/SourceFiles/ui/special_buttons.cpp index e66ea4d8eb..a3a249234d 100644 --- a/Telegram/SourceFiles/ui/special_buttons.cpp +++ b/Telegram/SourceFiles/ui/special_buttons.cpp @@ -158,16 +158,13 @@ void HistoryDownButton::paintEvent(QPaintEvent *e) { ((over || down) ? _st.iconAboveOver : _st.iconAbove).paint(p, _st.iconPosition, width()); if (_unreadCount > 0) { auto unreadString = QString::number(_unreadCount); - if (unreadString.size() > 4) { - unreadString = qsl("..") + unreadString.mid(unreadString.size() - 4); - } Dialogs::Layout::UnreadBadgeStyle st; st.align = style::al_center; st.font = st::historyToDownBadgeFont; st.size = st::historyToDownBadgeSize; st.sizeId = Dialogs::Layout::UnreadBadgeInHistoryToDown; - Dialogs::Layout::paintUnreadCount(p, unreadString, width(), 0, st, nullptr); + Dialogs::Layout::paintUnreadCount(p, unreadString, width(), 0, st, nullptr, 4); } }