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{
46 Q_OBJECT
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 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 comment or description associated with the palette.
85 *
86 * @return A string for which value contains the comment/description of palette.
87 */
88 QString comment();
89
90 /**
91 * @brief the comment or description associated with the palette.
92 *
93 * @param comment set the comment or description associated with the palette.
94 */
95 void setComment(QString comment);
96
97 /**
98 * @brief Palette content can be organized in groups.
99 *
100 * @return The list of group names (list of string). This list follow the order the groups are defined in palette.
101 */
102 QStringList groupNames() const;
103
104 /**
105 * @brief Palette content can be organized in groups.
106 * This method allows to add a new group in palette.
107 *
108 * @param name The name of the new group to add.
109 */
110 void addGroup(QString name);
111
112 /**
113 * @brief Palette content can be organized in groups.
114 * This method allows to remove an existing group from palette.
115 *
116 * @param name The name of the new group to remve.
117 * @param keepColors whether or not to delete all the colors inside, or to move them to the default group.
118 */
119 void removeGroup(QString name, bool keepColors = true);
120
121 /**
122 * @brief number of colors (swatches) in palette
123 * NOTE: same as `numberOfEntries()`
124 *
125 * @return total number of colors
126 */
127 int colorsCountTotal();
128
129 /**
130 * @brief colorSetEntryByIndex
131 * get the colorsetEntry from the global index.
132 *
133 * DEPRECATED: use `entryByIndex()` instead
134 *
135 * @param index the global index
136 * @return the colorset entry
137 */
138 Q_DECL_DEPRECATED Swatch *colorSetEntryByIndex(int index);
139
140 /**
141 * @brief get color (swatch) from the global index.
142 *
143 * @param index the global index
144 * @return The Swatch color for given index.
145 */
146 Swatch *entryByIndex(int index);
147
148 /**
149 * @brief colorSetEntryFromGroup
150 *
151 * DEPRECATED: use `entryByIndexFromGroup()` instead
152 *
153 * @param index index in the group.
154 * @param groupName the name of the group to get the color from.
155 * @return the colorsetentry.
156 */
157 Q_DECL_DEPRECATED Swatch *colorSetEntryFromGroup(int index, const QString &groupName);
158
159 /**
160 * @brief get color (swatch) from the given group index.
161 *
162 * @param index index in the group.
163 * @param groupName the name of the group to get the color from.
164 * @return The Swatch color for given index within given group name.
165 */
166 Swatch *entryByIndexFromGroup(int index, const QString &groupName);
167
168 /**
169 * @brief add a color entry to a group.
170 * Color is appended to the end.
171 *
172 * @param entry the entry
173 * @param groupName the name of the group to add to.
174 */
175 void addEntry(Swatch entry, QString groupName = QString());
176
177 /**
178 * @brief remove from defined group a color entry designed by given index.
179 *
180 * @param index index in the group.
181 * @param groupName the name of the group within which color have to be removed.
182 */
183 void removeEntry(int index, const QString &groupName);
184
185 /**
186 * @brief changeGroupName
187 * change the group name.
188 *
189 * DEPRECATED: use `renameGroup()` instead
190 *
191 * @param oldGroupName the old groupname to change.
192 * @param newGroupName the new name to change it into.
193 * @return whether successful. Reasons for failure include not knowing have oldGroupName
194 */
195 Q_DECL_DEPRECATED void changeGroupName(QString oldGroupName, QString newGroupName);
196
197 /**
198 * @brief rename a group
199 *
200 * @param oldGroupName the old groupname to change.
201 * @param newGroupName the new name to change it into.
202 */
203 void renameGroup(QString oldGroupName, QString newGroupName);
204
205 /**
206 * @brief Move the group `groupName` to position before group `groupNameInsertBefore`.
207 *
208 * @param groupName group to move.
209 * @param groupNameInsertBefore reference group for which `groupName` have to be moved before.
210 */
211 void moveGroup(const QString &groupName, const QString &groupNameInsertBefore = QString());
212
213 /**
214 * @brief save the palette
215 *
216 * WARNING: this method does nothing and need to be implemented!
217 *
218 * @return always False
219 */
220 bool save();
221
222private:
223 friend class PaletteView;
224 struct Private;
225 Private *const d;
226
227 /**
228 * @brief colorSet
229 * @return gives qa KoColorSet object back
230 */
231 KoColorSetSP colorSet();
232
233};
234
235#endif // LIBKIS_PALETTE_H
The ManagedColor class is a class to handle colors that are color managed.
The PaletteView class is a wrapper around a MVC method for handling palettes.
Definition PaletteView.h:32
The Palette class Palette is a resource object that stores organised color data.
Definition Palette.h:45
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
Q_SLOTSQ_SLOTS
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:02:09 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.