Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Krita
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tusooa Zhu
Krita
Commits
7e755c3e
Commit
7e755c3e
authored
Jul 30, 2019
by
Tusooa Zhu
➡
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Port shearing and keyboard-initated moving to the stroke system
parent
24355db3
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
82 additions
and
31 deletions
+82
-31
libs/flake/KoFlake.cpp
libs/flake/KoFlake.cpp
+27
-0
libs/flake/KoFlake.h
libs/flake/KoFlake.h
+6
-0
libs/ui/tool/strokes/KisNodeReplaceBasedStrokeStrategy.cpp
libs/ui/tool/strokes/KisNodeReplaceBasedStrokeStrategy.cpp
+14
-2
libs/ui/tool/strokes/KisNodeReplaceBasedStrokeStrategy.h
libs/ui/tool/strokes/KisNodeReplaceBasedStrokeStrategy.h
+2
-2
plugins/tools/defaulttool/defaulttool/DefaultTool.cpp
plugins/tools/defaulttool/defaulttool/DefaultTool.cpp
+6
-1
plugins/tools/defaulttool/defaulttool/ShapeShearStrategy.cpp
plugins/tools/defaulttool/defaulttool/ShapeShearStrategy.cpp
+17
-17
plugins/tools/defaulttool/defaulttool/ShapeShearStrategy.h
plugins/tools/defaulttool/defaulttool/ShapeShearStrategy.h
+10
-9
No files found.
libs/flake/KoFlake.cpp
View file @
7e755c3e
...
...
@@ -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
());
}
}
libs/flake/KoFlake.h
View file @
7e755c3e
...
...
@@ -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
libs/ui/tool/strokes/KisNodeReplaceBasedStrokeStrategy.cpp
View file @
7e755c3e
...
...
@@ -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
);
}
libs/ui/tool/strokes/KisNodeReplaceBasedStrokeStrategy.h
View file @
7e755c3e
...
...
@@ -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
;
...
...
plugins/tools/defaulttool/defaulttool/DefaultTool.cpp
View file @
7e755c3e
...
...
@@ -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
;
}
}
...
...
plugins/tools/defaulttool/defaulttool/ShapeShearStrategy.cpp
View file @
7e755c3e
...
...
@@ -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
;
}
plugins/tools/defaulttool/defaulttool/ShapeShearStrategy.h
View file @
7e755c3e
...
...
@@ -20,7 +20,7 @@
#ifndef SHAPESHEARSTRATEGY_H
#define SHAPESHEARSTRATEGY_H
#include <K
o
InteractionStrategy.h>
#include <K
isStrokeBased
InteractionStrategy.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
K
o
InteractionStrategy
class
ShapeShearStrategy
:
public
K
isStrokeBased
InteractionStrategy
{
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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment