From 230dd29af5968e00e28e8d0effe8a56b15e3da24 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 6 Aug 2019 12:27:11 +0100 Subject: [PATCH] More large emoji layout improvements. --- Telegram/SourceFiles/history/history.cpp | 5 ++++ Telegram/SourceFiles/history/history.h | 1 + .../SourceFiles/history/history_widget.cpp | 11 +++++++- .../view/media/history_view_large_emoji.h | 4 +++ .../view/media/history_view_media_common.h | 2 +- .../media/history_view_media_unwrapped.cpp | 27 +++++++++++++------ .../view/media/history_view_media_unwrapped.h | 3 +++ 7 files changed, 43 insertions(+), 10 deletions(-) diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index 9d421fb5e..67388f727 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -2759,6 +2759,11 @@ void History::resizeToWidth(int newWidth) { _height = y; } +void History::forceFullResize() { + _width = 0; + _flags |= Flag::f_has_pending_resized_items; +} + ChannelId History::channelId() const { return peerToChannel(peer->id); } diff --git a/Telegram/SourceFiles/history/history.h b/Telegram/SourceFiles/history/history.h index efc6e54dc..3f2a03436 100644 --- a/Telegram/SourceFiles/history/history.h +++ b/Telegram/SourceFiles/history/history.h @@ -207,6 +207,7 @@ public: HistoryItem *lastSentMessage() const; void resizeToWidth(int newWidth); + void forceFullResize(); int height() const; void itemRemoved(not_null item); diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index bf17260f1..4b8b0c9fe 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -455,7 +455,16 @@ HistoryWidget::HistoryWidget( ActivateWindow(controller); }); - subscribe(Adaptive::Changed(), [=] { update(); }); + subscribe(Adaptive::Changed(), [=] { + if (_history) { + _history->forceFullResize(); + if (_migrated) { + _migrated->forceFullResize(); + } + updateHistoryGeometry(); + update(); + } + }); session().data().itemRemoved( ) | rpl::start_with_next([=](not_null item) { itemRemoved(item); diff --git a/Telegram/SourceFiles/history/view/media/history_view_large_emoji.h b/Telegram/SourceFiles/history/view/media/history_view_large_emoji.h index 508d09350..554cd6d34 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_large_emoji.h +++ b/Telegram/SourceFiles/history/view/media/history_view_large_emoji.h @@ -29,6 +29,10 @@ public: QSize size() override; void draw(Painter &p, const QRect &r, bool selected) override; + bool alwaysShowOutTimestamp() override { + return true; + } + private: const not_null _parent; const std::array< diff --git a/Telegram/SourceFiles/history/view/media/history_view_media_common.h b/Telegram/SourceFiles/history/view/media/history_view_media_common.h index 22b0507e4..c64e93035 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media_common.h +++ b/Telegram/SourceFiles/history/view/media/history_view_media_common.h @@ -45,7 +45,7 @@ int unitedLineHeight(); [[nodiscard]] inline QSize DownscaledSize(QSize size, QSize box) { return (size.width() > box.width() || size.height() > box.height()) - ? size.scaled(box, Qt::IgnoreAspectRatio) + ? size.scaled(box, Qt::KeepAspectRatio) : size; } diff --git a/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp b/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp index a1416354d..70c31b0cc 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp @@ -32,12 +32,7 @@ QSize UnwrappedMedia::countOptimalSize() { _content->size(), { st::maxStickerSize, st::maxStickerSize })); auto maxWidth = _contentSize.width(); - const auto infoHeight = st::msgDateImgPadding.y() * 2 - + st::msgDateFont->height; - const auto minimal = st::largeEmojiSize - + 2 * st::largeEmojiOutline - + st::msgDateImgDelta - + infoHeight; + const auto minimal = st::largeEmojiSize + 2 * st::largeEmojiOutline; auto minHeight = std::max(_contentSize.height(), minimal); if (_parent->media() == this) { const auto item = _parent->data(); @@ -45,6 +40,8 @@ QSize UnwrappedMedia::countOptimalSize() { const auto reply = item->Get(); maxWidth += additionalWidth(via, reply); if (const auto surrounding = surroundingHeight(via, reply)) { + const auto infoHeight = st::msgDateImgPadding.y() * 2 + + st::msgDateFont->height; const auto minimal = surrounding + st::msgDateImgDelta + infoHeight; @@ -72,7 +69,17 @@ QSize UnwrappedMedia::countCurrentSize(int newWidth) { } } } - return { newWidth, minHeight() }; + auto newHeight = minHeight(); + if (_parent->hasOutLayout() && !Adaptive::ChatWide()) { + // Add some height to isolated emoji for the timestamp info. + const auto infoHeight = st::msgDateImgPadding.y() * 2 + + st::msgDateFont->height; + const auto minimal = st::largeEmojiSize + + 2 * st::largeEmojiOutline + + (st::msgDateImgDelta + infoHeight); + accumulate_max(newHeight, minimal); + } + return { newWidth, newHeight }; } void UnwrappedMedia::draw( @@ -285,7 +292,11 @@ TextState UnwrappedMedia::textState(QPoint point, StateRequest request) const { } bool UnwrappedMedia::needInfoDisplay() const { - return (_parent->data()->id < 0 || _parent->isUnderCursor()); + return (_parent->data()->id < 0) + || (_parent->isUnderCursor()) + || (_parent->hasOutLayout() + && !Adaptive::ChatWide() + && _content->alwaysShowOutTimestamp()); } int UnwrappedMedia::additionalWidth(const HistoryMessageVia *via, const HistoryMessageReply *reply) const { diff --git a/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.h b/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.h index 3ea9f19ea..badbb0096 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.h +++ b/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.h @@ -38,6 +38,9 @@ public: } virtual void refreshLink() { } + [[nodiscard]] virtual bool alwaysShowOutTimestamp() { + return false; + } virtual ~Content() = 0; };