Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Add rectangle above color sampler preview option

Carsten Hartenfels3cc9ce4259cf
diff --git a/libs/ui/dialogs/kis_dlg_preferences.cc b/libs/ui/dialogs/kis_dlg_preferences.cc
index 74a6cd93f7..523bad4f09 100644
--- a/libs/ui/dialogs/kis_dlg_preferences.cc
+++ b/libs/ui/dialogs/kis_dlg_preferences.cc
@@ -1059,6 +1059,7 @@ void GeneralTab::setColorSamplerPreviewStyleItems(QComboBox *cmb)
i18nc("Preview option for a circular/ring-shaped color sampler", "Circle"),
i18nc("Preview option for a rectangular color sampler left of the cursor", "Rectangle Left"),
i18nc("Preview option for a rectangular color sampler right of the cursor", "Rectangle Right"),
+ i18nc("Preview option for a rectangular color sampler above the cursor", "Rectangle Above"),
});
}
diff --git a/libs/ui/kis_config.h b/libs/ui/kis_config.h
index a18472471e..5752fbba64 100644
--- a/libs/ui/kis_config.h
+++ b/libs/ui/kis_config.h
@@ -140,6 +140,7 @@ public:
Circle,
RectangleLeft,
RectangleRight,
+ RectangleAbove,
Count,
};
diff --git a/libs/ui/tool/KisAsyncColorSamplerHelper.cpp b/libs/ui/tool/KisAsyncColorSamplerHelper.cpp
index 5d521ea2a6..679c55fa1d 100644
--- a/libs/ui/tool/KisAsyncColorSamplerHelper.cpp
+++ b/libs/ui/tool/KisAsyncColorSamplerHelper.cpp
@@ -41,6 +41,7 @@ bool colorPreviewHasForegroundComparison(KisConfig::ColorSamplerPreviewStyle sty
switch (style) {
case KisConfig::ColorSamplerPreviewStyle::RectangleLeft:
case KisConfig::ColorSamplerPreviewStyle::RectangleRight:
+ case KisConfig::ColorSamplerPreviewStyle::RectangleAbove:
return true;
default:
return false;
@@ -100,19 +101,44 @@ struct KisAsyncColorSamplerHelper::Private
return *canvas->imageView()->viewConverter();
}
- QRectF colorPreviewRectForRectangle(bool left)
+ QRectF colorPreviewRectForRectangle() const
{
+ // Offsetting to the sides is both vertical and horizontal, when
+ // offsetting above it's only vertical, so it needs a bit more space.
constexpr qreal OFFSET = 32.0;
+ constexpr qreal OFFSET_ABOVE = OFFSET * 1.5;
constexpr qreal SIZE = PREVIEW_RECT_SIZE;
bool mirrored = canvas->xAxisMirrored();
- if (mirrored) {
- left = !left;
+ bool flipped = canvas->yAxisMirrored();
+
+ KisConfig::ColorSamplerPreviewStyle effectiveStyle;
+ if (mirrored && style == KisConfig::ColorSamplerPreviewStyle::RectangleLeft) {
+ effectiveStyle = KisConfig::ColorSamplerPreviewStyle::RectangleRight;
+ } else if (mirrored && style == KisConfig::ColorSamplerPreviewStyle::RectangleRight) {
+ effectiveStyle = KisConfig::ColorSamplerPreviewStyle::RectangleLeft;
+ } else {
+ effectiveStyle = style;
}
qreal width = haveSample ? SIZE * 2.0 : SIZE;
- qreal x = left ? -(OFFSET + width) : OFFSET;
- qreal y = canvas->yAxisMirrored() ? -(OFFSET + SIZE) : OFFSET;
+
+ qreal x, y;
+ switch (effectiveStyle) {
+ case KisConfig::ColorSamplerPreviewStyle::RectangleLeft:
+ x = -(OFFSET + width);
+ y = flipped ? -(OFFSET + SIZE) : OFFSET;
+ break;
+ case KisConfig::ColorSamplerPreviewStyle::RectangleRight:
+ x = OFFSET;
+ y = flipped ? -(OFFSET + SIZE) : OFFSET;
+ break;
+ default:
+ x = width / -2.0;
+ y = flipped ? OFFSET_ABOVE : -(OFFSET_ABOVE + SIZE);
+ break;
+ }
+
QRectF rect(x, y, width, SIZE);
qreal canvasRotationAngle = canvas->rotationAngle();
@@ -137,10 +163,9 @@ struct KisAsyncColorSamplerHelper::Private
case KisConfig::ColorSamplerPreviewStyle::None:
return QRectF();
case KisConfig::ColorSamplerPreviewStyle::RectangleLeft:
- colorPreviewViewRect = colorPreviewRectForRectangle(true);
- break;
case KisConfig::ColorSamplerPreviewStyle::RectangleRight:
- colorPreviewViewRect = colorPreviewRectForRectangle(false);
+ case KisConfig::ColorSamplerPreviewStyle::RectangleAbove:
+ colorPreviewViewRect = colorPreviewRectForRectangle();
break;
default:
if (!haveSample) {
@@ -345,6 +370,7 @@ void KisAsyncColorSamplerHelper::paint(QPainter &gc, const KoViewConverter &conv
switch (m_d->style) {
case KisConfig::ColorSamplerPreviewStyle::RectangleLeft:
case KisConfig::ColorSamplerPreviewStyle::RectangleRight:
+ case KisConfig::ColorSamplerPreviewStyle::RectangleAbove:
paintRectangle(gc, viewRectF, currentColor, baseColor);
break;
default: