File indexing completed on 2025-02-02 04:14:49
0001 /* This file is part of the KDE project 0002 * SPDX-FileCopyrightText: 2010 Jeremy Lugagne <lugagne.jeremy@gmail.com> 0003 * SPDX-FileCopyrightText: 2011 Jean-Nicolas Artaud <jeannicolasartaud@gmail.com> 0004 * 0005 * SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include "KoPathShapeMarkerCommand.h" 0009 #include "KoMarker.h" 0010 #include "KoPathShape.h" 0011 #include <QExplicitlySharedDataPointer> 0012 0013 #include "kis_command_ids.h" 0014 0015 #include <klocalizedstring.h> 0016 0017 struct Q_DECL_HIDDEN KoPathShapeMarkerCommand::Private 0018 { 0019 QList<KoPathShape*> shapes; ///< the shapes to set marker for 0020 QList<QExplicitlySharedDataPointer<KoMarker>> oldMarkers; ///< the old markers, one for each shape 0021 QExplicitlySharedDataPointer<KoMarker> marker; ///< the new marker to set 0022 KoFlake::MarkerPosition position; 0023 QList<bool> oldAutoFillMarkers; 0024 }; 0025 0026 KoPathShapeMarkerCommand::KoPathShapeMarkerCommand(const QList<KoPathShape*> &shapes, KoMarker *marker, KoFlake::MarkerPosition position, KUndo2Command *parent) 0027 : KUndo2Command(kundo2_i18n("Set marker"), parent), 0028 m_d(new Private) 0029 { 0030 m_d->shapes = shapes; 0031 m_d->marker = marker; 0032 m_d->position = position; 0033 0034 // save old markers 0035 Q_FOREACH (KoPathShape *shape, m_d->shapes) { 0036 m_d->oldMarkers.append(QExplicitlySharedDataPointer<KoMarker>(shape->marker(position))); 0037 m_d->oldAutoFillMarkers.append(shape->autoFillMarkers()); 0038 } 0039 } 0040 0041 KoPathShapeMarkerCommand::~KoPathShapeMarkerCommand() 0042 { 0043 } 0044 0045 void KoPathShapeMarkerCommand::redo() 0046 { 0047 KUndo2Command::redo(); 0048 Q_FOREACH (KoPathShape *shape, m_d->shapes) { 0049 const QRectF oldDirtyRect = shape->boundingRect(); 0050 shape->setMarker(m_d->marker.data(), m_d->position); 0051 0052 // we have no GUI for selection auto-filling yet! So just enable it! 0053 shape->setAutoFillMarkers(true); 0054 0055 shape->updateAbsolute(oldDirtyRect | shape->boundingRect()); 0056 } 0057 } 0058 0059 void KoPathShapeMarkerCommand::undo() 0060 { 0061 KUndo2Command::undo(); 0062 auto markerIt = m_d->oldMarkers.begin(); 0063 auto autoFillIt = m_d->oldAutoFillMarkers.begin(); 0064 Q_FOREACH (KoPathShape *shape, m_d->shapes) { 0065 const QRectF oldDirtyRect = shape->boundingRect(); 0066 shape->setMarker((*markerIt).data(), m_d->position); 0067 shape->setAutoFillMarkers(*autoFillIt); 0068 shape->updateAbsolute(oldDirtyRect | shape->boundingRect()); 0069 ++markerIt; 0070 ++autoFillIt; 0071 } 0072 } 0073 0074 int KoPathShapeMarkerCommand::id() const 0075 { 0076 return KisCommandUtils::ChangeShapeMarkersId; 0077 } 0078 0079 bool KoPathShapeMarkerCommand::mergeWith(const KUndo2Command *command) 0080 { 0081 const KoPathShapeMarkerCommand *other = dynamic_cast<const KoPathShapeMarkerCommand*>(command); 0082 0083 if (!other || 0084 other->m_d->shapes != m_d->shapes || 0085 other->m_d->position != m_d->position) { 0086 0087 return false; 0088 } 0089 0090 m_d->marker = other->m_d->marker; 0091 return true; 0092 }