Krita

Palette.h
1 /*
2  * SPDX-FileCopyrightText: 2017 Wolthera van Hövell tot Westerflier <[email protected]>
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 
19 class 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
30 import sys
31 from krita import *
32 
33 resources = Application.resources("palette")
34 
35 for (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  c = palette.colorForEntry(entry);
41  print(x, entry.name(), entry.id(), entry.spotColor(), c.toQString())
42  * @endcode
43  */
44 
45 class KRITALIBKIS_EXPORT Palette : public QObject
46 {
47 public:
48  Palette(Resource *resource);
49  ~Palette() override;
50 
51  /**
52  * @brief numberOfEntries
53  * @return
54  */
55  int numberOfEntries() const;
56 
57  /**
58  * @brief columnCount
59  * @return the amount of columns this palette is set to use.
60  */
61  int columnCount();
62  /**
63  * @brief setColumnCount
64  * Set the amount of columns this palette should use.
65  */
66  void setColumnCount(int columns);
67  /**
68  * @brief comment
69  * @return the comment or description associated with the palette.
70  */
71  QString comment();
72  /**
73  * @brief setComment
74  * set the comment or description associated with the palette.
75  * @param comment
76  */
77  void setComment(QString comment);
78  /**
79  * @brief groupNames
80  * @return the list of group names. This is list is in the order these groups are in the file.
81  */
82  QStringList groupNames() const;
83  /**
84  * @brief addGroup
85  * @param name of the new group
86  * @return whether adding the group was successful.
87  */
88  void addGroup(QString name);
89  /**
90  * @brief removeGroup
91  * @param name the name of the group to remove.
92  * @param keepColors whether or not to delete all the colors inside, or to move them to the default group.
93  * @return
94  */
95  void removeGroup(QString name, bool keepColors = true);
96 
97  /**
98  * @brief colorsCountTotal
99  * @return the total amount of entries in the whole group
100  */
101  int colorsCountTotal();
102 
103  /**
104  * @brief colorSetEntryByIndex
105  * get the colorsetEntry from the global index.
106  * @param index the global index
107  * @return the colorset entry
108  */
109  Swatch *colorSetEntryByIndex(int index);
110  /**
111  * @brief colorSetEntryFromGroup
112  * @param index index in the group.
113  * @param groupName the name of the group to get the color from.
114  * @return the colorsetentry.
115  */
116  Swatch *colorSetEntryFromGroup(int index, const QString &groupName);
117 
118  /**
119  * @brief addEntry
120  * add an entry to a group. Gets appended to the end.
121  * @param entry the entry
122  * @param groupName the name of the group to add to.
123  */
124  void addEntry(Swatch entry, QString groupName = QString());
125  /**
126  * @brief removeEntry
127  * remove the entry at @p index from the group @p groupName.
128  */
129  void removeEntry(int index, const QString &groupName);
130 
131  /**
132  * @brief changeGroupName
133  * change the group name.
134  * @param oldGroupName the old groupname to change.
135  * @param newGroupName the new name to change it into.
136  * @return whether successful. Reasons for failure include not knowing have oldGroupName
137  */
138  void changeGroupName(QString oldGroupName, QString newGroupName);
139  /**
140  * @brief moveGroup
141  * move the group to before groupNameInsertBefore.
142  * @param groupName group to move.
143  * @param groupNameInsertBefore group to inset before.
144  * @return whether successful. Reasons for failure include either group not existing.
145  */
146  void moveGroup(const QString &groupName, const QString &groupNameInsertBefore = QString());
147 
148  /**
149  * @brief save
150  * save the palette
151  * @return whether it was successful.
152  */
153  bool save();
154 
155 private:
156  friend class PaletteView;
157  struct Private;
158  Private *const d;
159 
160  /**
161  * @brief colorSet
162  * @return gives qa KoColorSet object back
163  */
164  KoColorSetSP colorSet();
165 
166 };
167 
168 #endif // LIBKIS_PALETTE_H
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:30
The Swatch class is a thin wrapper around the KisSwatch class.
Definition: Swatch.h:21
The ManagedColor class is a class to handle colors that are color managed.
Definition: ManagedColor.h:45
The PaletteView class is a wrapper around a MVC method for handling palettes. This class shows a nice...
Definition: PaletteView.h:31
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Fri Sep 22 2023 04:09:51 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.