Commit 190fd2c3 authored by Dmitry Kazakov's avatar Dmitry Kazakov Committed by Boudewijn 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
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(modifiers);
Q_UNUSED(currentNode);
setRandomOffset();
return true; // ignore the event by default
}
......
......@@ -65,7 +65,7 @@ public:
* 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.
*/
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
......
......@@ -111,7 +111,17 @@ KisSpacingInformation KisDuplicateOp::paintAt(const KisPaintInformation& info)
realSourceDevice = m_image->projection();
}
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);
......
......@@ -68,11 +68,12 @@ QPointF KisDuplicateOpSettings::position() const
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;
if (modifiers == Qt::ControlModifier) {
m_sourceNode = currentNode;
m_position = info.pos();
m_isOffsetNotUptodate = true;
ignoreEvent = false;
......@@ -88,6 +89,10 @@ bool KisDuplicateOpSettings::mousePressEvent(const KisPaintInformation &info, Qt
return ignoreEvent;
}
KisNodeWSP KisDuplicateOpSettings::sourceNode() const
{
return m_sourceNode;
}
void KisDuplicateOpSettings::activate()
{
......
......@@ -45,7 +45,7 @@ public:
QPointF offset() 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 fromXML(const QDomElement& elt);
......@@ -54,11 +54,14 @@ public:
KisPaintOpSettingsSP clone() const;
QPainterPath brushOutline(const KisPaintInformation &info, OutlineMode mode) const;
KisNodeWSP sourceNode() const;
public:
QPointF m_offset;
bool m_isOffsetNotUptodate;
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
event->rotation(),
event->tangentialPressure(),
perspective, 0, 0),
event->modifiers());
event->modifiers(),
currentNode());
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