Commit 9f738371 authored by Tusooa Zhu's avatar Tusooa Zhu 🅱

Move KoPathTool to plugins

We need to move KoPathTool to the plugins directory since
the interaction strategies for the new system would depend on,
at least, kritaimage. Image depends on flake so the tool cannot
stay in flake.

The unit test for KoPathTool is temporarily disabled.
parent 591f86aa
......@@ -174,15 +174,7 @@ set(kritaflake_SRCS
html/HtmlWriter.cpp
tools/KoCreateShapeStrategy.cpp
tools/KoPathToolFactory.cpp
tools/KoPathTool.cpp
tools/KoPathToolSelection.cpp
tools/KoPathToolHandle.cpp
tools/PathToolOptionWidget.cpp
tools/KoPathPointRubberSelectStrategy.cpp
tools/KoPathPointMoveStrategy.cpp
tools/KoPathConnectionPointStrategy.cpp
tools/KoPathControlPointMoveStrategy.cpp
tools/KoParameterChangeStrategy.cpp
tools/KoZoomTool.cpp
tools/KoZoomToolFactory.cpp
......@@ -194,7 +186,6 @@ set(kritaflake_SRCS
tools/KoCreateShapesTool.cpp
tools/KoCreateShapesToolFactory.cpp
tools/KoShapeRubberSelectStrategy.cpp
tools/KoPathSegmentChangeStrategy.cpp
svg/KoShapePainter.cpp
svg/SvgUtil.cpp
......@@ -227,7 +218,6 @@ set(kritaflake_SRCS
)
ki18n_wrap_ui(kritaflake_SRCS
tools/PathToolOptionWidgetBase.ui
KoConnectionShapeConfigWidget.ui
tools/KoZoomToolWidget.ui
)
......
......@@ -22,9 +22,11 @@
#include <QObject>
#include <QScopedPointer>
#include <kritaflake_export.h>
class KoCanvasBase;
class KoShapeFillResourceConnector : public QObject
class KRITAFLAKE_EXPORT KoShapeFillResourceConnector : public QObject
{
Q_OBJECT
public:
......
......@@ -26,7 +26,6 @@
#include "tools/KoCreateShapesToolFactory.h"
#include "tools/KoCreateShapesTool.h"
#include "tools/KoPathToolFactory.h"
#include "tools/KoZoomTool.h"
#include "tools/KoZoomToolFactory.h"
#include "KoToolManager.h"
......@@ -53,7 +52,6 @@ void KoToolRegistry::init()
// register generic tools
add(new KoCreateShapesToolFactory());
add(new KoPathToolFactory());
add(new KoZoomToolFactory());
KConfigGroup cfg = KSharedConfig::openConfig()->group("calligra");
......
......@@ -25,10 +25,12 @@
#include <QList>
#include "KoPathPointData.h"
#include <kritaflake_export.h>
class KoPathPoint;
/// Command to break a subpath at points.
class KoPathBreakAtPointCommand : public KUndo2Command
class KRITAFLAKE_EXPORT KoPathBreakAtPointCommand : public KUndo2Command
{
public:
/**
......
......@@ -24,8 +24,10 @@
#include <kundo2command.h>
#include "KoPathPointData.h"
#include <kritaflake_export.h>
/// The undo / redo command for breaking a subpath by removing the segment
class KoPathSegmentBreakCommand : public KUndo2Command
class KRITAFLAKE_EXPORT KoPathSegmentBreakCommand : public KUndo2Command
{
public:
/**
......
......@@ -9,7 +9,6 @@ macro_add_unittest_definitions()
ecm_add_tests(
TestPosition.cpp
TestSelection.cpp
TestPathTool.cpp
TestShapeAt.cpp
TestShapePainting.cpp
TestKoShapeFactory.cpp
......
......@@ -10,3 +10,4 @@ add_subdirectory( karbonplugins )
add_subdirectory( tool_lazybrush )
add_subdirectory( tool_smart_patch )
add_subdirectory( svgtexttool )
add_subdirectory( pathtool )
project(pathtool)
add_subdirectory(tests)
set(pathtool_SRCS
KoPathTool.cpp
KoPathToolFactory.cpp
KoPathToolHandle.cpp
KoPathToolSelection.cpp
PathToolOptionWidget.cpp
KoPathControlPointMoveStrategy.cpp
KoPathPointMoveStrategy.cpp
KoPathPointRubberSelectStrategy.cpp
KoPathSegmentChangeStrategy.cpp
PathToolPlugin.cpp
)
ki18n_wrap_ui(pathtool_SRCS
tools/PathToolOptionWidgetBase.ui
)
add_library(krita_tool_path MODULE ${pathtool_SRCS})
target_link_libraries(krita_tool_path kritaui kritaflake)
install(TARGETS krita_tool_path DESTINATION ${KRITA_PLUGIN_INSTALL_DIR})
......@@ -3,6 +3,7 @@
* Copyright (C) 2006,2007 Thorsten Zachmann <zachmann@kde.org>
* Copyright (C) 2007, 2010 Thomas Zander <zander@kde.org>
* Copyright (C) 2007 Boudewijn Rempt <boud@valdyas.org>
* Copyright (C) 2019 Tusooa Zhu <tusooa@vista.aero>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -34,7 +35,6 @@
#include "KoPointerEvent.h"
#include "commands/KoPathBreakAtPointCommand.h"
#include "commands/KoPathSegmentBreakCommand.h"
#include "commands/KoParameterToPathCommand.h"
#include "commands/KoSubpathJoinCommand.h"
#include <commands/KoMultiPathPointMergeCommand.h>
#include <commands/KoMultiPathPointJoinCommand.h>
......@@ -421,10 +421,6 @@ void KoPathTool::convertToPath()
}
}
if (!parameterShapes.isEmpty()) {
d->canvas->addCommand(new KoParameterToPathCommand(parameterShapes));
}
QList<KoSvgTextShape*> textShapes;
Q_FOREACH (KoShape *shape, selection->selectedEditableShapes()) {
if (KoSvgTextShape *text = dynamic_cast<KoSvgTextShape*>(shape)) {
......@@ -432,38 +428,42 @@ void KoPathTool::convertToPath()
}
}
if (!textShapes.isEmpty()) {
KUndo2Command *cmd = new KUndo2Command(kundo2_i18n("Convert to Path")); // TODO: reuse the text from KoParameterToPathCommand
const QList<KoShape*> oldSelectedShapes = implicitCastList<KoShape*>(textShapes);
new KoKeepShapesSelectedCommand(oldSelectedShapes, {}, canvas()->selectedShapesProxy(),
KisCommandUtils::FlipFlopCommand::State::INITIALIZING, cmd);
QList<KoShape*> newSelectedShapes;
Q_FOREACH (KoSvgTextShape *shape, textShapes) {
const QPainterPath path = shape->textOutline();
if (path.isEmpty()) continue;
if (!parameterShapes.isEmpty() || !textShapes.isEmpty()) {
KoCanvasBase *canvas = this->canvas();
KoSelection *selection = canvas->selectedShapesProxy()->selection();
canvas->strokeHelper()->run(kundo2_i18n("Convert to Path"),
[parameterShapes, canvas, textShapes, selection]() {
for (int i = 0; i < parameterShapes.size(); ++i) {
KoParameterShape* parameterShape = parameterShapes.at(i);
parameterShape->update();
parameterShape->setParametricShape(false);
parameterShape->update();
}
KoPathShape *pathShape = KoPathShape::createShapeFromPainterPath(path);
Q_FOREACH (KoSvgTextShape* shape, textShapes) {
const QPainterPath path = shape->textOutline();
if (path.isEmpty()) continue;
pathShape->setBackground(shape->background());
pathShape->setStroke(shape->stroke());
pathShape->setZIndex(shape->zIndex());
pathShape->setTransformation(shape->transformation());
KoPathShape* pathShape = KoPathShape::createShapeFromPainterPath(path);
KoShapeContainer *parent = shape->parent();
canvas()->shapeController()->addShapeDirect(pathShape, parent, cmd);
pathShape->setBackground(shape->background());
pathShape->setStroke(shape->stroke());
pathShape->setZIndex(shape->zIndex());
pathShape->setTransformation(shape->transformation());
newSelectedShapes << pathShape;
}
KoShapeContainer* parent = shape->parent();
canvas->shapeController()->addShapeDirect(pathShape, parent);
selection->deselect(shape);
selection->select(pathShape);
}
canvas()->shapeController()->removeShapes(oldSelectedShapes, cmd);
canvas->shapeController()->removeShapes(implicitCastList<KoShape*>(textShapes));
return true;
});
}
new KoKeepShapesSelectedCommand({}, newSelectedShapes, canvas()->selectedShapesProxy(),
KisCommandUtils::FlipFlopCommand::State::FINALIZING, cmd);
if (!textShapes.isEmpty()) {
canvas()->addCommand(cmd);
}
updateOptionsWidget();
......
......@@ -3,6 +3,7 @@
* Copyright (C) 2006,2007 Thorsten Zachmann <zachmann@kde.org>
* Copyright (C) 2007 Thomas Zander <zander@kde.org>
* Copyright (C) 2007 Boudewijn Rempt <boud@valdyas.org>
* Copyright (C) 2019 Tusooa Zhu <tusooa@vista.aero>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -45,7 +46,7 @@ class QMenu;
/// The tool for editing a KoPathShape or a KoParameterShape.
/// See KoCreatePathTool for code handling the initial path creation.
class KRITAFLAKE_EXPORT KoPathTool : public KoToolBase
class KoPathTool : public KoToolBase
{
Q_OBJECT
public:
......
......@@ -38,7 +38,7 @@ class QPainter;
* This class handles the selection of points. It makes sure
* the canvas is repainted when the selection changes.
*/
class KRITAFLAKE_EXPORT KoPathToolSelection : public KoToolSelection, public KoPathShape::PointSelectionChangeListener
class KoPathToolSelection : public KoToolSelection, public KoPathShape::PointSelectionChangeListener
{
Q_OBJECT
......
/* This file is part of the KDE project
* Copyright (C) 2007 Thomas Zander <zander@kde.org>
* Copyright (C) 2019 Tusooa Zhu <tusooa@vista.aero>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "PathToolPlugin.h"
#include "KoPathToolFactory.h"
#include <KoToolRegistry.h>
#include <kpluginfactory.h>
K_PLUGIN_FACTORY_WITH_JSON(PluginFactory, "pathtool.json", registerPlugin<PathToolPlugin>();)
PathToolPlugin::PathToolPlugin(QObject *parent, const QVariantList &)
: QObject(parent)
{
KoToolRegistry::instance()->add(new KoPathToolFactory);
}
#include <PathToolPlugin.moc>
/* This file is part of the KDE project
* Copyright (C) 2007 Thomas Zander <zander@kde.org>
* Copyright (C) 2019 Tusooa Zhu <tusooa@vista.aero>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef PATH_TOOL_PLUGIN_H
#define PATH_TOOL_PLUGIN_H
#include <QObject>
#include <QVariantList>
class PathToolPlugin : public QObject
{
Q_OBJECT
public:
PathToolPlugin(QObject *parent, const QVariantList &);
~PathToolPlugin() override = default;
};
#endif
{
"Id": "Path Tool",
"Type": "Service",
"X-Flake-MinVersion": "28",
"X-Flake-PluginVersion": "28",
"X-KDE-Library": "krita_tool_path",
"X-KDE-PluginInfo-Name": "pathtool",
"X-KDE-ServiceTypes": [
"Calligra/Tool"
]
}
set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} )
include(ECMAddTests)
include(KritaAddBrokenUnitTest)
include_directories(${CMAKE_SOURCE_DIR}/libs/flake/tests)
macro_add_unittest_definitions()
#ecm_add_test(
# TestPathTool.cpp
# ../KoPathTool.cpp
# ../KoPathToolSelection.cpp
# TEST_NAME TestPathTool
# LINK_LIBRARIES kritaflake Qt5::Test
# NAME_PREFIX "plugins-tools-path-")
......@@ -19,10 +19,10 @@
#include "TestPathTool.h"
#include <QPainterPath>
#include "../KoPathShape.h"
#include "../tools/KoPathTool.h"
#include "../tools/KoPathToolSelection.h"
#include "../KoPathPointData.h"
#include "KoPathShape.h"
#include "../KoPathTool.h"
#include "../KoPathToolSelection.h"
#include "KoPathPointData.h"
#include <MockShapes.h>
#include <QTest>
......
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