From 877f1713c127316fec284706cdf06dcaf8d1711c Mon Sep 17 00:00:00 2001 From: askmeaboutloom Date: Wed, 23 Oct 2024 07:26:55 +0200 Subject: [PATCH] Properly apply opacity to non-editable fills They previewed correctly, but then got applied with 100% opacity instead. --- src/libclient/tools/floodfill.cpp | 18 +++++++++--------- src/libclient/tools/floodfill.h | 3 ++- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/libclient/tools/floodfill.cpp b/src/libclient/tools/floodfill.cpp index 1ef64871bd..3bd7555615 100644 --- a/src/libclient/tools/floodfill.cpp +++ b/src/libclient/tools/floodfill.cpp @@ -241,6 +241,7 @@ void FloodFill::fillAt(const QPointF &point, int activeLayerId, bool editable) m_lastActiveLayerId = activeLayerId; m_originalLayerId = activeLayerId; m_originalBlendMode = m_blendMode; + m_originalOpacity = m_opacity; QColor fillColor = m_blendMode == DP_BLEND_MODE_ERASE ? Qt::black @@ -366,7 +367,7 @@ void FloodFill::previewPending() disposePending(); } } else { - adjustPendingImage(false); + adjustPendingImage(true, false); canvas->paintEngine()->previewFill( layerId, m_blendMode, m_opacity, m_pendingPos.x(), m_pendingPos.y(), m_pendingImage); @@ -391,9 +392,7 @@ void FloodFill::flushPending() .data(canvas::LayerListModel::IsGroupRole) .toBool(); if(canFill) { - if(m_pendingEditable) { - adjustPendingImage(true); - } + adjustPendingImage(m_pendingEditable, true); net::Client *client = m_owner.client(); uint8_t contextId = client->myId(); net::MessageList msgs; @@ -421,12 +420,13 @@ void FloodFill::disposePending() } } -void FloodFill::adjustPendingImage(bool adjustOpacity) +void FloodFill::adjustPendingImage(bool adjustColor, bool adjustOpacity) { QColor color = m_owner.foregroundColor(); - bool needsColorChange = - m_blendMode != DP_BLEND_MODE_ERASE && m_pendingColor != color; - bool needsOpacityChange = adjustOpacity && m_opacity < 1.0; + qreal opacity = m_pendingEditable ? m_opacity : m_originalOpacity; + bool needsColorChange = adjustColor && m_blendMode != DP_BLEND_MODE_ERASE && + m_pendingColor != color; + bool needsOpacityChange = adjustOpacity && opacity < 1.0; if(needsColorChange || needsOpacityChange) { QPainter painter(&m_pendingImage); QRect rect = m_pendingImage.rect(); @@ -437,7 +437,7 @@ void FloodFill::adjustPendingImage(bool adjustOpacity) } if(needsOpacityChange) { painter.setCompositionMode(QPainter::CompositionMode_DestinationIn); - painter.setOpacity(m_opacity); + painter.setOpacity(opacity); painter.fillRect(rect, Qt::black); } } diff --git a/src/libclient/tools/floodfill.h b/src/libclient/tools/floodfill.h index fac5444695..e42be9abee 100644 --- a/src/libclient/tools/floodfill.h +++ b/src/libclient/tools/floodfill.h @@ -59,7 +59,7 @@ class FloodFill final : public Tool { void flushPending(); void disposePending(); - void adjustPendingImage(bool adjustOpacity); + void adjustPendingImage(bool adjustColor, bool adjustOpacity); void emitFloodFillStateChanged(); @@ -87,6 +87,7 @@ class FloodFill final : public Tool { QColor m_pendingColor; int m_originalLayerId = 0; int m_originalBlendMode; + qreal m_originalOpacity; QCursor m_bucketCursor; QCursor m_pendingCursor; QCursor m_confirmCursor;