From c20bd17029c06852d50885132ce08651da4779e7 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 3 Oct 2023 16:16:39 +0300 Subject: [PATCH] Moved zoom out button to right side above chart. --- .../statistics/chart_header_widget.cpp | 4 +++ .../statistics/chart_header_widget.h | 1 + .../SourceFiles/statistics/chart_widget.cpp | 32 +++++++++++-------- .../SourceFiles/statistics/statistics.style | 2 +- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/Telegram/SourceFiles/statistics/chart_header_widget.cpp b/Telegram/SourceFiles/statistics/chart_header_widget.cpp index 5c92fd9fc..88dea4150 100644 --- a/Telegram/SourceFiles/statistics/chart_header_widget.cpp +++ b/Telegram/SourceFiles/statistics/chart_header_widget.cpp @@ -12,6 +12,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Statistic { +QString Header::title() const { + return _title.toString(); +} + void Header::setTitle(QString title) { _title.setText(st::statisticsHeaderTitleTextStyle, std::move(title)); } diff --git a/Telegram/SourceFiles/statistics/chart_header_widget.h b/Telegram/SourceFiles/statistics/chart_header_widget.h index ae83bc3fe..0f82505df 100644 --- a/Telegram/SourceFiles/statistics/chart_header_widget.h +++ b/Telegram/SourceFiles/statistics/chart_header_widget.h @@ -15,6 +15,7 @@ class Header final : public Ui::RpWidget { public: using Ui::RpWidget::RpWidget; + [[nodiscard]] QString title() const; void setTitle(QString title); void setRightInfo(QString rightInfo); diff --git a/Telegram/SourceFiles/statistics/chart_widget.cpp b/Telegram/SourceFiles/statistics/chart_widget.cpp index 1bd9a6b4e..6b79ef57e 100644 --- a/Telegram/SourceFiles/statistics/chart_widget.cpp +++ b/Telegram/SourceFiles/statistics/chart_widget.cpp @@ -1260,6 +1260,7 @@ void ChartWidget::processLocalZoom(int xIndex) { ) | rpl::start_with_next([=](const QRect &g) { header->setGeometry(g); }, header->lifetime()); + header->setTitle(_header->title()); header->setRightInfo(_chartData.getDayString(xIndex)); const auto enableMouse = [=](bool value) { @@ -1291,6 +1292,9 @@ void ChartWidget::processLocalZoom(int xIndex) { header, tr::lng_stats_zoom_out(), st::statisticsHeaderButton); + zoomOutButton->moveToRight( + 0, + (st::statisticsChartHeaderHeight - zoomOutButton->height()) / 2); zoomOutButton->show(); zoomOutButton->setTextTransform( Ui::RoundButton::TextTransform::NoTransform); @@ -1324,8 +1328,6 @@ void ChartWidget::processLocalZoom(int xIndex) { Ui::Animations::ShowWidgets({ header }); - zoomOutButton->moveToLeft(0, 0); - const auto finish = [=](const Limits &zoomLimitIndices) { createMouseTracking(); _footer->xPercentageLimitsChange( @@ -1460,11 +1462,17 @@ void ChartWidget::setZoomedChartData( const auto customHeader = Ui::CreateChild
( _zoomedChartWidget.get()); - const auto xIndex = std::distance( - begin(_chartData.x), - ranges::find(_chartData.x, x)); - if ((xIndex >= 0) && (xIndex < _chartData.x.size())) { - customHeader->setRightInfo(_chartData.getDayString(xIndex)); + { + const auto xIndex = std::distance( + begin(_chartData.x), + ranges::find(_chartData.x, x)); + customHeader->setTitle(_header->title()); + if ((xIndex >= 0) && (xIndex < _chartData.x.size())) { + customHeader->setRightInfo(_chartData.getDayString(xIndex)); + } + const auto &headerPadding = st::statisticsChartHeaderPadding; + customHeader->moveToLeft(headerPadding.left(), headerPadding.top()); + customHeader->resizeToWidth(width() - rect::m::sum::h(headerPadding)); } const auto zoomOutButton = Ui::CreateChild( @@ -1473,6 +1481,9 @@ void ChartWidget::setZoomedChartData( st::statisticsHeaderButton); zoomOutButton->setTextTransform( Ui::RoundButton::TextTransform::NoTransform); + zoomOutButton->moveToRight( + 0, + (st::statisticsChartHeaderHeight - zoomOutButton->height()) / 2); zoomOutButton->setClickedCallback([=] { shownValue( ) | rpl::start_with_next([=](bool shown) { @@ -1486,13 +1497,6 @@ void ChartWidget::setZoomedChartData( Ui::Animations::ShowWidgets({ _zoomedChartWidget.get(), customHeader }); Ui::Animations::HideWidgets({ this }); - - { - const auto &headerPadding = st::statisticsChartHeaderPadding; - customHeader->moveToLeft(headerPadding.left(), headerPadding.top()); - customHeader->resizeToWidth(width() - rect::m::sum::h(headerPadding)); - } - zoomOutButton->moveToLeft(0, 0); } rpl::producer ChartWidget::zoomRequests() { diff --git a/Telegram/SourceFiles/statistics/statistics.style b/Telegram/SourceFiles/statistics/statistics.style index ccf0b8e0d..0f73a60f2 100644 --- a/Telegram/SourceFiles/statistics/statistics.style +++ b/Telegram/SourceFiles/statistics/statistics.style @@ -68,7 +68,7 @@ statisticsHeaderDatesTextStyle: TextStyle(defaultTextStyle) { } statisticsHeaderButton: RoundButton(defaultLightButton) { width: -14px; - height: statisticsChartHeaderHeight; + height: 20px; textTop: 2px; font: font(11px semibold); }