[calligra/calligra/2.9] krita/plugins/tools/tool_transform2: Finish continuation of the transformation action

Dmitry Kazakov dimula73 at gmail.com
Sat Jul 4 10:47:58 UTC 2015


Git commit 1a3e977b1d1d8296f5e089221d2d36ac0cb951e8 by Dmitry Kazakov.
Committed on 04/07/2015 at 10:44.
Pushed by dkazakov into branch 'calligra/2.9'.

Finish continuation of the transformation action

Now the user can edit/compare transformations incrementally:

1) Transform your piece of image
2) Apply transformation
3) Click on the canvas with the transfomration tool again

Now the previously applied transformation is *continued*

If you cancel/reset your transformation, it will be reset to the
correct state, that is to the partial transformation where it has
been started.

If you switch the transformation mode during a continued action,
the previous action will be baked into the image and a new-mode-stroke
will be started.

BUG:331708




CC:kimageshop at kde.org

M  +33   -9    krita/plugins/tools/tool_transform2/kis_tool_transform.cc
M  +1    -1    krita/plugins/tools/tool_transform2/kis_tool_transform.h
M  +22   -0    krita/plugins/tools/tool_transform2/tool_transform_args.cc
M  +11   -0    krita/plugins/tools/tool_transform2/tool_transform_args.h

http://commits.kde.org/calligra/1a3e977b1d1d8296f5e089221d2d36ac0cb951e8

diff --git a/krita/plugins/tools/tool_transform2/kis_tool_transform.cc b/krita/plugins/tools/tool_transform2/kis_tool_transform.cc
index d533d47..982f0b7 100644
--- a/krita/plugins/tools/tool_transform2/kis_tool_transform.cc
+++ b/krita/plugins/tools/tool_transform2/kis_tool_transform.cc
@@ -658,15 +658,17 @@ bool KisToolTransform::tryInitTransformModeFromNode(KisNodeSP node)
     return result;
 }
 
