Moved out chart header to separated files.

This commit is contained in:
23rd 2023-09-19 17:51:24 +03:00 committed by John Preston
parent 6ffe555f6a
commit 32cd454554
5 changed files with 80 additions and 48 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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<void(QPainter &, const QRect &)>;

View File

@ -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 {