mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added paint of inactive area in footer in chart widget.
This commit is contained in:
parent
40ab042fb5
commit
8ba2e95e6c
1 changed files with 55 additions and 6 deletions
|
@ -14,6 +14,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/effects/animation_value_f.h"
|
#include "ui/effects/animation_value_f.h"
|
||||||
#include "ui/painter.h"
|
#include "ui/painter.h"
|
||||||
#include "ui/rect.h"
|
#include "ui/rect.h"
|
||||||
|
#include "ui/round_rect.h"
|
||||||
|
#include "ui/effects/ripple_animation.h"
|
||||||
|
#include "ui/image/image_prepare.h"
|
||||||
|
#include "styles/style_layers.h"
|
||||||
#include "styles/style_boxes.h"
|
#include "styles/style_boxes.h"
|
||||||
#include "styles/style_statistics.h"
|
#include "styles/style_statistics.h"
|
||||||
|
|
||||||
|
@ -232,6 +236,11 @@ public:
|
||||||
void setFullHeightLimits(Limits limits);
|
void setFullHeightLimits(Limits limits);
|
||||||
[[nodiscard]] const Limits &fullHeightLimits() const;
|
[[nodiscard]] const Limits &fullHeightLimits() const;
|
||||||
|
|
||||||
|
void setPaintChartCallback(Fn<void(QPainter &p)> paintChartCallback);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void paintEvent(QPaintEvent *e) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
not_null<RpMouseWidget*> _left;
|
not_null<RpMouseWidget*> _left;
|
||||||
not_null<RpMouseWidget*> _right;
|
not_null<RpMouseWidget*> _right;
|
||||||
|
@ -246,16 +255,25 @@ private:
|
||||||
int right = 0;
|
int right = 0;
|
||||||
} _limits;
|
} _limits;
|
||||||
|
|
||||||
|
Fn<void(QPainter &p)> _paintChartCallback;
|
||||||
|
const std::array<QImage, 4> _corners;
|
||||||
|
|
||||||
|
QImage _frame;
|
||||||
|
QImage _mask;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ChartWidget::Footer::Footer(not_null<Ui::RpWidget*> parent)
|
ChartWidget::Footer::Footer(not_null<Ui::RpWidget*> parent)
|
||||||
: Ui::AbstractButton(parent)
|
: Ui::AbstractButton(parent)
|
||||||
, _left(Ui::CreateChild<RpMouseWidget>(this))
|
, _left(Ui::CreateChild<RpMouseWidget>(this))
|
||||||
, _right(Ui::CreateChild<RpMouseWidget>(this)) {
|
, _right(Ui::CreateChild<RpMouseWidget>(this))
|
||||||
|
, _corners(Images::PrepareCorners(ImageRoundRadius::Small, st::boxBg)) {
|
||||||
sizeValue(
|
sizeValue(
|
||||||
) | rpl::start_with_next([=](const QSize &s) {
|
) | rpl::start_with_next([=](const QSize &s) {
|
||||||
_left->resize(st::colorSliderWidth, s.height());
|
_left->resize(st::colorSliderWidth, s.height());
|
||||||
_right->resize(st::colorSliderWidth, s.height());
|
_right->resize(st::colorSliderWidth, s.height());
|
||||||
|
_mask = Ui::RippleAnimation::RoundRectMask(s, st::boxRadius);
|
||||||
|
_frame = _mask;
|
||||||
}, _left->lifetime());
|
}, _left->lifetime());
|
||||||
_left->paintRequest(
|
_left->paintRequest(
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
|
@ -313,6 +331,7 @@ ChartWidget::Footer::Footer(not_null<Ui::RpWidget*> parent)
|
||||||
_limits = {};
|
_limits = {};
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
|
update();
|
||||||
}, side->lifetime());
|
}, side->lifetime());
|
||||||
};
|
};
|
||||||
handleDrag(
|
handleDrag(
|
||||||
|
@ -325,6 +344,38 @@ ChartWidget::Footer::Footer(not_null<Ui::RpWidget*> parent)
|
||||||
[=] { return width() - _right->width(); });
|
[=] { return width() - _right->width(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChartWidget::Footer::setPaintChartCallback(
|
||||||
|
Fn<void(QPainter &p)> paintChartCallback) {
|
||||||
|
_paintChartCallback = std::move(paintChartCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChartWidget::Footer::paintEvent(QPaintEvent *e) {
|
||||||
|
auto p = QPainter(this);
|
||||||
|
|
||||||
|
const auto r = rect();
|
||||||
|
const auto inactiveLeftRect = Rect(QSize(_left->x(), r.height()));
|
||||||
|
const auto inactiveRightRect = r
|
||||||
|
- QMargins({ rect::right(_right), 0, 0, 0 });
|
||||||
|
const auto &inactiveColor = st::shadowFg;
|
||||||
|
|
||||||
|
_frame.fill(Qt::transparent);
|
||||||
|
{
|
||||||
|
auto p = QPainter(&_frame);
|
||||||
|
|
||||||
|
if (_paintChartCallback) {
|
||||||
|
_paintChartCallback(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
p.fillRect(inactiveLeftRect, inactiveColor);
|
||||||
|
p.fillRect(inactiveRightRect, inactiveColor);
|
||||||
|
|
||||||
|
p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
|
||||||
|
p.drawImage(0, 0, _mask);
|
||||||
|
}
|
||||||
|
|
||||||
|
p.drawImage(0, 0, _frame);
|
||||||
|
}
|
||||||
|
|
||||||
rpl::producer<Limits> ChartWidget::Footer::xPercentageLimitsChange() const {
|
rpl::producer<Limits> ChartWidget::Footer::xPercentageLimitsChange() const {
|
||||||
return _xPercentageLimitsChange.events();
|
return _xPercentageLimitsChange.events();
|
||||||
}
|
}
|
||||||
|
@ -767,10 +818,8 @@ void ChartWidget::updateBottomDates() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChartWidget::setupFooter() {
|
void ChartWidget::setupFooter() {
|
||||||
_footer->paintRequest(
|
_footer->setPaintChartCallback([=, fullXLimits = Limits{ 0., 1. }](
|
||||||
) | rpl::start_with_next([=, fullXLimits = Limits{ 0., 1. }] {
|
QPainter &p) {
|
||||||
auto p = QPainter(_footer.get());
|
|
||||||
|
|
||||||
if (_chartData) {
|
if (_chartData) {
|
||||||
auto detailsPaintContext = DetailsPaintContext{ .xIndex = -1 };
|
auto detailsPaintContext = DetailsPaintContext{ .xIndex = -1 };
|
||||||
p.fillRect(_footer->rect(), st::boxBg);
|
p.fillRect(_footer->rect(), st::boxBg);
|
||||||
|
@ -782,7 +831,7 @@ void ChartWidget::setupFooter() {
|
||||||
_footer->rect(),
|
_footer->rect(),
|
||||||
detailsPaintContext);
|
detailsPaintContext);
|
||||||
}
|
}
|
||||||
}, _footer->lifetime());
|
});
|
||||||
|
|
||||||
rpl::merge(
|
rpl::merge(
|
||||||
_animationController.heightAnimationStarts(),
|
_animationController.heightAnimationStarts(),
|
||||||
|
|
Loading…
Add table
Reference in a new issue