-bool KisToolTransform::tryFetchArgsFromCommandAndUndo(ToolTransformArgs *args)
+bool KisToolTransform::tryFetchArgsFromCommandAndUndo(ToolTransformArgs *args, ToolTransformArgs::TransformMode mode)
 {
     bool result = false;
 
     const KUndo2Command *lastCommand = image()->undoAdapter()->presentCommand();
 
     if (lastCommand &&
-        TransformStrokeStrategy::fetchArgsFromCommand(lastCommand,
-                                                      args)) {
+        TransformStrokeStrategy::fetchArgsFromCommand(lastCommand, args) &&
+        args->mode() == mode) {
+
+        args->saveContinuedState();
 
         image()->undoAdapter()->undoLastCommand();
         // FIXME: can we make it async?
@@ -850,7 +852,7 @@ void KisToolTransform::startStroke(ToolTransformArgs::TransformMode mode)
     }
 
     ToolTransformArgs fetchedArgs;
-    const bool fetchedFromCommand = tryFetchArgsFromCommandAndUndo(&fetchedArgs);
+    bool fetchedFromCommand = tryFetchArgsFromCommandAndUndo(&fetchedArgs, mode);
 
     if (m_optionsWidget) {
         m_workRecursively = m_optionsWidget->workRecursively() ||
@@ -930,9 +932,14 @@ void KisToolTransform::cancelStroke()
 {
     if (!m_strokeData.strokeId()) return;
 
-    image()->cancelStroke(m_strokeData.strokeId());
-    m_strokeData.clear();
-    m_changesTracker.reset();
+    if (m_currentArgs.continuedTransform()) {
+        m_currentArgs.restoreContinuedState();
+        endStroke();
+    } else {
+        image()->cancelStroke(m_strokeData.strokeId());
+        m_strokeData.clear();
+        m_changesTracker.reset();
+    }
 }
 
 void KisToolTransform::commitChanges()
@@ -1067,8 +1074,25 @@ void KisToolTransform::slotApplyTransform()
 
 void KisToolTransform::slotResetTransform()
 {
-    initTransformMode(m_currentArgs.mode());
-    slotEditingFinished();
+    if (m_currentArgs.continuedTransform()) {
+        ToolTransformArgs::TransformMode savedMode = m_currentArgs.mode();
+
+        if (m_currentArgs.continuedTransform()->mode() == savedMode) {
+            m_currentArgs.restoreContinuedState();
+            initGuiAfterTransformMode();
+            slotEditingFinished();
+
+        } else {
+            cancelStroke();
+            image()->waitForDone();
+            startStroke(savedMode);
+
+            KIS_ASSERT_RECOVER_NOOP(!m_currentArgs.continuedTransform());
+        }
+    } else {
+        initTransformMode(m_currentArgs.mode());
+        slotEditingFinished();
+    }
 }
 
 void KisToolTransform::slotRestartTransform()
diff --git a/krita/plugins/tools/tool_transform2/kis_tool_transform.h b/krita/plugins/tools/tool_transform2/kis_tool_transform.h
index 9d054ea..2ca261e 100644
--- a/krita/plugins/tools/tool_transform2/kis_tool_transform.h
+++ b/krita/plugins/tools/tool_transform2/kis_tool_transform.h
@@ -229,7 +229,7 @@ private:
 
 
     bool tryInitTransformModeFromNode(KisNodeSP node);
-    bool tryFetchArgsFromCommandAndUndo(ToolTransformArgs *args);
+    bool tryFetchArgsFromCommandAndUndo(ToolTransformArgs *args, ToolTransformArgs::TransformMode mode);
     void initTransformMode(ToolTransformArgs::TransformMode mode);
     void initGuiAfterTransformMode();
 
diff --git a/krita/plugins/tools/tool_transform2/tool_transform_args.cc b/krita/plugins/tools/tool_transform2/tool_transform_args.cc
index 1ff96db..06b68d4 100644
--- a/krita/plugins/tools/tool_transform2/tool_transform_args.cc
+++ b/krita/plugins/tools/tool_transform2/tool_transform_args.cc
@@ -95,6 +95,8 @@ void ToolTransformArgs::init(const ToolTransformArgs& args)
     if (args.m_liquifyWorker) {
         m_liquifyWorker.reset(new KisLiquifyTransformWorker(*args.m_liquifyWorker.data()));
     }
+
+    m_continuedTransformation.reset(args.m_continuedTransformation ? new ToolTransformArgs(*args.m_continuedTransformation) : 0);
 }
 
 void ToolTransformArgs::clear()
@@ -409,3 +411,23 @@ ToolTransformArgs ToolTransformArgs::fromXML(const QDomElement &e)
 
     return args;
 }
+
+void ToolTransformArgs::saveContinuedState()
+{
+    m_continuedTransformation.reset();
+    m_continuedTransformation.reset(new ToolTransformArgs(*this));
+}
+
+void ToolTransformArgs::restoreContinuedState()
+{
+    QScopedPointer<ToolTransformArgs> tempTransformation(
+        new ToolTransformArgs(*m_continuedTransformation));
+
+    *this = *tempTransformation;
+    m_continuedTransformation.swap(tempTransformation);
+}
+
+const ToolTransformArgs* ToolTransformArgs::continuedTransform() const
+{
+    return m_continuedTransformation.data();
+}
diff --git a/krita/plugins/tools/tool_transform2/tool_transform_args.h b/krita/plugins/tools/tool_transform2/tool_transform_args.h
index bd091ba..7f5b499 100644
--- a/krita/plugins/tools/tool_transform2/tool_transform_args.h
+++ b/krita/plugins/tools/tool_transform2/tool_transform_args.h
@@ -261,6 +261,10 @@ public:
 
     void translate(const QPointF &offset);
 
+    void saveContinuedState();
+    void restoreContinuedState();
+    const ToolTransformArgs* continuedTransform() const;
+
 private:
     void clear();
     void init(const ToolTransformArgs& args);
@@ -299,6 +303,13 @@ private:
     bool m_editTransformPoints;
     QSharedPointer<KisLiquifyProperties> m_liquifyProperties;
     QScopedPointer<KisLiquifyTransformWorker> m_liquifyWorker;
+
+    /**
+     * When we continue a transformation, m_continuedTransformation
+     * stores the initial step of our transform. All cancel and revert
+     * operations should revert to it.
+     */
+    QScopedPointer<ToolTransformArgs> m_continuedTransformation;
 };
 
 #endif // TOOL_TRANSFORM_ARGS_H_


More information about the kimageshop mailing list