Krita Source Code Documentation
Loading...
Searching...
No Matches
Palette Class Reference

The Palette class Palette is a resource object that stores organised color data. It's purpose is to allow artists to save colors and store them. More...

#include <Palette.h>

+ Inheritance diagram for Palette:

Public Slots

void addEntry (Swatch entry, QString groupName=QString())
 add a color entry to a group. Color is appended to the end.
 
void addGroup (QString name)
 Palette content can be organized in groups. This method allows to add a new group in palette.
 
Q_DECL_DEPRECATED void changeGroupName (QString oldGroupName, QString newGroupName)
 changeGroupName change the group name.
 
int colorsCountGroup (QString name)
 colorsCountGroup
 
int colorsCountTotal ()
 number of filled colors (swatches) in palette NOTE: same as numberOfEntries()
 
Q_DECL_DEPRECATED SwatchcolorSetEntryByIndex (int index)
 colorSetEntryByIndex get the colorsetEntry from the global index.
 
Q_DECL_DEPRECATED SwatchcolorSetEntryFromGroup (int index, const QString &groupName)
 colorSetEntryFromGroup
 
int columnCount ()
 Palettes are defined in grids. The number of column define grid width. The number of rows will depend of columns and total number of entries.
 
QString comment ()
 the comment or description associated with the palette.
 
SwatchentryByIndex (int index)
 get color (swatch) from the global index.
 
SwatchentryByIndexFromGroup (int index, const QString &groupName)
 get color (swatch) from the given group index.
 
QStringList groupNames () const
 Palette content can be organized in groups.
 
void moveGroup (const QString &groupName, const QString &groupNameInsertBefore=QString())
 Move the group groupName to position before group groupNameInsertBefore.
 
int numberOfEntries () const
 number of filled colors (swatches) in palette NOTE: same as colorsCountTotal()
 
void removeEntry (int index)
 Remove the color entry at the given index in this palette.
 
void removeEntryFromGroup (int index, const QString &groupName)
 Remove the color entry at the given index in the given group.
 
void removeGroup (QString name, bool keepColors=true)
 Palette content can be organized in groups. This method allows to remove an existing group from palette.
 
void renameGroup (QString oldGroupName, QString newGroupName)
 rename a group
 
int rowCount ()
 The number of rows in the palette grid. If the palette has groups, the row count is defined by the groups' row count. Otherwise, it's determined by the number of columns and entries.
 
int rowCountGroup (QString name)
 The number of rows defined in the given group.
 
bool save ()
 save the palette
 
void setColumnCount (int columns)
 Palettes are defined in grids. The number of column define grid width, this value can be defined. The number of rows will depend of columns and total number of entries.
 
void setComment (QString comment)
 the comment or description associated with the palette.
 
void setRowCountGroup (int rows, QString name)
 Set the number of rows defined in the given group.
 
int slotCount ()
 number of slots for swatches in palette This includes any empty slots not filled by a color.
 
int slotCountGroup (QString name)
 number of slots for swatches in group This includes any empty slots not filled by a color.
 

Public Member Functions

bool operator!= (const Palette &other) const
 
bool operator== (const Palette &other) const
 
 Palette (Resource *resource, QObject *parent=0)
 
 ~Palette () override
 

Private Member Functions

KoColorSetSP colorSet ()
 colorSet
 

Private Attributes

Private *const d
 

Friends

class PaletteView
 

Detailed Description

The Palette class Palette is a resource object that stores organised color data. It's purpose is to allow artists to save colors and store them.

An example for printing all the palettes and the entries:

import sys
from krita import *
resources = Application.resources("palette")
for (k, v) in resources.items():
print(k)
for x in range(palette.numberOfEntries()):
print(x, entry.name(), entry.id(), entry.spotColor())
qreal v
Palette(Resource *resource, QObject *parent=0)
Definition Palette.cpp:18
Q_DECL_DEPRECATED Swatch * colorSetEntryByIndex(int index)
colorSetEntryByIndex get the colorsetEntry from the global index.
Definition Palette.cpp:139
rgba palette[MAX_PALETTE]
Definition palette.c:35

Definition at line 43 of file Palette.h.

Constructor & Destructor Documentation

◆ Palette()

Palette::Palette ( Resource * resource,
QObject * parent = 0 )
explicit

Definition at line 18 of file Palette.cpp.

19 : QObject(parent)
20 , d(new Private()) {
21 d->palette = resource->resource().dynamicCast<KoColorSet>();
22}
Private *const d
Definition Palette.h:277
KoResourceSP resource() const
Definition Resource.cpp:116
KoColorSetSP palette
Definition Palette.cpp:15

References d, krita::Palette::Private::palette, and Resource::resource().

◆ ~Palette()

