Commit d9a09cc9 authored by Dmitry Kazakov's avatar Dmitry Kazakov
Browse files

[FEATURE] Make color picking with shortcuts work in Wrap Around mode

CC:kimageshop@kde.org
BUG:336122
parent 9c6d0f17
......@@ -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;
}
......
......@@ -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());
......
......@@ -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);
......
......@@ -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.
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment