Krita Source Code Documentation
Loading...
Searching...
No Matches
KoFilterEffectLoadingContext.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2* SPDX-FileCopyrightText: 2010 Jan Hambrecht <jaham@gmx.net>
3*
4* SPDX-License-Identifier: LGPL-2.1-or-later
5*/
6
8
9#include <QString>
10#include <QRectF>
11#include <QFileInfo>
12#include <QDir>
13
15{
16public:
18 : convertFilterUnits(false), convertFilterPrimitiveUnits(false)
19 {}
20 QString basePath;
21 QRectF shapeBound;
24};
25
27 : d(new Private())
28{
29 d->basePath = basePath;
30}
31
36
38{
39 d->shapeBound = shapeBound;
40}
41
43{
44 d->convertFilterUnits = enable;
45}
46
48{
49 d->convertFilterPrimitiveUnits = enable;
50}
51
53{
54 if (!d->convertFilterUnits)
55 return value;
56
57 return QPointF(convertFilterUnitsX(value.x()), convertFilterUnitsY(value.y()));
58}
59
61{
62 if (!d->convertFilterUnits)
63 return value;
64
65 return value / d->shapeBound.width();
66}
67
69{
70 if (!d->convertFilterUnits)
71 return value;
72
73 return value / d->shapeBound.height();
74}
75
77{
78 if (!d->convertFilterPrimitiveUnits)
79 return value;
80
82}
83
85{
86 if (!d->convertFilterPrimitiveUnits)
87 return value;
88
89 return value / d->shapeBound.width();
90}
91
93{
94 if (!d->convertFilterPrimitiveUnits)
95 return value;
96
97 return value / d->shapeBound.height();
98}
99
100QString KoFilterEffectLoadingContext::pathFromHref(const QString &href) const
101{
102 QFileInfo info(href);
103 if (! info.isRelative())
104 return href;
105
106 QFileInfo pathInfo(QFileInfo(d->basePath).filePath());
107
108 QString relFile = href;
109 while (relFile.startsWith(QLatin1String("../"))) {
110 relFile.remove(0, 3);
111 pathInfo.setFile(pathInfo.dir(), QString());
112 }
113
114 QString absFile = pathInfo.absolutePath() + '/' + relFile;
115
116 return absFile;
117}
float value(const T *src, size_t ch)
This class provides a loading context for filter effects.
qreal convertFilterPrimitiveUnitsX(qreal value) const
Converts an x value from user space to bounding box coordinates.
qreal convertFilterUnitsX(qreal value) const
Converts an x value from user space to bounding box coordinates.
qreal convertFilterUnitsY(qreal value) const
Converts an y value from user space to bounding box coordinates.
KoFilterEffectLoadingContext(const QString &basePath=QString())
void enableFilterPrimitiveUnitsConversion(bool enable)
Enables conversion of filter primitive units.
qreal convertFilterPrimitiveUnitsY(qreal value) const
Converts an y value from user space to bounding box coordinates.
void enableFilterUnitsConversion(bool enable)
Enables conversion of filter units.
void setShapeBoundingBox(const QRectF &shapeBound)
QString pathFromHref(const QString &href) const
Converts a href to an absolute path name.