Palette::~Palette ( )
override

Definition at line 24 of file Palette.cpp.

25{
26 delete d;
27}

References d.

Member Function Documentation

◆ addEntry

void Palette::addEntry ( Swatch entry,
QString groupName = QString() )
slot

add a color entry to a group. Color is appended to the end.

Parameters
entrythe entry
groupNamethe name of the group to add to.

Definition at line 170 of file Palette.cpp.

171{
172 d->palette->addSwatch(entry.kisSwatch(), groupName);
173}
KisSwatch kisSwatch() const
Definition Swatch.cpp:100

References d, Swatch::kisSwatch(), and krita::Palette::Private::palette.

◆ addGroup

void Palette::addGroup ( QString name)
slot

Palette content can be organized in groups. This method allows to add a new group in palette.

Parameters
nameThe name of the new group to add.

Definition at line 99 of file Palette.cpp.

100{
101 if (!d->palette) return;
102 d->palette->addGroup(name);
103}

References d, and krita::Palette::Private::palette.

◆ changeGroupName

void Palette::changeGroupName ( QString oldGroupName,
QString newGroupName )
slot

changeGroupName change the group name.

DEPRECATED: use renameGroup() instead

Parameters
oldGroupNamethe old groupname to change.
newGroupNamethe new name to change it into.
Returns
whether successful. Reasons for failure include not knowing have oldGroupName

Definition at line 203 of file Palette.cpp.

204{
205 warnScript << "DEPRECATED Palette.changeGroupName() - use Palette.renameGroup() instead";
206 return renameGroup(oldGroupName, newGroupName);
207}
void renameGroup(QString oldGroupName, QString newGroupName)
rename a group
Definition Palette.cpp:209
#define warnScript
Definition kis_debug.h:98

References renameGroup(), and warnScript.

◆ colorsCountGroup

int Palette::colorsCountGroup ( QString name)
slot

colorsCountGroup

Parameters
nameof the group to check. Empty is the default group.
Returns
the amount of filled colors within that group.

Definition at line 117 of file Palette.cpp.

118{
119 if (!d->palette) return 0;
120 KisSwatchGroupSP group = d->palette->getGroup(name);
121 if (!group) return 0;
122 return group->colorCount();
123}

References d, and krita::Palette::Private::palette.

◆ colorsCountTotal

int Palette::colorsCountTotal ( )
slot

number of filled colors (swatches) in palette NOTE: same as numberOfEntries()

Returns
total number of colors

Definition at line 111 of file Palette.cpp.

112{
113 if (!d->palette) return 0;
114 return d->palette->colorCount();
115}

References d, and krita::Palette::Private::palette.

◆ colorSet()

KoColorSetSP Palette::colorSet ( )
private

colorSet

Returns
gives a KoColorSet object back

Definition at line 224 of file Palette.cpp.

225{
226 return d->palette;
227}

References d, and krita::Palette::Private::palette.

◆ colorSetEntryByIndex

Swatch * Palette::colorSetEntryByIndex ( int index)
slot

colorSetEntryByIndex get the colorsetEntry from the global index.

DEPRECATED: use entryByIndex() instead

Parameters
indexthe global index
Returns
the colorset entry

Definition at line 139 of file Palette.cpp.

140{
141 warnScript << "DEPRECATED Palette.colorSetEntryByIndex() - use Palette.entryByIndex() instead";
142 return entryByIndex(index);
143}
Swatch * entryByIndex(int index)
get color (swatch) from the global index.
Definition Palette.cpp:145

References entryByIndex(), and warnScript.

◆ colorSetEntryFromGroup

Swatch * Palette::colorSetEntryFromGroup ( int index,
const QString & groupName )
slot

colorSetEntryFromGroup

DEPRECATED: use entryByIndexFromGroup() instead

Parameters
indexindex in the group.
groupNamethe name of the group to get the color from.
Returns
the colorsetentry.

Definition at line 155 of file Palette.cpp.

156{
157 warnScript << "DEPRECATED Palette.colorSetEntryFromGroup() - use Palette.entryByIndexFromGroup() instead";
158 return entryByIndexFromGroup(index, groupName);
159}
Swatch * entryByIndexFromGroup(int index, const QString &groupName)
get color (swatch) from the given group index.
Definition Palette.cpp:161

References entryByIndexFromGroup(), and warnScript.

◆ columnCount

int Palette::columnCount ( )
slot

Palettes are defined in grids. The number of column define grid width. The number of rows will depend of columns and total number of entries.

Returns
the number of columns this palette is set to use.

Definition at line 46 of file Palette.cpp.

47{
48 if (!d->palette) return 0;
49 return d->palette->columnCount();
50}

References d, and krita::Palette::Private::palette.

◆ comment

QString Palette::comment ( )
slot

