From b5d80a3c151766554fafc794f4f7bf81a638b23c Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 12 Sep 2019 15:14:12 +0300 Subject: [PATCH] Improve BottomInfo layout. --- Telegram/SourceFiles/history/history_item.cpp | 2 + .../history/view/history_view_bottom_info.cpp | 38 +++++++++++++++++-- .../history/view/history_view_bottom_info.h | 1 + .../history/view/history_view_element.cpp | 4 ++ .../history/view/history_view_element.h | 1 + .../history/view/history_view_message.cpp | 36 ++++++++++++++---- .../history/view/history_view_message.h | 18 +++++---- .../history/view/media/history_view_gif.cpp | 2 +- .../view/media/history_view_location.cpp | 2 +- .../history/view/media/history_view_photo.cpp | 2 +- .../history/view/media/history_view_poll.cpp | 2 +- 11 files changed, 85 insertions(+), 23 deletions(-) diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index a332f0a48..821066edb 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -753,6 +753,7 @@ void HistoryItem::addReaction(const QString &reaction) { _reactions = std::make_unique(this); } _reactions->add(reaction); + history()->owner().notifyItemDataChange(this); } void HistoryItem::updateReactions(const MTPMessageReactions &reactions) { @@ -764,6 +765,7 @@ void HistoryItem::updateReactions(const MTPMessageReactions &reactions) { _reactions = std::make_unique(this); } _reactions->set(data.vresults().v, data.is_min()); + history()->owner().notifyItemDataChange(this); }); } diff --git a/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp b/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp index fdcf5b5a7..3179ef7fc 100644 --- a/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp +++ b/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp @@ -14,12 +14,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history_item_components.h" #include "history/history_message.h" #include "history/view/history_view_message.h" +#include "data/data_message_reactions.h" #include "styles/style_chat.h" #include "styles/style_dialogs.h" namespace HistoryView { -BottomInfo::BottomInfo(Data &&data) : _data(std::move(data)) { +BottomInfo::BottomInfo(Data &&data) +: _data(std::move(data)) +, _reactions(st::msgMinWidth / 2) { layout(); } @@ -39,6 +42,17 @@ QSize BottomInfo::size() const { return _size; } +int BottomInfo::firstLineWidth() const { + if (_size.height() == _optimalSize.height()) { + return _size.width(); + } + const auto reactionsWidth = _reactions.maxWidth(); + const auto noReactionsWidth = _optimalSize.width() + - st::historyReactionsSkip + - reactionsWidth; + return noReactionsWidth; +} + bool BottomInfo::pointInTime(QPoint position) const { return QRect( _size.width() - _dateWidth, @@ -144,7 +158,7 @@ void BottomInfo::paint( } else { const auto available = _size.width(); const auto use = std::min(available, _reactions.maxWidth()); - _reactions.drawLeftElided( + _reactions.drawLeft( p, position.x() + _size.width() - use, position.y() + st::msgDateFont->height, @@ -157,12 +171,25 @@ void BottomInfo::paint( int BottomInfo::resizeToWidth(int newWidth) { if (newWidth >= _optimalSize.width()) { _size = _optimalSize; - return _size.height(); + } else { + const auto reactionsWidth = _reactions.maxWidth(); + const auto noReactionsWidth = _optimalSize.width() + - st::historyReactionsSkip + - reactionsWidth; + accumulate_min(newWidth, std::max(noReactionsWidth, reactionsWidth)); + _size = QSize( + newWidth, + st::msgDateFont->height + _reactions.countHeight(newWidth)); } - return 2 * st::msgDateFont->height; + return _size.height(); } void BottomInfo::layout() { + //const auto good = ::Data::MessageReactions::SuggestList(); + //for (const auto &item : good) { + // _data.reactions.emplace(item, rand_value() + 1); + //} + layoutDateText(); layoutViewsText(); layoutRepliesText(); @@ -234,6 +261,9 @@ void BottomInfo::layoutReactionsText() { auto fullCount = 0; auto text = QString(); for (const auto &[string, count] : sorted) { + //for (auto i = 0, n = rand_value() % 8 + 1; i != n; ++i) { + // text.append(string); + //} text.append(string); fullCount += count; } diff --git a/Telegram/SourceFiles/history/view/history_view_bottom_info.h b/Telegram/SourceFiles/history/view/history_view_bottom_info.h index 2731a2e32..a61c1df48 100644 --- a/Telegram/SourceFiles/history/view/history_view_bottom_info.h +++ b/Telegram/SourceFiles/history/view/history_view_bottom_info.h @@ -46,6 +46,7 @@ public: [[nodiscard]] QSize optimalSize() const; [[nodiscard]] QSize size() const; + [[nodiscard]] int firstLineWidth() const; [[nodiscard]] bool pointInTime(QPoint position) const; [[nodiscard]] bool isSignedAuthorElided() const; diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index 5d0ff8f85..891e38876 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -466,6 +466,10 @@ int Element::infoWidth() const { return 0; } +int Element::bottomInfoFirstLineWidth() const { + return 0; +} + bool Element::isHiddenByGroup() const { return _flags & Flag::HiddenByGroup; } diff --git a/Telegram/SourceFiles/history/view/history_view_element.h b/Telegram/SourceFiles/history/view/history_view_element.h index 5f5d2312d..bb16805e7 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.h +++ b/Telegram/SourceFiles/history/view/history_view_element.h @@ -261,6 +261,7 @@ public: int skipBlockHeight() const; QString skipBlock() const; virtual int infoWidth() const; + virtual int bottomInfoFirstLineWidth() const; bool isHiddenByGroup() const; virtual bool isHidden() const; diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 681784d46..a24503697 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -634,6 +634,10 @@ void Message::draw(Painter &p, const PaintContext &context) const { if (entry) { trect.setHeight(trect.height() - entry->height()); } + const auto needDrawInfo = needInfoDisplay(); + if (needDrawInfo) { + trect.setHeight(trect.height() - (_bottomInfo.size().height() - st::msgDateFont->height)); + } paintText(p, trect, context); if (mediaDisplayed) { auto mediaHeight = media->height(); @@ -660,11 +664,6 @@ void Message::draw(Painter &p, const PaintContext &context) const { entry->draw(p, entryContext); p.translate(-entryLeft, -entryTop); } - const auto needDrawInfo = entry - ? !entry->customInfoLayout() - : (mediaDisplayed - ? !media->customInfoLayout() - : true); if (needDrawInfo) { const auto bottomSelected = context.selected() || (!mediaSelectionIntervals.empty() @@ -1802,6 +1801,10 @@ int Message::infoWidth() const { return _bottomInfo.optimalSize().width(); } +int Message::bottomInfoFirstLineWidth() const { + return _bottomInfo.firstLineWidth(); +} + bool Message::isSignedAuthorElided() const { return _bottomInfo.isSignedAuthorElided(); } @@ -2464,8 +2467,10 @@ int Message::resizeContentGetHeight(int newWidth) { } } } - _bottomInfo.resizeToWidth( - std::min(_bottomInfo.optimalSize().width(), contentWidth)); + const auto bottomInfoHeight = _bottomInfo.resizeToWidth( + std::min( + _bottomInfo.optimalSize().width(), + contentWidth - st::msgPadding.left() - st::msgPadding.right() - 2 * st::msgDateDelta.x())); if (bubble) { auto reply = displayedReply(); @@ -2536,6 +2541,9 @@ int Message::resizeContentGetHeight(int newWidth) { reply->resize(contentWidth - st::msgPadding.left() - st::msgPadding.right()); newHeight += st::msgReplyPadding.top() + st::msgReplyBarSize.height() + st::msgReplyPadding.bottom(); } + if (needInfoDisplay()) { + newHeight += (bottomInfoHeight - st::msgDateFont->height); + } if (item->repliesAreComments() || item->externalReply()) { newHeight += st::historyCommentsButtonHeight; @@ -2556,6 +2564,20 @@ int Message::resizeContentGetHeight(int newWidth) { return newHeight; } +bool Message::needInfoDisplay() const { + const auto media = this->media(); + const auto mediaDisplayed = media ? media->isDisplayed() : false; + const auto entry = logEntryOriginal(); + + // Entry page is always a bubble bottom. + const auto mediaOnBottom = (mediaDisplayed && media->isBubbleBottom()) || (entry/* && entry->isBubbleBottom()*/); + return entry + ? !entry->customInfoLayout() + : (mediaDisplayed + ? !media->customInfoLayout() + : true); +} + bool Message::hasVisibleText() const { if (message()->emptyText()) { return false; diff --git a/Telegram/SourceFiles/history/view/history_view_message.h b/Telegram/SourceFiles/history/view/history_view_message.h index 8e649ede3..ed9db5c1a 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.h +++ b/Telegram/SourceFiles/history/view/history_view_message.h @@ -106,14 +106,15 @@ public: int left, int top, int outerWidth) const override; - ClickHandlerPtr rightActionLink() const override; - bool displayEditedBadge() const override; - TimeId displayedEditDate() const override; - HistoryMessageReply *displayedReply() const override; - bool toggleSelectionByHandlerClick( + [[nodiscard]] ClickHandlerPtr rightActionLink() const override; + [[nodiscard]] bool displayEditedBadge() const override; + [[nodiscard]] TimeId displayedEditDate() const override; + [[nodiscard]] HistoryMessageReply *displayedReply() const override; + [[nodiscard]] bool toggleSelectionByHandlerClick( const ClickHandlerPtr &handler) const override; - int infoWidth() const override; - bool isSignedAuthorElided() const override; + [[nodiscard]] int infoWidth() const override; + [[nodiscard]] int bottomInfoFirstLineWidth() const override; + [[nodiscard]] bool isSignedAuthorElided() const override; void itemDataChanged() override; @@ -202,6 +203,7 @@ private: QSize performCountOptimalSize() override; QSize performCountCurrentSize(int newWidth) override; bool hasVisibleText() const override; + [[nodiscard]] bool needInfoDisplay() const; [[nodiscard]] bool isPinnedContext() const; @@ -219,7 +221,7 @@ private: void updateViewButtonExistence(); [[nodiscard]] int viewButtonHeight() const; - WebPage *logEntryOriginal() const; + [[nodiscard]] WebPage *logEntryOriginal() const; [[nodiscard]] ClickHandlerPtr createGoToCommentsLink() const; [[nodiscard]] ClickHandlerPtr psaTooltipLink() const; diff --git a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp index 9482f452f..2be39a618 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp @@ -217,7 +217,7 @@ QSize Gif::countCurrentSize(int newWidth) { newWidth = std::clamp( std::max(tw, _parent->infoWidth() + 2 * (st::msgDateImgDelta + st::msgDateImgPadding.x())), st::minPhotoSize, - maxSize); + std::min(newWidth, maxSize)); auto newHeight = qMax(th, st::minPhotoSize); if (!activeCurrentStreamed()) { accumulate_max(newWidth, gifMaxStatusWidth(_data) + 2 * (st::msgDateImgDelta + st::msgDateImgPadding.x())); diff --git a/Telegram/SourceFiles/history/view/media/history_view_location.cpp b/Telegram/SourceFiles/history/view/media/history_view_location.cpp index affed2807..e3732ae16 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_location.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_location.cpp @@ -124,7 +124,7 @@ QSize Location::countCurrentSize(int newWidth) { auto minWidth = std::clamp( _parent->minWidthForMedia(), st::minPhotoSize, - st::maxMediaSize); + std::min(newWidth, st::maxMediaSize)); accumulate_max(newWidth, minWidth); accumulate_max(newHeight, st::minPhotoSize); if (_parent->hasBubble()) { diff --git a/Telegram/SourceFiles/history/view/media/history_view_photo.cpp b/Telegram/SourceFiles/history/view/media/history_view_photo.cpp index e0aedeb49..4e0bf9dd2 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_photo.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_photo.cpp @@ -210,7 +210,7 @@ QSize Photo::countCurrentSize(int newWidth) { const auto minWidth = std::clamp( _parent->minWidthForMedia(), (_parent->hasBubble() ? st::historyPhotoBubbleMinWidth : st::minPhotoSize), - st::maxMediaSize); + std::min(newWidth, st::maxMediaSize)); newWidth = qMax(_pixw, minWidth); auto newHeight = qMax(_pixh, st::minPhotoSize); if (_parent->hasBubble() && !_caption.isEmpty()) { diff --git a/Telegram/SourceFiles/history/view/media/history_view_poll.cpp b/Telegram/SourceFiles/history/view/media/history_view_poll.cpp index e04851da1..8324b0368 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_poll.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_poll.cpp @@ -799,7 +799,7 @@ void Poll::paintInlineFooter( top, std::min( _totalVotesLabel.maxWidth(), - paintw - _parent->infoWidth()), + paintw - _parent->bottomInfoFirstLineWidth()), width()); }