Added credits icon to statistical charts.
This commit is contained in:
parent
1196b6a3fb
commit
db4c9b83f3
7 changed files with 88 additions and 17 deletions
43
Telegram/SourceFiles/statistics/statistics_graphics.cpp
Normal file
43
Telegram/SourceFiles/statistics/statistics_graphics.cpp
Normal file
|
@ -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<QColor> 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
|
20
Telegram/SourceFiles/statistics/statistics_graphics.h
Normal file
20
Telegram/SourceFiles/statistics/statistics_graphics.h
Normal file
|
@ -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<QColor> color);
|
||||||
|
|
||||||
|
} // namespace Statistic
|
|
@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "statistics/chart_lines_filter_controller.h"
|
#include "statistics/chart_lines_filter_controller.h"
|
||||||
#include "statistics/statistics_common.h"
|
#include "statistics/statistics_common.h"
|
||||||
|
#include "statistics/statistics_graphics.h"
|
||||||
#include "styles/style_basic.h"
|
#include "styles/style_basic.h"
|
||||||
#include "styles/style_statistics.h"
|
#include "styles/style_statistics.h"
|
||||||
|
|
||||||
|
@ -37,7 +38,7 @@ void ChartRulersView::setChartData(
|
||||||
_isDouble = (type == ChartViewType::DoubleLinear)
|
_isDouble = (type == ChartViewType::DoubleLinear)
|
||||||
|| chartData.currencyRate;
|
|| chartData.currencyRate;
|
||||||
if (chartData.currencyRate) {
|
if (chartData.currencyRate) {
|
||||||
_currencyIcon = &st::statisticsCurrencyIcon;
|
_currencyIcon = ChartCurrencyIcon(chartData, {});
|
||||||
_leftCustomCaption = [=](float64 value) {
|
_leftCustomCaption = [=](float64 value) {
|
||||||
return FormatF(value / float64(Data::kEarnMultiplier));
|
return FormatF(value / float64(Data::kEarnMultiplier));
|
||||||
};
|
};
|
||||||
|
@ -92,7 +93,9 @@ void ChartRulersView::paintCaptionsToRulers(
|
||||||
for (auto &ruler : _rulers) {
|
for (auto &ruler : _rulers) {
|
||||||
const auto rulerAlpha = alpha * ruler.alpha;
|
const auto rulerAlpha = alpha * ruler.alpha;
|
||||||
p.setOpacity(rulerAlpha);
|
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) {
|
for (const auto &line : ruler.lines) {
|
||||||
const auto y = offset + r.height() * line.relativeValue;
|
const auto y = offset + r.height() * line.relativeValue;
|
||||||
const auto hasLinesFilter = _isDouble && _linesFilter;
|
const auto hasLinesFilter = _isDouble && _linesFilter;
|
||||||
|
@ -102,11 +105,11 @@ void ChartRulersView::paintCaptionsToRulers(
|
||||||
} else {
|
} else {
|
||||||
p.setPen(st::windowSubTextFg);
|
p.setPen(st::windowSubTextFg);
|
||||||
}
|
}
|
||||||
if (_currencyIcon) {
|
if (!_currencyIcon.isNull()) {
|
||||||
const auto iconTop = y
|
const auto iconTop = y
|
||||||
- _currencyIcon->height()
|
- _currencyIcon.height() / style::DevicePixelRatio()
|
||||||
+ st::statisticsChartRulerCaptionSkip;
|
+ st::statisticsChartRulerCaptionSkip;
|
||||||
_currencyIcon->paint(p, 0, iconTop, r.width());
|
p.drawImage(0, iconTop, _currencyIcon);
|
||||||
}
|
}
|
||||||
p.drawText(
|
p.drawText(
|
||||||
left,
|
left,
|
||||||
|
|
|
@ -42,7 +42,7 @@ private:
|
||||||
QPen _rightPen;
|
QPen _rightPen;
|
||||||
int _leftLineId = 0;
|
int _leftLineId = 0;
|
||||||
int _rightLineId = 0;
|
int _rightLineId = 0;
|
||||||
const style::icon *_currencyIcon = nullptr;
|
QImage _currencyIcon;
|
||||||
|
|
||||||
Fn<QString(float64)> _leftCustomCaption = nullptr;
|
Fn<QString(float64)> _leftCustomCaption = nullptr;
|
||||||
Fn<QString(float64)> _rightCustomCaption = nullptr;
|
Fn<QString(float64)> _rightCustomCaption = nullptr;
|
||||||
|
|
|
@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "statistics/statistics_common.h"
|
#include "statistics/statistics_common.h"
|
||||||
#include "statistics/statistics_format_values.h"
|
#include "statistics/statistics_format_values.h"
|
||||||
|
#include "statistics/statistics_graphics.h"
|
||||||
#include "statistics/view/stack_linear_chart_common.h"
|
#include "statistics/view/stack_linear_chart_common.h"
|
||||||
#include "ui/cached_round_corners.h"
|
#include "ui/cached_round_corners.h"
|
||||||
#include "ui/effects/ripple_animation.h"
|
#include "ui/effects/ripple_animation.h"
|
||||||
|
@ -135,9 +136,7 @@ PointDetailsWidget::PointDetailsWidget(
|
||||||
, _zoomEnabled(zoomEnabled)
|
, _zoomEnabled(zoomEnabled)
|
||||||
, _chartData(chartData)
|
, _chartData(chartData)
|
||||||
, _textStyle(st::statisticsDetailsPopupStyle)
|
, _textStyle(st::statisticsDetailsPopupStyle)
|
||||||
, _headerStyle(st::statisticsDetailsPopupHeaderStyle)
|
, _headerStyle(st::statisticsDetailsPopupHeaderStyle) {
|
||||||
, _valueIcon(chartData.currencyRate ? &st::statisticsCurrencyIcon : nullptr) {
|
|
||||||
|
|
||||||
if (zoomEnabled) {
|
if (zoomEnabled) {
|
||||||
rpl::single(rpl::empty_value()) | rpl::then(
|
rpl::single(rpl::empty_value()) | rpl::then(
|
||||||
style::PaletteChanged()
|
style::PaletteChanged()
|
||||||
|
@ -205,7 +204,9 @@ PointDetailsWidget::PointDetailsWidget(
|
||||||
+ rect::m::sum::h(st::statisticsDetailsPopupPadding)
|
+ rect::m::sum::h(st::statisticsDetailsPopupPadding)
|
||||||
+ st::statisticsDetailsPopupPadding.left() // Between strings.
|
+ st::statisticsDetailsPopupPadding.left() // Between strings.
|
||||||
+ maxNameTextWidth
|
+ maxNameTextWidth
|
||||||
+ (_valueIcon ? _valueIcon->width() : 0)
|
+ (_valueIcon.isNull()
|
||||||
|
? 0
|
||||||
|
: _valueIcon.width() / style::DevicePixelRatio())
|
||||||
+ _maxPercentageWidth;
|
+ _maxPercentageWidth;
|
||||||
}();
|
}();
|
||||||
sizeValue(
|
sizeValue(
|
||||||
|
@ -310,6 +311,9 @@ void PointDetailsWidget::setXIndex(int xIndex) {
|
||||||
}
|
}
|
||||||
_lines.push_back(std::move(textLine));
|
_lines.push_back(std::move(textLine));
|
||||||
}
|
}
|
||||||
|
if (_chartData.currencyRate && _valueIcon.isNull()) {
|
||||||
|
_valueIcon = ChartCurrencyIcon(_chartData, _lines.front().valueColor);
|
||||||
|
}
|
||||||
const auto clickable = _zoomEnabled && hasPositiveValues;
|
const auto clickable = _zoomEnabled && hasPositiveValues;
|
||||||
_hasPositiveValues = hasPositiveValues;
|
_hasPositiveValues = hasPositiveValues;
|
||||||
QWidget::setAttribute(
|
QWidget::setAttribute(
|
||||||
|
@ -408,13 +412,12 @@ void PointDetailsWidget::paintEvent(QPaintEvent *e) {
|
||||||
.outerWidth = _textRect.width(),
|
.outerWidth = _textRect.width(),
|
||||||
.availableWidth = valueWidth,
|
.availableWidth = valueWidth,
|
||||||
};
|
};
|
||||||
if (!i && _valueIcon) {
|
if (!i && !_valueIcon.isNull()) {
|
||||||
_valueIcon->paint(
|
p.drawImage(
|
||||||
p,
|
valueContext.position.x()
|
||||||
valueContext.position.x() - _valueIcon->width(),
|
- _valueIcon.width() / style::DevicePixelRatio(),
|
||||||
lineY,
|
lineY,
|
||||||
valueContext.outerWidth,
|
_valueIcon);
|
||||||
line.valueColor);
|
|
||||||
}
|
}
|
||||||
const auto nameContext = Ui::Text::PaintContext{
|
const auto nameContext = Ui::Text::PaintContext{
|
||||||
.position = QPoint(
|
.position = QPoint(
|
||||||
|
|
|
@ -47,7 +47,7 @@ private:
|
||||||
const style::TextStyle &_textStyle;
|
const style::TextStyle &_textStyle;
|
||||||
const style::TextStyle &_headerStyle;
|
const style::TextStyle &_headerStyle;
|
||||||
Ui::Text::String _header;
|
Ui::Text::String _header;
|
||||||
const style::icon *_valueIcon = nullptr;
|
QImage _valueIcon;
|
||||||
|
|
||||||
void invalidateCache();
|
void invalidateCache();
|
||||||
|
|
||||||
|
|
|
@ -214,6 +214,8 @@ PRIVATE
|
||||||
statistics/statistics_data_deserialize.h
|
statistics/statistics_data_deserialize.h
|
||||||
statistics/statistics_format_values.cpp
|
statistics/statistics_format_values.cpp
|
||||||
statistics/statistics_format_values.h
|
statistics/statistics_format_values.h
|
||||||
|
statistics/statistics_graphics.cpp
|
||||||
|
statistics/statistics_graphics.h
|
||||||
statistics/statistics_types.h
|
statistics/statistics_types.h
|
||||||
statistics/view/abstract_chart_view.cpp
|
statistics/view/abstract_chart_view.cpp
|
||||||
statistics/view/abstract_chart_view.h
|
statistics/view/abstract_chart_view.h
|
||||||
|
|
Loading…
Reference in a new issue