the comment or description associated with the palette.

Returns
A string for which value contains the comment/description of palette.

Definition at line 81 of file Palette.cpp.

82{
83 if (!d->palette) return "";
84 return d->palette->comment();
85}

References d, and krita::Palette::Private::palette.

◆ entryByIndex

Swatch * Palette::entryByIndex ( int index)
slot

get color (swatch) from the global index.

Parameters
indexthe global index
Returns
The Swatch color for given index.

Definition at line 145 of file Palette.cpp.

146{
147 if (!d->palette || columnCount() == 0) {
148 return new Swatch();
149 }
150 int col = index % columnCount();
151 int row = (index - col) / columnCount();
152 return new Swatch(d->palette->getColorGlobal(col, row));
153}
int columnCount()
Palettes are defined in grids. The number of column define grid width. The number of rows will depend...
Definition Palette.cpp:46
The Swatch class is a thin wrapper around the KisSwatch class.
Definition Swatch.h:22

References columnCount(), d, and krita::Palette::Private::palette.

◆ entryByIndexFromGroup

Swatch * Palette::entryByIndexFromGroup ( int index,
const QString & groupName )
slot

get color (swatch) from the given group index.

Parameters
indexindex in the group.
groupNamethe name of the group to get the color from.
Returns
The Swatch color for given index within given group name.

Definition at line 161 of file Palette.cpp.

162{
163 if (!d->palette || columnCount() == 0) {
164 return new Swatch();
165 }
166 int col = index % columnCount();
167 return new Swatch(d->palette->getSwatchFromGroup(col, (index - col) / columnCount(), groupName));
168}

References columnCount(), d, and krita::Palette::Private::palette.

◆ groupNames

QStringList Palette::groupNames ( ) const
slot

Palette content can be organized in groups.

Returns
The list of group names (list of string). This list follow the order the groups are defined in palette.

Definition at line 93 of file Palette.cpp.

94{
95 if (!d->palette) return QStringList();
96 return d->palette->swatchGroupNames();
97}
QList< QString > QStringList

References d, and krita::Palette::Private::palette.

◆ moveGroup

void Palette::moveGroup ( const QString & groupName,
const QString & groupNameInsertBefore = QString() )
slot

Move the group groupName to position before group groupNameInsertBefore.

Parameters
groupNamegroup to move.
groupNameInsertBeforereference group for which groupName have to be moved before.

Definition at line 214 of file Palette.cpp.

215{
216 return d->palette->moveGroup(groupName, groupNameInsertBefore);
217}

References d, and krita::Palette::Private::palette.

◆ numberOfEntries

int Palette::numberOfEntries ( ) const
slot

number of filled colors (swatches) in palette NOTE: same as colorsCountTotal()

Returns
total number of colors

Definition at line 40 of file Palette.cpp.

41{
42 if (!d->palette) return 0;
43 return d->palette->colorCount();
44}

References d, and krita::Palette::Private::palette.

◆ operator!=()

bool Palette::operator!= ( const Palette & other) const

Definition at line 34 of file Palette.cpp.

35{
36 return !(operator==(other));
37}
bool operator==(const Palette &other) const
Definition Palette.cpp:29

References operator==().

◆ operator==()

bool Palette::operator== ( const Palette & other) const

Definition at line 29 of file Palette.cpp.

30{
31 return (d->palette == other.d->palette);
32}

References d, and krita::Palette::Private::palette.

◆ removeEntry

void Palette::removeEntry ( int index)
slot

Remove the color entry at the given index in this palette.

Parameters
indexindex in this palette.

Definition at line 175 of file Palette.cpp.

176{
177 int col = index % columnCount();
178 int tmp = index;
179 int row = (index - col) / columnCount();
180 KisSwatchGroupSP groupFoundIn;
181 Q_FOREACH(const QString &name, groupNames()) {
182 KisSwatchGroupSP g = d->palette->getGroup(name);
183 tmp -= g->rowCount() * columnCount();
184 if (tmp < 0) {
185 groupFoundIn = g;
186 break;
187 }
188 row -= g->rowCount();
189 }
190 if (!groupFoundIn) { return; }
191 d->palette->removeSwatch(col, row, groupFoundIn);
192}
QStringList groupNames() const
Palette content can be organized in groups.
Definition Palette.cpp:93

References columnCount(), d, groupNames(), and krita::Palette::Private::palette.

◆ removeEntryFromGroup

void Palette::removeEntryFromGroup ( int index,
const QString & groupName )
slot

Remove the color entry at the given index in the given group.

Parameters
indexindex in the group.
groupNamethe name of the group to remove the entry from.

Definition at line 193 of file Palette.cpp.

