From 5c3748db56e9cd88ac1aff9756967bf08a090543 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Fri, 30 Jun 2023 22:36:13 +0300 Subject: [PATCH] Added tools to test animation for left and right edges with same speed. --- .../SourceFiles/statistics/chart_widget.cpp | 151 ++++++++++++++---- 1 file changed, 121 insertions(+), 30 deletions(-) diff --git a/Telegram/SourceFiles/statistics/chart_widget.cpp b/Telegram/SourceFiles/statistics/chart_widget.cpp index 4bd34914d..c70dbf820 100644 --- a/Telegram/SourceFiles/statistics/chart_widget.cpp +++ b/Telegram/SourceFiles/statistics/chart_widget.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "statistics/chart_widget.h" +#include "base/qt/qt_key_modifiers.h" #include "statistics/linear_chart_view.h" #include "ui/abstract_button.h" #include "ui/effects/animation_value_f.h" @@ -86,6 +87,7 @@ public: [[nodiscard]] rpl::producer xPercentageLimitsChange() const; [[nodiscard]] rpl::producer<> userInteractionFinished() const; + [[nodiscard]] rpl::producer<> directionChanges() const; private: not_null _left; @@ -93,11 +95,13 @@ private: rpl::event_stream _xPercentageLimitsChange; rpl::event_stream<> _userInteractionFinished; + rpl::event_stream<> _directionChanges; struct { int x = 0; int leftLimit = 0; int rightLimit = 0; + int diffX = 0; } _start; }; @@ -140,15 +144,27 @@ ChartWidget::Footer::Footer(not_null parent) const auto pos = static_cast(e.get())->pos(); switch (e->type()) { case QEvent::MouseMove: { - const auto nextX = std::clamp( - side->x() + (pos.x() - _start.x), - _start.leftLimit, - _start.rightLimit); - side->move(nextX, side->y()); + const auto nowDiffXDirection = (pos.x() - _start.x) < 0; + const auto wasDiffXDirection = _start.diffX < 0; + if (base::IsCtrlPressed()) { + const auto diff = (pos.x() - _start.x); + _left->move(_left->x() + diff, side->y()); + _right->move(_right->x() + diff, side->y()); + } else { + _start.diffX = pos.x() - _start.x; + const auto nextX = std::clamp( + side->x() + (pos.x() - _start.x), + _start.leftLimit, + _start.rightLimit); + side->move(nextX, side->y()); + } _xPercentageLimitsChange.fire({ .min = _left->x() / float64(width()), .max = rect::right(_right) / float64(width()), }); + if (nowDiffXDirection != wasDiffXDirection) { + _directionChanges.fire({}); + } } break; case QEvent::MouseButtonPress: { _start.x = pos.x(); @@ -156,11 +172,11 @@ ChartWidget::Footer::Footer(not_null parent) _start.rightLimit = rightLimit(); } break; case QEvent::MouseButtonRelease: { + _userInteractionFinished.fire({}); _xPercentageLimitsChange.fire({ .min = _left->x() / float64(width()), .max = rect::right(_right) / float64(width()), }); - _userInteractionFinished.fire({}); _start = {}; } break; } @@ -184,6 +200,10 @@ rpl::producer<> ChartWidget::Footer::userInteractionFinished() const { return _userInteractionFinished.events(); } +rpl::producer<> ChartWidget::Footer::directionChanges() const { + return _directionChanges.events(); +} + ChartWidget::ChartWidget(not_null parent) : Ui::RpWidget(parent) , _footer(std::make_unique