Added icon to widget for point details on chart when zoom is enabled.
This commit is contained in:
parent
2106747496
commit
54fecd497e
|
@ -8,6 +8,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "statistics/point_details_widget.h"
|
#include "statistics/point_details_widget.h"
|
||||||
|
|
||||||
#include "ui/cached_round_corners.h"
|
#include "ui/cached_round_corners.h"
|
||||||
|
#include "ui/effects/ripple_animation.h"
|
||||||
|
#include "ui/painter.h"
|
||||||
#include "ui/rect.h"
|
#include "ui/rect.h"
|
||||||
#include "ui/widgets/shadow.h"
|
#include "ui/widgets/shadow.h"
|
||||||
#include "styles/style_layers.h"
|
#include "styles/style_layers.h"
|
||||||
|
@ -35,13 +37,38 @@ PointDetailsWidget::PointDetailsWidget(
|
||||||
const Data::StatisticalChart &chartData,
|
const Data::StatisticalChart &chartData,
|
||||||
float64 maxAbsoluteValue,
|
float64 maxAbsoluteValue,
|
||||||
bool zoomEnabled)
|
bool zoomEnabled)
|
||||||
: Ui::AbstractButton(parent)
|
: Ui::RippleButton(parent, st::defaultRippleAnimation)
|
||||||
, _zoomEnabled(zoomEnabled)
|
, _zoomEnabled(zoomEnabled)
|
||||||
, _chartData(chartData)
|
, _chartData(chartData)
|
||||||
, _textStyle(st::statisticsDetailsPopupStyle)
|
, _textStyle(st::statisticsDetailsPopupStyle)
|
||||||
, _headerStyle(st::statisticsDetailsPopupHeaderStyle)
|
, _headerStyle(st::statisticsDetailsPopupHeaderStyle)
|
||||||
, _longFormat(u"ddd, MMM d hh:mm"_q)
|
, _longFormat(u"ddd, MMM d hh:mm"_q)
|
||||||
, _shortFormat(u"ddd, MMM d"_q) {
|
, _shortFormat(u"ddd, MMM d"_q) {
|
||||||
|
|
||||||
|
if (zoomEnabled) {
|
||||||
|
rpl::single(rpl::empty_value()) | rpl::then(
|
||||||
|
style::PaletteChanged()
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
const auto w = st::statisticsDetailsArrowShift;
|
||||||
|
const auto stroke = style::ConvertScaleExact(
|
||||||
|
st::statisticsDetailsArrowStroke);
|
||||||
|
_arrow = QImage(
|
||||||
|
QSize(w + stroke, w * 2 + stroke) * style::DevicePixelRatio(),
|
||||||
|
QImage::Format_ARGB32_Premultiplied);
|
||||||
|
_arrow.fill(Qt::transparent);
|
||||||
|
{
|
||||||
|
auto p = QPainter(&_arrow);
|
||||||
|
|
||||||
|
const auto hq = PainterHighQualityEnabler(p);
|
||||||
|
const auto s = stroke / 2.;
|
||||||
|
|
||||||
|
p.setPen(QPen(st::windowSubTextFg, stroke));
|
||||||
|
p.drawLine(QLineF(s, s, w, w + s));
|
||||||
|
p.drawLine(QLineF(s, s + w * 2, w, w + s));
|
||||||
|
}
|
||||||
|
}, lifetime());
|
||||||
|
}
|
||||||
|
|
||||||
const auto calculatedWidth = [&]{
|
const auto calculatedWidth = [&]{
|
||||||
const auto maxValueText = Ui::Text::String(
|
const auto maxValueText = Ui::Text::String(
|
||||||
_textStyle,
|
_textStyle,
|
||||||
|
@ -171,6 +198,7 @@ void PointDetailsWidget::paintEvent(QPaintEvent *e) {
|
||||||
|
|
||||||
Ui::Shadow::paint(p, _innerRect, width(), st::boxRoundShadow);
|
Ui::Shadow::paint(p, _innerRect, width(), st::boxRoundShadow);
|
||||||
Ui::FillRoundRect(p, _innerRect, st::boxBg, Ui::BoxCorners);
|
Ui::FillRoundRect(p, _innerRect, st::boxBg, Ui::BoxCorners);
|
||||||
|
Ui::RippleButton::paintRipple(p, _innerRect.topLeft());
|
||||||
|
|
||||||
p.setPen(st::boxTextFg);
|
p.setPen(st::boxTextFg);
|
||||||
const auto headerContext = Ui::Text::PaintContext{
|
const auto headerContext = Ui::Text::PaintContext{
|
||||||
|
@ -196,6 +224,24 @@ void PointDetailsWidget::paintEvent(QPaintEvent *e) {
|
||||||
p.setPen(line.valueColor);
|
p.setPen(line.valueColor);
|
||||||
line.value.draw(p, valueContext);
|
line.value.draw(p, valueContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_zoomEnabled) {
|
||||||
|
const auto s = _arrow.size() / style::DevicePixelRatio();
|
||||||
|
const auto x = rect::right(_textRect) - s.width();
|
||||||
|
const auto y = _textRect.y()
|
||||||
|
+ (_headerStyle.font->height - s.height()) / 2.;
|
||||||
|
p.drawImage(x, y, _arrow);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QPoint PointDetailsWidget::prepareRippleStartPosition() const {
|
||||||
|
return mapFromGlobal(QCursor::pos()) - _innerRect.topLeft();
|
||||||
|
}
|
||||||
|
|
||||||
|
QImage PointDetailsWidget::prepareRippleMask() const {
|
||||||
|
return Ui::RippleAnimation::RoundRectMask(
|
||||||
|
_innerRect.size(),
|
||||||
|
st::boxRadius);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Statistic
|
} // namespace Statistic
|
||||||
|
|
|
@ -8,11 +8,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "data/data_statistics.h"
|
#include "data/data_statistics.h"
|
||||||
#include "ui/abstract_button.h"
|
#include "ui/widgets/buttons.h"
|
||||||
|
|
||||||
namespace Statistic {
|
namespace Statistic {
|
||||||
|
|
||||||
class PointDetailsWidget : public Ui::AbstractButton {
|
class PointDetailsWidget : public Ui::RippleButton {
|
||||||
public:
|
public:
|
||||||
PointDetailsWidget(
|
PointDetailsWidget(
|
||||||
not_null<Ui::RpWidget*> parent,
|
not_null<Ui::RpWidget*> parent,
|
||||||
|
@ -29,6 +29,9 @@ public:
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *e) override;
|
void paintEvent(QPaintEvent *e) override;
|
||||||
|
|
||||||
|
QImage prepareRippleMask() const override;
|
||||||
|
QPoint prepareRippleStartPosition() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const bool _zoomEnabled;
|
const bool _zoomEnabled;
|
||||||
const Data::StatisticalChart &_chartData;
|
const Data::StatisticalChart &_chartData;
|
||||||
|
@ -52,6 +55,7 @@ private:
|
||||||
|
|
||||||
QRect _innerRect;
|
QRect _innerRect;
|
||||||
QRect _textRect;
|
QRect _textRect;
|
||||||
|
QImage _arrow;
|
||||||
|
|
||||||
int _xIndex = -1;
|
int _xIndex = -1;
|
||||||
float64 _alpha = 1.;
|
float64 _alpha = 1.;
|
||||||
|
|
|
@ -12,6 +12,8 @@ using "ui/widgets/widgets.style";
|
||||||
|
|
||||||
statisticsChartHeight: 150px;
|
statisticsChartHeight: 150px;
|
||||||
|
|
||||||
|
statisticsDetailsArrowShift: 2px;
|
||||||
|
statisticsDetailsArrowStroke: 1.5;
|
||||||
statisticsDetailsPopupMargins: margins(8px, 8px, 8px, 8px);
|
statisticsDetailsPopupMargins: margins(8px, 8px, 8px, 8px);
|
||||||
statisticsDetailsPopupPadding: margins(6px, 6px, 6px, 6px);
|
statisticsDetailsPopupPadding: margins(6px, 6px, 6px, 6px);
|
||||||
statisticsDetailsPopupMidLineSpace: 4px;
|
statisticsDetailsPopupMidLineSpace: 4px;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user