194{
195 if (!d->palette) return;
196 KisSwatchGroupSP group = d->palette->getGroup(groupName);
197 if (!group) return;
198 int col = index % columnCount();
199 int row = (index - col) / columnCount();
200 d->palette->removeSwatch(col, row, group);
201}

References columnCount(), d, and krita::Palette::Private::palette.

◆ removeGroup

void Palette::removeGroup ( QString name,
bool keepColors = true )
slot

Palette content can be organized in groups. This method allows to remove an existing group from palette.

Parameters
nameThe name of the group to remove.
keepColorswhether or not to delete all the colors inside, or to move them to the default group.

Definition at line 105 of file Palette.cpp.

106{
107 if (!d->palette) return;
108 return d->palette->removeGroup(name, keepColors);
109}

References d, and krita::Palette::Private::palette.

◆ renameGroup

void Palette::renameGroup ( QString oldGroupName,
QString newGroupName )
slot

rename a group

Parameters
oldGroupNamethe old groupname to change.
newGroupNamethe new name to change it into.

Definition at line 209 of file Palette.cpp.

210{
211 d->palette->changeGroupName(oldGroupName, newGroupName);
212}

References d, and krita::Palette::Private::palette.

◆ rowCount

int Palette::rowCount ( )
slot

The number of rows in the palette grid. If the palette has groups, the row count is defined by the groups' row count. Otherwise, it's determined by the number of columns and entries.

Returns
the number of rows this palette has.

Definition at line 58 of file Palette.cpp.

59{
60 if (!d->palette) return 0;
61 return d->palette->rowCount();
62}

References d, and krita::Palette::Private::palette.

◆ rowCountGroup

int Palette::rowCountGroup ( QString name)
slot

The number of rows defined in the given group.

Parameters
nameof the group to check.
Returns
the number of rows this group is set to use.

Definition at line 64 of file Palette.cpp.

65{
66 if (!d->palette) return 0;
67 KisSwatchGroupSP group = d->palette->getGroup(name);
68 if (!group) return 0;
69 return group->rowCount();
70}

References d, and krita::Palette::Private::palette.

◆ save

bool Palette::save ( )
slot

save the palette

WARNING: this method does nothing and need to be implemented!

Returns
always False

Definition at line 219 of file Palette.cpp.

220{
221 return false;
222}

◆ setColumnCount

void Palette::setColumnCount ( int columns)
slot

Palettes are defined in grids. The number of column define grid width, this value can be defined. The number of rows will depend of columns and total number of entries.

Parameters
columnsSet the amount of columns this palette should use.

Definition at line 52 of file Palette.cpp.

53{
54 if (d->palette && columns > 0)
55 d->palette->setColumnCount(columns);
56}

References d, and krita::Palette::Private::palette.

◆ setComment

void Palette::setComment ( QString comment)
slot

the comment or description associated with the palette.

Parameters
commentset the comment or description associated with the palette.

Definition at line 87 of file Palette.cpp.

88{
89 if (!d->palette) return;
90 return d->palette->setComment(comment);
91}
QString comment()
the comment or description associated with the palette.
Definition Palette.cpp:81

References comment(), d, and krita::Palette::Private::palette.

◆ setRowCountGroup

void Palette::setRowCountGroup ( int rows,
QString name )
slot

Set the number of rows defined in the given group.

Parameters
rowsthe amount of rows this group should use.
nameof the group to modify.

Definition at line 72 of file Palette.cpp.

73{
74 if (!d->palette) return;
75 KisSwatchGroupSP group = d->palette->getGroup(name);
76 if (!group) return;
77 if (rows > 0)
78 group->setRowCount(rows);
79}

References d, and krita::Palette::Private::palette.

◆ slotCount

int Palette::slotCount ( )
slot

number of slots for swatches in palette This includes any empty slots not filled by a color.

Returns
total number of slots

Definition at line 125 of file Palette.cpp.

126{
127 if (!d->palette) return 0;
128 return d->palette->slotCount();
129}

References d, and krita::Palette::Private::palette.

◆ slotCountGroup

int Palette::slotCountGroup ( QString name)
slot

number of slots for swatches in group This includes any empty slots not filled by a color.

Parameters
nameof the group to check. Empty is the default group.
Returns
number of slots in group

Definition at line 131 of file Palette.cpp.

132{
133 if (!d->palette) return 0;
134 KisSwatchGroupSP group = d->palette->getGroup(name);
135 if (!group) return 0;
136 return group->slotCount();
137}

References d, and krita::Palette::Private::palette.

Friends And Related Symbol Documentation

◆ PaletteView

friend class PaletteView
friend

Definition at line 275 of file Palette.h.

Member Data Documentation

◆ d

Private* const Palette::d
private

Definition at line 277 of file Palette.h.


The documentation for this class was generated from the following files: