diff --git a/Telegram/SourceFiles/ui/controls/silent_toggle.cpp b/Telegram/SourceFiles/ui/controls/silent_toggle.cpp index e583af790..2968c80fd 100644 --- a/Telegram/SourceFiles/ui/controls/silent_toggle.cpp +++ b/Telegram/SourceFiles/ui/controls/silent_toggle.cpp @@ -31,23 +31,29 @@ SilentToggle::SilentToggle(QWidget *parent, not_null channel) resize(_st.width, _st.height); - paintRequest( - ) | rpl::start_with_next([=](const QRect &clip) { - auto p = QPainter(this); - paintRipple(p, _st.rippleAreaPosition, nullptr); - - //const auto checked = _crossLineAnimation.value(_checked ? 1. : 0.); - const auto over = isOver(); - (_checked - ? (over - ? st::historySilentToggleOnOver - : st::historySilentToggleOn) - : (over - ? st::historySilentToggle.iconOver - : st::historySilentToggle.icon)).paintInCenter(p, rect()); - }, lifetime()); - setMouseTracking(true); + + clicks( + ) | rpl::start_with_next([=] { + setChecked(!_checked); + Ui::Tooltip::Show(0, this); + _channel->owner().notifySettings().update(_channel, {}, _checked); + }, lifetime()); +} + +void SilentToggle::paintEvent(QPaintEvent *e) { + auto p = QPainter(this); + paintRipple(p, _st.rippleAreaPosition, nullptr); + + //const auto checked = _crossLineAnimation.value(_checked ? 1. : 0.); + const auto over = isOver(); + (_checked + ? (over + ? st::historySilentToggleOnOver + : st::historySilentToggleOn) + : (over + ? st::historySilentToggle.iconOver + : st::historySilentToggle.icon)).paintInCenter(p, rect()); } void SilentToggle::mouseMoveEvent(QMouseEvent *e) { @@ -62,11 +68,12 @@ void SilentToggle::mouseMoveEvent(QMouseEvent *e) { void SilentToggle::setChecked(bool checked) { if (_checked != checked) { _checked = checked; - _crossLineAnimation.start( - [=] { update(); }, - _checked ? 0. : 1., - _checked ? 1. : 0., - kAnimationDuration); + update(); + // _crossLineAnimation.start( + // [=] { update(); }, + // _checked ? 0. : 1., + // _checked ? 1. : 0., + // kAnimationDuration); } } @@ -75,13 +82,6 @@ void SilentToggle::leaveEventHook(QEvent *e) { Ui::Tooltip::Hide(); } -void SilentToggle::mouseReleaseEvent(QMouseEvent *e) { - setChecked(!_checked); - RippleButton::mouseReleaseEvent(e); - Ui::Tooltip::Show(0, this); - _channel->owner().notifySettings().update(_channel, {}, _checked); -} - QString SilentToggle::tooltipText() const { return _checked ? tr::lng_wont_be_notified(tr::now) diff --git a/Telegram/SourceFiles/ui/controls/silent_toggle.h b/Telegram/SourceFiles/ui/controls/silent_toggle.h index 358f958d5..e38d52fac 100644 --- a/Telegram/SourceFiles/ui/controls/silent_toggle.h +++ b/Telegram/SourceFiles/ui/controls/silent_toggle.h @@ -29,8 +29,8 @@ public: bool tooltipWindowActive() const override; protected: + void paintEvent(QPaintEvent *e) override; void mouseMoveEvent(QMouseEvent *e) override; - void mouseReleaseEvent(QMouseEvent *e) override; void leaveEventHook(QEvent *e) override; QImage prepareRippleMask() const override; @@ -42,7 +42,7 @@ private: not_null _channel; bool _checked = false; - Animations::Simple _crossLineAnimation; + // Animations::Simple _crossLineAnimation; };