Commit 190fd2c3 authored by Dmitry Kazakov's avatar Dmitry Kazakov Committed by Halla Rempt

Fix Clone Tool when picking from a different layer

More than that, you can pick your source from a
different image opened in Krita even! :)

BUG:347961
parent 0c277257
...@@ -93,10 +93,11 @@ KisPaintOpPresetWSP KisPaintOpSettings::preset() const ...@@ -93,10 +93,11 @@ KisPaintOpPresetWSP KisPaintOpSettings::preset() const
return d->preset; return d->preset;
} }
bool KisPaintOpSettings::mousePressEvent(const KisPaintInformation &pos, Qt::KeyboardModifiers modifiers) bool KisPaintOpSettings::mousePressEvent(const KisPaintInformation &pos, Qt::KeyboardModifiers modifiers, KisNodeWSP currentNode)
{ {
Q_UNUSED(pos); Q_UNUSED(pos);
Q_UNUSED(modifiers); Q_UNUSED(modifiers);
Q_UNUSED(currentNode);
setRandomOffset(); setRandomOffset();
return true; // ignore the event by default return true; // ignore the event by default
} }
......
...@@ -65,7 +65,7 @@ public: ...@@ -65,7 +65,7 @@ public:
* If the tool is supposed to ignore the event, the paint op should return false * If the tool is supposed to ignore the event, the paint op should return false
* and if the tool is supposed to use the event, return true. * and if the tool is supposed to use the event, return true.
*/ */
virtual bool mousePressEvent(const KisPaintInformation &pos, Qt::KeyboardModifiers modifiers); virtual bool mousePressEvent(const KisPaintInformation &pos, Qt::KeyboardModifiers modifiers, KisNodeWSP currentNode);
/** /**
* This function is called to set random offsets to the brush whenever the mouse is clicked. It is * This function is called to set random offsets to the brush whenever the mouse is clicked. It is
......
...@@ -111,7 +111,17 @@ KisSpacingInformation KisDuplicateOp::paintAt(const KisPaintInformation& info) ...@@ -111,7 +111,17 @@ KisSpacingInformation KisDuplicateOp::paintAt(const KisPaintInformation& info)
realSourceDevice = m_image->projection(); realSourceDevice = m_image->projection();
} }
else { else {
realSourceDevice = m_node->projection(); KisNodeSP externalSourceNode = m_settings->sourceNode();
/**
* The saved layer might have been deleted by then, so check if it
* still belongs to a graph
*/
if (!externalSourceNode || !externalSourceNode->graphListener()) {
externalSourceNode = m_node;
}
realSourceDevice = externalSourceNode->projection();
} }
qreal scale = m_sizeOption.apply(info); qreal scale = m_sizeOption.apply(info);
......
...@@ -68,11 +68,12 @@ QPointF KisDuplicateOpSettings::position() const ...@@ -68,11 +68,12 @@ QPointF KisDuplicateOpSettings::position() const
return m_position; return m_position;
} }
bool KisDuplicateOpSettings::mousePressEvent(const KisPaintInformation &info, Qt::KeyboardModifiers modifiers) bool KisDuplicateOpSettings::mousePressEvent(const KisPaintInformation &info, Qt::KeyboardModifiers modifiers, KisNodeWSP currentNode)
{ {
bool ignoreEvent = true; bool ignoreEvent = true;
if (modifiers == Qt::ControlModifier) { if (modifiers == Qt::ControlModifier) {
m_sourceNode = currentNode;
m_position = info.pos(); m_position = info.pos();
m_isOffsetNotUptodate = true; m_isOffsetNotUptodate = true;
ignoreEvent = false; ignoreEvent = false;
...@@ -88,6 +89,10 @@ bool KisDuplicateOpSettings::mousePressEvent(const KisPaintInformation &info, Qt ...@@ -88,6 +89,10 @@ bool KisDuplicateOpSettings::mousePressEvent(const KisPaintInformation &info, Qt
return ignoreEvent; return ignoreEvent;
} }
KisNodeWSP KisDuplicateOpSettings::sourceNode() const
{
return m_sourceNode;
}
void KisDuplicateOpSettings::activate() void KisDuplicateOpSettings::activate()
{ {
......
...@@ -45,7 +45,7 @@ public: ...@@ -45,7 +45,7 @@ public:
QPointF offset() const; QPointF offset() const;
QPointF position() const; QPointF position() const;
virtual bool mousePressEvent(const KisPaintInformation& pos, Qt::KeyboardModifiers modifiers); virtual bool mousePressEvent(const KisPaintInformation& pos, Qt::KeyboardModifiers modifiers, KisNodeWSP currentNode);
void activate(); void activate();
void fromXML(const QDomElement& elt); void fromXML(const QDomElement& elt);
...@@ -54,11 +54,14 @@ public: ...@@ -54,11 +54,14 @@ public:
KisPaintOpSettingsSP clone() const; KisPaintOpSettingsSP clone() const;
QPainterPath brushOutline(const KisPaintInformation &info, OutlineMode mode) const; QPainterPath brushOutline(const KisPaintInformation &info, OutlineMode mode) const;
KisNodeWSP sourceNode() const;
public: public:
QPointF m_offset; QPointF m_offset;
bool m_isOffsetNotUptodate; bool m_isOffsetNotUptodate;
QPointF m_position; // Give the position of the last alt-click QPointF m_position; // Give the position of the last alt-click
KisNodeWSP m_sourceNode;
}; };
......
...@@ -265,7 +265,8 @@ bool KisToolFreehand::tryPickByPaintOp(KoPointerEvent *event, AlternateAction ac ...@@ -265,7 +265,8 @@ bool KisToolFreehand::tryPickByPaintOp(KoPointerEvent *event, AlternateAction ac
event->rotation(), event->rotation(),
event->tangentialPressure(), event->tangentialPressure(),
perspective, 0, 0), perspective, 0, 0),
event->modifiers()); event->modifiers(),
currentNode());
return !paintOpIgnoredEvent; return !paintOpIgnoredEvent;
} }
......
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