Commit 7e755c3e authored by Tusooa Zhu's avatar Tusooa Zhu

Port shearing and keyboard-initated moving to the stroke system

parent 24355db3
......@@ -344,3 +344,30 @@ QPointF KoFlake::anchorToPoint(AnchorPosition anchor, const QRectF rect, bool *v
return rect.topLeft();
}
}
void KoFlake::moveShapes(const QList<KoShape *>& shapes, const QPointF& offset)
{
QList<QPointF> newPositions;
Q_FOREACH (KoShape *shape, shapes) {
const QPointF pos = shape->absolutePosition();
newPositions << pos + offset;
}
moveShapes(shapes, newPositions, KoFlake::Center);
}
void KoFlake::moveShapes(const QList<KoShape *>& shapes, const QList<QPointF>& newPositions, KoFlake::AnchorPosition anchor)
{
KIS_ASSERT_RECOVER_NOOP(shapes.length() == newPositions.length());
for (int i = 0; i < shapes.count(); i++) {
KoShape *shape = shapes.at(i);
const QRectF oldDirtyRect = shape->boundingRect();
shape->setAbsolutePosition(newPositions.at(i), anchor);
shape->updateAbsolute(oldDirtyRect | shape->boundingRect());
}
}
......@@ -145,6 +145,12 @@ namespace KoFlake
const QPointF &absoluteStillPoint,
bool useGlobalMode,
bool usePostScaling, const QTransform &postScalingCoveringTransform);
KRITAFLAKE_EXPORT void moveShapes(const QList<KoShape *> &shapes, const QPointF &offset);
KRITAFLAKE_EXPORT void moveShapes(const QList<KoShape *> &shapes,
const QList<QPointF> &newPositions,
KoFlake::AnchorPosition anchor);
}
#endif
......@@ -17,10 +17,13 @@
*/
#include "KisNodeReplaceBasedStrokeStrategy.h"
#include <kis_node.h>
#include <kundo2command.h>
#include <kis_canvas2.h>
#include <kis_post_execution_undo_adapter.h>
#include <KisStrokesFacade.h>
#include <KisRunnableStrokeJobData.h>
struct KisNodeReplaceBasedStrokeStrategy::Private
{
......@@ -137,7 +140,16 @@ void KisNodeReplaceBasedStrokeStrategy::setChanged(bool changed)
m_d->nodeChanged = changed;
}
KisNodeSP KisNodeReplaceBasedStrokeStrategy::nodeOriginalState()
void KisNodeReplaceBasedStrokeStrategy::runInStrokeOnce(KisStrokesFacade *strokesFacade, KisCanvas2 *canvas, const KUndo2MagicString &name, std::function<void()> callback, bool createCommand)
{
return m_d->originalState;
KisNodeReplaceBasedStrokeStrategy *strategy = new KisNodeReplaceBasedStrokeStrategy("LAMBDA_STROKE", canvas, name);
KisStrokeId stroke = strokesFacade->startStroke(strategy);
strokesFacade->addJob(stroke, new KisRunnableStrokeJobData(callback,
KisStrokeJobData::BARRIER,
KisStrokeJobData::EXCLUSIVE));
if (createCommand) {
strokesFacade->addJob(stroke, new KisRunnableStrokeJobData([strategy]() { strategy->setChanged(true); }));
}
strokesFacade->endStroke(stroke);
}
......@@ -27,6 +27,7 @@
#include <kritaui_export.h>
class KisCanvas2;
class KisStrokesFacade;
class KRITAUI_EXPORT KisNodeReplaceBasedStrokeStrategy : public KisRunnableBasedStrokeStrategy
{
......@@ -50,8 +51,7 @@ public:
void setChanged(bool changed);
public:
/// internal
KisNodeSP nodeOriginalState();
static void runInStrokeOnce(KisStrokesFacade *strokesFacade, KisCanvas2 *canvas, const KUndo2MagicString &name, std::function<void()> callback, bool createCommand);
private:
struct Private;
......
......@@ -829,7 +829,12 @@ bool DefaultTool::moveSelection(int direction, Qt::KeyboardModifiers modifiers)
QList<KoShape *> shapes = koSelection()->selectedEditableShapes();
if (!shapes.isEmpty()) {
canvas()->addCommand(new KoShapeMoveCommand(shapes, QPointF(x, y)));
KisCanvas2 *kisCanvas = dynamic_cast<KisCanvas2 *>(canvas());
KisNodeReplaceBasedStrokeStrategy::runInStrokeOnce(kisCanvas->image().data(),
kisCanvas,
kundo2_i18n("Move shapes (new) (lambda)"),
[shapes, x, y]() { KoFlake::moveShapes(shapes, QPointF(x, y)); },
/* createCommand = */ true);
result = true;
}
}
......
......@@ -37,8 +37,17 @@
#include <QDebug>
#include <klocalizedstring.h>
#include <kis_canvas2.h>
ShapeShearStrategy::ShapeShearStrategy(KoToolBase *tool, KoSelection *selection, const QPointF &clicked, KoFlake::SelectionHandle direction)
: KoInteractionStrategy(tool)
: KisStrokeBasedInteractionStrategy(tool)
{
startStroke(new ShapeShearStrokeStrategy(tool, selection, clicked, direction));
}
ShapeShearStrokeStrategy::ShapeShearStrokeStrategy(KoToolBase *tool, KoSelection *selection, const QPointF &clicked, KoFlake::SelectionHandle direction)
: KisStrokeBasedInteractionStrategy::StrokeStrategy("SHEAR_SHAPES", dynamic_cast<KisCanvas2 *>(tool->canvas()),
kundo2_i18n("Shear Shapes (new)"))
, m_start(clicked)
{
/**
......@@ -114,7 +123,11 @@ ShapeShearStrategy::ShapeShearStrategy(KoToolBase *tool, KoSelection *selection,
m_isMirrored = (top.x() * left.y() - top.y() * left.x()) < 0.0;
}
void ShapeShearStrategy::handleMouseMove(const QPointF &point, Qt::KeyboardModifiers modifiers)
ShapeShearStrokeStrategy::~ShapeShearStrokeStrategy()
{
}
void ShapeShearStrokeStrategy::mouseMoveCallback(const QPointF &point, Qt::KeyboardModifiers modifiers)
{
Q_UNUSED(modifiers);
QPointF shearVector = point - m_start;
......@@ -156,21 +169,8 @@ void ShapeShearStrategy::handleMouseMove(const QPointF &point, Qt::KeyboardModif
shape->updateAbsolute(oldDirtyRect | shape->boundingRect());
}
m_shearMatrix = matrix;
}
void ShapeShearStrategy::paint(QPainter &painter, const KoViewConverter &converter)
{
Q_UNUSED(painter);
Q_UNUSED(converter);
}
KUndo2Command *ShapeShearStrategy::createCommand()
{
QList<QTransform> newTransforms;
Q_FOREACH (KoShape *shape, m_transformedShapesAndSelection) {
newTransforms << shape->transformation();
if (m_start != point) {
setChanged(true);
}
KoShapeTransformCommand *cmd = new KoShapeTransformCommand(m_transformedShapesAndSelection, m_oldTransforms, newTransforms);
cmd->setText(kundo2_i18n("Shear"));
return cmd;
}
......@@ -20,7 +20,7 @@
#ifndef SHAPESHEARSTRATEGY_H
#define SHAPESHEARSTRATEGY_H
#include <KoInteractionStrategy.h>
#include <KisStrokeBasedInteractionStrategy.h>
#include <KoFlake.h>
#include <QPointF>
......@@ -36,7 +36,7 @@ class KoSelection;
* This strategy is invoked when the user starts a shear of a selection of objects,
* the stategy will then shear the objects interactively and provide a command afterwards.
*/
class ShapeShearStrategy : public KoInteractionStrategy
class ShapeShearStrategy : public KisStrokeBasedInteractionStrategy
{
public:
/**
......@@ -47,14 +47,15 @@ public:
*/
ShapeShearStrategy(KoToolBase *tool, KoSelection *selection, const QPointF &clicked, KoFlake::SelectionHandle direction);
~ShapeShearStrategy() override {}
};
class ShapeShearStrokeStrategy : public KisStrokeBasedInteractionStrategy::StrokeStrategy
{
public:
ShapeShearStrokeStrategy(KoToolBase *tool, KoSelection *selection, const QPointF &clicked, KoFlake::SelectionHandle direction);
~ShapeShearStrokeStrategy() override;
void handleMouseMove(const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers) override;
KUndo2Command *createCommand() override;
void finishInteraction(Qt::KeyboardModifiers modifiers) override
{
Q_UNUSED(modifiers);
}
void paint(QPainter &painter, const KoViewConverter &converter) override;
void mouseMoveCallback(const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers) override;
private:
QPointF m_start;
......
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