File indexing completed on 2024-05-12 15:56:41
0001 /* 0002 * SPDX-FileCopyrightText: 2016 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef KOFLAKEUTILS_H 0008 #define KOFLAKEUTILS_H 0009 0010 #include <KoShape.h> 0011 #include <KoFlakeTypes.h> 0012 #include <KoShapeStroke.h> 0013 0014 #include "kis_global.h" 0015 #include "KoShapeStrokeCommand.h" 0016 0017 0018 namespace KoFlake { 0019 0020 template <typename ModifyFunction> 0021 auto modifyShapesStrokes(QList<KoShape*> shapes, ModifyFunction modifyFunction) 0022 -> decltype(modifyFunction(KoShapeStrokeSP()), (KUndo2Command*)(0)) 0023 { 0024 if (shapes.isEmpty()) return 0; 0025 0026 QList<KoShapeStrokeModelSP> newStrokes; 0027 0028 Q_FOREACH(KoShape *shape, shapes) { 0029 KoShapeStrokeSP shapeStroke = shape->stroke() ? 0030 qSharedPointerDynamicCast<KoShapeStroke>(shape->stroke()) : 0031 KoShapeStrokeSP(); 0032 0033 KoShapeStrokeSP newStroke = 0034 toQShared(shapeStroke ? 0035 new KoShapeStroke(*shapeStroke) : 0036 new KoShapeStroke()); 0037 0038 modifyFunction(newStroke); 0039 0040 newStrokes << newStroke; 0041 } 0042 0043 return new KoShapeStrokeCommand(shapes, newStrokes); 0044 } 0045 0046 template <class Policy> 0047 bool compareShapePropertiesEqual(const QList<KoShape*> shapes, const Policy &policy) 0048 { 0049 if (shapes.size() == 1) return true; 0050 0051 typename Policy::PointerType bg = 0052 policy.getProperty(shapes.first()); 0053 0054 Q_FOREACH (KoShape *shape, shapes) { 0055 typename Policy::PointerType otherBg = policy.getProperty(shape); 0056 0057 if ( 0058 !( 0059 (!bg && !otherBg) || 0060 (bg && otherBg && policy.compareTo(bg, otherBg)) 0061 )) { 0062 0063 return false; 0064 } 0065 } 0066 0067 return true; 0068 } 0069 0070 template <class Policy> 0071 bool compareShapePropertiesEqual(const QList<KoShape*> shapes) 0072 { 0073 return compareShapePropertiesEqual<Policy>(shapes, Policy()); 0074 } 0075 0076 } 0077 0078 #endif // KOFLAKEUTILS_H 0079