From 43e9128014c5239a6732ae34bdfe007efb9692c8 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 25 Jan 2023 11:22:56 +0400 Subject: [PATCH] Report animate phases from PopupMenu. --- ui/widgets/popup_menu.cpp | 11 ++++++++++- ui/widgets/popup_menu.h | 11 +++++++++++ ui/widgets/scroll_area.cpp | 12 ++++++++---- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/ui/widgets/popup_menu.cpp b/ui/widgets/popup_menu.cpp index 1459f4a..7321e84 100644 --- a/ui/widgets/popup_menu.cpp +++ b/ui/widgets/popup_menu.cpp @@ -484,7 +484,10 @@ void PopupMenu::paintEvent(QPaintEvent *e) { _showAnimation->paintFrame(p, 0, 0, width(), 1., 1.); _showAnimation.reset(); _showStateChanges.fire({}); - PostponeCall(this, [=] { showChildren(); }); + PostponeCall(this, [=] { + showChildren(); + _animatePhase = AnimatePhase::Shown; + }); } else { paintBg(p); } @@ -750,6 +753,7 @@ void PopupMenu::hideFinished() { _hiding = false; _a_show.stop(); _cache = QPixmap(); + _animatePhase = AnimatePhase::Hidden; if (!isHidden()) { hide(); } @@ -790,6 +794,9 @@ void PopupMenu::startOpacityAnimation(bool hiding) { _hiding = false; prepareCache(); _hiding = hiding; + _animatePhase = hiding + ? AnimatePhase::StartHide + : AnimatePhase::StartShow; hideChildren(); _a_opacity.start( [=] { opacityAnimationCallback(); }, @@ -832,6 +839,7 @@ void PopupMenu::startShowAnimation() { } _showAnimation->start(); } + _animatePhase = AnimatePhase::StartShow; hideChildren(); _a_show.start([this] { showAnimationCallback(); }, 0., 1., _st.showDuration); fireCurrentShowState(); @@ -858,6 +866,7 @@ void PopupMenu::opacityAnimationCallback() { hideFinished(); } else { showChildren(); + _animatePhase = AnimatePhase::Shown; } } } diff --git a/ui/widgets/popup_menu.h b/ui/widgets/popup_menu.h index a535219..87bd105 100644 --- a/ui/widgets/popup_menu.h +++ b/ui/widgets/popup_menu.h @@ -30,6 +30,13 @@ public: Bottom, }; + enum class AnimatePhase { + Hidden, + StartShow, + Shown, + StartHide, + }; + PopupMenu(QWidget *parent, const style::PopupMenu &st = st::defaultPopupMenu); PopupMenu(QWidget *parent, QMenu *menu, const style::PopupMenu &st = st::defaultPopupMenu); ~PopupMenu(); @@ -40,6 +47,9 @@ public: [[nodiscard]] QRect inner() const { return _inner; } + [[nodiscard]] rpl::producer animatePhaseValue() const { + return _animatePhase.value(); + } not_null addAction(base::unique_qptr widget); not_null addAction( @@ -195,6 +205,7 @@ private: std::unique_ptr _showAnimation; Animations::Simple _a_show; rpl::event_stream _showStateChanges; + rpl::variable _animatePhase = AnimatePhase::Hidden; bool _useTransparency = true; bool _hiding = false; diff --git a/ui/widgets/scroll_area.cpp b/ui/widgets/scroll_area.cpp index 706bc14..bb63b0c 100644 --- a/ui/widgets/scroll_area.cpp +++ b/ui/widgets/scroll_area.cpp @@ -198,14 +198,18 @@ void ScrollBar::paintEvent(QPaintEvent *e) { bg.setAlpha(anim::interpolate(0, bg.alpha(), opacity)); auto bar = anim::color(_st->barBg, _st->barBgOver, _a_barOver.value((_overbar || _moving) ? 1. : 0.)); bar.setAlpha(anim::interpolate(0, bar.alpha(), opacity)); - if (_st->round) { + const auto outer = QRect(deltal, deltat, width() - deltal - deltar, height() - deltat - deltab); + const auto radius = (_st->round < 0) + ? (std::min(outer.width(), outer.height()) / 2.) + : _st->round; + if (radius) { PainterHighQualityEnabler hq(p); p.setBrush(bg); - p.drawRoundedRect(QRect(deltal, deltat, width() - deltal - deltar, height() - deltat - deltab), _st->round, _st->round); + p.drawRoundedRect(outer, radius, radius); p.setBrush(bar); - p.drawRoundedRect(_bar, _st->round, _st->round); + p.drawRoundedRect(_bar, radius, radius); } else { - p.fillRect(QRect(deltal, deltat, width() - deltal - deltar, height() - deltat - deltab), bg); + p.fillRect(outer, bg); p.fillRect(_bar, bar); } }