From 32cd4545540538b782f73da758f1949821baa2c1 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 19 Sep 2023 17:51:24 +0300 Subject: [PATCH] Moved out chart header to separated files. --- Telegram/CMakeLists.txt | 2 + .../statistics/chart_header_widget.cpp | 45 +++++++++++++++++ .../statistics/chart_header_widget.h | 31 ++++++++++++ .../SourceFiles/statistics/chart_widget.cpp | 48 +------------------ .../SourceFiles/statistics/chart_widget.h | 2 +- 5 files changed, 80 insertions(+), 48 deletions(-) create mode 100644 Telegram/SourceFiles/statistics/chart_header_widget.cpp create mode 100644 Telegram/SourceFiles/statistics/chart_header_widget.h diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 19202d5c3b..5c6c7e7713 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -1282,6 +1282,8 @@ PRIVATE settings/settings_type.h settings/settings_websites.cpp settings/settings_websites.h + statistics/chart_header_widget.cpp + statistics/chart_header_widget.h statistics/chart_horizontal_lines_data.cpp statistics/chart_horizontal_lines_data.h statistics/chart_widget.cpp diff --git a/Telegram/SourceFiles/statistics/chart_header_widget.cpp b/Telegram/SourceFiles/statistics/chart_header_widget.cpp new file mode 100644 index 0000000000..661432b571 --- /dev/null +++ b/Telegram/SourceFiles/statistics/chart_header_widget.cpp @@ -0,0 +1,45 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "statistics/chart_header_widget.h" + +#include "ui/painter.h" +#include "styles/style_statistics.h" + +namespace Statistic { + +void Header::setTitle(QString title) { + _titleWidth = st::statisticsHeaderTitleTextStyle.font->width(title); + _title.setText(st::statisticsHeaderTitleTextStyle, std::move(title)); +} + +void Header::setRightInfo(QString rightInfo) { + _rightInfo.setText( + st::statisticsHeaderDatesTextStyle, + std::move(rightInfo)); +} + +void Header::paintEvent(QPaintEvent *e) { + auto p = Painter(this); + + p.fillRect(rect(), st::boxBg); + + 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); +} + +} // namespace Statistic diff --git a/Telegram/SourceFiles/statistics/chart_header_widget.h b/Telegram/SourceFiles/statistics/chart_header_widget.h new file mode 100644 index 0000000000..b0c3efaa6c --- /dev/null +++ b/Telegram/SourceFiles/statistics/chart_header_widget.h @@ -0,0 +1,31 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +#include "ui/rp_widget.h" + +namespace Statistic { + +class Header final : public Ui::RpWidget { +public: + using Ui::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; + +}; + +} // namespace Statistic diff --git a/Telegram/SourceFiles/statistics/chart_widget.cpp b/Telegram/SourceFiles/statistics/chart_widget.cpp index 27f22bf34d..90cc3cc4bf 100644 --- a/Telegram/SourceFiles/statistics/chart_widget.cpp +++ b/Telegram/SourceFiles/statistics/chart_widget.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/effects/show_animation.h" #include "base/qt/qt_key_modifiers.h" #include "lang/lang_keys.h" +#include "statistics/chart_header_widget.h" #include "statistics/chart_lines_filter_widget.h" #include "statistics/point_details_widget.h" #include "statistics/view/abstract_chart_view.h" @@ -164,53 +165,6 @@ 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.fillRect(rect(), st::boxBg); - - 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; diff --git a/Telegram/SourceFiles/statistics/chart_widget.h b/Telegram/SourceFiles/statistics/chart_widget.h index ef0446c2d2..6aa5d91b42 100644 --- a/Telegram/SourceFiles/statistics/chart_widget.h +++ b/Telegram/SourceFiles/statistics/chart_widget.h @@ -20,6 +20,7 @@ class RpMouseWidget; class PointDetailsWidget; class ChartLinesFilterWidget; class AbstractChartView; +class Header; class ChartWidget : public Ui::RpWidget { public: @@ -50,7 +51,6 @@ protected: int resizeGetHeight(int newWidth) override; private: - class Header; class Footer; class ChartAnimationController final {