Changeset View
Changeset View
Standalone View
Standalone View
libs/widgets/KisPaletteModel.cpp
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | * Copyright (c) 2013 Sven Langkamp <sven.langkamp@gmail.com> | 2 | * Copyright (c) 2013 Sven Langkamp <sven.langkamp@gmail.com> | ||
3 | * Copyright (c) 2018 Michael Zhou <simeirxh@gmail.com> | ||||
3 | * | 4 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | 5 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | 6 | * it under the terms of the GNU General Public License as published by | ||
Context not available. | |||||
31 | #include <KoColorDisplayRendererInterface.h> | 32 | #include <KoColorDisplayRendererInterface.h> | ||
32 | 33 | | |||
33 | KisPaletteModel::KisPaletteModel(QObject* parent) | 34 | KisPaletteModel::KisPaletteModel(QObject* parent) | ||
34 | : QAbstractTableModel(parent), | 35 | : QAbstractTableModel(parent) | ||
35 | m_colorSet(0), | 36 | , m_colorSet(Q_NULLPTR) | ||
36 | m_displayRenderer(KoDumbColorDisplayRenderer::instance()) | 37 | , m_displayRenderer(KoDumbColorDisplayRenderer::instance()) | ||
37 | { | 38 | { | ||
39 | connect(this, SIGNAL(sigPaletteModified()), SLOT(slotPaletteModified())); | ||||
38 | } | 40 | } | ||
39 | 41 | | |||
40 | KisPaletteModel::~KisPaletteModel() | 42 | KisPaletteModel::~KisPaletteModel() | ||
41 | { | 43 | { | ||
42 | } | 44 | } | ||
43 | 45 | | |||
44 | void KisPaletteModel::setDisplayRenderer(KoColorDisplayRendererInterface *displayRenderer) | | |||
45 | { | | |||
46 | if (displayRenderer) { | | |||
47 | if (m_displayRenderer) { | | |||
48 | disconnect(m_displayRenderer, 0, this, 0); | | |||
49 | } | | |||
50 | m_displayRenderer = displayRenderer; | | |||
51 | connect(m_displayRenderer, SIGNAL(displayConfigurationChanged()), | | |||
52 | SLOT(slotDisplayConfigurationChanged())); | | |||
53 | } else { | | |||
54 | m_displayRenderer = KoDumbColorDisplayRenderer::instance(); | | |||
55 | } | | |||
56 | } | | |||
57 | | ||||
58 | void KisPaletteModel::slotDisplayConfigurationChanged() | | |||
59 | { | | |||
60 | beginResetModel(); | | |||
61 | endResetModel(); | | |||
62 | } | | |||
63 | | ||||
64 | QModelIndex KisPaletteModel::getLastEntryIndex() | | |||
65 | { | | |||
66 | int endRow = rowCount(); | | |||
67 | int endColumn = columnCount(); | | |||
68 | if (m_colorSet->nColors()>0) { | | |||
69 | QModelIndex i = this->index(endRow, endColumn, QModelIndex()); | | |||
70 | while (qvariant_cast<QStringList>(i.data(RetrieveEntryRole)).isEmpty()) { | | |||
71 | i = this->index(endRow, endColumn); | | |||
72 | endColumn -=1; | | |||
73 | if (endColumn<0) { | | |||
74 | endColumn = columnCount(); | | |||
75 | endRow-=1; | | |||
76 | } | | |||
77 | } | | |||
78 | return i; | | |||
79 | } | | |||
80 | return QModelIndex(); | | |||
81 | } | | |||
82 | | ||||
83 | QVariant KisPaletteModel::data(const QModelIndex& index, int role) const | 46 | QVariant KisPaletteModel::data(const QModelIndex& index, int role) const | ||
84 | { | 47 | { | ||
85 | KoColorSetEntry entry; | 48 | if (!index.isValid()) { return QVariant(); } | ||
86 | if (m_colorSet && m_displayRenderer) { | 49 | bool groupNameRow = m_groupNameRows.contains(index.row()); | ||
87 | //now to figure out whether we have a groupname row or not. | 50 | if (role == IsGroupNameRole) { | ||
88 | bool groupNameRow = false; | 51 | return groupNameRow; | ||
89 | quint32 indexInGroup = 0; | 52 | } | ||
90 | QString indexGroupName = QString(); | 53 | if (groupNameRow) { | ||
91 | 54 | return dataForGroupNameRow(index, role); | |||
92 | int rowstotal = m_colorSet->nColorsGroup()/columnCount(); | 55 | } else { | ||
93 | if (index.row()<=rowstotal && (quint32)(index.row()*columnCount()+index.column())<m_colorSet->nColorsGroup()) { | 56 | return dataForSwatch(index, role); | ||
94 | indexInGroup = (quint32)(index.row()*columnCount()+index.column()); | | |||
95 | } | | |||
96 | if (m_colorSet->nColorsGroup()==0) { | | |||
97 | rowstotal+=1; //always add one for the default group when considering groups. | | |||
98 | } | | |||
99 | Q_FOREACH (QString groupName, m_colorSet->getGroupNames()){ | | |||
100 | //we make an int for the rows added by the current group. | | |||
101 | int newrows = 1+m_colorSet->nColorsGroup(groupName)/columnCount(); | | |||
102 | if (m_colorSet->nColorsGroup(groupName)%columnCount() > 0) { | | |||
103 | newrows+=1; | | |||
104 | } | | |||
105 | if (newrows==0) { | | |||
106 | newrows+=1; //always add one for the group when considering groups. | | |||
107 | } | | |||
108 | quint32 tempIndex = (quint32)((index.row()-(rowstotal+2))*columnCount()+index.column()); | | |||
109 | if (index.row() == rowstotal+1) { | | |||
110 | //rowstotal+1 is taken up by the groupname. | | |||
111 | indexGroupName = groupName; | | |||
112 | groupNameRow = true; | | |||
113 | } else if (index.row() > (rowstotal+1) && index.row() <= rowstotal+newrows && | | |||
114 | tempIndex<m_colorSet->nColorsGroup(groupName)){ | | |||
115 | //otherwise it's an index to the colors in the group. | | |||
116 | indexGroupName = groupName; | | |||
117 | indexInGroup = tempIndex; | | |||
118 | } | | |||
119 | //add the new rows to the totalrows we've looked at. | | |||
120 | rowstotal += newrows; | | |||
121 | } | | |||
122 | if (groupNameRow) { | | |||
123 | switch (role) { | | |||
124 | case Qt::ToolTipRole: | | |||
125 | case Qt::DisplayRole: { | | |||
126 | return indexGroupName; | | |||
127 | } | | |||
128 | case IsHeaderRole: { | | |||
129 | return true; | | |||
130 | } | | |||
131 | case RetrieveEntryRole: { | | |||
132 | QStringList entryList; | | |||
133 | entryList.append(indexGroupName); | | |||
134 | entryList.append(QString::number(0)); | | |||
135 | return entryList; | | |||
136 | } | | |||
137 | } | | |||
138 | } else { | | |||
139 | if (indexInGroup < m_colorSet->nColorsGroup(indexGroupName)) { | | |||
140 | entry = m_colorSet->getColorGroup(indexInGroup, indexGroupName); | | |||
141 | switch (role) { | | |||
142 | case Qt::ToolTipRole: | | |||
143 | case Qt::DisplayRole: { | | |||
144 | return entry.name(); | | |||
145 | } | | |||
146 | case Qt::BackgroundRole: { | | |||
147 | QColor color = m_displayRenderer->toQColor(entry.color()); | | |||
148 | return QBrush(color); | | |||
149 | } | | |||
150 | case IsHeaderRole: { | | |||
151 | return false; | | |||
152 | } | | |||
153 | case RetrieveEntryRole: { | | |||
154 | QStringList entryList; | | |||
155 | entryList.append(indexGroupName); | | |||
156 | entryList.append(QString::number(indexInGroup)); | | |||
157 | return entryList; | | |||
158 | } | | |||
159 | } | | |||
160 | } | | |||
161 | } | | |||
162 | } | 57 | } | ||
163 | return QVariant(); | | |||
164 | } | 58 | } | ||
165 | 59 | | |||
166 | int KisPaletteModel::rowCount(const QModelIndex& /*parent*/) const | 60 | int KisPaletteModel::rowCount(const QModelIndex& /*parent*/) const | ||
167 | { | 61 | { | ||
168 | if (!m_colorSet) { | 62 | if (!m_colorSet) | ||
169 | return 0; | 63 | return 0; | ||
170 | } | 64 | return m_colorSet->rowCount() // count of color rows | ||
171 | if (m_colorSet->nColors()==0) { | 65 | + m_groupNameRows.size() // rows for names | ||
172 | return 0; | 66 | - 1; // global doesn't have a name | ||
173 | } | | |||
174 | if (columnCount() > 0) { | | |||
175 | int countedrows = m_colorSet->nColorsGroup("")/columnCount(); | | |||
176 | if (m_colorSet->nColorsGroup()%columnCount() > 0) { | | |||
177 | countedrows+=1; | | |||
178 | } | | |||
179 | if (m_colorSet->nColorsGroup()==0) { | | |||
180 | countedrows+=1; | | |||
181 | } | | |||
182 | Q_FOREACH (QString groupName, m_colorSet->getGroupNames()) { | | |||
183 | countedrows += 1; //add one for the name; | | |||
184 | countedrows += 1+(m_colorSet->nColorsGroup(groupName)/ columnCount()); | | |||
185 | if (m_colorSet->nColorsGroup(groupName)%columnCount() > 0) { | | |||
186 | countedrows+=1; | | |||
187 | } | | |||
188 | if (m_colorSet->nColorsGroup(groupName)==0) { | | |||
189 | countedrows+=1; | | |||
190 | } | | |||
191 | } | | |||
192 | countedrows +=1; //Our code up till now doesn't take 0 into account. | | |||
193 | return countedrows; | | |||
194 | } | | |||
195 | return m_colorSet->nColors()/15 + 1; | | |||
196 | } | 67 | } | ||
197 | 68 | | |||
198 | int KisPaletteModel::columnCount(const QModelIndex& /*parent*/) const | 69 | int KisPaletteModel::columnCount(const QModelIndex& /*parent*/) const | ||
Context not available. | |||||
200 | if (m_colorSet && m_colorSet->columnCount() > 0) { | 71 | if (m_colorSet && m_colorSet->columnCount() > 0) { | ||
201 | return m_colorSet->columnCount(); | 72 | return m_colorSet->columnCount(); | ||
202 | } | 73 | } | ||
203 | return 15; | 74 | if (!m_colorSet) { | ||
75 | return 0; | ||||
76 | } | ||||
77 | return 16; | ||||
204 | } | 78 | } | ||
205 | 79 | | |||
206 | Qt::ItemFlags KisPaletteModel::flags(const QModelIndex& index) const | 80 | Qt::ItemFlags KisPaletteModel::flags(const QModelIndex& index) const | ||
207 | { | 81 | { | ||
208 | if (index.isValid()) { | 82 | if (index.isValid()) { | ||
209 | return Qt::ItemIsSelectable | Qt::ItemIsEnabled | 83 | return Qt::ItemIsSelectable | | ||
210 | | Qt::ItemIsUserCheckable | 84 | Qt::ItemIsEnabled | | ||
211 | | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled; | 85 | Qt::ItemIsUserCheckable | | ||
86 | Qt::ItemIsDragEnabled | | ||||
87 | Qt::ItemIsDropEnabled; | ||||
212 | } | 88 | } | ||
213 | return Qt::ItemIsDropEnabled; | 89 | return Qt::ItemIsDropEnabled; | ||
214 | } | 90 | } | ||
215 | 91 | | |||
216 | QModelIndex KisPaletteModel::index(int row, int column, const QModelIndex& parent) const | 92 | QModelIndex KisPaletteModel::index(int row, int column, const QModelIndex& parent) const | ||
217 | { | 93 | { | ||
218 | if (m_colorSet) { | 94 | Q_UNUSED(parent); | ||
95 | Q_ASSERT(m_colorSet); | ||||
96 | int groupNameRow = groupNameRowForRow(row); | ||||
97 | KisSwatchGroup *group = m_colorSet->getGroup(m_groupNameRows[groupNameRow]); | ||||
98 | Q_ASSERT(group); | ||||
99 | return createIndex(row, column, group); | ||||
100 | } | ||||
219 | 101 | | |||
220 | //make an int to hold the amount of rows we've looked at. The initial is the total rows in the default group. | 102 | void KisPaletteModel::resetGroupNameRows() | ||
221 | int rowstotal = m_colorSet->nColorsGroup()/columnCount(); | 103 | { | ||
222 | if (row<=rowstotal && (quint32)(row*columnCount()+column)<m_colorSet->nColorsGroup()) { | 104 | m_groupNameRows.clear(); | ||
223 | //if the total rows are in the default group, we just return an index. | 105 | int row = -1; | ||
224 | return QAbstractTableModel::index(row, column, parent); | 106 | for (const QString &groupName : m_colorSet->getGroupNames()) { | ||
225 | } else if(row<0 && column<0) { | 107 | m_groupNameRows[row] = groupName; | ||
226 | return QAbstractTableModel::index(0, 0, parent); | 108 | row += m_colorSet->getGroup(groupName)->rowCount(); | ||
227 | } | 109 | row += 1; // row for group name | ||
228 | if (m_colorSet->nColorsGroup()==0) { | | |||
229 | rowstotal+=1; //always add one for the default group when considering groups. | | |||
230 | } | | |||
231 | Q_FOREACH (QString groupName, m_colorSet->getGroupNames()){ | | |||
232 | //we make an int for the rows added by the current group. | | |||
233 | int newrows = 1+m_colorSet->nColorsGroup(groupName)/columnCount(); | | |||
234 | if (m_colorSet->nColorsGroup(groupName)%columnCount() > 0) { | | |||
235 | newrows+=1; | | |||
236 | } | | |||
237 | if (m_colorSet->nColorsGroup(groupName)==0) { | | |||
238 | newrows+=1; //always add one for the group when considering groups. | | |||
239 | } | | |||
240 | if (rowstotal + newrows>rowCount()) { | | |||
241 | newrows = rowCount() - rowstotal; | | |||
242 | } | | |||
243 | quint32 tempIndex = (quint32)((row-(rowstotal+2))*columnCount()+column); | | |||
244 | if (row == rowstotal+1) { | | |||
245 | //rowstotal+1 is taken up by the groupname. | | |||
246 | return QAbstractTableModel::index(row, 0, parent); | | |||
247 | } else if (row > (rowstotal+1) && row <= rowstotal+newrows && tempIndex<m_colorSet->nColorsGroup(groupName)){ | | |||
248 | //otherwise it's an index to the colors in the group. | | |||
249 | return QAbstractTableModel::index(row, column, parent); | | |||
250 | } | | |||
251 | //add the new rows to the totalrows we've looked at. | | |||
252 | rowstotal += newrows; | | |||
253 | } | | |||
254 | } | 110 | } | ||
255 | return QModelIndex(); | | |||
256 | } | 111 | } | ||
257 | 112 | | |||
258 | void KisPaletteModel::setColorSet(KoColorSet* colorSet) | 113 | void KisPaletteModel::setPalette(KoColorSet* palette) | ||
259 | { | 114 | { | ||
260 | m_colorSet = colorSet; | | |||
261 | beginResetModel(); | 115 | beginResetModel(); | ||
116 | m_colorSet = palette; | ||||
117 | if (palette) { | ||||
118 | resetGroupNameRows(); | ||||
119 | } | ||||
262 | endResetModel(); | 120 | endResetModel(); | ||
121 | emit sigPaletteChanged(); | ||||
263 | } | 122 | } | ||
264 | 123 | | |||
265 | KoColorSet* KisPaletteModel::colorSet() const | 124 | KoColorSet* KisPaletteModel::colorSet() const | ||
Context not available. | |||||
267 | return m_colorSet; | 126 | return m_colorSet; | ||
268 | } | 127 | } | ||
269 | 128 | | |||
270 | QModelIndex KisPaletteModel::indexFromId(int i) const | 129 | int KisPaletteModel::rowNumberInGroup(int rowInModel) const | ||
271 | { | | |||
272 | QModelIndex index = QModelIndex(); | | |||
273 | if (!colorSet() || colorSet()->nColors() == 0) { | | |||
274 | return index; | | |||
275 | } | | |||
276 | | ||||
277 | if (i > (int)colorSet()->nColors()) { | | |||
278 | qWarning()<<"index is too big"<<i<<"/"<<colorSet()->nColors(); | | |||
279 | index = this->index(0,0); | | |||
280 | } | | |||
281 | | ||||
282 | if (i < (int)colorSet()->nColorsGroup(0)) { | | |||
283 | index = QAbstractTableModel::index(i/columnCount(), i % columnCount()); | | |||
284 | if (!index.isValid()) { | | |||
285 | index = QAbstractTableModel::index(0, 0, QModelIndex()); | | |||
286 | } | | |||
287 | return index; | | |||
288 | } else { | | |||
289 | int rowstotal = 1 + m_colorSet->nColorsGroup() / columnCount(); | | |||
290 | if (m_colorSet->nColorsGroup() == 0) { | | |||
291 | rowstotal += 1; | | |||
292 | } | | |||
293 | int totalIndexes = colorSet()->nColorsGroup(); | | |||
294 | Q_FOREACH (QString groupName, m_colorSet->getGroupNames()){ | | |||
295 | if (i + 1 <= (int)(totalIndexes + colorSet()->nColorsGroup(groupName)) && i + 1 > (int)totalIndexes) { | | |||
296 | int col = (i - totalIndexes) % columnCount(); | | |||
297 | int row = rowstotal + 1 + ((i - totalIndexes) / columnCount()); | | |||
298 | index = this->index(row, col); | | |||
299 | return index; | | |||
300 | } else { | | |||
301 | rowstotal += 1 + m_colorSet->nColorsGroup(groupName) / columnCount(); | | |||
302 | totalIndexes += colorSet()->nColorsGroup(groupName); | | |||
303 | if (m_colorSet->nColorsGroup(groupName)%columnCount() > 0) { | | |||
304 | rowstotal += 1; | | |||
305 | } | | |||
306 | if (m_colorSet->nColorsGroup(groupName)==0) { | | |||
307 | rowstotal += 1; //always add one for the group when considering groups. | | |||
308 | } | | |||
309 | } | | |||
310 | } | | |||
311 | } | | |||
312 | return index; | | |||
313 | } | | |||
314 | | ||||
315 | int KisPaletteModel::idFromIndex(const QModelIndex &index) const | | |||
316 | { | 130 | { | ||
317 | if (index.isValid()==false) { | 131 | if (m_groupNameRows.contains(rowInModel)) { | ||
318 | return -1; | | |||
319 | qWarning()<<"invalid index"; | | |||
320 | } | | |||
321 | int i=0; | | |||
322 | QStringList entryList = qvariant_cast<QStringList>(data(index, RetrieveEntryRole)); | | |||
323 | if (entryList.isEmpty()) { | | |||
324 | return -1; | 132 | return -1; | ||
325 | qWarning()<<"invalid index, there's no data to retrieve here"; | | |||
326 | } | | |||
327 | if (entryList.at(0)==QString()) { | | |||
328 | return entryList.at(1).toUInt(); | | |||
329 | } | 133 | } | ||
330 | 134 | for (auto it = m_groupNameRows.keys().rbegin(); it != m_groupNameRows.keys().rend(); it++) { | |||
331 | i = colorSet()->nColorsGroup(""); | 135 | if (*it < rowInModel) { | ||
332 | //find at which position the group is. | 136 | return rowInModel - *it - 1; | ||
333 | int groupIndex = colorSet()->getGroupNames().indexOf(entryList.at(0)); | 137 | } | ||
334 | //add all the groupsizes onto it till we get to our group. | | |||
335 | for(int g=0; g<groupIndex; g++) { | | |||
336 | i+=colorSet()->nColorsGroup(colorSet()->getGroupNames().at(g)); | | |||
337 | } | 138 | } | ||
338 | //then add the index. | 139 | return rowInModel; | ||
339 | i += entryList.at(1).toUInt(); | | |||
340 | return i; | | |||
341 | } | 140 | } | ||
342 | 141 | | |||
343 | KoColorSetEntry KisPaletteModel::colorSetEntryFromIndex(const QModelIndex &index) const | 142 | int KisPaletteModel::groupNameRowForName(const QString &groupName) | ||
344 | { | 143 | { | ||
345 | KoColorSetEntry blank = KoColorSetEntry(); | 144 | for (auto it = m_groupNameRows.begin(); it != m_groupNameRows.end(); it++) { | ||
346 | if (!index.isValid()) { | 145 | if (it.value() == groupName) { | ||
347 | return blank; | 146 | return it.key(); | ||
348 | } | 147 | } | ||
349 | QStringList entryList = qvariant_cast<QStringList>(data(index, RetrieveEntryRole)); | | |||
350 | if (entryList.isEmpty()) { | | |||
351 | return blank; | | |||
352 | } | 148 | } | ||
353 | QString groupName = entryList.at(0); | 149 | return -1; | ||
354 | quint32 indexInGroup = entryList.at(1).toUInt(); | | |||
355 | return m_colorSet->getColorGroup(indexInGroup, groupName); | | |||
356 | } | 150 | } | ||
357 | 151 | | |||
358 | bool KisPaletteModel::addColorSetEntry(KoColorSetEntry entry, QString groupName) | 152 | bool KisPaletteModel::addEntry(const KisSwatch &entry, const QString &groupName) | ||
359 | { | 153 | { | ||
360 | int col = m_colorSet->nColorsGroup(groupName)%columnCount(); | 154 | beginInsertRows(QModelIndex(), rowCount(), rowCount() + 1); | ||
361 | QModelIndex i = getLastEntryIndex(); | | |||
362 | if (col+1 > columnCount()) { | | |||
363 | beginInsertRows(QModelIndex(), i.row(), i.row()+1); | | |||
364 | } | | |||
365 | if ((int)m_colorSet->nColors() < columnCount()) { | | |||
366 | beginInsertColumns(QModelIndex(), m_colorSet->nColors(), m_colorSet->nColors()+1); | | |||
367 | } | | |||
368 | m_colorSet->add(entry, groupName); | 155 | m_colorSet->add(entry, groupName); | ||
369 | if (col + 1 > columnCount()) { | 156 | endInsertRows(); | ||
370 | endInsertRows(); | 157 | if (m_colorSet->isGlobal()) { | ||
371 | } | 158 | m_colorSet->save(); | ||
372 | if (m_colorSet->nColors() < (quint32)columnCount()) { | | |||
373 | endInsertColumns(); | | |||
374 | } | 159 | } | ||
160 | emit sigPaletteModified(); | ||||
375 | return true; | 161 | return true; | ||
376 | } | 162 | } | ||
377 | 163 | | |||
378 | bool KisPaletteModel::removeEntry(QModelIndex index, bool keepColors) | 164 | bool KisPaletteModel::removeEntry(const QModelIndex &index, bool keepColors) | ||
379 | { | 165 | { | ||
380 | QStringList entryList = qvariant_cast<QStringList>(index.data(RetrieveEntryRole)); | 166 | if (!qvariant_cast<bool>(data(index, IsGroupNameRole))) { | ||
381 | if (entryList.empty()) { | 167 | static_cast<KisSwatchGroup*>(index.internalPointer())->removeEntry(index.column(), | ||
382 | return false; | 168 | rowNumberInGroup(index.row())); | ||
383 | } | 169 | emit dataChanged(index, index); | ||
384 | QString groupName = entryList.at(0); | | |||
385 | quint32 indexInGroup = entryList.at(1).toUInt(); | | |||
386 | | ||||
387 | if (qvariant_cast<bool>(index.data(IsHeaderRole))==false) { | | |||
388 | if (index.column()-1<0 | | |||
389 | && m_colorSet->nColorsGroup(groupName)%columnCount() <1 | | |||
390 | && index.row()-1>0 | | |||
391 | && m_colorSet->nColorsGroup(groupName)/columnCount()>0) { | | |||
392 | beginRemoveRows(QModelIndex(), index.row(), index.row()-1); | | |||
393 | } | | |||
394 | m_colorSet->removeAt(indexInGroup, groupName); | | |||
395 | if (index.column()-1<0 | | |||
396 | && m_colorSet->nColorsGroup(groupName)%columnCount() <1 | | |||
397 | && index.row()-1>0 | | |||
398 | && m_colorSet->nColorsGroup(groupName)/columnCount()>0) { | | |||
399 | endRemoveRows(); | | |||
400 | } | | |||
401 | } else { | 170 | } else { | ||
402 | beginRemoveRows(QModelIndex(), index.row(), index.row()-1); | 171 | int groupNameRow = groupNameRowForRow(index.row()); | ||
403 | m_colorSet->removeGroup(groupName, keepColors); | 172 | QString groupName = m_groupNameRows[groupNameRow]; | ||
404 | endRemoveRows(); | 173 | removeGroup(groupName, keepColors); | ||
405 | } | 174 | } | ||
175 | emit sigPaletteModified(); | ||||
406 | return true; | 176 | return true; | ||
407 | } | 177 | } | ||
408 | 178 | | |||
409 | bool KisPaletteModel::addGroup(QString groupName) | 179 | void KisPaletteModel::removeGroup(const QString &groupName, bool keepColors) | ||
410 | { | 180 | { | ||
411 | QModelIndex i = getLastEntryIndex(); | 181 | int removeStart = groupNameRowForName(groupName); | ||
412 | beginInsertRows(QModelIndex(), i.row(), i.row()+1); | 182 | int removedRowCount = m_colorSet->getGroup(groupName)->rowCount(); | ||
413 | m_colorSet->addGroup(groupName); | 183 | beginRemoveRows(QModelIndex(), | ||
414 | endInsertRows(); | 184 | removeStart, | ||
415 | return true; | 185 | removeStart + removedRowCount); | ||
416 | } | 186 | m_colorSet->removeGroup(groupName, keepColors); | ||
417 | 187 | resetGroupNameRows(); | |||
418 | bool KisPaletteModel::removeRows(int row, int count, const QModelIndex &parent) | | |||
419 | { | | |||
420 | Q_ASSERT(!parent.isValid()); | | |||
421 | | ||||
422 | int beginRow = qMax(0, row); | | |||
423 | int endRow = qMin(row + count - 1, (int)m_colorSet->nColors() - 1); | | |||
424 | beginRemoveRows(parent, beginRow, endRow); | | |||
425 | | ||||
426 | // Find the palette entry at row, count, remove from KoColorSet | | |||
427 | | ||||
428 | endRemoveRows(); | 188 | endRemoveRows(); | ||
429 | return true; | 189 | int insertStart = m_colorSet->getGlobalGroup()->rowCount(); | ||
190 | beginInsertRows(QModelIndex(), insertStart, insertStart + removedRowCount); | ||||
191 | endInsertRows(); | ||||
192 | emit sigPaletteModified(); | ||||
430 | } | 193 | } | ||
431 | 194 | | |||
432 | bool KisPaletteModel::dropMimeData(const QMimeData *data, Qt::DropAction action, | 195 | bool KisPaletteModel::dropMimeData(const QMimeData *data, Qt::DropAction action, | ||
433 | int row, int column, const QModelIndex &parent) | 196 | int row, int column, const QModelIndex &parent) | ||
434 | { | 197 | { | ||
198 | Q_UNUSED(row); | ||||
199 | Q_UNUSED(column); | ||||
435 | if (!data->hasFormat("krita/x-colorsetentry") && !data->hasFormat("krita/x-colorsetgroup")) { | 200 | if (!data->hasFormat("krita/x-colorsetentry") && !data->hasFormat("krita/x-colorsetgroup")) { | ||
436 | return false; | 201 | return false; | ||
437 | } | 202 | } | ||
Context not available. | |||||
439 | return false; | 204 | return false; | ||
440 | } | 205 | } | ||
441 | 206 | | |||
442 | int endRow; | 207 | QModelIndex finalIndex = parent; | ||
443 | int endColumn; | 208 | if (!finalIndex.isValid()) { return false; } | ||
444 | | ||||
445 | if (!parent.isValid()) { | | |||
446 | if (row < 0) { | | |||
447 | endRow = indexFromId(m_colorSet->nColors()).row(); | | |||
448 | endColumn = indexFromId(m_colorSet->nColors()).column(); | | |||
449 | } else { | | |||
450 | endRow = qMin(row, indexFromId(m_colorSet->nColors()).row()); | | |||
451 | endColumn = qMin(column, m_colorSet->columnCount()); | | |||
452 | } | | |||
453 | } else { | | |||
454 | endRow = qMin(parent.row(), rowCount()); | | |||
455 | endColumn = qMin(parent.column(), columnCount()); | | |||
456 | } | | |||
457 | 209 | | |||
458 | if (data->hasFormat("krita/x-colorsetgroup")) { | 210 | if (data->hasFormat("krita/x-colorsetgroup")) { | ||
211 | // dragging group not supported for now | ||||
459 | QByteArray encodedData = data->data("krita/x-colorsetgroup"); | 212 | QByteArray encodedData = data->data("krita/x-colorsetgroup"); | ||
460 | QDataStream stream(&encodedData, QIODevice::ReadOnly); | 213 | QDataStream stream(&encodedData, QIODevice::ReadOnly); | ||
461 | 214 | | |||
462 | while (!stream.atEnd()) { | 215 | while (!stream.atEnd()) { | ||
463 | QString groupName; | 216 | QString groupNameDroppedOn = qvariant_cast<QString>(finalIndex.data(GroupNameRole)); | ||
464 | stream >> groupName; | 217 | if (groupNameDroppedOn == KoColorSet::GLOBAL_GROUP_NAME) { | ||
465 | QModelIndex index = this->index(endRow, 0); | 218 | return false; | ||
466 | if (index.isValid()) { | 219 | } | ||
467 | QStringList entryList = qvariant_cast<QStringList>(index.data(RetrieveEntryRole)); | 220 | QString groupNameDragged; | ||
468 | QString groupDroppedOn = QString(); | 221 | stream >> groupNameDragged; | ||
469 | if (!entryList.isEmpty()) { | 222 | KisSwatchGroup *groupDragged = m_colorSet->getGroup(groupNameDragged); | ||
470 | groupDroppedOn = entryList.at(0); | 223 | int start = groupNameRowForName(groupNameDragged); | ||
471 | } | 224 | int end = start + groupDragged->rowCount(); | ||
472 | int groupIndex = colorSet()->getGroupNames().indexOf(groupName); | 225 | if (!beginMoveRows(QModelIndex(), start, end, QModelIndex(), groupNameRowForName(groupNameDroppedOn))) { | ||
473 | beginMoveRows( QModelIndex(), groupIndex, groupIndex, QModelIndex(), endRow); | 226 | return false; | ||
474 | m_colorSet->moveGroup(groupName, groupDroppedOn); | 227 | } | ||
228 | m_colorSet->moveGroup(groupNameDragged, groupNameDroppedOn); | ||||
229 | resetGroupNameRows(); | ||||
230 | endMoveRows(); | ||||
231 | emit sigPaletteModified(); | ||||
232 | if (m_colorSet->isGlobal()) { | ||||
475 | m_colorSet->save(); | 233 | m_colorSet->save(); | ||
476 | endMoveRows(); | | |||
477 | | ||||
478 | ++endRow; | | |||
479 | } | 234 | } | ||
480 | } | 235 | } | ||
481 | } else { | 236 | return true; | ||
482 | QByteArray encodedData = data->data("krita/x-colorsetentry"); | 237 | } | ||
483 | QDataStream stream(&encodedData, QIODevice::ReadOnly); | | |||
484 | 238 | | |||
485 | while (!stream.atEnd()) { | 239 | if (qvariant_cast<bool>(finalIndex.data(KisPaletteModel::IsGroupNameRole))) { | ||
486 | KoColorSetEntry entry; | 240 | return true; | ||
487 | QString oldGroupName; | 241 | } | ||
488 | int indexInGroup; | | |||
489 | QString colorXml; | | |||
490 | | ||||
491 | QString name, id; | | |||
492 | bool spotColor; | | |||
493 | stream >> name | | |||
494 | >> id | | |||
495 | >> spotColor | | |||
496 | >> indexInGroup | | |||
497 | >> oldGroupName | | |||
498 | >> colorXml; | | |||
499 | entry.setName(name); | | |||
500 | entry.setId(id); | | |||
501 | entry.setSpotColor(spotColor); | | |||
502 | 242 | | |||
503 | QDomDocument doc; | 243 | QByteArray encodedData = data->data("krita/x-colorsetentry"); | ||
504 | doc.setContent(colorXml); | 244 | QDataStream stream(&encodedData, QIODevice::ReadOnly); | ||
505 | QDomElement e = doc.documentElement(); | 245 | | ||
506 | QDomElement c = e.firstChildElement(); | 246 | while (!stream.atEnd()) { | ||
507 | if (!c.isNull()) { | 247 | KisSwatch entry; | ||
508 | QString colorDepthId = c.attribute("bitdepth", Integer8BitsColorDepthID.id()); | 248 | | ||
509 | entry.setColor(KoColor::fromXML(c, colorDepthId)); | 249 | QString name, id; | ||
510 | } | 250 | bool spotColor; | ||
251 | QString oldGroupName; | ||||
252 | int oriRow; | ||||
253 | int oriColumn; | ||||
254 | QString colorXml; | ||||
255 | | ||||
256 | stream >> name >> id >> spotColor | ||||
257 | >> oriRow >> oriColumn | ||||
258 | >> oldGroupName | ||||
259 | >> colorXml; | ||||
260 | | ||||
261 | entry.setName(name); | ||||
262 | entry.setId(id); | ||||
263 | entry.setSpotColor(spotColor); | ||||
264 | | ||||
265 | QDomDocument doc; | ||||
266 | doc.setContent(colorXml); | ||||
267 | QDomElement e = doc.documentElement(); | ||||
268 | QDomElement c = e.firstChildElement(); | ||||
269 | if (!c.isNull()) { | ||||
270 | QString colorDepthId = c.attribute("bitdepth", Integer8BitsColorDepthID.id()); | ||||
271 | entry.setColor(KoColor::fromXML(c, colorDepthId)); | ||||
272 | } | ||||
511 | 273 | | |||
512 | QModelIndex index = this->index(endRow, endColumn); | 274 | if (action == Qt::MoveAction){ | ||
513 | if (qvariant_cast<bool>(index.data(IsHeaderRole))){ | 275 | KisSwatchGroup *g = m_colorSet->getGroup(oldGroupName); | ||
514 | endRow+=1; | 276 | if (g) { | ||
515 | } | 277 | if (qvariant_cast<bool>(finalIndex.data(KisPaletteModel::CheckSlotRole))) { | ||
516 | if (index.isValid()) { | 278 | g->setEntry(getEntry(finalIndex), oriColumn, oriRow); | ||
517 | /*this is to figure out the row of the old color. | | |||
518 | * That way we can in turn avoid moverows from complaining the | | |||
519 | * index is out of bounds when using index. | | |||
520 | * Makes me wonder if we shouldn't just insert the index of the | | |||
521 | * old color when requesting the mimetype... | | |||
522 | */ | | |||
523 | int i = indexInGroup; | | |||
524 | if (oldGroupName != QString()) { | | |||
525 | colorSet()->nColorsGroup(""); | | |||
526 | //find at which position the group is. | | |||
527 | int groupIndex = colorSet()->getGroupNames().indexOf(oldGroupName); | | |||
528 | //add all the groupsizes onto it till we get to our group. | | |||
529 | for(int g=0; g<groupIndex; g++) { | | |||
530 | i+=colorSet()->nColorsGroup(colorSet()->getGroupNames().at(g)); | | |||
531 | } | | |||
532 | } | | |||
533 | QModelIndex indexOld = indexFromId(i); | | |||
534 | if (action == Qt::MoveAction){ | | |||
535 | if (indexOld.row()!=qMax(endRow, 0) && indexOld.row()!=qMax(endRow+1,1)) { | | |||
536 | beginMoveRows(QModelIndex(), indexOld.row(), indexOld.row(), QModelIndex(), qMax(endRow+1,1)); | | |||
537 | } | | |||
538 | if (indexOld.column()!=qMax(endColumn, 0) && indexOld.column()!=qMax(endColumn+1,1)) { | | |||
539 | beginMoveColumns(QModelIndex(), indexOld.column(), indexOld.column(), QModelIndex(), qMax(endColumn+1,1)); | | |||
540 | } | | |||
541 | } else { | 279 | } else { | ||
542 | beginInsertRows(QModelIndex(), endRow, endRow); | 280 | g->removeEntry(oriColumn, oriRow); | ||
543 | } | | |||
544 | QStringList entryList = qvariant_cast<QStringList>(index.data(RetrieveEntryRole)); | | |||
545 | QString entryInGroup = "0"; | | |||
546 | QString groupName = QString(); | | |||
547 | if (!entryList.isEmpty()) { | | |||
548 | groupName = entryList.at(0); | | |||
549 | entryInGroup = entryList.at(1); | | |||
550 | } | | |||
551 | | ||||
552 | int location = entryInGroup.toInt(); | | |||
553 | // Insert the entry | | |||
554 | if (groupName==oldGroupName && qvariant_cast<bool>(index.data(IsHeaderRole))==true) { | | |||
555 | groupName=QString(); | | |||
556 | location=m_colorSet->nColorsGroup(); | | |||
557 | } | | |||
558 | m_colorSet->insertBefore(entry, location, groupName); | | |||
559 | if (groupName==oldGroupName && location<indexInGroup) { | | |||
560 | indexInGroup+=1; | | |||
561 | } | | |||
562 | if (action == Qt::MoveAction){ | | |||
563 | m_colorSet->removeAt(indexInGroup, oldGroupName); | | |||
564 | } | 281 | } | ||
282 | } | ||||
283 | setEntry(entry, finalIndex); | ||||
284 | emit sigPaletteModified(); | ||||
285 | if (m_colorSet->isGlobal()) { | ||||
565 | m_colorSet->save(); | 286 | m_colorSet->save(); | ||
566 | if (action == Qt::MoveAction){ | | |||
567 | if (indexOld.row()!=qMax(endRow, 0) && indexOld.row()!=qMax(endRow+1,1)) { | | |||
568 | endMoveRows(); | | |||
569 | } | | |||
570 | if (indexOld.column()!=qMax(endColumn, 0) && indexOld.column()!=qMax(endColumn+1,1)) { | | |||
571 | endMoveColumns(); | | |||
572 | } | | |||
573 | | ||||
574 | } else { | | |||
575 | endInsertRows(); | | |||
576 | } | | |||
577 | | ||||
578 | ++endRow; | | |||
579 | } | 287 | } | ||
580 | } | 288 | } | ||
581 | } | 289 | } | ||
Context not available. | |||||
589 | QByteArray encodedData; | 297 | QByteArray encodedData; | ||
590 | 298 | | |||
591 | QDataStream stream(&encodedData, QIODevice::WriteOnly); | 299 | QDataStream stream(&encodedData, QIODevice::WriteOnly); | ||
592 | QString mimeTypeName = "krita/x-colorsetentry"; | | |||
593 | //Q_FOREACH(const QModelIndex &index, indexes) { | | |||
594 | QModelIndex index = indexes.last(); | 300 | QModelIndex index = indexes.last(); | ||
595 | if (index.isValid()) { | 301 | if (index.isValid() && qvariant_cast<bool>(index.data(CheckSlotRole))) { | ||
596 | if (qvariant_cast<bool>(index.data(IsHeaderRole))==false) { | 302 | QString mimeTypeName = "krita/x-colorsetentry"; | ||
597 | KoColorSetEntry entry = colorSetEntryFromIndex(index); | 303 | if (qvariant_cast<bool>(index.data(IsGroupNameRole))==false) { | ||
598 | QStringList entryList = qvariant_cast<QStringList>(index.data(RetrieveEntryRole)); | 304 | KisSwatch entry = getEntry(index); | ||
599 | QString groupName = QString(); | | |||
600 | int indexInGroup = 0; | | |||
601 | if (!entryList.isEmpty()) { | | |||
602 | groupName = entryList.at(0); | | |||
603 | QString iig = entryList.at(1); | | |||
604 | indexInGroup = iig.toInt(); | | |||
605 | } | | |||
606 | 305 | | |||
607 | QDomDocument doc; | 306 | QDomDocument doc; | ||
608 | QDomElement root = doc.createElement("Color"); | 307 | QDomElement root = doc.createElement("Color"); | ||
Context not available. | |||||
610 | doc.appendChild(root); | 309 | doc.appendChild(root); | ||
611 | entry.color().toXML(doc, root); | 310 | entry.color().toXML(doc, root); | ||
612 | 311 | | |||
613 | stream << entry.name() | 312 | stream << entry.name() << entry.id() << entry.spotColor() | ||
614 | << entry.id() | 313 | << rowNumberInGroup(index.row()) << index.column() | ||
615 | << entry.spotColor() | 314 | << qvariant_cast<QString>(index.data(GroupNameRole)) | ||
616 | << indexInGroup | | |||
617 | << groupName | | |||
618 | << doc.toString(); | 315 | << doc.toString(); | ||
619 | } else { | 316 | } else { | ||
620 | mimeTypeName = "krita/x-colorsetgroup"; | 317 | mimeTypeName = "krita/x-colorsetgroup"; | ||
621 | QStringList entryList = qvariant_cast<QStringList>(index.data(RetrieveEntryRole)); | 318 | QString groupName = qvariant_cast<QString>(index.data(GroupNameRole)); | ||
622 | QString groupName = QString(); | | |||
623 | if (!entryList.isEmpty()) { | | |||
624 | groupName = entryList.at(0); | | |||
625 | } | | |||
626 | stream << groupName; | 319 | stream << groupName; | ||
627 | } | 320 | } | ||
321 | mimeData->setData(mimeTypeName, encodedData); | ||||
628 | } | 322 | } | ||
629 | 323 | | |||
630 | mimeData->setData(mimeTypeName, encodedData); | | |||
631 | return mimeData; | 324 | return mimeData; | ||
632 | } | 325 | } | ||
633 | 326 | | |||
Context not available. | |||||
640 | { | 333 | { | ||
641 | return Qt::MoveAction; | 334 | return Qt::MoveAction; | ||
642 | } | 335 | } | ||
336 | | ||||
337 | void KisPaletteModel::setEntry(const KisSwatch &entry, | ||||
338 | const QModelIndex &index) | ||||
339 | { | ||||
340 | KisSwatchGroup *group = static_cast<KisSwatchGroup*>(index.internalPointer()); | ||||
341 | Q_ASSERT(group); | ||||
342 | group->setEntry(entry, index.column(), rowNumberInGroup(index.row())); | ||||
343 | emit sigPaletteModified(); | ||||
344 | emit dataChanged(index, index); | ||||
345 | if (m_colorSet->isGlobal()) { | ||||
346 | m_colorSet->save(); | ||||
347 | } | ||||
348 | } | ||||
349 | | ||||
350 | bool KisPaletteModel::renameGroup(const QString &groupName, const QString &newName) | ||||
351 | { | ||||
352 | beginResetModel(); | ||||
353 | bool success = m_colorSet->changeGroupName(groupName, newName); | ||||
354 | for (auto it = m_groupNameRows.begin(); it != m_groupNameRows.end(); it++) { | ||||
355 | if (it.value() == groupName) { | ||||
356 | m_groupNameRows[it.key()] = newName; | ||||
357 | break; | ||||
358 | } | ||||
359 | } | ||||
360 | endResetModel(); | ||||
361 | emit sigPaletteModified(); | ||||
362 | return success; | ||||
363 | } | ||||
364 | | ||||
365 | void KisPaletteModel::addGroup(const KisSwatchGroup &group) | ||||
366 | { | ||||
367 | beginInsertRows(QModelIndex(), rowCount(), rowCount() + group.rowCount()); | ||||
368 | m_colorSet->addGroup(group.name()); | ||||
369 | *m_colorSet->getGroup(group.name()) = group; | ||||
370 | endInsertColumns(); | ||||
371 | | ||||
372 | emit sigPaletteModified(); | ||||
373 | } | ||||
374 | | ||||
375 | void KisPaletteModel::setRowNumber(const QString &groupName, int rowCount) | ||||
376 | { | ||||
377 | beginResetModel(); | ||||
378 | KisSwatchGroup *g = m_colorSet->getGroup(groupName); | ||||
379 | if (g) { | ||||
380 | g->setRowCount(rowCount); | ||||
381 | } | ||||
382 | endResetModel(); | ||||
383 | } | ||||
384 | | ||||
385 | void KisPaletteModel::clear() | ||||
386 | { | ||||
387 | beginResetModel(); | ||||
388 | m_colorSet->clear(); | ||||
389 | endResetModel(); | ||||
390 | } | ||||
391 | | ||||
392 | QVariant KisPaletteModel::dataForGroupNameRow(const QModelIndex &idx, int role) const | ||||
393 | { | ||||
394 | KisSwatchGroup *group = static_cast<KisSwatchGroup*>(idx.internalPointer()); | ||||
395 | Q_ASSERT(group); | ||||
396 | QString groupName = group->name(); | ||||
397 | switch (role) { | ||||
398 | case Qt::ToolTipRole: | ||||
399 | case Qt::DisplayRole: { | ||||
400 | return groupName; | ||||
401 | } | ||||
402 | case GroupNameRole: { | ||||
403 | return groupName; | ||||
404 | } | ||||
405 | case CheckSlotRole: { | ||||
406 | return true; | ||||
407 | } | ||||
408 | case RowInGroupRole: { | ||||
409 | return -1; | ||||
410 | } | ||||
411 | default: { | ||||
412 | return QVariant(); | ||||
413 | } | ||||
414 | } | ||||
415 | } | ||||
416 | | ||||
417 | QVariant KisPaletteModel::dataForSwatch(const QModelIndex &idx, int role) const | ||||
418 | { | ||||
419 | KisSwatchGroup *group = static_cast<KisSwatchGroup*>(idx.internalPointer()); | ||||
420 | Q_ASSERT(group); | ||||
421 | int rowInGroup = rowNumberInGroup(idx.row()); | ||||
422 | bool entryPresent = group->checkEntry(idx.column(), rowInGroup); | ||||
423 | KisSwatch entry; | ||||
424 | if (entryPresent) { | ||||
425 | entry = group->getEntry(idx.column(), rowInGroup); | ||||
426 | } | ||||
427 | switch (role) { | ||||
428 | case Qt::ToolTipRole: | ||||
429 | case Qt::DisplayRole: { | ||||
430 | return entryPresent ? entry.name() : i18n("Empty slot"); | ||||
431 | } | ||||
432 | case Qt::BackgroundRole: { | ||||
433 | QColor color(0, 0, 0, 0); | ||||
434 | if (entryPresent) { | ||||
435 | color = m_displayRenderer->toQColor(entry.color()); | ||||
436 | } | ||||
437 | return QBrush(color); | ||||
438 | } | ||||
439 | case GroupNameRole: { | ||||
440 | return group->name(); | ||||
441 | } | ||||
442 | case CheckSlotRole: { | ||||
443 | return entryPresent; | ||||
444 | } | ||||
445 | case RowInGroupRole: { | ||||
446 | return rowInGroup; | ||||
447 | } | ||||
448 | default: { | ||||
449 | return QVariant(); | ||||
450 | } | ||||
451 | } | ||||
452 | } | ||||
453 | | ||||
454 | void KisPaletteModel::setDisplayRenderer(const KoColorDisplayRendererInterface *displayRenderer) | ||||
455 | { | ||||
456 | if (displayRenderer) { | ||||
457 | if (m_displayRenderer) { | ||||
458 | disconnect(m_displayRenderer, 0, this, 0); | ||||
459 | } | ||||
460 | m_displayRenderer = displayRenderer; | ||||
461 | connect(m_displayRenderer, SIGNAL(displayConfigurationChanged()), | ||||
462 | SLOT(slotDisplayConfigurationChanged())); | ||||
463 | } else { | ||||
464 | m_displayRenderer = KoDumbColorDisplayRenderer::instance(); | ||||
465 | } | ||||
466 | } | ||||
467 | | ||||
468 | void KisPaletteModel::slotDisplayConfigurationChanged() | ||||
469 | { | ||||
470 | beginResetModel(); | ||||
471 | endResetModel(); | ||||
472 | } | ||||
473 | | ||||
474 | void KisPaletteModel::slotPaletteModified() { | ||||
475 | m_colorSet->setPaletteType(KoColorSet::KPL); | ||||
476 | } | ||||
477 | | ||||
478 | QModelIndex KisPaletteModel::indexForClosest(const KoColor &compare) | ||||
479 | { | ||||
480 | KisSwatchGroup::SwatchInfo info = colorSet()->getClosestColorInfo(compare); | ||||
481 | return createIndex(indexRowForInfo(info), info.column, colorSet()->getGroup(info.group)); | ||||
482 | } | ||||
483 | | ||||
484 | int KisPaletteModel::indexRowForInfo(const KisSwatchGroup::SwatchInfo &info) | ||||
485 | { | ||||
486 | for (auto it = m_groupNameRows.begin(); it != m_groupNameRows.end(); it++) { | ||||
487 | if (it.value() == info.group) { | ||||
488 | return it.key() + info.row + 1; | ||||
489 | } | ||||
490 | } | ||||
491 | return info.row; | ||||
492 | } | ||||
493 | | ||||
494 | KisSwatch KisPaletteModel::getEntry(const QModelIndex &index) const | ||||
495 | { | ||||
496 | KisSwatchGroup *group = static_cast<KisSwatchGroup*>(index.internalPointer()); | ||||
497 | if (!group || !group->checkEntry(index.column(), rowNumberInGroup(index.row()))) { | ||||
498 | return KisSwatch(); | ||||
499 | } | ||||
500 | return group->getEntry(index.column(), rowNumberInGroup(index.row())); | ||||
501 | } | ||||
502 | | ||||
503 | int KisPaletteModel::groupNameRowForRow(int rowInModel) const | ||||
504 | { | ||||
505 | return rowInModel - rowNumberInGroup(rowInModel) - 1; | ||||
506 | } | ||||
Context not available. |