Commit b9b283b3 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Make move tool show correct cursor in all modes

When the user activates "Layer with content" mode, the
disability cursor should work correctly as well :)
parent 5c54c1a5
......@@ -60,7 +60,8 @@ struct KisToolMoveState : KisToolChangesTrackerData, boost::equality_comparable<
KisToolMove::KisToolMove(KoCanvasBase * canvas)
: KisTool(canvas, KisCursor::moveCursor())
: KisTool(canvas, KisCursor::moveCursor()),
m_updateCursorCompressor(100, KisSignalCompressor::FIRST_ACTIVE)
{
m_canvas = dynamic_cast<KisCanvas2*>(canvas);
......@@ -107,6 +108,8 @@ KisToolMove::KisToolMove(KoCanvasBase * canvas)
connect(&m_changesTracker,
SIGNAL(sigConfigChanged(KisToolChangesTrackerDataSP)),
SLOT(slotTrackerChangedConfig(KisToolChangesTrackerDataSP)));
connect(&m_updateCursorCompressor, SIGNAL(timeout()), this, SLOT(resetCursorStyle()));
}
KisToolMove::~KisToolMove()
......@@ -118,22 +121,26 @@ void KisToolMove::resetCursorStyle()
{
KisTool::resetCursorStyle();
overrideCursorIfNotEditable();
}
bool KisToolMove::startStrokeImpl(MoveToolMode mode, const QPoint *pos)
{
KisNodeSP node;
KisNodeList nodes;
if (!isActive()) return;
KisImageSP image = this->image();
KisResourcesSnapshotSP resources =
new KisResourcesSnapshot(image, currentNode(), this->canvas()->resourceManager());
KisSelectionSP selection = resources->activeSelection();
KisNodeList nodes = fetchSelectedNodes(moveToolMode(), &m_lastCursorPos, selection);
if (mode != MoveSelectedLayer && pos) {
bool wholeGroup = !selection && mode == MoveGroup;
node = KisToolUtils::findNode(image->root(), *pos, wholeGroup);
if (nodes.isEmpty()) {
canvas()->setCursor(Qt::ForbiddenCursor);
}
}
KisNodeList KisToolMove::fetchSelectedNodes(MoveToolMode mode, const QPoint *pixelPoint, KisSelectionSP selection)
{
KisNodeList nodes;
KisImageSP image = this->image();
if (mode != MoveSelectedLayer && pixelPoint) {
const bool wholeGroup = !selection && mode == MoveGroup;
KisNodeSP node = KisToolUtils::findNode(image->root(), *pixelPoint, wholeGroup);
if (node) {
nodes = {node};
}
......@@ -148,6 +155,20 @@ bool KisToolMove::startStrokeImpl(MoveToolMode mode, const QPoint *pos)
});
}
return nodes;
}
bool KisToolMove::startStrokeImpl(MoveToolMode mode, const QPoint *pos)
{
KisNodeSP node;
KisImageSP image = this->image();
KisResourcesSnapshotSP resources =
new KisResourcesSnapshot(image, currentNode(), this->canvas()->resourceManager());
KisSelectionSP selection = resources->activeSelection();
KisNodeList nodes = fetchSelectedNodes(mode, pos, selection);
if (nodes.size() == 1) {
node = nodes.first();
}
......@@ -390,6 +411,16 @@ void KisToolMove::endAlternateAction(KoPointerEvent *event, AlternateAction acti
endAction(event);
}
void KisToolMove::mouseMoveEvent(KoPointerEvent *event)
{
m_lastCursorPos = convertToPixelCoord(event).toPoint();
KisTool::mouseMoveEvent(event);
if (moveToolMode() == MoveFirstLayer) {
m_updateCursorCompressor.start();
}
}
void KisToolMove::startAction(KoPointerEvent *event, MoveToolMode mode)
{
QPoint pos = convertToPixelCoordAndSnap(event).toPoint();
......
......@@ -31,6 +31,7 @@
#include <QGroupBox>
#include <QRadioButton>
#include "KisToolChangesTracker.h"
#include "kis_signal_compressor.h"
#include "kis_canvas2.h"
......@@ -93,6 +94,8 @@ public:
void continueAlternateAction(KoPointerEvent *event, AlternateAction action) override;
void endAlternateAction(KoPointerEvent *event, AlternateAction action) override;
void mouseMoveEvent(KoPointerEvent *event) override;
void startAction(KoPointerEvent *event, MoveToolMode mode);
void continueAction(KoPointerEvent *event);
void endAction(KoPointerEvent *event);
......@@ -130,6 +133,7 @@ private:
QPoint currentOffset() const;
void notifyGuiAfterMove(bool showFloatingMessage = true);
bool tryEndPreviousStroke(KisNodeList nodes);
KisNodeList fetchSelectedNodes(MoveToolMode mode, const QPoint *pixelPoint, KisSelectionSP selection);
private Q_SLOTS:
......@@ -156,6 +160,9 @@ private:
QRect m_handlesRect;
KisToolChangesTracker m_changesTracker;
QPoint m_lastCursorPos;
KisSignalCompressor m_updateCursorCompressor;
};
......
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