From 160794b26c17616167319a16b9648f4dc856fe61 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 24 Aug 2023 23:01:39 +0300 Subject: [PATCH] Added support of chart titles to Data and API classes for statistics. --- .../SourceFiles/statistics/chart_widget.cpp | 80 ++++++++++++++++++- .../SourceFiles/statistics/chart_widget.h | 4 + .../SourceFiles/statistics/statistics.style | 8 ++ .../SourceFiles/statistics/statistics_box.cpp | 2 + 4 files changed, 92 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/statistics/chart_widget.cpp b/Telegram/SourceFiles/statistics/chart_widget.cpp index 4fecc711b5..7fdc58255b 100644 --- a/Telegram/SourceFiles/statistics/chart_widget.cpp +++ b/Telegram/SourceFiles/statistics/chart_widget.cpp @@ -192,6 +192,51 @@ void RpMouseWidget::mouseReleaseEvent(QMouseEvent *e) { _mouseStateChanged.fire({ e->pos(), QEvent::MouseButtonRelease }); } +class ChartWidget::Header final : public RpWidget { +public: + using RpWidget::RpWidget; + + void setTitle(QString title); + void setRightInfo(QString rightInfo); + +protected: + void paintEvent(QPaintEvent *e) override; + +private: + Ui::Text::String _title; + Ui::Text::String _rightInfo; + int _titleWidth = 0; + +}; + +void ChartWidget::Header::setTitle(QString title) { + _titleWidth = st::statisticsHeaderTitleTextStyle.font->width(title); + _title.setText(st::statisticsHeaderTitleTextStyle, std::move(title)); +} + +void ChartWidget::Header::setRightInfo(QString rightInfo) { + _rightInfo.setText( + st::statisticsHeaderDatesTextStyle, + std::move(rightInfo)); +} + +void ChartWidget::Header::paintEvent(QPaintEvent *e) { + auto p = Painter(this); + + p.setPen(st::boxTextFg); + const auto top = (height() + - st::statisticsHeaderTitleTextStyle.font->height) / 2; + _title.drawLeftElided(p, 0, top, width(), width()); + _rightInfo.drawRightElided( + p, + 0, + top, + width() - _titleWidth, + width(), + 1, + style::al_right); +} + class ChartWidget::Footer final : public RpMouseWidget { public: using PaintCallback = Fn; @@ -823,6 +868,7 @@ bool ChartWidget::ChartAnimationController::isFPSSlow() const { ChartWidget::ChartWidget(not_null parent) : Ui::RpWidget(parent) , _chartArea(base::make_unique_q(this)) +, _header(std::make_unique
(this)) , _footer(std::make_unique