diff --git a/Telegram/SourceFiles/media/player/media_player_volume_controller.cpp b/Telegram/SourceFiles/media/player/media_player_volume_controller.cpp index a453f74cf2..9c524e1c77 100644 --- a/Telegram/SourceFiles/media/player/media_player_volume_controller.cpp +++ b/Telegram/SourceFiles/media/player/media_player_volume_controller.cpp @@ -13,7 +13,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/continuous_sliders.h" #include "ui/ui_utility.h" #include "ui/cached_round_corners.h" -#include "base/object_ptr.h" #include "mainwindow.h" #include "main/main_session.h" #include "window/window_session_controller.h" @@ -81,16 +80,12 @@ VolumeWidget::VolumeWidget( QWidget *parent, not_null controller) : RpWidget(parent) -, _controller(this, controller) { +, _controller(this, controller) +, _hideTimer([=] { startHide(); }) +, _showTimer([=] { startShow(); }) { hide(); _controller->setIsVertical(true); - _hideTimer.setSingleShot(true); - connect(&_hideTimer, SIGNAL(timeout()), this, SLOT(onHideStart())); - - _showTimer.setSingleShot(true); - connect(&_showTimer, SIGNAL(timeout()), this, SLOT(onShowStart())); - macWindowDeactivateEvents( ) | rpl::filter([=] { return !isHidden(); @@ -150,44 +145,44 @@ void VolumeWidget::paintEvent(QPaintEvent *e) { } void VolumeWidget::enterEventHook(QEnterEvent *e) { - _hideTimer.stop(); + _hideTimer.cancel(); if (_a_appearance.animating()) { - onShowStart(); + startShow(); } else { - _showTimer.start(0); + _showTimer.callOnce(0); } return RpWidget::enterEventHook(e); } void VolumeWidget::leaveEventHook(QEvent *e) { - _showTimer.stop(); + _showTimer.cancel(); if (_a_appearance.animating()) { - onHideStart(); + startHide(); } else { - _hideTimer.start(300); + _hideTimer.callOnce(300); } return RpWidget::leaveEventHook(e); } void VolumeWidget::otherEnter() { - _hideTimer.stop(); + _hideTimer.cancel(); if (_a_appearance.animating()) { - onShowStart(); + startShow(); } else { - _showTimer.start(0); + _showTimer.callOnce(0); } } void VolumeWidget::otherLeave() { - _showTimer.stop(); + _showTimer.cancel(); if (_a_appearance.animating()) { - onHideStart(); + startHide(); } else { - _hideTimer.start(0); + _hideTimer.callOnce(0); } } -void VolumeWidget::onShowStart() { +void VolumeWidget::startShow() { if (isHidden()) { show(); } else if (!_hiding) { @@ -197,8 +192,10 @@ void VolumeWidget::onShowStart() { startAnimation(); } -void VolumeWidget::onHideStart() { - if (_hiding) return; +void VolumeWidget::startHide() { + if (_hiding) { + return; + } _hiding = true; startAnimation(); diff --git a/Telegram/SourceFiles/media/player/media_player_volume_controller.h b/Telegram/SourceFiles/media/player/media_player_volume_controller.h index 3869108179..bda9d80feb 100644 --- a/Telegram/SourceFiles/media/player/media_player_volume_controller.h +++ b/Telegram/SourceFiles/media/player/media_player_volume_controller.h @@ -10,8 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/effects/animations.h" #include "ui/rp_widget.h" #include "base/object_ptr.h" - -#include +#include "base/timer.h" namespace Ui { class IconButton; @@ -44,9 +43,7 @@ private: }; -class VolumeWidget : public Ui::RpWidget { - Q_OBJECT - +class VolumeWidget final : public Ui::RpWidget { public: VolumeWidget( QWidget *parent, @@ -64,11 +61,10 @@ protected: bool eventFilter(QObject *obj, QEvent *e) override; -private Q_SLOTS: - void onShowStart(); - void onHideStart(); - private: + void startHide(); + void startShow(); + void otherEnter(); void otherLeave(); @@ -81,10 +77,11 @@ private: QPixmap _cache; Ui::Animations::Simple _a_appearance; - QTimer _hideTimer, _showTimer; - object_ptr _controller; + base::Timer _hideTimer; + base::Timer _showTimer; + }; } // namespace Player