Changeset View
Changeset View
Standalone View
Standalone View
libs/pigment/resources/KoColorSet.h
Context not available. | |||||
27 | 27 | | |||
---|---|---|---|---|---|
28 | #include <resources/KoResource.h> | 28 | #include <resources/KoResource.h> | ||
29 | #include "KoColor.h" | 29 | #include "KoColor.h" | ||
30 | #include "KoColorSetEntry.h" | 30 | #include "KisSwatch.h" | ||
31 | #include "KisSwatchGroup.h" | ||||
31 | 32 | | |||
32 | /** | 33 | /** | ||
34 | * Also called palette. | ||||
33 | * Open Gimp, Photoshop or RIFF palette files. This is a straight port | 35 | * Open Gimp, Photoshop or RIFF palette files. This is a straight port | ||
34 | * from the Gimp. | 36 | * from the Gimp. | ||
35 | */ | 37 | */ | ||
Context not available. | |||||
37 | { | 39 | { | ||
38 | Q_OBJECT | 40 | Q_OBJECT | ||
39 | public: | 41 | public: | ||
42 | static const QString GLOBAL_GROUP_NAME; | ||||
43 | static const QString KPL_VERSION_ATTR; | ||||
44 | static const QString KPL_GROUP_ROW_COUNT_ATTR; | ||||
45 | static const QString KPL_PALETTE_COLUMN_COUNT_ATTR; | ||||
46 | static const QString KPL_PALETTE_NAME_ATTR; | ||||
47 | static const QString KPL_PALETTE_COMMENT_ATTR; | ||||
48 | static const QString KPL_PALETTE_FILENAME_ATTR; | ||||
49 | static const QString KPL_PALETTE_READONLY_ATTR; | ||||
50 | static const QString KPL_COLOR_MODEL_ID_ATTR; | ||||
51 | static const QString KPL_COLOR_DEPTH_ID_ATTR; | ||||
52 | static const QString KPL_GROUP_NAME_ATTR; | ||||
53 | static const QString KPL_SWATCH_ROW_ATTR; | ||||
54 | static const QString KPL_SWATCH_COL_ATTR; | ||||
55 | static const QString KPL_SWATCH_NAME_ATTR; | ||||
56 | static const QString KPL_SWATCH_SPOT_ATTR; | ||||
57 | static const QString KPL_SWATCH_ID_ATTR; | ||||
58 | static const QString KPL_SWATCH_BITDEPTH_ATTR; | ||||
59 | static const QString KPL_PALETTE_PROFILE_TAG; | ||||
60 | static const QString KPL_SWATCH_POS_TAG; | ||||
61 | static const QString KPL_SWATCH_TAG; | ||||
62 | static const QString KPL_GROUP_TAG; | ||||
63 | static const QString KPL_PALETTE_TAG; | ||||
40 | 64 | | |||
65 | public: | ||||
41 | enum PaletteType { | 66 | enum PaletteType { | ||
42 | UNKNOWN = 0, | 67 | UNKNOWN = 0, | ||
43 | GPL, // GIMP | 68 | GPL, // GIMP | ||
Context not available. | |||||
57 | * a Krita palette, | 82 | * a Krita palette, | ||
58 | * a Scribus palette or a SwatchBooker palette. | 83 | * a Scribus palette or a SwatchBooker palette. | ||
59 | */ | 84 | */ | ||
60 | explicit KoColorSet(const QString &filename); | 85 | explicit KoColorSet(const QString &filename = QString()); | ||
61 | | ||||
62 | /// Create an empty color set | | |||
63 | KoColorSet(); | | |||
64 | 86 | | |||
65 | /// Explicit copy constructor (KoResource copy constructor is private) | 87 | // Explicit copy constructor (KoResource copy constructor is private) | ||
66 | KoColorSet(const KoColorSet& rhs); | 88 | KoColorSet(const KoColorSet& rhs); | ||
67 | 89 | | |||
90 | public /* overridden methods */: // KoResource | ||||
68 | ~KoColorSet() override; | 91 | ~KoColorSet() override; | ||
69 | 92 | | |||
70 | bool load() override; | 93 | bool load() override; | ||
71 | bool loadFromDevice(QIODevice *dev) override; | 94 | bool loadFromDevice(QIODevice *dev) override; | ||
72 | bool save() override; | 95 | bool save() override; | ||
73 | bool saveToDevice(QIODevice* dev) const override; | 96 | bool saveToDevice(QIODevice* dev) const override; | ||
74 | | ||||
75 | QString defaultFileExtension() const override; | 97 | QString defaultFileExtension() const override; | ||
76 | 98 | | |||
99 | | ||||
100 | public /* methods */: | ||||
77 | void setColumnCount(int columns); | 101 | void setColumnCount(int columns); | ||
78 | int columnCount(); | 102 | int columnCount() const; | ||
79 | /** | | |||
80 | * @brief comment | | |||
81 | * @return the comment. | | |||
82 | */ | | |||
83 | QString comment(); | | |||
84 | 103 | | |||
85 | void setComment(QString comment); | 104 | void setComment(QString comment); | ||
105 | QString comment(); | ||||
86 | 106 | | |||
87 | public: | 107 | int rowCount() const; | ||
108 | quint32 colorCount() const; | ||||
109 | | ||||
110 | PaletteType paletteType() const; | ||||
111 | void setPaletteType(PaletteType paletteType); | ||||
88 | 112 | | |||
89 | /** | 113 | /** | ||
90 | * @brief add Add a color to the palette. | 114 | * @brief isGlobal | ||
91 | * @param groupName color to add the group to. If empty, it will be added to the unsorted. | 115 | * A global color set is a set stored in the config directory | ||
116 | * Such a color set would be opened every time Krita is launched. | ||||
117 | * | ||||
118 | * A non-global color set, on contrary, would be stored in a kra file, | ||||
119 | * and would only be opened when that file is opened by Krita. | ||||
120 | * @return | ||||
92 | */ | 121 | */ | ||
93 | void add(const KoColorSetEntry &, QString groupName = QString()); | 122 | bool isGlobal() const; | ||
123 | void setIsGlobal(bool); | ||||
124 | | ||||
125 | bool isEditable() const; | ||||
126 | void setIsEditable(bool isEditable); | ||||
127 | | ||||
128 | QByteArray toByteArray() const; | ||||
129 | bool fromByteArray(QByteArray &data); | ||||
94 | 130 | | |||
95 | /** | 131 | /** | ||
96 | * @brief insertBefore insert color before index into group. | 132 | * @brief add Add a color to the palette. | ||
97 | * @param index | 133 | * @param groupName color to add the group to. If empty, it will be added to the unsorted. | ||
98 | * @param groupName name of the group that the color goes into. | | |||
99 | * @return new index of index after the prepending. | | |||
100 | */ | 134 | */ | ||
101 | quint32 insertBefore(const KoColorSetEntry &, qint32 index, const QString &groupName = QString()); | 135 | void add(const KisSwatch &, const QString &groupName = GLOBAL_GROUP_NAME); | ||
102 | 136 | void setEntry(const KisSwatch &e, int x, int y, const QString &groupName = GLOBAL_GROUP_NAME); | |||
103 | void removeAt(quint32 index, QString groupName = QString()); | | |||
104 | 137 | | |||
105 | /** | 138 | /** | ||
106 | * @brief getColorGlobal | 139 | * @brief getColorGlobal | ||
Context not available. | |||||
108 | * @param globalIndex the global index over the whole palette. | 141 | * @param globalIndex the global index over the whole palette. | ||
109 | * @return the entry. | 142 | * @return the entry. | ||
110 | */ | 143 | */ | ||
111 | KoColorSetEntry getColorGlobal(quint32 globalIndex); | 144 | KisSwatch getColorGlobal(quint32 x, quint32 y) const; | ||
145 | | ||||
112 | /** | 146 | /** | ||
113 | * @brief getColorGroup | 147 | * @brief getColorGroup | ||
114 | * A function for getting the color from a specific group. | 148 | * A function for getting the color from a specific group. | ||
Context not available. | |||||
116 | * @param index the index within the group. | 150 | * @param index the index within the group. | ||
117 | * @return the entry | 151 | * @return the entry | ||
118 | */ | 152 | */ | ||
119 | KoColorSetEntry getColorGroup(quint32 index, QString groupName = QString()); | 153 | KisSwatch getColorGroup(quint32 x, quint32 y, QString groupName); | ||
120 | | ||||
121 | QString findGroupByGlobalIndex(quint32 globalIndex, quint32 *index); | | |||
122 | QString findGroupByColorName(const QString &name, quint32 *index); | | |||
123 | QString findGroupByID(const QString &id,quint32 *index); | | |||
124 | 154 | | |||
125 | /** | 155 | /** | ||
126 | * @brief getGroupNames | 156 | * @brief getGroupNames | ||
Context not available. | |||||
128 | */ | 158 | */ | ||
129 | QStringList getGroupNames(); | 159 | QStringList getGroupNames(); | ||
130 | 160 | | |||
131 | bool changeGroupName(QString oldGroupName, QString newGroupName); | | |||
132 | | ||||
133 | bool changeColorSetEntry(KoColorSetEntry entry, QString groupName, quint32 index); | | |||
134 | | ||||
135 | /** | 161 | /** | ||
136 | * @brief nColorsGroup | 162 | * @brief getGroup | ||
137 | * @param groupName string name of the group, when not specified, returns unsorted colors. | 163 | * @param name | ||
138 | * @return the amount of colors in this group. | 164 | * @return the group with the name given; global group if no parameter is given | ||
165 | * null pointer if not found. | ||||
139 | */ | 166 | */ | ||
140 | quint32 nColorsGroup(QString groupName = QString()); | 167 | KisSwatchGroup *getGroup(const QString &name); | ||
141 | /** | 168 | KisSwatchGroup *getGlobalGroup(); | ||
142 | * @brief nColors | 169 | | ||
143 | * @return total colors in palette. | 170 | bool changeGroupName(const QString &oldGroupName, const QString &newGroupName); | ||
144 | */ | 171 | | ||
145 | quint32 nColors(); | | |||
146 | 172 | | |||
147 | /** | 173 | /** | ||
148 | * @brief addGroup | 174 | * @brief addGroup | ||
Context not available. | |||||
159 | * @param groupNameInsertBefore the groupname to insert before. Empty means it will be added to the end. | 185 | * @param groupNameInsertBefore the groupname to insert before. Empty means it will be added to the end. | ||
160 | * @return | 186 | * @return | ||
161 | */ | 187 | */ | ||
162 | bool moveGroup(const QString &groupName, const QString &groupNameInsertBefore = QString()); | 188 | bool moveGroup(const QString &groupName, const QString &groupNameInsertBefore = GLOBAL_GROUP_NAME); | ||
163 | /** | 189 | /** | ||
164 | * @brief removeGroup | 190 | * @brief removeGroup | ||
165 | * Remove a group from the KoColorSet | 191 | * Remove a group from the KoColorSet | ||
Context not available. | |||||
180 | * when the two colors' colorspaces don't match. Else it'll use the entry's colorspace. | 206 | * when the two colors' colorspaces don't match. Else it'll use the entry's colorspace. | ||
181 | * @return returns the int of the closest match. | 207 | * @return returns the int of the closest match. | ||
182 | */ | 208 | */ | ||
183 | quint32 getIndexClosestColor(KoColor color, bool useGivenColorSpace = true); | 209 | KisSwatchGroup::SwatchInfo getClosestColorInfo(KoColor compare, bool useGivenColorSpace = true); | ||
184 | | ||||
185 | /** | | |||
186 | * @brief closestColorName | | |||
187 | * convenience function to get the name of the closest match. | | |||
188 | * @param color | | |||
189 | * @param useGivenColorSpace | | |||
190 | * @return | | |||
191 | */ | | |||
192 | QString closestColorName(KoColor color, bool useGivenColorSpace = true); | | |||
193 | 210 | | |||
194 | private: | 211 | private: | ||
195 | 212 | class Private; | |||
196 | | ||||
197 | bool init(); | | |||
198 | | ||||
199 | bool saveGpl(QIODevice *dev) const; | | |||
200 | bool loadGpl(); | | |||
201 | | ||||
202 | bool loadAct(); | | |||
203 | bool loadRiff(); | | |||
204 | bool loadPsp(); | | |||
205 | bool loadAco(); | | |||
206 | bool loadXml(); | | |||
207 | bool loadSbz(); | | |||
208 | | ||||
209 | bool saveKpl(QIODevice *dev) const; | | |||
210 | bool loadKpl(); | | |||
211 | | ||||
212 | | ||||
213 | | ||||
214 | struct Private; | | |||
215 | const QScopedPointer<Private> d; | 213 | const QScopedPointer<Private> d; | ||
216 | 214 | | |||
217 | }; | 215 | }; | ||
218 | #endif // KOCOLORSET | 216 | #endif // KOCOLORSET | ||
219 | | ||||
Context not available. |