Changeset View
Changeset View
Standalone View
Standalone View
libs/flake/KoFlakeUtils.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (c) 2016 Dmitry Kazakov <dimula73@gmail.com> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or modify | ||||
5 | * it under the terms of the GNU General Public License as published by | ||||
6 | * the Free Software Foundation; either version 2 of the License, or | ||||
7 | * (at your option) any later version. | ||||
8 | * | ||||
9 | * This program is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
12 | * GNU General Public License for more details. | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU General Public License | ||||
15 | * along with this program; if not, write to the Free Software | ||||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
17 | */ | ||||
18 | | ||||
19 | #ifndef KOFLAKEUTILS_H | ||||
20 | #define KOFLAKEUTILS_H | ||||
21 | | ||||
22 | #include <KoShape.h> | ||||
23 | #include <KoFlakeTypes.h> | ||||
24 | #include <KoShapeStroke.h> | ||||
25 | | ||||
26 | #include "kis_global.h" | ||||
27 | #include "KoShapeStrokeCommand.h" | ||||
28 | | ||||
29 | | ||||
30 | namespace KoFlake { | ||||
31 | | ||||
32 | template <typename ModifyFunction> | ||||
33 | auto modifyShapesStrokes(QList<KoShape*> shapes, ModifyFunction modifyFunction) | ||||
34 | -> decltype(modifyFunction(KoShapeStrokeSP()), (KUndo2Command*)(0)) | ||||
35 | { | ||||
36 | if (shapes.isEmpty()) return 0; | ||||
37 | | ||||
38 | QList<KoShapeStrokeModelSP> newStrokes; | ||||
39 | | ||||
40 | Q_FOREACH(KoShape *shape, shapes) { | ||||
41 | KoShapeStrokeSP shapeStroke = shape->stroke() ? | ||||
42 | qSharedPointerDynamicCast<KoShapeStroke>(shape->stroke()) : | ||||
43 | KoShapeStrokeSP(); | ||||
44 | | ||||
45 | KoShapeStrokeSP newStroke = | ||||
46 | toQShared(shapeStroke ? | ||||
47 | new KoShapeStroke(*shapeStroke) : | ||||
48 | new KoShapeStroke()); | ||||
49 | | ||||
50 | modifyFunction(newStroke); | ||||
51 | | ||||
52 | newStrokes << newStroke; | ||||
53 | } | ||||
54 | | ||||
55 | return new KoShapeStrokeCommand(shapes, newStrokes); | ||||
56 | } | ||||
57 | | ||||
58 | template <class Policy> | ||||
59 | bool compareShapePropertiesEqual(const QList<KoShape*> shapes, const Policy &policy) | ||||
60 | { | ||||
61 | if (shapes.size() == 1) return true; | ||||
62 | | ||||
63 | typename Policy::PointerType bg = | ||||
64 | policy.getProperty(shapes.first()); | ||||
65 | | ||||
66 | Q_FOREACH (KoShape *shape, shapes) { | ||||
67 | if ( | ||||
68 | !( | ||||
69 | (!bg && !policy.getProperty(shape)) || | ||||
70 | (bg && policy.compareTo(bg, policy.getProperty(shape))) | ||||
71 | )) { | ||||
72 | | ||||
73 | return false; | ||||
74 | } | ||||
75 | } | ||||
76 | | ||||
77 | return true; | ||||
78 | } | ||||
79 | | ||||
80 | template <class Policy> | ||||
81 | bool compareShapePropertiesEqual(const QList<KoShape*> shapes) | ||||
82 | { | ||||
83 | return compareShapePropertiesEqual<Policy>(shapes, Policy()); | ||||
84 | } | ||||
85 | | ||||
86 | } | ||||
87 | | ||||
88 | #endif // KOFLAKEUTILS_H | ||||
89 | |