mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-08 16:13:56 +02:00
Added support to hide chart elements with opacity from chart view.
This commit is contained in:
parent
a9b0464726
commit
7ac9ab3a51
4 changed files with 26 additions and 12 deletions
|
@ -47,6 +47,7 @@ void PaintBottomLine(
|
||||||
int y,
|
int y,
|
||||||
int captionIndicesOffset) {
|
int captionIndicesOffset) {
|
||||||
p.setFont(st::statisticsDetailsBottomCaptionStyle.font);
|
p.setFont(st::statisticsDetailsBottomCaptionStyle.font);
|
||||||
|
const auto opacity = p.opacity();
|
||||||
|
|
||||||
const auto startXIndex = chartData.findStartIndex(
|
const auto startXIndex = chartData.findStartIndex(
|
||||||
xPercentageLimits.min);
|
xPercentageLimits.min);
|
||||||
|
@ -105,7 +106,8 @@ void PaintBottomLine(
|
||||||
0.,
|
0.,
|
||||||
1. + ((chartWidth - rect::right(r)) / edgeAlphaSize))
|
1. + ((chartWidth - rect::right(r)) / edgeAlphaSize))
|
||||||
: 1.;
|
: 1.;
|
||||||
p.setOpacity(edgeAlpha
|
p.setOpacity(opacity
|
||||||
|
* edgeAlpha
|
||||||
* (hasFastAlpha ? fastAlpha : resultAlpha));
|
* (hasFastAlpha ? fastAlpha : resultAlpha));
|
||||||
p.drawText(r, chartData.getDayString(i), style::al_center);
|
p.drawText(r, chartData.getDayString(i), style::al_center);
|
||||||
}
|
}
|
||||||
|
@ -450,7 +452,11 @@ void ChartWidget::Footer::paintEvent(QPaintEvent *e) {
|
||||||
if (_paintChartCallback) {
|
if (_paintChartCallback) {
|
||||||
auto q = QPainter(&_frame);
|
auto q = QPainter(&_frame);
|
||||||
|
|
||||||
|
{
|
||||||
|
const auto opacity = q.opacity();
|
||||||
_paintChartCallback(q, Rect(innerRect.size()));
|
_paintChartCallback(q, Rect(innerRect.size()));
|
||||||
|
q.setOpacity(opacity);
|
||||||
|
}
|
||||||
|
|
||||||
q.setCompositionMode(QPainter::CompositionMode_DestinationIn);
|
q.setCompositionMode(QPainter::CompositionMode_DestinationIn);
|
||||||
q.drawImage(0, 0, _mask);
|
q.drawImage(0, 0, _mask);
|
||||||
|
|
|
@ -39,9 +39,9 @@ void ChartHorizontalLinesView::setChartData(
|
||||||
void ChartHorizontalLinesView::paintHorizontalLines(
|
void ChartHorizontalLinesView::paintHorizontalLines(
|
||||||
QPainter &p,
|
QPainter &p,
|
||||||
const QRect &r) {
|
const QRect &r) {
|
||||||
for (auto &horizontalLine : _horizontalLines) {
|
|
||||||
const auto alpha = p.opacity();
|
const auto alpha = p.opacity();
|
||||||
p.setOpacity(horizontalLine.alpha);
|
for (auto &horizontalLine : _horizontalLines) {
|
||||||
|
p.setOpacity(alpha * horizontalLine.alpha);
|
||||||
for (const auto &line : horizontalLine.lines) {
|
for (const auto &line : horizontalLine.lines) {
|
||||||
const auto lineRect = QRect(
|
const auto lineRect = QRect(
|
||||||
0,
|
0,
|
||||||
|
@ -50,8 +50,8 @@ void ChartHorizontalLinesView::paintHorizontalLines(
|
||||||
st::lineWidth);
|
st::lineWidth);
|
||||||
p.fillRect(lineRect, st::windowSubTextFg);
|
p.fillRect(lineRect, st::windowSubTextFg);
|
||||||
}
|
}
|
||||||
p.setOpacity(alpha);
|
|
||||||
}
|
}
|
||||||
|
p.setOpacity(alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChartHorizontalLinesView::paintCaptionsToHorizontalLines(
|
void ChartHorizontalLinesView::paintCaptionsToHorizontalLines(
|
||||||
|
@ -59,9 +59,9 @@ void ChartHorizontalLinesView::paintCaptionsToHorizontalLines(
|
||||||
const QRect &r) {
|
const QRect &r) {
|
||||||
const auto offset = r.y() - st::statisticsChartHorizontalLineCaptionSkip;
|
const auto offset = r.y() - st::statisticsChartHorizontalLineCaptionSkip;
|
||||||
p.setFont(st::statisticsDetailsBottomCaptionStyle.font);
|
p.setFont(st::statisticsDetailsBottomCaptionStyle.font);
|
||||||
for (auto &horizontalLine : _horizontalLines) {
|
|
||||||
const auto alpha = p.opacity();
|
const auto alpha = p.opacity();
|
||||||
p.setOpacity(horizontalLine.alpha);
|
for (auto &horizontalLine : _horizontalLines) {
|
||||||
|
p.setOpacity(alpha * horizontalLine.alpha);
|
||||||
for (const auto &line : horizontalLine.lines) {
|
for (const auto &line : horizontalLine.lines) {
|
||||||
const auto y = offset + r.height() * line.relativeValue;
|
const auto y = offset + r.height() * line.relativeValue;
|
||||||
p.setPen(_isDouble ? _leftPen : st::windowSubTextFg);
|
p.setPen(_isDouble ? _leftPen : st::windowSubTextFg);
|
||||||
|
@ -83,8 +83,8 @@ void ChartHorizontalLinesView::paintCaptionsToHorizontalLines(
|
||||||
: line.scaledLineCaption);
|
: line.scaledLineCaption);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.setOpacity(alpha);
|
|
||||||
}
|
}
|
||||||
|
p.setOpacity(alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChartHorizontalLinesView::computeRelative(
|
void ChartHorizontalLinesView::computeRelative(
|
||||||
|
|
|
@ -71,6 +71,7 @@ void LinearChartView::paint(QPainter &p, const PaintContext &c) {
|
||||||
c.heightLimits,
|
c.heightLimits,
|
||||||
c.rect.size());
|
c.rect.size());
|
||||||
|
|
||||||
|
const auto opacity = p.opacity();
|
||||||
const auto imageSize = c.rect.size() * style::DevicePixelRatio();
|
const auto imageSize = c.rect.size() * style::DevicePixelRatio();
|
||||||
const auto cacheScale = 1. / style::DevicePixelRatio();
|
const auto cacheScale = 1. / style::DevicePixelRatio();
|
||||||
auto &caches = (c.footer ? _footerCaches : _mainCaches);
|
auto &caches = (c.footer ? _footerCaches : _mainCaches);
|
||||||
|
@ -117,6 +118,7 @@ void LinearChartView::paint(QPainter &p, const PaintContext &c) {
|
||||||
cache.lastToken = cacheToken;
|
cache.lastToken = cacheToken;
|
||||||
cache.image = std::move(image);
|
cache.image = std::move(image);
|
||||||
}
|
}
|
||||||
|
p.setOpacity(opacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LinearChartView::paintSelectedXIndex(
|
void LinearChartView::paintSelectedXIndex(
|
||||||
|
|
|
@ -130,10 +130,11 @@ void StackLinearChartView::paintChartOrZoomAnimation(
|
||||||
const PaintContext &c) {
|
const PaintContext &c) {
|
||||||
if (_transitionProgress == 1.) {
|
if (_transitionProgress == 1.) {
|
||||||
if (c.footer) {
|
if (c.footer) {
|
||||||
return paintZoomedFooter(p, c);
|
paintZoomedFooter(p, c);
|
||||||
} else {
|
} else {
|
||||||
return paintZoomed(p, c);
|
paintZoomed(p, c);
|
||||||
}
|
}
|
||||||
|
return p.setOpacity(0.);
|
||||||
}
|
}
|
||||||
const auto &[localStart, localEnd] = _lastPaintedXIndices;
|
const auto &[localStart, localEnd] = _lastPaintedXIndices;
|
||||||
_skipPoints = std::vector<bool>(c.chartData.lines.size(), false);
|
_skipPoints = std::vector<bool>(c.chartData.lines.size(), false);
|
||||||
|
@ -365,7 +366,7 @@ void StackLinearChartView::paintChartOrZoomAnimation(
|
||||||
|
|
||||||
auto hq = PainterHighQualityEnabler(p);
|
auto hq = PainterHighQualityEnabler(p);
|
||||||
|
|
||||||
p.fillRect(c.rect, st::boxBg);
|
p.fillRect(c.rect + QMargins(0, 0, 0, st::lineWidth), st::boxBg);
|
||||||
if (!ovalPath.isEmpty()) {
|
if (!ovalPath.isEmpty()) {
|
||||||
p.setClipPath(ovalPath);
|
p.setClipPath(ovalPath);
|
||||||
}
|
}
|
||||||
|
@ -401,13 +402,18 @@ void StackLinearChartView::paintChartOrZoomAnimation(
|
||||||
p.setPen(st::boxBg);
|
p.setPen(st::boxBg);
|
||||||
p.drawPath(ovalPath);
|
p.drawPath(ovalPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!ovalPath.isEmpty()) {
|
||||||
|
p.setClipRect(c.rect, Qt::NoClip);
|
||||||
|
}
|
||||||
|
p.setOpacity(1. - _transitionProgress);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StackLinearChartView::paintZoomed(QPainter &p, const PaintContext &c) {
|
void StackLinearChartView::paintZoomed(QPainter &p, const PaintContext &c) {
|
||||||
if (c.footer) {
|
if (c.footer) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
p.fillRect(c.rect, st::boxBg);
|
p.fillRect(c.rect + QMargins(0, 0, 0, st::lineWidth), st::boxBg);
|
||||||
const auto center = QPointF(c.rect.center());
|
const auto center = QPointF(c.rect.center());
|
||||||
const auto side = (c.rect.width() / 2.) * kCircleSizeRatio;
|
const auto side = (c.rect.width() / 2.) * kCircleSizeRatio;
|
||||||
const auto rectF = QRectF(
|
const auto rectF = QRectF(
|
||||||
|
|
Loading…
Add table
Reference in a new issue