From 42d6d0d58af6d84c212a7d7bc219c53888229c3d Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 21 May 2024 05:42:03 +0300 Subject: [PATCH] Added tooltip to balance label in credits settings for high values. --- .../SourceFiles/settings/settings_credits.cpp | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/settings/settings_credits.cpp b/Telegram/SourceFiles/settings/settings_credits.cpp index 4ed6e8ac26..a31c68e10c 100644 --- a/Telegram/SourceFiles/settings/settings_credits.cpp +++ b/Telegram/SourceFiles/settings/settings_credits.cpp @@ -30,6 +30,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/buttons.h" #include "ui/widgets/discrete_sliders.h" #include "ui/widgets/labels.h" +#include "ui/widgets/tooltip.h" #include "ui/wrap/fade_wrap.h" #include "ui/wrap/slide_wrap.h" #include "ui/wrap/vertical_layout.h" @@ -49,6 +50,45 @@ namespace { using SectionCustomTopBarData = Info::Settings::SectionCustomTopBarData; +class Balance final + : public Ui::RpWidget + , public Ui::AbstractTooltipShower { +public: + using Ui::RpWidget::RpWidget; + + void setBalance(uint64 balance) { + _balance = balance; + _tooltip = Lang::FormatCountDecimal(balance); + } + + void enterEventHook(QEnterEvent *e) override { + if (_balance >= 10'000) { + Ui::Tooltip::Show(1000, this); + } + } + + void leaveEventHook(QEvent *e) override { + Ui::Tooltip::Hide(); + } + + QString tooltipText() const override { + return _tooltip; + } + + QPoint tooltipPos() const override { + return QCursor::pos(); + } + + bool tooltipWindowActive() const override { + return Ui::AppInFocus() && Ui::InFocusChain(window()); + } + +private: + QString _tooltip; + uint64 _balance = 0; + +}; + [[nodiscard]] uint64 UniqueIdFromOption( const Data::CreditTopupOption &d) { const auto string = QString::number(d.credits) @@ -516,7 +556,7 @@ QPointer Credits::createPinnedToTop( } }, content->lifetime()); - const auto balance = Ui::CreateChild(content); + const auto balance = Ui::CreateChild(content); { const auto starSize = _balanceStar.size() / style::DevicePixelRatio(); const auto label = balance->lifetime().make_state( @@ -541,6 +581,7 @@ QPointer Credits::createPinnedToTop( count->setText( st::semiboldTextStyle, Lang::FormatCountToShort(slice.balance).string); + balance->setBalance(slice.balance); resize(); }); balance->paintRequest(