diff --git a/Telegram/SourceFiles/statistics/statistics_graphics.cpp b/Telegram/SourceFiles/statistics/statistics_graphics.cpp new file mode 100644 index 000000000..167082a5a --- /dev/null +++ b/Telegram/SourceFiles/statistics/statistics_graphics.cpp @@ -0,0 +1,43 @@ +/* +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/statistics_graphics.h" + +#include "data/data_statistics_chart.h" +#include "ui/effects/credits_graphics.h" // GenerateStars. +#include "ui/painter.h" +#include "styles/style_basic.h" +#include "styles/style_statistics.h" + +namespace Statistic { + +QImage ChartCurrencyIcon( + const Data::StatisticalChart &chartData, + std::optional color) { + auto result = QImage(); + const auto iconSize = st::statisticsCurrencyIcon.size(); + if (chartData.currency == Data::StatisticalCurrency::Ton) { + result = QImage( + iconSize * style::DevicePixelRatio(), + QImage::Format_ARGB32_Premultiplied); + result.setDevicePixelRatio(style::DevicePixelRatio()); + result.fill(Qt::transparent); + { + auto p = Painter(&result); + if (const auto w = iconSize.width(); w && color) { + st::statisticsCurrencyIcon.paint(p, 0, 0, w, *color); + } else { + st::statisticsCurrencyIcon.paint(p, 0, 0, iconSize.width()); + } + } + } else if (chartData.currency == Data::StatisticalCurrency::Credits) { + return Ui::GenerateStars(iconSize.height(), 1); + } + return result; +} + +} // namespace Statistic diff --git a/Telegram/SourceFiles/statistics/statistics_graphics.h b/Telegram/SourceFiles/statistics/statistics_graphics.h new file mode 100644 index 000000000..e6c3a8011 --- /dev/null +++ b/Telegram/SourceFiles/statistics/statistics_graphics.h @@ -0,0 +1,20 @@ +/* +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 + +namespace Data { +struct StatisticalChart; +} // namespace Data + +namespace Statistic { + +[[nodiscard]] QImage ChartCurrencyIcon( + const Data::StatisticalChart &chartData, + std::optional color); + +} // namespace Statistic diff --git a/Telegram/SourceFiles/statistics/view/chart_rulers_view.cpp b/Telegram/SourceFiles/statistics/view/chart_rulers_view.cpp index 6925f30e5..ac9dc4582 100644 --- a/Telegram/SourceFiles/statistics/view/chart_rulers_view.cpp +++ b/Telegram/SourceFiles/statistics/view/chart_rulers_view.cpp @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "statistics/chart_lines_filter_controller.h" #include "statistics/statistics_common.h" +#include "statistics/statistics_graphics.h" #include "styles/style_basic.h" #include "styles/style_statistics.h" @@ -37,7 +38,7 @@ void ChartRulersView::setChartData( _isDouble = (type == ChartViewType::DoubleLinear) || chartData.currencyRate; if (chartData.currencyRate) { - _currencyIcon = &st::statisticsCurrencyIcon; + _currencyIcon = ChartCurrencyIcon(chartData, {}); _leftCustomCaption = [=](float64 value) { return FormatF(value / float64(Data::kEarnMultiplier)); }; @@ -92,7 +93,9 @@ void ChartRulersView::paintCaptionsToRulers( for (auto &ruler : _rulers) { const auto rulerAlpha = alpha * ruler.alpha; p.setOpacity(rulerAlpha); - const auto left = _currencyIcon ? _currencyIcon->width() : 0; + const auto left = _currencyIcon.isNull() + ? 0 + : _currencyIcon.width() / style::DevicePixelRatio(); for (const auto &line : ruler.lines) { const auto y = offset + r.height() * line.relativeValue; const auto hasLinesFilter = _isDouble && _linesFilter; @@ -102,11 +105,11 @@ void ChartRulersView::paintCaptionsToRulers( } else { p.setPen(st::windowSubTextFg); } - if (_currencyIcon) { + if (!_currencyIcon.isNull()) { const auto iconTop = y - - _currencyIcon->height() + - _currencyIcon.height() / style::DevicePixelRatio() + st::statisticsChartRulerCaptionSkip; - _currencyIcon->paint(p, 0, iconTop, r.width()); + p.drawImage(0, iconTop, _currencyIcon); } p.drawText( left, diff --git a/Telegram/SourceFiles/statistics/view/chart_rulers_view.h b/Telegram/SourceFiles/statistics/view/chart_rulers_view.h index 44326d15e..8ce8e989f 100644 --- a/Telegram/SourceFiles/statistics/view/chart_rulers_view.h +++ b/Telegram/SourceFiles/statistics/view/chart_rulers_view.h @@ -42,7 +42,7 @@ private: QPen _rightPen; int _leftLineId = 0; int _rightLineId = 0; - const style::icon *_currencyIcon = nullptr; + QImage _currencyIcon; Fn _leftCustomCaption = nullptr; Fn _rightCustomCaption = nullptr; diff --git a/Telegram/SourceFiles/statistics/widgets/point_details_widget.cpp b/Telegram/SourceFiles/statistics/widgets/point_details_widget.cpp index 305010866..f96c4ac3a 100644 --- a/Telegram/SourceFiles/statistics/widgets/point_details_widget.cpp +++ b/Telegram/SourceFiles/statistics/widgets/point_details_widget.cpp @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "statistics/statistics_common.h" #include "statistics/statistics_format_values.h" +#include "statistics/statistics_graphics.h" #include "statistics/view/stack_linear_chart_common.h" #include "ui/cached_round_corners.h" #include "ui/effects/ripple_animation.h" @@ -135,9 +136,7 @@ PointDetailsWidget::PointDetailsWidget( , _zoomEnabled(zoomEnabled) , _chartData(chartData) , _textStyle(st::statisticsDetailsPopupStyle) -, _headerStyle(st::statisticsDetailsPopupHeaderStyle) -, _valueIcon(chartData.currencyRate ? &st::statisticsCurrencyIcon : nullptr) { - +, _headerStyle(st::statisticsDetailsPopupHeaderStyle) { if (zoomEnabled) { rpl::single(rpl::empty_value()) | rpl::then( style::PaletteChanged() @@ -205,7 +204,9 @@ PointDetailsWidget::PointDetailsWidget( + rect::m::sum::h(st::statisticsDetailsPopupPadding) + st::statisticsDetailsPopupPadding.left() // Between strings. + maxNameTextWidth - + (_valueIcon ? _valueIcon->width() : 0) + + (_valueIcon.isNull() + ? 0 + : _valueIcon.width() / style::DevicePixelRatio()) + _maxPercentageWidth; }(); sizeValue( @@ -310,6 +311,9 @@ void PointDetailsWidget::setXIndex(int xIndex) { } _lines.push_back(std::move(textLine)); } + if (_chartData.currencyRate && _valueIcon.isNull()) { + _valueIcon = ChartCurrencyIcon(_chartData, _lines.front().valueColor); + } const auto clickable = _zoomEnabled && hasPositiveValues; _hasPositiveValues = hasPositiveValues; QWidget::setAttribute( @@ -408,13 +412,12 @@ void PointDetailsWidget::paintEvent(QPaintEvent *e) { .outerWidth = _textRect.width(), .availableWidth = valueWidth, }; - if (!i && _valueIcon) { - _valueIcon->paint( - p, - valueContext.position.x() - _valueIcon->width(), + if (!i && !_valueIcon.isNull()) { + p.drawImage( + valueContext.position.x() + - _valueIcon.width() / style::DevicePixelRatio(), lineY, - valueContext.outerWidth, - line.valueColor); + _valueIcon); } const auto nameContext = Ui::Text::PaintContext{ .position = QPoint( diff --git a/Telegram/SourceFiles/statistics/widgets/point_details_widget.h b/Telegram/SourceFiles/statistics/widgets/point_details_widget.h index a1e3dcccc..cdf6b3bd3 100644 --- a/Telegram/SourceFiles/statistics/widgets/point_details_widget.h +++ b/Telegram/SourceFiles/statistics/widgets/point_details_widget.h @@ -47,7 +47,7 @@ private: const style::TextStyle &_textStyle; const style::TextStyle &_headerStyle; Ui::Text::String _header; - const style::icon *_valueIcon = nullptr; + QImage _valueIcon; void invalidateCache(); diff --git a/Telegram/cmake/td_ui.cmake b/Telegram/cmake/td_ui.cmake index ca5cb6003..34063bb22 100644 --- a/Telegram/cmake/td_ui.cmake +++ b/Telegram/cmake/td_ui.cmake @@ -214,6 +214,8 @@ PRIVATE statistics/statistics_data_deserialize.h statistics/statistics_format_values.cpp statistics/statistics_format_values.h + statistics/statistics_graphics.cpp + statistics/statistics_graphics.h statistics/statistics_types.h statistics/view/abstract_chart_view.cpp statistics/view/abstract_chart_view.h