diff --git a/Telegram/SourceFiles/history/history_view_top_toast.cpp b/Telegram/SourceFiles/history/history_view_top_toast.cpp new file mode 100644 index 0000000000..f3ae8b012e --- /dev/null +++ b/Telegram/SourceFiles/history/history_view_top_toast.cpp @@ -0,0 +1,63 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "history/history_view_top_toast.h" + +#include "ui/toast/toast.h" +#include "styles/style_chat.h" + +namespace HistoryView { + +namespace { + +[[nodiscard]] crl::time CountToastDuration(const TextWithEntities &text) { + return std::clamp( + crl::time(1000) * int(text.text.size()) / 14, + crl::time(1000) * 5, + crl::time(1000) * 8); +} + +} // namespace + +InfoTooltip::InfoTooltip() = default; + +void InfoTooltip::show( + not_null parent, + const TextWithEntities &text, + Fn hiddenCallback) { + hide(anim::type::normal); + _topToast = Ui::Toast::Show(parent, Ui::Toast::Config{ + .text = text, + .st = &st::historyInfoToast, + .durationMs = CountToastDuration(text), + .multiline = true, + .dark = true, + .slideSide = RectPart::Top, + }); + if (const auto strong = _topToast.get()) { + if (hiddenCallback) { + QObject::connect( + strong->widget(), + &QObject::destroyed, + hiddenCallback); + } + } else if (hiddenCallback) { + hiddenCallback(); + } +} + +void InfoTooltip::hide(anim::type animated) { + if (const auto strong = _topToast.get()) { + if (animated == anim::type::normal) { + strong->hideAnimated(); + } else { + strong->hide(); + } + } +} + +} // namespace HistoryView diff --git a/Telegram/SourceFiles/history/history_view_top_toast.h b/Telegram/SourceFiles/history/history_view_top_toast.h new file mode 100644 index 0000000000..1eb02fbaa2 --- /dev/null +++ b/Telegram/SourceFiles/history/history_view_top_toast.h @@ -0,0 +1,33 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +#include "base/weak_ptr.h" + +namespace Ui::Toast { +class Instance; +} // namespace Ui::Toast + +namespace HistoryView { + +class InfoTooltip final { +public: + InfoTooltip(); + + void show( + not_null parent, + const TextWithEntities &text, + Fn hiddenCallback); + void hide(anim::type animated); + +private: + base::weak_ptr _topToast; + +}; + +} // namespace HistoryView diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 1e21514b2c..6279a7da58 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -198,13 +198,6 @@ base::options::toggle AutoScrollInactiveChat({ "even when the window is not in focus.", }); -[[nodiscard]] crl::time CountToastDuration(const TextWithEntities &text) { - return std::clamp( - crl::time(1000) * int(text.text.size()) / 14, - crl::time(1000) * 5, - crl::time(1000) * 8); -} - [[nodiscard]] rpl::producer ActivePeerValue( not_null controller) { return controller->activeChatValue( @@ -2020,7 +2013,7 @@ void HistoryWidget::showHistory( _highlighter.clear(); controller()->sendingAnimation().clear(); - hideInfoTooltip(anim::type::instant); + _topToast.hide(anim::type::instant); if (_history) { if (_peer->id == peerId && !reload) { updateForwarding(); @@ -6723,32 +6716,7 @@ bool HistoryWidget::sendExistingPhoto( void HistoryWidget::showInfoTooltip( const TextWithEntities &text, Fn hiddenCallback) { - hideInfoTooltip(anim::type::normal); - _topToast = Ui::Toast::Show(_scroll, Ui::Toast::Config{ - .text = text, - .st = &st::historyInfoToast, - .durationMs = CountToastDuration(text), - .multiline = true, - .dark = true, - .slideSide = RectPart::Top, - }); - if (const auto strong = _topToast.get()) { - if (hiddenCallback) { - connect(strong->widget(), &QObject::destroyed, hiddenCallback); - } - } else if (hiddenCallback) { - hiddenCallback(); - } -} - -void HistoryWidget::hideInfoTooltip(anim::type animated) { - if (const auto strong = _topToast.get()) { - if (animated == anim::type::normal) { - strong->hideAnimated(); - } else { - strong->hide(); - } - } + _topToast.show(_scroll.data(), text, std::move(hiddenCallback)); } void HistoryWidget::showPremiumStickerTooltip( diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index df04a5fd63..38aa438b08 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history_drag_area.h" #include "history/history_view_highlight_manager.h" +#include "history/history_view_top_toast.h" #include "history/history.h" #include "chat_helpers/bot_command.h" #include "chat_helpers/field_autocomplete.h" @@ -74,9 +75,6 @@ struct PreparedList; class SendFilesWay; class SendAsButton; enum class ReportReason; -namespace Toast { -class Instance; -} // namespace Toast class ChooseThemeController; class ContinuousScroll; } // namespace Ui @@ -265,7 +263,6 @@ public: void showInfoTooltip( const TextWithEntities &text, Fn hiddenCallback); - void hideInfoTooltip(anim::type animated); void showPremiumStickerTooltip( not_null view); @@ -779,7 +776,7 @@ private: base::Timer _saveDraftTimer; base::Timer _saveCloudDraftTimer; - base::weak_ptr _topToast; + HistoryView::InfoTooltip _topToast; std::unique_ptr _stickerToast; std::unique_ptr _chooseForReport; diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index d5729eee33..02b411b7a1 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -1447,8 +1447,10 @@ void ListWidget::elementCancelUpload(const FullMsgId &context) { } void ListWidget::elementShowTooltip( - const TextWithEntities &text, - Fn hiddenCallback) { + const TextWithEntities &text, + Fn hiddenCallback) { + // Under the parent is supposed to be a scroll widget. + _topToast.show(parentWidget(), text, hiddenCallback); } bool ListWidget::elementIsGifPaused() { diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.h b/Telegram/SourceFiles/history/view/history_view_list_widget.h index e125502c2e..2233f8e5c2 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.h @@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_messages.h" #include "history/view/history_view_element.h" #include "history/history_view_highlight_manager.h" +#include "history/history_view_top_toast.h" namespace Main { class Session; @@ -641,6 +642,8 @@ private: Ui::DraggingScrollManager _selectScroll; + InfoTooltip _topToast; + rpl::event_stream _requestedToEditMessage; rpl::event_stream _requestedToReplyToMessage; rpl::event_stream _requestedToReadMessage; diff --git a/Telegram/cmake/td_ui.cmake b/Telegram/cmake/td_ui.cmake index 79ae207736..269e48773f 100644 --- a/Telegram/cmake/td_ui.cmake +++ b/Telegram/cmake/td_ui.cmake @@ -85,6 +85,9 @@ PRIVATE editor/scene/scene_item_line.cpp editor/scene/scene_item_line.h + history/history_view_top_toast.cpp + history/history_view_top_toast.h + layout/abstract_layout_item.cpp layout/abstract_layout_item.h layout/layout_mosaic.cpp