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

KDE's Doxygen guidelines are available online.