From 3c19d7b30267a4c81113cc881037a69d3b072765 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 27 Jul 2022 14:24:34 +0300 Subject: [PATCH] Show shared link long URL tooltips. --- .../history/view/history_view_list_widget.cpp | 2 +- .../info/media/info_media_list_widget.cpp | 24 ++++++++++++++++++- .../info/media/info_media_list_widget.h | 9 ++++++- .../SourceFiles/overview/overview_layout.cpp | 2 +- .../SourceFiles/overview/overview_layout.h | 6 ++--- 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index bc32e3f75..987f1c7a5 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -2838,7 +2838,7 @@ void ListWidget::mouseActionUpdate() { } } } - auto lnkChanged = ClickHandler::setActive(dragState.link, lnkhost); + const auto lnkChanged = ClickHandler::setActive(dragState.link, lnkhost); if (lnkChanged || dragState.cursor != _mouseCursorState) { Ui::Tooltip::Hide(); } diff --git a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp index 82170fd9e..da44e93e9 100644 --- a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp +++ b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp @@ -449,6 +449,21 @@ bool ListWidget::itemVisible(not_null item) { return true; } +QString ListWidget::tooltipText() const { + if (const auto link = ClickHandler::getActive()) { + return link->tooltip(); + } + return QString(); +} + +QPoint ListWidget::tooltipPos() const { + return _mousePosition; +} + +bool ListWidget::tooltipWindowActive() const { + return Ui::AppInFocus() && Ui::InFocusChain(window()); +} + void ListWidget::openPhoto(not_null photo, FullMsgId id) { _controller->parentController()->openPhoto(photo, id); } @@ -1293,6 +1308,7 @@ void ListWidget::leaveEventHook(QEvent *e) { } } ClickHandler::clearActive(); + Ui::Tooltip::Hide(); if (!ClickHandler::getPressed() && _cursor != style::cur_default) { _cursor = style::cur_default; setCursor(_cursor); @@ -1361,7 +1377,13 @@ void ListWidget::mouseActionUpdate(const QPoint &globalPosition) { dragState = _overLayout->getState(_overState.cursor, request); lnkhost = _overLayout; } - ClickHandler::setActive(dragState.link, lnkhost); + const auto lnkChanged = ClickHandler::setActive(dragState.link, lnkhost); + if (lnkChanged || dragState.cursor != _mouseCursorState) { + Ui::Tooltip::Hide(); + } + if (dragState.link) { + Ui::Tooltip::Show(1000, this); + } if (_mouseAction == MouseAction::None) { _mouseCursorState = dragState.cursor; diff --git a/Telegram/SourceFiles/info/media/info_media_list_widget.h b/Telegram/SourceFiles/info/media/info_media_list_widget.h index bb35c27f4..fec9cd055 100644 --- a/Telegram/SourceFiles/info/media/info_media_list_widget.h +++ b/Telegram/SourceFiles/info/media/info_media_list_widget.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "ui/rp_widget.h" +#include "ui/widgets/tooltip.h" #include "info/media/info_media_widget.h" #include "info/media/info_media_common.h" #include "overview/overview_layout_delegate.h" @@ -53,7 +54,8 @@ class ListProvider; class ListWidget final : public Ui::RpWidget - , public Overview::Layout::Delegate { + , public Overview::Layout::Delegate + , public Ui::AbstractTooltipShower { public: ListWidget( QWidget *parent, @@ -83,6 +85,11 @@ public: void repaintItem(not_null item) override; bool itemVisible(not_null item) override; + // AbstractTooltipShower interface + QString tooltipText() const override; + QPoint tooltipPos() const override; + bool tooltipWindowActive() const override; + void openPhoto(not_null photo, FullMsgId id) override; void openDocument( not_null document, diff --git a/Telegram/SourceFiles/overview/overview_layout.cpp b/Telegram/SourceFiles/overview/overview_layout.cpp index ae72fb3b3..060a72352 100644 --- a/Telegram/SourceFiles/overview/overview_layout.cpp +++ b/Telegram/SourceFiles/overview/overview_layout.cpp @@ -1516,7 +1516,7 @@ Link::Link( const auto createHandler = [](const QString &url) { return UrlClickHandler::IsSuspicious(url) ? std::make_shared(url) - : std::make_shared(url); + : std::make_shared(url, false); }; _page = media ? media->webpage() : nullptr; if (_page) { diff --git a/Telegram/SourceFiles/overview/overview_layout.h b/Telegram/SourceFiles/overview/overview_layout.h index fc89197b0..cab6005b8 100644 --- a/Telegram/SourceFiles/overview/overview_layout.h +++ b/Telegram/SourceFiles/overview/overview_layout.h @@ -438,11 +438,11 @@ private: bool _thumbnailBlurred = true; struct LinkEntry { - LinkEntry() : width(0) { - } + LinkEntry() = default; LinkEntry(const QString &url, const QString &text); + QString text; - int32 width; + int width = 0; std::shared_ptr lnk; }; QVector _links;