From 5c54d3690c5996dbf64e9530cd7cae9cfe885afc Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 23 May 2021 03:00:24 +0300 Subject: [PATCH] Added floating date badge to Shared Photos and Shared Videos. --- .../history/view/history_view_list_widget.cpp | 5 +- Telegram/SourceFiles/info/info.style | 3 + .../info/media/info_media_list_widget.cpp | 72 ++++++++++++++++++- .../info/media/info_media_list_widget.h | 17 ++++- Telegram/SourceFiles/ui/chat/chat.style | 1 + 5 files changed, 93 insertions(+), 5 deletions(-) diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index 2849fc1fb..6377493e0 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -51,7 +51,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace HistoryView { namespace { -constexpr auto kScrollDateHideTimeout = 1000; constexpr auto kPreloadedScreensCount = 4; constexpr auto kPreloadIfLessThanScreens = 2; constexpr auto kPreloadedScreensCountFull @@ -743,7 +742,7 @@ void ListWidget::scrollDateCheck() { } _scrollDateLastItem = _visibleTopItem; _scrollDateLastItemTop = _visibleTopFromItem; - _scrollDateHideTimer.callOnce(kScrollDateHideTimeout); + _scrollDateHideTimer.callOnce(st::historyScrollDateHideTimeout); } } @@ -766,7 +765,7 @@ void ListWidget::keepScrollDateForNow() { && _scrollDateOpacity.animating()) { toggleScrollDateShown(); } - _scrollDateHideTimer.callOnce(kScrollDateHideTimeout); + _scrollDateHideTimer.callOnce(st::historyScrollDateHideTimeout); } void ListWidget::toggleScrollDateShown() { diff --git a/Telegram/SourceFiles/info/info.style b/Telegram/SourceFiles/info/info.style index be68973b4..e9b823a40 100644 --- a/Telegram/SourceFiles/info/info.style +++ b/Telegram/SourceFiles/info/info.style @@ -947,3 +947,6 @@ inviteLinkQrValuePadding: margins(22px, 0px, 22px, 12px); infoAboutGigagroup: FlatLabel(defaultFlatLabel) { minWidth: 274px; } + +infoScrollDateHideTimeout: historyScrollDateHideTimeout; +infoDateFadeDuration: historyDateFadeDuration; diff --git a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp index 922aa5b90..b0a466405 100644 --- a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp +++ b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp @@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history_item.h" #include "history/history.h" #include "history/view/history_view_cursor_state.h" +#include "history/view/history_view_service_message.h" #include "window/themes/window_theme.h" #include "window/window_session_controller.h" #include "window/window_peer_menu.h" @@ -568,7 +569,12 @@ ListWidget::ListWidget( , _peer(_controller->key().peer()) , _migrated(_controller->migrated()) , _type(_controller->section().mediaType()) -, _slice(sliceKey(_universalAroundId)) { +, _slice(sliceKey(_universalAroundId)) +, _dateBadge(DateBadge{ + .check = SingleQueuedInvokation([=] { scrollDateCheck(); }), + .hideTimer = base::Timer([=] { scrollDateHide(); }), + .goodType = (_type == Type::Photo || _type == Type::Video), +}) { setMouseTracking(true); start(); } @@ -1070,6 +1076,55 @@ void ListWidget::visibleTopBottomUpdated( checkMoveToOtherViewer(); clearHeavyItems(); + + if (_dateBadge.goodType) { + updateDateBadgeFor(_visibleTop); + if (!_visibleTop) { + if (_dateBadge.shown) { + scrollDateHide(); + } else { + update(_dateBadge.rect); + } + } else { + _dateBadge.check.call(); + } + } +} + +void ListWidget::updateDateBadgeFor(int top) { + if (_sections.empty()) { + return; + } + const auto layout = findItemByPoint({ st::infoMediaSkip, top }).layout; + const auto rectHeight = st::msgServiceMargin.top() + + st::msgServicePadding.top() + + st::msgServiceFont->height + + st::msgServicePadding.bottom(); + + _dateBadge.text = ItemDateText(layout->getItem(), false); + _dateBadge.rect = QRect(0, top, width(), rectHeight); +} + +void ListWidget::scrollDateCheck() { + if (!_dateBadge.shown) { + toggleScrollDateShown(); + } + _dateBadge.hideTimer.callOnce(st::infoScrollDateHideTimeout); +} + +void ListWidget::scrollDateHide() { + if (_dateBadge.shown) { + toggleScrollDateShown(); + } +} + +void ListWidget::toggleScrollDateShown() { + _dateBadge.shown = !_dateBadge.shown; + _dateBadge.opacity.start( + [=] { update(_dateBadge.rect); }, + _dateBadge.shown ? 0. : 1., + _dateBadge.shown ? 1. : 0., + st::infoDateFadeDuration); } void ListWidget::checkMoveToOtherViewer() { @@ -1217,6 +1272,21 @@ void ListWidget::paintEvent(QPaintEvent *e) { it->paint(p, context, clip.translated(0, -top), outerWidth); p.translate(0, -top); } + + if (_dateBadge.goodType && clip.intersects(_dateBadge.rect)) { + const auto scrollDateOpacity = + _dateBadge.opacity.value(_dateBadge.shown ? 1. : 0.); + if (scrollDateOpacity > 0.) { + p.setOpacity(scrollDateOpacity); + HistoryView::ServiceMessagePainter::paintDate( + p, + _dateBadge.text, + _visibleTop, + outerWidth, + st::roundedBg, + st::roundedFg); + } + } } void ListWidget::mousePressEvent(QMouseEvent *e) { diff --git a/Telegram/SourceFiles/info/media/info_media_list_widget.h b/Telegram/SourceFiles/info/media/info_media_list_widget.h index 5713cf159..146c3b544 100644 --- a/Telegram/SourceFiles/info/media/info_media_list_widget.h +++ b/Telegram/SourceFiles/info/media/info_media_list_widget.h @@ -271,6 +271,11 @@ private: void updateDragSelection(); void clearDragSelection(); + void updateDateBadgeFor(int top); + void scrollDateCheck(); + void scrollDateHide(); + void toggleScrollDateShown(); + void trySwitchToWordSelection(); void switchToWordSelection(); void validateTrippleClickStartTime(); @@ -282,7 +287,7 @@ private: const not_null _controller; const not_null _peer; PeerData * const _migrated = nullptr; - Type _type = Type::Photo; + const Type _type = Type::Photo; static constexpr auto kMinimalIdsLimit = 16; static constexpr auto kDefaultAroundId = (ServerMaxMsgId - 1); @@ -317,6 +322,16 @@ private: DragSelectAction _dragSelectAction = DragSelectAction::None; bool _wasSelectedText = false; // was some text selected in current drag action + struct DateBadge { + SingleQueuedInvokation check; + base::Timer hideTimer; + Ui::Animations::Simple opacity; + bool goodType = false; + bool shown = false; + QString text; + QRect rect; + } _dateBadge; + base::unique_qptr _contextMenu; rpl::event_stream<> _checkForHide; QPointer _actionBoxWeak; diff --git a/Telegram/SourceFiles/ui/chat/chat.style b/Telegram/SourceFiles/ui/chat/chat.style index 3fa8ca553..0086dbd8a 100644 --- a/Telegram/SourceFiles/ui/chat/chat.style +++ b/Telegram/SourceFiles/ui/chat/chat.style @@ -497,6 +497,7 @@ botKbTinyButton: BotKeyboardButton { } botKbScroll: defaultSolidScroll; +historyScrollDateHideTimeout: 1000; historyDateFadeDuration: 200; historyDiceToast: Toast(defaultToast) { minWidth: msgMinWidth;