mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-14 13:17:08 +02:00
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 "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,
|
||||
|
|
|
@ -42,7 +42,7 @@ private:
|
|||
QPen _rightPen;
|
||||
int _leftLineId = 0;
|
||||
int _rightLineId = 0;
|
||||
const style::icon *_currencyIcon = nullptr;
|
||||
QImage _currencyIcon;
|
||||
|
||||
Fn<QString(float64)> _leftCustomCaption = nullptr;
|
||||
Fn<QString(float64)> _rightCustomCaption = nullptr;
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue