Added ability to move slider in chart widget footer from outside.

This commit is contained in:
23rd 2023-09-18 22:25:22 +03:00 committed by John Preston
parent c5f294a1ac
commit e4e85e5a39
1 changed files with 20 additions and 3 deletions

View File

@ -215,6 +215,9 @@ public:
Footer(not_null<Ui::RpWidget*> parent);
void setXPercentageLimits(const Limits &xLimits);
[[nodiscard]] Limits xPercentageLimits() const;
[[nodiscard]] rpl::producer<Limits> xPercentageLimitsChange() const;
[[nodiscard]] rpl::producer<> userInteractionFinished() const;
@ -355,11 +358,15 @@ ChartWidget::Footer::Footer(not_null<Ui::RpWidget*> parent)
}, lifetime());
}
void ChartWidget::Footer::fire() const {
_xPercentageLimitsChange.fire({
Limits ChartWidget::Footer::xPercentageLimits() const {
return {
.min = _leftSide.min / float64(width()),
.max = _rightSide.max / float64(width()),
});
};
}
void ChartWidget::Footer::fire() const {
_xPercentageLimitsChange.fire(xPercentageLimits());
}
void ChartWidget::Footer::moveCenter(
@ -482,6 +489,16 @@ void ChartWidget::Footer::paintEvent(QPaintEvent *e) {
p.drawImage(_rightSide.min, 0, _rightCache);
}
void ChartWidget::Footer::setXPercentageLimits(const Limits &xLimits) {
const auto left = xLimits.min * width();
const auto w = float64(st::statisticsChartFooterSideWidth);
const auto right = xLimits.max * width() - w;
moveSide(true, left);
moveSide(false, right);
fire();
update();
}
rpl::producer<Limits> ChartWidget::Footer::xPercentageLimitsChange() const {
return _xPercentageLimitsChange.events();
}