diff --git a/libs/flake/commands/KoPathControlPointMoveCommand.cpp b/libs/flake/commands/KoPathControlPointMoveCommand.cpp index 882a111d3d..e17734d78e 100644 --- a/libs/flake/commands/KoPathControlPointMoveCommand.cpp +++ b/libs/flake/commands/KoPathControlPointMoveCommand.cpp @@ -1,117 +1,117 @@ /* This file is part of the KDE project * Copyright (C) 2006 Jan Hambrecht * Copyright (C) 2006,2007 Thorsten Zachmann * * 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 "KoPathControlPointMoveCommand.h" #include #include #include "kis_command_ids.h" KoPathControlPointMoveCommand::KoPathControlPointMoveCommand( const KoPathPointData &pointData, const QPointF &offset, KoPathPoint::PointType pointType, KUndo2Command *parent) : KUndo2Command(parent) , m_pointData(pointData) , m_pointType(pointType) { Q_ASSERT(offset.x() < 1e14 && offset.y() < 1e14); KoPathShape * pathShape = m_pointData.pathShape; KoPathPoint * point = pathShape->pointByIndex(m_pointData.pointIndex); if (point) { m_offset = point->parent()->documentToShape(offset) - point->parent()->documentToShape(QPointF(0, 0)); } setText(kundo2_i18n("Move control point")); } void KoPathControlPointMoveCommand::redo() { KUndo2Command::redo(); KoPathShape * pathShape = m_pointData.pathShape; KoPathPoint * point = pathShape->pointByIndex(m_pointData.pointIndex); if (point) { - pathShape->update(); + const QRectF oldDirtyRect = pathShape->boundingRect(); if (m_pointType == KoPathPoint::ControlPoint1) { point->setControlPoint1(point->controlPoint1() + m_offset); if (point->properties() & KoPathPoint::IsSymmetric) { // set the other control point so that it lies on the line between the moved // control point and the point, with the same distance to the point as the moved point point->setControlPoint2(2.0 * point->point() - point->controlPoint1()); } else if (point->properties() & KoPathPoint::IsSmooth) { // move the other control point so that it lies on the line through point and control point // keeping its distance to the point QPointF direction = point->point() - point->controlPoint1(); direction /= sqrt(direction.x() * direction.x() + direction.y() * direction.y()); QPointF distance = point->point() - point->controlPoint2(); qreal length = sqrt(distance.x() * distance.x() + distance.y() * distance.y()); point->setControlPoint2(point->point() + length * direction); } } else if (m_pointType == KoPathPoint::ControlPoint2) { point->setControlPoint2(point->controlPoint2() + m_offset); if (point->properties() & KoPathPoint::IsSymmetric) { // set the other control point so that it lies on the line between the moved // control point and the point, with the same distance to the point as the moved point point->setControlPoint1(2.0 * point->point() - point->controlPoint2()); } else if (point->properties() & KoPathPoint::IsSmooth) { // move the other control point so that it lies on the line through point and control point // keeping its distance to the point QPointF direction = point->point() - point->controlPoint2(); direction /= sqrt(direction.x() * direction.x() + direction.y() * direction.y()); QPointF distance = point->point() - point->controlPoint1(); qreal length = sqrt(distance.x() * distance.x() + distance.y() * distance.y()); point->setControlPoint1(point->point() + length * direction); } } pathShape->normalize(); - pathShape->update(); + pathShape->updateAbsolute(oldDirtyRect | pathShape->boundingRect()); } } void KoPathControlPointMoveCommand::undo() { KUndo2Command::undo(); m_offset *= -1.0; redo(); m_offset *= -1.0; } int KoPathControlPointMoveCommand::id() const { return KisCommandUtils::ChangePathShapeControlPointId; } bool KoPathControlPointMoveCommand::mergeWith(const KUndo2Command *command) { const KoPathControlPointMoveCommand *other = dynamic_cast(command); if (!other || other->m_pointData != m_pointData || other->m_pointType != m_pointType) { return false; } m_offset += other->m_offset; return true; } diff --git a/libs/flake/commands/KoPathPointMoveCommand.cpp b/libs/flake/commands/KoPathPointMoveCommand.cpp index e5ca17d40b..59a3ddc9ff 100644 --- a/libs/flake/commands/KoPathPointMoveCommand.cpp +++ b/libs/flake/commands/KoPathPointMoveCommand.cpp @@ -1,138 +1,139 @@ /* This file is part of the KDE project * Copyright (C) 2006,2008-2009 Jan Hambrecht * Copyright (C) 2006,2007 Thorsten Zachmann * Copyright (C) 2007 Thomas Zander * * 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 "KoPathPointMoveCommand.h" #include "KoPathPoint.h" #include #include "kis_command_ids.h" #include "krita_container_utils.h" class KoPathPointMoveCommandPrivate { public: KoPathPointMoveCommandPrivate() { } void applyOffset(qreal factor); QMap points; QSet paths; }; KoPathPointMoveCommand::KoPathPointMoveCommand(const QList &pointData, const QPointF &offset, KUndo2Command *parent) : KUndo2Command(parent), d(new KoPathPointMoveCommandPrivate()) { setText(kundo2_i18n("Move points")); foreach (const KoPathPointData &data, pointData) { if (!d->points.contains(data)) { d->points[data] = offset; d->paths.insert(data.pathShape); } } } KoPathPointMoveCommand::KoPathPointMoveCommand(const QList &pointData, const QList &offsets, KUndo2Command *parent) : KUndo2Command(parent), d(new KoPathPointMoveCommandPrivate()) { Q_ASSERT(pointData.count() == offsets.count()); setText(kundo2_i18n("Move points")); uint dataCount = pointData.count(); for (uint i = 0; i < dataCount; ++i) { const KoPathPointData & data = pointData[i]; if (!d->points.contains(data)) { d->points[data] = offsets[i]; d->paths.insert(data.pathShape); } } } KoPathPointMoveCommand::~KoPathPointMoveCommand() { delete d; } void KoPathPointMoveCommand::redo() { KUndo2Command::redo(); d->applyOffset(1.0); } void KoPathPointMoveCommand::undo() { KUndo2Command::undo(); d->applyOffset(-1.0); } int KoPathPointMoveCommand::id() const { return KisCommandUtils::ChangePathShapePointId; } bool KoPathPointMoveCommand::mergeWith(const KUndo2Command *command) { const KoPathPointMoveCommand *other = dynamic_cast(command); if (!other || other->d->paths != d->paths || !KritaUtils::compareListsUnordered(other->d->points.keys(), d->points.keys())) { return false; } auto it = d->points.begin(); while (it != d->points.end()) { it.value() += other->d->points[it.key()]; ++it; } return true; } void KoPathPointMoveCommandPrivate::applyOffset(qreal factor) { + QMap oldDirtyRects; + foreach (KoPathShape *path, paths) { - // repaint old bounding rect - path->update(); + oldDirtyRects[path] = path->boundingRect(); } QMap::iterator it(points.begin()); for (; it != points.end(); ++it) { KoPathShape *path = it.key().pathShape; // transform offset from document to shape coordinate system QPointF shapeOffset = path->documentToShape(factor*it.value()) - path->documentToShape(QPointF()); QTransform matrix; matrix.translate(shapeOffset.x(), shapeOffset.y()); KoPathPoint *p = path->pointByIndex(it.key().pointIndex); if (p) p->map(matrix); } foreach (KoPathShape *path, paths) { path->normalize(); // repaint new bounding rect - path->update(); + path->updateAbsolute(oldDirtyRects[path] | path->boundingRect()); } }