From 7b921dea3b4a825986a44aaa770cca87037b0730 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 27 Jul 2023 07:06:36 +0300 Subject: [PATCH] Replaced bad sizeValue with intended resizeGetHeight in chart widget. --- .../SourceFiles/statistics/chart_widget.cpp | 90 ++++++++----------- .../SourceFiles/statistics/chart_widget.h | 4 +- 2 files changed, 41 insertions(+), 53 deletions(-) diff --git a/Telegram/SourceFiles/statistics/chart_widget.cpp b/Telegram/SourceFiles/statistics/chart_widget.cpp index 99de6a696d..cd61fdbce2 100644 --- a/Telegram/SourceFiles/statistics/chart_widget.cpp +++ b/Telegram/SourceFiles/statistics/chart_widget.cpp @@ -829,53 +829,58 @@ ChartWidget::ChartWidget(not_null parent) _footer->update(); } }) { - sizeValue( - ) | rpl::filter([](const QSize &s) { - return !s.isNull(); - }) | rpl::start_with_next([=](const QSize &s) { - const auto filtersHeight = _filterButtons - ? _filterButtons->height() - : 0; + setupChartArea(); + setupFooter(); +} + +int ChartWidget::resizeGetHeight(int newWidth) { + if (_filterButtons) { + auto texts = std::vector(); + auto colors = std::vector(); + auto ids = std::vector(); + texts.reserve(_chartData.lines.size()); + colors.reserve(_chartData.lines.size()); + ids.reserve(_chartData.lines.size()); + for (const auto &line : _chartData.lines) { + texts.push_back(line.name); + colors.push_back(line.color); + ids.push_back(line.id); + } + + _filterButtons->fillButtons(texts, colors, ids, newWidth); + } + const auto filtersHeight = _filterButtons + ? _filterButtons->height() + : 0; + const auto resultHeight = st::statisticsChartHeight + + st::statisticsChartFooterHeight + + st::statisticsChartFooterSkip + + filtersHeight; + { _footer->setGeometry( 0, - s.height() - st::statisticsChartFooterHeight - filtersHeight, - s.width(), + resultHeight - st::statisticsChartFooterHeight - filtersHeight, + newWidth, st::statisticsChartFooterHeight); if (_filterButtons) { - _filterButtons->setGeometry( - 0, - s.height() - filtersHeight, - s.width(), - filtersHeight); + _filterButtons->show(); + _filterButtons->moveToLeft(0, resultHeight - filtersHeight); } _chartArea->setGeometry( 0, 0, - s.width(), - s.height() + newWidth, + resultHeight - st::statisticsChartFooterHeight - filtersHeight - st::statisticsChartFooterSkip); { - updateChartFullWidth(s.width()); + updateChartFullWidth(newWidth); updateBottomDates(); } - }, lifetime()); - - setupChartArea(); - setupFooter(); - - resizeHeight(); -} - -void ChartWidget::resizeHeight() { - resize( - width(), - st::statisticsChartHeight - + st::statisticsChartFooterHeight - + st::statisticsChartFooterSkip - + (_filterButtons ? _filterButtons->height() : 0)); + } + return resultHeight; } void ChartWidget::updateChartFullWidth(int w) { @@ -1192,26 +1197,7 @@ void ChartWidget::setupFilterButtons() { return; } _filterButtons = base::make_unique_q(this); - - sizeValue( - ) | rpl::filter([](const QSize &s) { - return s.width() > 0; - }) | rpl::take(2) | rpl::start_with_next([=](const QSize &s) { - auto texts = std::vector(); - auto colors = std::vector(); - auto ids = std::vector(); - texts.reserve(_chartData.lines.size()); - colors.reserve(_chartData.lines.size()); - ids.reserve(_chartData.lines.size()); - for (const auto &line : _chartData.lines) { - texts.push_back(line.name); - colors.push_back(line.color); - ids.push_back(line.id); - } - - _filterButtons->fillButtons(texts, colors, ids, s.width()); - resizeHeight(); - }, _filterButtons->lifetime()); + _filterButtons->show(); _filterButtons->buttonEnabledChanges( ) | rpl::start_with_next([=](const ChartLinesFilterWidget::Entry &e) { diff --git a/Telegram/SourceFiles/statistics/chart_widget.h b/Telegram/SourceFiles/statistics/chart_widget.h index f6932d01a6..1b043f650c 100644 --- a/Telegram/SourceFiles/statistics/chart_widget.h +++ b/Telegram/SourceFiles/statistics/chart_widget.h @@ -39,6 +39,9 @@ public: float64 fixedAlpha = 0.; }; +protected: + int resizeGetHeight(int newWidth) override; + private: class Footer; @@ -123,7 +126,6 @@ private: void updateBottomDates(); - void resizeHeight(); void updateChartFullWidth(int w); const base::unique_qptr _chartArea;