Krita

Palette.h
1/*
2 * SPDX-FileCopyrightText: 2017 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7#ifndef LIBKIS_PALETTE_H
8#define LIBKIS_PALETTE_H
9
10#include <QObject>
11#include <QList>
12
13#include "kritalibkis_export.h"
14#include "libkis.h"
15#include "Resource.h"
16#include "KoColorSet.h"
17#include <Swatch.h>
18
19class ManagedColor;
20
21
22/**
23 * @brief The Palette class
24 * Palette is a resource object that stores organised color data.
25 * It's purpose is to allow artists to save colors and store them.
26 *
27 * An example for printing all the palettes and the entries:
28 *
29 * @code
30import sys
31from krita import *
32
33resources = Application.resources("palette")
34
35for (k, v) in resources.items():
36 print(k)
37 palette = Palette(v)
38 for x in range(palette.numberOfEntries()):
39 entry = palette.colorSetEntryByIndex(x)
40 print(x, entry.name(), entry.id(), entry.spotColor())
41 * @endcode
42 */
43
44class KRITALIBKIS_EXPORT Palette : public QObject
45{
47 Q_DISABLE_COPY(Palette)
48
49public:
50 explicit Palette(Resource *resource, QObject *parent = 0);
51 ~Palette() override;
52
53 bool operator==(const Palette &other) const;
54 bool operator!=(const Palette &other) const;
55
56public Q_SLOTS:
57
58 /**
59 * @brief number of filled colors (swatches) in palette
60 * NOTE: same as `colorsCountTotal()`
61 *
62 * @return total number of colors
63 */
64 int numberOfEntries() const;
65
66 /**
67 * @brief Palettes are defined in grids.
68 * The number of column define grid width.
69 * The number of rows will depend of columns and total number of entries.
70 *
71 * @return the number of columns this palette is set to use.
72 */
73 int columnCount();
74 /**
75 * @brief Palettes are defined in grids.
76 * The number of column define grid width, this value can be defined.
77 * The number of rows will depend of columns and total number of entries.
78 *
79 * @param columns Set the amount of columns this palette should use.
80 */
81 void setColumnCount(int columns);
82
83 /**
84 * @brief The number of rows in the palette grid.
85 * If the palette has groups, the row count is defined by the groups' row count.
86 * Otherwise, it's determined by the number of columns and entries.
87 * @return the number of rows this palette has.
88 */
89 int rowCount();
90
91 /**
92 * @brief The number of rows defined in the given group.
93 * @param name of the group to check.
94 * @return the number of rows this group is set to use.
95 */
96 int rowCountGroup(QString name);
97
98 /**
99 * @brief Set the number of rows defined in the given group.
100 * @param rows the amount of rows this group should use.
101 * @param name of the group to modify.
102 */
103 void setRowCountGroup(int rows, QString name);
104
105 /**
106 * @brief the comment or description associated with the palette.
107 *
108 * @return A string for which value contains the comment/description of palette.
109 */
111
112 /**
113 * @brief the comment or description associated with the palette.
114 *
115 * @param comment set the comment or description associated with the palette.
116 */
118
119 /**
120 * @brief Palette content can be organized in groups.
121 *
122 * @return The list of group names (list of string). This list follow the order the groups are defined in palette.
123 */
124 QStringList groupNames() const;
125
126 /**
127 * @brief Palette content can be organized in groups.
128 * This method allows to add a new group in palette.
129 *
130 * @param name The name of the new group to add.
131 */
132 void addGroup(QString name);
133
134 /**
135 * @brief Palette content can be organized in groups.
136 * This method allows to remove an existing group from palette.
137 *
138 * @param name The name of the group to remove.
139 * @param keepColors whether or not to delete all the colors inside, or to move them to the default group.
140 */
141 void removeGroup(QString name, bool keepColors = true);
142
143 /**
144 * @brief number of filled colors (swatches) in palette
145 * NOTE: same as `numberOfEntries()`
146 *
147 * @return total number of colors
148 */
149 int colorsCountTotal();
150
151 /**
152 * @brief colorsCountGroup
153 * @param name of the group to check. Empty is the default group.
154 * @return the amount of filled colors within that group.
155 */
156 int colorsCountGroup(QString name);
157
158 /**
159 * @brief number of slots for swatches in palette
160 * This includes any empty slots not filled by a color.
161 *
162 * @return total number of slots
163 */
164 int slotCount();
165
166 /**
167 * @brief number of slots for swatches in group
168 * This includes any empty slots not filled by a color.
169 *
170 * @param name of the group to check. Empty is the default group.
171 * @return number of slots in group
172 */
173 int slotCountGroup(QString name);
174
175 /**
176 * @brief colorSetEntryByIndex
177 * get the colorsetEntry from the global index.
178 *
179 * DEPRECATED: use `entryByIndex()` instead
180 *
181 * @param index the global index
182 * @return the colorset entry
183 */
184 Q_DECL_DEPRECATED Swatch *colorSetEntryByIndex(int index);
185
186 /**
187 * @brief get color (swatch) from the global index.
188 *
189 * @param index the global index
190 * @return The Swatch color for given index.
191 */
192 Swatch *entryByIndex(int index);
193
194 /**
195 * @brief colorSetEntryFromGroup
196 *
197 * DEPRECATED: use `entryByIndexFromGroup()` instead
198 *
199 * @param index index in the group.
200 * @param groupName the name of the group to get the color from.
201 * @return the colorsetentry.
202 */
203 Q_DECL_DEPRECATED Swatch *colorSetEntryFromGroup(int index, const QString &groupName);
204
205 /**
206 * @brief get color (swatch) from the given group index.
207 *
208 * @param index index in the group.
209 * @param groupName the name of the group to get the color from.
210 * @return The Swatch color for given index within given group name.
211 */
212 Swatch *entryByIndexFromGroup(int index, const QString &groupName);
213
214 /**
215 * @brief add a color entry to a group.
216 * Color is appended to the end.
217 *
218 * @param entry the entry
219 * @param groupName the name of the group to add to.
220 */
221 void addEntry(Swatch entry, QString groupName = QString());
222
223 /**
224 * @brief Remove the color entry at the given index in this palette.
225 *
226 * @param index index in this palette.
227 */
228 void removeEntry(int index);
229
230 /**
231 * @brief Remove the color entry at the given index in the given group.
232 *
233 * @param index index in the group.
234 * @param groupName the name of the group to remove the entry from.
235 */
236 void removeEntryFromGroup(int index, const QString &groupName);
237
238 /**
239 * @brief changeGroupName
240 * change the group name.
241 *
242 * DEPRECATED: use `renameGroup()` instead
243 *
244 * @param oldGroupName the old groupname to change.
245 * @param newGroupName the new name to change it into.
246 * @return whether successful. Reasons for failure include not knowing have oldGroupName
247 */
248 Q_DECL_DEPRECATED void changeGroupName(QString oldGroupName, QString newGroupName);
249
250 /**
251 * @brief rename a group
252 *
253 * @param oldGroupName the old groupname to change.
254 * @param newGroupName the new name to change it into.
255 */
256 void renameGroup(QString oldGroupName, QString newGroupName);
257
258 /**
259 * @brief Move the group `groupName` to position before group `groupNameInsertBefore`.
260 *
261 * @param groupName group to move.
262 * @param groupNameInsertBefore reference group for which `groupName` have to be moved before.
263 */
264 void moveGroup(const QString &groupName, const QString &groupNameInsertBefore = QString());
265
266 /**
267 * @brief save the palette
268 *
269 * WARNING: this method does nothing and need to be implemented!
270 *
271 * @return always False
272 */
273 bool save();
274
275private:
276 friend class PaletteView;
277 struct Private;
278 Private *const d;
279
280 /**
281 * @brief colorSet
282 * @return gives a KoColorSet object back
283 */
284 KoColorSetSP colorSet();
285
286};
287
288#endif // LIBKIS_PALETTE_H
The ManagedColor class is a class to handle colors that are color managed.
int colorsCountGroup(QString name)
colorsCountGroup
Definition Palette.cpp:117
void moveGroup(const QString &groupName, const QString &groupNameInsertBefore=QString())
Move the group groupName to position before group groupNameInsertBefore.
Definition Palette.cpp:214
bool save()
save the palette
Definition Palette.cpp:219
void setColumnCount(int columns)
Palettes are defined in grids.
Definition Palette.cpp:52
Swatch * entryByIndexFromGroup(int index, const QString &groupName)
get color (swatch) from the given group index.
Definition Palette.cpp:161
void removeEntry(int index)
Remove the color entry at the given index in this palette.
Definition Palette.cpp:175
Q_DECL_DEPRECATED void changeGroupName(QString oldGroupName, QString newGroupName)
changeGroupName change the group name.
Definition Palette.cpp:203
Swatch * entryByIndex(int index)
get color (swatch) from the global index.
Definition Palette.cpp:145
void addGroup(QString name)
Palette content can be organized in groups.
Definition Palette.cpp:99
int slotCountGroup(QString name)
number of slots for swatches in group This includes any empty slots not filled by a color.
Definition Palette.cpp:131
int numberOfEntries() const
number of filled colors (swatches) in palette NOTE: same as colorsCountTotal()
Definition Palette.cpp:40
Q_DECL_DEPRECATED Swatch * colorSetEntryFromGroup(int index, const QString &groupName)
colorSetEntryFromGroup
Definition Palette.cpp:155
Q_DECL_DEPRECATED Swatch * colorSetEntryByIndex(int index)
colorSetEntryByIndex get the colorsetEntry from the global index.
Definition Palette.cpp:139
QString comment()
the comment or description associated with the palette.
Definition Palette.cpp:81
int colorsCountTotal()
number of filled colors (swatches) in palette NOTE: same as numberOfEntries()
Definition Palette.cpp:111
void renameGroup(QString oldGroupName, QString newGroupName)
rename a group
Definition Palette.cpp:209
int columnCount()
Palettes are defined in grids.
Definition Palette.cpp:46
void setRowCountGroup(int rows, QString name)
Set the number of rows defined in the given group.
Definition Palette.cpp:72
int slotCount()
number of slots for swatches in palette This includes any empty slots not filled by a color.
Definition Palette.cpp:125
void removeGroup(QString name, bool keepColors=true)
Palette content can be organized in groups.
Definition Palette.cpp:105
int rowCountGroup(QString name)
The number of rows defined in the given group.
Definition Palette.cpp:64
void removeEntryFromGroup(int index, const QString &groupName)
Remove the color entry at the given index in the given group.
Definition Palette.cpp:193
void setComment(QString comment)
the comment or description associated with the palette.
Definition Palette.cpp:87
void addEntry(Swatch entry, QString groupName=QString())
add a color entry to a group.
Definition Palette.cpp:170
int rowCount()
The number of rows in the palette grid.
Definition Palette.cpp:58
QStringList groupNames() const
Palette content can be organized in groups.
Definition Palette.cpp:93
A Resource represents a gradient, pattern, brush tip, brush preset, palette or workspace definition.
Definition Resource.h:31
The Swatch class is a thin wrapper around the KisSwatch class.
Definition Swatch.h:22
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
Q_SLOTSQ_SLOTS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Apr 18 2025 12:12:36 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.