Changeset View
Changeset View
Standalone View
Standalone View
libs/libkis/Palette.cpp
Context not available. | |||||
18 | 18 | | |||
---|---|---|---|---|---|
19 | #include "Palette.h" | 19 | #include "Palette.h" | ||
20 | #include <KoColorSet.h> | 20 | #include <KoColorSet.h> | ||
21 | #include <KisSwatch.h> | ||||
22 | #include <KisSwatchGroup.h> | ||||
21 | #include <ManagedColor.h> | 23 | #include <ManagedColor.h> | ||
24 | #include <KisPaletteModel.h> | ||||
22 | 25 | | |||
23 | struct Palette::Private { | 26 | struct Palette::Private { | ||
24 | KoColorSet *palette {0}; | 27 | KoColorSet *palette {0}; | ||
Context not available. | |||||
36 | int Palette::numberOfEntries() const | 39 | int Palette::numberOfEntries() const | ||
37 | { | 40 | { | ||
38 | if (!d->palette) return 0; | 41 | if (!d->palette) return 0; | ||
39 | return d->palette->nColors(); | 42 | return d->palette->colorCount(); | ||
40 | } | 43 | } | ||
41 | 44 | | |||
42 | int Palette::columnCount() | 45 | int Palette::columnCount() | ||
Context not available. | |||||
63 | return d->palette->setComment(comment); | 66 | return d->palette->setComment(comment); | ||
64 | } | 67 | } | ||
65 | 68 | | |||
66 | QStringList Palette::groupNames() | 69 | QStringList Palette::groupNames() const | ||
67 | { | 70 | { | ||
68 | if (!d->palette) return QStringList(); | 71 | if (!d->palette) return QStringList(); | ||
69 | return d->palette->getGroupNames(); | 72 | return d->palette->getGroupNames(); | ||
Context not available. | |||||
84 | int Palette::colorsCountTotal() | 87 | int Palette::colorsCountTotal() | ||
85 | { | 88 | { | ||
86 | if (!d->palette) return 0; | 89 | if (!d->palette) return 0; | ||
87 | return d->palette->nColors(); | 90 | return d->palette->colorCount(); | ||
88 | } | 91 | } | ||
89 | 92 | | |||
90 | int Palette::colorsCountGroup(QString name) | 93 | KisSwatch Palette::colorSetEntryByIndex(int index) | ||
91 | { | 94 | { | ||
92 | if (!d->palette) return 0; | 95 | if (!d->palette) return KisSwatch(); | ||
93 | return d->palette->nColorsGroup(name); | 96 | int col = index % columnCount(); | ||
94 | } | 97 | int row = (index - col) / columnCount(); | ||
95 | 98 | return d->palette->getColorGlobal(col, row); | |||
96 | KoColorSetEntry Palette::colorSetEntryByIndex(int index) | 99 | return KisSwatch(); | ||
97 | { | | |||
98 | if (!d->palette) return KoColorSetEntry(); | | |||
99 | return d->palette->getColorGlobal(index); | | |||
100 | } | 100 | } | ||
101 | 101 | | |||
102 | KoColorSetEntry Palette::colorSetEntryFromGroup(int index, const QString &groupName) | 102 | KisSwatch Palette::colorSetEntryFromGroup(int index, const QString &groupName) | ||
103 | { | 103 | { | ||
104 | if (!d->palette) return KoColorSetEntry(); | 104 | if (!d->palette) return KisSwatch(); | ||
105 | 105 | int row = index % columnCount(); | |||
106 | return d->palette->getColorGroup(index, groupName); | 106 | return d->palette->getColorGroup((index - row) / columnCount(), row, groupName); | ||
107 | } | 107 | } | ||
108 | 108 | | |||
109 | ManagedColor *Palette::colorForEntry(KoColorSetEntry entry) | 109 | ManagedColor *Palette::colorForEntry(KisSwatch entry) | ||
110 | { | 110 | { | ||
111 | if (!d->palette) return 0; | 111 | if (!d->palette) return Q_NULLPTR; | ||
112 | ManagedColor *color = new ManagedColor(entry.color()); | 112 | ManagedColor *color = new ManagedColor(entry.color()); | ||
113 | return color; | 113 | return color; | ||
114 | } | 114 | } | ||
115 | 115 | | |||
116 | void Palette::addEntry(KoColorSetEntry entry, QString groupName) | 116 | void Palette::addEntry(KisSwatch entry, QString groupName) | ||
117 | { | 117 | { | ||
118 | d->palette->add(entry, groupName); | 118 | d->palette->add(entry, groupName); | ||
119 | } | 119 | } | ||
120 | 120 | | |||
121 | void Palette::removeEntry(int index, const QString &groupName) | 121 | void Palette::removeEntry(int index, const QString &groupName) | ||
122 | { | 122 | { | ||
123 | d->palette->removeAt(index, groupName); | 123 | int col = index % columnCount(); | ||
124 | } | 124 | int tmp = index; | ||
125 | 125 | int row = (index - col) / columnCount(); | |||
126 | void Palette::insertEntry(int index, KoColorSetEntry entry, QString groupName) | 126 | KisSwatchGroup *groupFoundIn = Q_NULLPTR; | ||
127 | { | 127 | Q_FOREACH(const QString &name, groupNames()) { | ||
128 | d->palette->insertBefore(entry, index, groupName); | 128 | KisSwatchGroup *g = d->palette->getGroup(name); | ||
129 | } | 129 | tmp -= g->rowCount() * columnCount(); | ||
130 | if (tmp < 0) { | ||||
131 | groupFoundIn = g; | ||||
132 | break; | ||||
133 | } | ||||
134 | row -= g->rowCount(); | ||||
130 | 135 | | |||
131 | bool Palette::editEntry(int index, KoColorSetEntry entry, QString groupName) | 136 | } | ||
132 | { | 137 | if (!groupFoundIn) { return; } | ||
133 | return d->palette->changeColorSetEntry(entry, groupName, index); | 138 | groupFoundIn->removeEntry(col, row); | ||
134 | } | 139 | } | ||
135 | 140 | | |||
136 | bool Palette::changeGroupName(QString oldGroupName, QString newGroupName) | 141 | bool Palette::changeGroupName(QString oldGroupName, QString newGroupName) | ||
Context not available. |