[calligra/calligra/2.9] krita: [FEATURE] Make color picking with shortcuts work in Wrap Around mode
Dmitry Kazakov
dimula73 at gmail.com
Thu Aug 20 14:21:42 UTC 2015
Git commit cdd7a6162cae1a0c9231a47956bfbd55a2fa53aa by Dmitry Kazakov.
Committed on 20/08/2015 at 14:21.
Pushed by dkazakov into branch 'calligra/2.9'.
[FEATURE] Make color picking with shortcuts work in Wrap Around mode
CC:kimageshop at kde.org
BUG:336122
M +19 -3 krita/plugins/tools/defaulttools/kis_tool_colorpicker.cc
M +1 -1 krita/ui/tool/kis_tool_paint.cc
M +17 -0 krita/ui/tool/kis_tool_utils.cpp
M +7 -0 krita/ui/tool/kis_tool_utils.h
http://commits.kde.org/calligra/cdd7a6162cae1a0c9231a47956bfbd55a2fa53aa
diff --git a/krita/plugins/tools/defaulttools/kis_tool_colorpicker.cc b/krita/plugins/tools/defaulttools/kis_tool_colorpicker.cc
index 4806a27..1615c2a 100644
--- a/krita/plugins/tools/defaulttools/kis_tool_colorpicker.cc
+++ b/krita/plugins/tools/defaulttools/kis_tool_colorpicker.cc
@@ -52,6 +52,9 @@
#include <KoChannelInfo.h>
#include <KoMixColorsOp.h>
+#include "kis_wrapped_rect.h"
+
+
namespace
{
// The location of the sample all visible layers in the combobox
@@ -177,7 +180,12 @@ void KisToolColorPicker::pickColor(const QPointF& pos)
}
if (m_config.radius == 1) {
- dev->pixel(pos.x(), pos.y(), &m_pickedColor);
+ QPoint realPos = pos.toPoint();
+ if (currentImage()->wrapAroundModePermitted()) {
+ realPos = KisWrappedRect::ptToWrappedPt(realPos, currentImage()->bounds());
+ }
+
+ dev->pixel(realPos.x(), realPos.y(), &m_pickedColor);
}
else {
@@ -193,7 +201,14 @@ void KisToolColorPicker::pickColor(const QPointF& pos)
for (int y = -m_config.radius; y <= m_config.radius; y++) {
for (int x = -m_config.radius; x <= m_config.radius; x++) {
if (((x * x) + (y * y)) < m_config.radius * m_config.radius) {
- accessor->moveTo(pos.x() + x, pos.y() + y);
+
+ QPoint realPos(pos.x() + x, pos.y() + y);
+
+ if (currentImage()->wrapAroundModePermitted()) {
+ realPos = KisWrappedRect::ptToWrappedPt(realPos, currentImage()->bounds());
+ }
+
+ accessor->moveTo(realPos.x(), realPos.y());
pixels << accessor->oldRawData();
}
}
@@ -248,7 +263,8 @@ void KisToolColorPicker::beginPrimaryAction(KoPointerEvent *event)
QPoint pos = convertToIntPixelCoord(event);
// the color picking has to start in the visible part of the layer
- if (!currentImage()->bounds().contains(pos)) {
+ if (!currentImage()->bounds().contains(pos) &&
+ !currentImage()->wrapAroundModePermitted()) {
event->ignore();
return;
}
diff --git a/krita/ui/tool/kis_tool_paint.cc b/krita/ui/tool/kis_tool_paint.cc
index 52eb823..f712c2f 100644
--- a/krita/ui/tool/kis_tool_paint.cc
+++ b/krita/ui/tool/kis_tool_paint.cc
@@ -395,7 +395,7 @@ bool KisToolPaint::pickColor(const QPointF &documentPixel,
KoColor color;
QColor previewColor;
- if (KisToolUtils::pick(device, imagePoint, &color)) {
+ if (KisToolUtils::pickWrapped(device, imagePoint, &color, image())) {
canvas()->resourceManager()->setResource(resource, color);
KisCanvas2 * kisCanvas = dynamic_cast<KisCanvas2*>(canvas());
diff --git a/krita/ui/tool/kis_tool_utils.cpp b/krita/ui/tool/kis_tool_utils.cpp
index 3bb2d01..3dfe206 100644
--- a/krita/ui/tool/kis_tool_utils.cpp
+++ b/krita/ui/tool/kis_tool_utils.cpp
@@ -21,9 +21,26 @@
#include <kis_paint_device.h>
#include <kis_layer.h>
#include <kis_group_layer.h>
+#include <kis_wrapped_rect.h>
+#include <kis_image.h>
+
namespace KisToolUtils {
+ bool pickWrapped(KisPaintDeviceSP dev, QPoint pos, KoColor *color, KisImageSP image)
+ {
+ if (!image->tryBarrierLock()) return false;
+
+ if (image->wrapAroundModePermitted()) {
+ pos = KisWrappedRect::ptToWrappedPt(pos, image->bounds());
+ }
+
+ bool result = pick(dev, pos, color);
+
+ image->unlock();
+ return result;
+ }
+
bool pick(KisPaintDeviceSP dev, const QPoint& pos, KoColor *color)
{
KIS_ASSERT(dev);
diff --git a/krita/ui/tool/kis_tool_utils.h b/krita/ui/tool/kis_tool_utils.h
index 3164b3c..57e5bbd 100644
--- a/krita/ui/tool/kis_tool_utils.h
+++ b/krita/ui/tool/kis_tool_utils.h
@@ -26,6 +26,13 @@
namespace KisToolUtils {
+
+/**
+ * return the color at the given position on the given paint device.
+ * NOTE: the function takes wraparound mode and image locking into account
+ */
+bool pickWrapped(KisPaintDeviceSP dev, QPoint pos, KoColor *color, KisImageSP image);
+
/**
* return the color at the given position on the given paint device.
*/
More information about the kimageshop
mailing list