Krita Source Code Documentation
Loading...
Searching...
No Matches
KoStopGradient.h
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2007 Sven Langkamp <sven.langkamp@gmail.com>
3
4 SPDX-License-Identifier: LGPL-2.1-or-later
5 */
6#ifndef KOSTOPGRADIENT_H
7#define KOSTOPGRADIENT_H
8
9#include <QPair>
10#include <QGradient>
11#include <QtAlgorithms>
12
13#include "KoColor.h"
15#include <KoResource.h>
16#include <kritapigment_export.h>
17#include <boost/operators.hpp>
18
25
26struct KoGradientStop : public boost::equality_comparable<KoGradientStop>
27{
30 qreal position;
31
32 KoGradientStop(qreal _position = 0.0, KoColor _color = KoColor(), KoGradientStopType _type = COLORSTOP)
33 {
34 type = _type;
35 color = _color;
36 position = _position;
37 }
38
39 bool operator == (const KoGradientStop& other) const
40 {
41 return this->type == other.type && this->color == other.color && this->position == other.position;
42 }
43
44
45
46 QString typeString() const
47 {
48 switch (type) {
49 case COLORSTOP:
50 return "color-stop";
51 case FOREGROUNDSTOP:
52 return "foreground-stop";
53 case BACKGROUNDSTOP:
54 return "background-stop";
55 default:
56 return "color-stop";
57 }
58 }
59
60 static KoGradientStopType typeFromString(QString typestring) {
61 if (typestring == "foreground-stop") {
62 return FOREGROUNDSTOP;
63 } else if (typestring == "background-stop") {
64 return BACKGROUNDSTOP;
65 } else {
66 return COLORSTOP;
67 }
68 }
69};
70
71
73{
74 inline bool operator() (const KoGradientStop& a, const KoGradientStop& b) {
75 return (a.color.toQColor().valueF() < b.color.toQColor().valueF());
76 }
77};
78
80{
81 inline bool operator() (const KoGradientStop& a, const KoGradientStop& b) {
82 return (a.color.toQColor().hueF() < b.color.toQColor().hueF());
83 }
84};
85
89class KRITAPIGMENT_EXPORT KoStopGradient : public KoAbstractGradient, public boost::equality_comparable<KoStopGradient>
90{
91
92public:
93
94 explicit KoStopGradient(const QString &filename = QString());
95 ~KoStopGradient() override;
97 bool operator==(const KoStopGradient &rhs) const;
99 KoResourceSP clone() const override;
100
101 bool loadFromDevice(QIODevice *dev, KisResourcesInterfaceSP resourcesInterface) override;
102 bool saveToDevice(QIODevice* dev) const override;
103
104 QPair<QString, QString> resourceType() const override {
105 return QPair<QString, QString>(ResourceType::Gradients, ResourceSubType::StopGradients);
106 }
107
109 QGradient* toQGradient() const override;
110
112 bool stopsAt(KoGradientStop& leftStop, KoGradientStop& rightStop, qreal t) const;
113
115 void colorAt(KoColor&, qreal t) const override;
116
118 static QSharedPointer<KoStopGradient> fromQGradient(const QGradient *gradient);
119
121 void setStops(QList<KoGradientStop> stops);
122 QList<KoGradientStop> stops() const;
123
124 QList<int> requiredCanvasResources() const override;
125 void bakeVariableColors(KoCanvasResourcesInterfaceSP canvasResourcesInterface) override;
126 void updateVariableColors(KoCanvasResourcesInterfaceSP canvasResourcesInterface) override;
127
128
130 QString defaultFileExtension() const override;
131
136 void toXML(QDomDocument& doc, QDomElement& gradientElt) const;
142 static KoStopGradient fromXML(const QDomElement& elt);
143
144 QString saveSvgGradient() const;
145
146protected:
147
149 bool m_hasVariableStops = false;
150 QPointF m_start;
151 QPointF m_stop;
153
154private:
155
156 void loadSvgGradient(QIODevice *file);
157 void parseSvgGradient(const QDomElement& element, QHash<QString, const KoColorProfile*> profiles);
158};
159
161
162#endif // KOSTOPGRADIENT_H
163
bool operator==(const KisRegion &lhs, const KisRegion &rhs)
KoGradientStopType
@ FOREGROUNDSTOP
@ BACKGROUNDSTOP
@ COLORSTOP
QSharedPointer< KoStopGradient > KoStopGradientSP
void toQColor(QColor *c) const
a convenience method for the above.
Definition KoColor.cpp:198
QList< KoGradientStop > m_stops
KoStopGradient & operator=(const KoStopGradient &rhs)=delete
QPair< QString, QString > resourceType() const override
const QString StopGradients
const QString Gradients
virtual void colorAt(KoColor &, qreal t) const
gets the color at position 0 <= t <= 1
virtual void bakeVariableColors(KoCanvasResourcesInterfaceSP canvasResourcesInterface)
virtual QGradient * toQGradient() const
virtual void updateVariableColors(KoCanvasResourcesInterfaceSP canvasResourcesInterface)
bool operator()(const KoGradientStop &a, const KoGradientStop &b)
bool operator()(const KoGradientStop &a, const KoGradientStop &b)
QString typeString() const
KoGradientStopType type
static KoGradientStopType typeFromString(QString typestring)
KoGradientStop(qreal _position=0.0, KoColor _color=KoColor(), KoGradientStopType _type=COLORSTOP)
bool operator==(const KoGradientStop &other) const
virtual KoResourceSP clone() const =0
virtual QList< int > requiredCanvasResources() const
virtual QString defaultFileExtension() const
virtual bool saveToDevice(QIODevice *dev) const
virtual bool loadFromDevice(QIODevice *dev, KisResourcesInterfaceSP resourcesInterface)=0