Added floating date badge to Shared Photos and Shared Videos.
This commit is contained in:
		
							parent
							
								
									2cd8b00610
								
							
						
					
					
						commit
						5c54d3690c
					
				
					 5 changed files with 93 additions and 5 deletions
				
			
		|  | @ -51,7 +51,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL | ||||||
| namespace HistoryView { | namespace HistoryView { | ||||||
| namespace { | namespace { | ||||||
| 
 | 
 | ||||||
| constexpr auto kScrollDateHideTimeout = 1000; |  | ||||||
| constexpr auto kPreloadedScreensCount = 4; | constexpr auto kPreloadedScreensCount = 4; | ||||||
| constexpr auto kPreloadIfLessThanScreens = 2; | constexpr auto kPreloadIfLessThanScreens = 2; | ||||||
| constexpr auto kPreloadedScreensCountFull | constexpr auto kPreloadedScreensCountFull | ||||||
|  | @ -743,7 +742,7 @@ void ListWidget::scrollDateCheck() { | ||||||
| 		} | 		} | ||||||
| 		_scrollDateLastItem = _visibleTopItem; | 		_scrollDateLastItem = _visibleTopItem; | ||||||
| 		_scrollDateLastItemTop = _visibleTopFromItem; | 		_scrollDateLastItemTop = _visibleTopFromItem; | ||||||
| 		_scrollDateHideTimer.callOnce(kScrollDateHideTimeout); | 		_scrollDateHideTimer.callOnce(st::historyScrollDateHideTimeout); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -766,7 +765,7 @@ void ListWidget::keepScrollDateForNow() { | ||||||
| 		&& _scrollDateOpacity.animating()) { | 		&& _scrollDateOpacity.animating()) { | ||||||
| 		toggleScrollDateShown(); | 		toggleScrollDateShown(); | ||||||
| 	} | 	} | ||||||
| 	_scrollDateHideTimer.callOnce(kScrollDateHideTimeout); | 	_scrollDateHideTimer.callOnce(st::historyScrollDateHideTimeout); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void ListWidget::toggleScrollDateShown() { | void ListWidget::toggleScrollDateShown() { | ||||||
|  |  | ||||||
|  | @ -947,3 +947,6 @@ inviteLinkQrValuePadding: margins(22px, 0px, 22px, 12px); | ||||||
| infoAboutGigagroup: FlatLabel(defaultFlatLabel) { | infoAboutGigagroup: FlatLabel(defaultFlatLabel) { | ||||||
| 	minWidth: 274px; | 	minWidth: 274px; | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | infoScrollDateHideTimeout: historyScrollDateHideTimeout; | ||||||
|  | infoDateFadeDuration: historyDateFadeDuration; | ||||||
|  |  | ||||||
|  | @ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL | ||||||
| #include "history/history_item.h" | #include "history/history_item.h" | ||||||
| #include "history/history.h" | #include "history/history.h" | ||||||
| #include "history/view/history_view_cursor_state.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/themes/window_theme.h" | ||||||
| #include "window/window_session_controller.h" | #include "window/window_session_controller.h" | ||||||
| #include "window/window_peer_menu.h" | #include "window/window_peer_menu.h" | ||||||
|  | @ -568,7 +569,12 @@ ListWidget::ListWidget( | ||||||
| , _peer(_controller->key().peer()) | , _peer(_controller->key().peer()) | ||||||
| , _migrated(_controller->migrated()) | , _migrated(_controller->migrated()) | ||||||
| , _type(_controller->section().mediaType()) | , _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); | 	setMouseTracking(true); | ||||||
| 	start(); | 	start(); | ||||||
| } | } | ||||||
|  | @ -1070,6 +1076,55 @@ void ListWidget::visibleTopBottomUpdated( | ||||||
| 
 | 
 | ||||||
| 	checkMoveToOtherViewer(); | 	checkMoveToOtherViewer(); | ||||||
| 	clearHeavyItems(); | 	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() { | void ListWidget::checkMoveToOtherViewer() { | ||||||
|  | @ -1217,6 +1272,21 @@ void ListWidget::paintEvent(QPaintEvent *e) { | ||||||
| 		it->paint(p, context, clip.translated(0, -top), outerWidth); | 		it->paint(p, context, clip.translated(0, -top), outerWidth); | ||||||
| 		p.translate(0, -top); | 		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) { | void ListWidget::mousePressEvent(QMouseEvent *e) { | ||||||
|  |  | ||||||
|  | @ -271,6 +271,11 @@ private: | ||||||
| 	void updateDragSelection(); | 	void updateDragSelection(); | ||||||
| 	void clearDragSelection(); | 	void clearDragSelection(); | ||||||
| 
 | 
 | ||||||
|  | 	void updateDateBadgeFor(int top); | ||||||
|  | 	void scrollDateCheck(); | ||||||
|  | 	void scrollDateHide(); | ||||||
|  | 	void toggleScrollDateShown(); | ||||||
|  | 
 | ||||||
| 	void trySwitchToWordSelection(); | 	void trySwitchToWordSelection(); | ||||||
| 	void switchToWordSelection(); | 	void switchToWordSelection(); | ||||||
| 	void validateTrippleClickStartTime(); | 	void validateTrippleClickStartTime(); | ||||||
|  | @ -282,7 +287,7 @@ private: | ||||||
| 	const not_null<AbstractController*> _controller; | 	const not_null<AbstractController*> _controller; | ||||||
| 	const not_null<PeerData*> _peer; | 	const not_null<PeerData*> _peer; | ||||||
| 	PeerData * const _migrated = nullptr; | 	PeerData * const _migrated = nullptr; | ||||||
| 	Type _type = Type::Photo; | 	const Type _type = Type::Photo; | ||||||
| 
 | 
 | ||||||
| 	static constexpr auto kMinimalIdsLimit = 16; | 	static constexpr auto kMinimalIdsLimit = 16; | ||||||
| 	static constexpr auto kDefaultAroundId = (ServerMaxMsgId - 1); | 	static constexpr auto kDefaultAroundId = (ServerMaxMsgId - 1); | ||||||
|  | @ -317,6 +322,16 @@ private: | ||||||
| 	DragSelectAction _dragSelectAction = DragSelectAction::None; | 	DragSelectAction _dragSelectAction = DragSelectAction::None; | ||||||
| 	bool _wasSelectedText = false; // was some text selected in current drag action
 | 	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<Ui::PopupMenu> _contextMenu; | 	base::unique_qptr<Ui::PopupMenu> _contextMenu; | ||||||
| 	rpl::event_stream<> _checkForHide; | 	rpl::event_stream<> _checkForHide; | ||||||
| 	QPointer<Ui::RpWidget> _actionBoxWeak; | 	QPointer<Ui::RpWidget> _actionBoxWeak; | ||||||
|  |  | ||||||
|  | @ -497,6 +497,7 @@ botKbTinyButton: BotKeyboardButton { | ||||||
| } | } | ||||||
| botKbScroll: defaultSolidScroll; | botKbScroll: defaultSolidScroll; | ||||||
| 
 | 
 | ||||||
|  | historyScrollDateHideTimeout: 1000; | ||||||
| historyDateFadeDuration: 200; | historyDateFadeDuration: 200; | ||||||
| historyDiceToast: Toast(defaultToast) { | historyDiceToast: Toast(defaultToast) { | ||||||
| 	minWidth: msgMinWidth; | 	minWidth: msgMinWidth; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 23rd
						23rd