[graphics/krita] libs/ui/tool: Change to vector crosshair

Emmet O'Neill <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 9da933ebd0c8f56d94deb4b9fd3bdac778752c46 by Emmet O'Neill, on behalf of Dat Le.
Committed on 13/08/2026 at 23:16.
Pushed by emmetoneill into branch 'master'.

Change to vector crosshair

M  +23   -34   libs/ui/tool/KisAsyncColorSamplerHelper.cpp

https://invent.kde.org/graphics/krita/-/commit/9da933ebd0c8f56d94deb4b9fd3bdac778752c46

diff --git a/libs/ui/tool/KisAsyncColorSamplerHelper.cpp b/libs/ui/tool/KisAsyncColorSamplerHelper.cpp
index c61d4ff98f8..d248b9ab733 100644
--- a/libs/ui/tool/KisAsyncColorSamplerHelper.cpp
+++ b/libs/ui/tool/KisAsyncColorSamplerHelper.cpp
@@ -79,7 +79,7 @@ struct KisAsyncColorSamplerHelper::Private
     QPainterPath cacheCircleInnerClip;
     QRect cacheCanvasPreviewRect;
     QImage cacheCanvasPreviewImage;
-    QImage cacheCrosshairImage;
+    QPainterPath cacheCrosshairPath;
     int cacheCirclePreviewDiameter;
 
     QColor currentColor;
@@ -246,38 +246,28 @@ struct KisAsyncColorSamplerHelper::Private
         return pixelRect;
     }
 
-    QImage crosshairForOffsettedCircle() {
-        if (!cacheCrosshairImage.isNull() && cacheCirclePreviewDiameter == circlePreviewDiameter) return cacheCrosshairImage;
+    QPainterPath crosshairForOffsettedCircle() {
+        if (!cacheCrosshairPath.isEmpty() && cacheCirclePreviewDiameter == circlePreviewDiameter) return cacheCrosshairPath;
 
         cacheCirclePreviewDiameter = circlePreviewDiameter;
 
-        int gap = 4;
+        int gap = 5; // Should be odd so it have a center point
         int crosshairRadius = circlePreviewDiameter / 2 * 0.3;
-        cacheCrosshairImage = QImage(crosshairRadius * 2 + 1, crosshairRadius * 2 + 1, QImage::Format_ARGB32);
-        cacheCrosshairImage.fill(Qt::transparent);
+        cacheCrosshairPath = QPainterPath(QPointF(-crosshairRadius, 0));
 
-        QPainter painter(&cacheCrosshairImage);\
-        painter.translate(crosshairRadius + 1, crosshairRadius + 1);
+        cacheCrosshairPath.lineTo(-gap, 0);
+        cacheCrosshairPath.moveTo(gap, 0);
+        cacheCrosshairPath.lineTo(crosshairRadius, 0);
 
-        painter.setBrush(Qt::NoBrush);
-
-        painter.setPen(Qt::black);
-        painter.drawLine(QLine(-crosshairRadius, 0, crosshairRadius, 0));
-        painter.drawLine(QLine(0, -crosshairRadius, 0, crosshairRadius));
-
-        painter.setPen(Qt::white);
-        painter.drawLine(QLine(-crosshairRadius, 1, crosshairRadius, 1));
-        painter.drawLine(QLine(1, -crosshairRadius, 1, crosshairRadius));
+        QTransform tf;
+        tf.translate(0, 0);
+        tf.rotate(90);
 
-        painter.drawLine(QLine(-crosshairRadius, -1, crosshairRadius, -1));
-        painter.drawLine(QLine(-1, -crosshairRadius, -1, crosshairRadius));
+        cacheCrosshairPath.moveTo(0,0);
 
-        painter.setCompositionMode(QPainter::CompositionMode_Clear);
-        painter.setPen(Qt::NoPen);
-        painter.setBrush(Qt::transparent);
-        painter.drawRect(QRect(QPoint(-gap, -gap), QPoint(gap, gap)));
+        cacheCrosshairPath.addPath(tf.map(cacheCrosshairPath));
 
-        return cacheCrosshairImage;
+        return cacheCrosshairPath;
     }
 };
 
@@ -688,19 +678,18 @@ void KisAsyncColorSamplerHelper::paintCircle(QPainter &gc,
 
         // Draw crosshair if preview is offseted
         if (m_d->circlePreviewPosition != KisConfig::ColorSamplerPreviewCirclePosition::Center) {
-            QImage crosshairImage = m_d->crosshairForOffsettedCircle();
-
-            QRectF targetRect = crosshairImage.rect();
-            targetRect.moveCenter(cacheCenter);
+            QColor crosshairColor = Qt::black;
+            // Apparently this fomular is outdated and inaccurate. But the accurate version require calculating power, probably overkill anyway
+            qreal luminance = (0.299 * currentColor.redF() + 0.587 * currentColor.greenF() + 0.114 * currentColor.blueF());
+            if (luminance < 0.5) crosshairColor = Qt::white;
 
             cachePainter.save();
-            cachePainter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
-
-            cachePainter.translate(cacheCenter);
-            cachePainter.rotate(-m_d->cacheRotation);
-            cachePainter.translate(-cacheCenter);
 
-            cachePainter.drawImage(targetRect, crosshairImage);
+            cachePainter.setPen(crosshairColor);
+            QTransform tf;
+            tf.translate(cacheCenter.x(), cacheCenter.y());
+            tf.rotate(-canvasRotationAngle);
+            cachePainter.drawPath(tf.map(m_d->crosshairForOffsettedCircle()));
 
             cachePainter.restore();
         }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.