From 8bfef7d8734e17518978045fe101e43fca3fa041 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 3 May 2019 17:02:00 +0400 Subject: [PATCH] Improve collapsed rows in small chats list. --- .../dialogs/dialogs_inner_widget.cpp | 17 ++++++-- .../SourceFiles/dialogs/dialogs_layout.cpp | 40 +++++++++++++++---- Telegram/SourceFiles/dialogs/dialogs_layout.h | 1 + 3 files changed, 47 insertions(+), 11 deletions(-) diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index d7cf82e7f..304e0158c 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -657,17 +657,28 @@ void InnerWidget::paintCollapsedRow( Painter &p, not_null row, bool selected) const { + const auto smallWidth = st::dialogsPadding.x() + + st::dialogsPhotoSize + + st::dialogsPhotoPadding; + const auto narrow = (width() <= smallWidth); const auto text = row->folder ? row->folder->chatListName() : (_mode == Dialogs::Mode::Important) - ? lang(lng_dialogs_show_all_chats) - : lang(lng_dialogs_hide_muted_chats); + ? (narrow ? "Show" : lang(lng_dialogs_show_all_chats)) + : (narrow ? "Hide" : lang(lng_dialogs_hide_muted_chats)); const auto unread = row->folder ? row->folder->chatListUnreadCount() : (_mode == Dialogs::Mode::Important) ? session().data().unreadOnlyMutedBadge() : 0; - Layout::PaintCollapsedRow(p, row->row, text, unread, width(), selected); + Layout::PaintCollapsedRow( + p, + row->row, + row->folder, + text, + unread, + width(), + selected); } bool InnerWidget::isSearchResultActive( diff --git a/Telegram/SourceFiles/dialogs/dialogs_layout.cpp b/Telegram/SourceFiles/dialogs/dialogs_layout.cpp index 339293e12..06081e552 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_layout.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_layout.cpp @@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history.h" #include "data/data_channel.h" #include "data/data_user.h" +#include "data/data_folder.h" namespace Dialogs { namespace Layout { @@ -849,21 +850,44 @@ QRect RowPainter::sendActionAnimationRect(int animationWidth, int animationHeigh return QRect(nameleft, texttop, textUpdated ? namewidth : animationWidth, animationHeight); } -void PaintCollapsedRow(Painter &p, const RippleRow &row, const QString &text, int unread, int fullWidth, bool selected) { +void PaintCollapsedRow( + Painter &p, + const RippleRow &row, + Data::Folder *folder, + const QString &text, + int unread, + int fullWidth, + bool selected) { p.fillRect(0, 0, fullWidth, st::dialogsImportantBarHeight, selected ? st::dialogsBgOver : st::dialogsBg); row.paintRipple(p, 0, 0, fullWidth); - p.setFont(st::semiboldFont); - p.setPen(st::dialogsNameFg); + const auto smallWidth = st::dialogsPadding.x() + + st::dialogsPhotoSize + + st::dialogsPhotoPadding; + const auto narrow = (fullWidth <= smallWidth); const auto unreadTop = (st::dialogsImportantBarHeight - st::dialogsUnreadHeight) / 2; - const auto textBaseline = unreadTop - + (st::dialogsUnreadHeight - st::dialogsUnreadFont->height) / 2 - + st::dialogsUnreadFont->ascent; - p.drawText(st::dialogsPadding.x(), textBaseline, text); + if (!narrow || !folder) { + p.setFont(st::semiboldFont); + p.setPen(st::dialogsNameFg); - if (unread) { + const auto textBaseline = unreadTop + + (st::dialogsUnreadHeight - st::dialogsUnreadFont->height) / 2 + + st::dialogsUnreadFont->ascent; + const auto left = narrow + ? ((fullWidth - st::semiboldFont->width(text)) / 2) + : st::dialogsPadding.x(); + p.drawText(left, textBaseline, text); + } else { + folder->paintUserpicLeft( + p, + (fullWidth - st::dialogsUnreadHeight) / 2, + unreadTop, + fullWidth, + st::dialogsUnreadHeight); + } + if (!narrow && unread) { const auto unreadRight = fullWidth - st::dialogsPadding.x(); UnreadBadgeStyle st; st.muted = true; diff --git a/Telegram/SourceFiles/dialogs/dialogs_layout.h b/Telegram/SourceFiles/dialogs/dialogs_layout.h index f16cc3100..adc67808f 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_layout.h +++ b/Telegram/SourceFiles/dialogs/dialogs_layout.h @@ -52,6 +52,7 @@ public: void PaintCollapsedRow( Painter &p, const RippleRow &row, + Data::Folder *folder, const QString &text, int unread, int fullWidth,