From 897bea2baf22cf8129ade32960f74c2a428ea1c6 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Fri, 3 Sep 2021 16:27:00 +0300 Subject: [PATCH] Removed Q_OBJECT from InnerDropdown. --- ui/widgets/inner_dropdown.cpp | 22 ++++++++++------------ ui/widgets/inner_dropdown.h | 13 ++++--------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/ui/widgets/inner_dropdown.cpp b/ui/widgets/inner_dropdown.cpp index 1edff2a..5e715eb 100644 --- a/ui/widgets/inner_dropdown.cpp +++ b/ui/widgets/inner_dropdown.cpp @@ -20,11 +20,9 @@ InnerDropdown::InnerDropdown( : RpWidget(parent) , _st(st) , _roundRect(ImageRoundRadius::Small, _st.bg) +, _hideTimer([=] { hideAnimated(); }) , _scroll(this, _st.scroll) { - _hideTimer.setSingleShot(true); - connect(&_hideTimer, SIGNAL(timeout()), this, SLOT(onHideAnimated())); - - connect(_scroll, SIGNAL(scrolled()), this, SLOT(onScroll())); + connect(_scroll, &ScrollArea::scrolled, [=] { scrolled(); }); hide(); @@ -89,11 +87,11 @@ void InnerDropdown::resizeEvent(QResizeEvent *e) { _scroll->setGeometry(rect().marginsRemoved(_st.padding).marginsRemoved(_st.scrollMargin)); if (auto widget = static_cast(_scroll->widget())) { widget->resizeToWidth(_scroll->width()); - onScroll(); + scrolled(); } } -void InnerDropdown::onScroll() { +void InnerDropdown::scrolled() { if (auto widget = static_cast(_scroll->widget())) { int visibleTop = _scroll->scrollTop(); int visibleBottom = visibleTop + _scroll->height(); @@ -140,7 +138,7 @@ void InnerDropdown::leaveEventHook(QEvent *e) { if (_a_show.animating() || _a_opacity.animating()) { hideAnimated(); } else { - _hideTimer.start(300); + _hideTimer.callOnce(300); } } return RpWidget::leaveEventHook(e); @@ -157,7 +155,7 @@ void InnerDropdown::otherLeave() { if (_a_show.animating() || _a_opacity.animating()) { hideAnimated(); } else { - _hideTimer.start(0); + _hideTimer.callOnce(0); } } } @@ -172,7 +170,7 @@ void InnerDropdown::showAnimated(PanelAnimation::Origin origin) { } void InnerDropdown::showAnimated() { - _hideTimer.stop(); + _hideTimer.cancel(); showStarted(); } @@ -183,7 +181,7 @@ void InnerDropdown::hideAnimated(HideOption option) { } if (_hiding) return; - _hideTimer.stop(); + _hideTimer.cancel(); startOpacityAnimation(true); } @@ -203,7 +201,7 @@ void InnerDropdown::finishAnimating() { } void InnerDropdown::showFast() { - _hideTimer.stop(); + _hideTimer.cancel(); finishAnimating(); if (isHidden()) { showChildren(); @@ -215,7 +213,7 @@ void InnerDropdown::showFast() { void InnerDropdown::hideFast() { if (isHidden()) return; - _hideTimer.stop(); + _hideTimer.cancel(); finishAnimating(); _hiding = false; hideFinished(); diff --git a/ui/widgets/inner_dropdown.h b/ui/widgets/inner_dropdown.h index e19a1ea..1ed1080 100644 --- a/ui/widgets/inner_dropdown.h +++ b/ui/widgets/inner_dropdown.h @@ -12,15 +12,13 @@ #include "ui/effects/animations.h" #include "ui/effects/panel_animation.h" #include "base/object_ptr.h" - -#include +#include "base/timer.h" namespace Ui { class ScrollArea; class InnerDropdown : public RpWidget { - Q_OBJECT public: InnerDropdown(QWidget *parent, const style::InnerDropdown &st = st::defaultInnerDropdown); @@ -81,11 +79,6 @@ protected: int resizeGetHeight(int newWidth) override; -private Q_SLOTS: - void onHideAnimated() { - hideAnimated(); - } - void onScroll(); private: QPointer doSetOwnedWidget(object_ptr widget); @@ -103,6 +96,8 @@ private: void updateHeight(); + void scrolled(); + const style::InnerDropdown &_st; RoundRect _roundRect; @@ -115,7 +110,7 @@ private: QPixmap _cache; Animations::Simple _a_opacity; - QTimer _hideTimer; + base::Timer _hideTimer; bool _ignoreShowEvents = false; Fn _showStartCallback; Fn _hideStartCallback;