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

The PaletteEditor class this class manipulates a KisPaletteModel using GUI elements and communicates with KisDocument. More...

#include <KisPaletteEditor.h>

+ Inheritance diagram for KisPaletteEditor:

Classes

struct  PaletteInfo
 
struct  Private
 

Public Member Functions

void addEntry (const KoColor &color)
 
QString addGroup ()
 Stage the addition of a new swatch group.
 
KoColorSetSP addPalette ()
 
void changeColumnCount (int)
 Stage a change of the palette's column count.
 
void changeGroupRowCount (const QString &name, int newRowCount)
 Stage a change to the row count of a group.
 
void clearStagedChanges ()
 
void endEditing (bool applyChanges=true)
 End editing and either apply or discard staged changes.
 
KoColorSetSP importPalette ()
 
bool isModified () const
 
 KisPaletteEditor (QObject *parent=0)
 
void modifyEntry (const QModelIndex &index)
 
QString oldNameFromNewName (const QString &newName) const
 oldNameFromNewName
 
void removeEntry (const QModelIndex &index)
 
bool removeGroup (const QString &name)
 Stage the removal of a group.
 
void removePalette (KoColorSetSP)
 
void rename (const QString &newName)
 Stage a palette rename.
 
QString renameGroup (const QString &oldName)
 Stage a rename of a group.
 
int rowCountOfGroup (const QString &originalName) const
 rowCountOfGroup
 
void saveNewPaletteVersion ()
 saveNewPaletteVersion
 
void setEntry (const KoColor &color, const QModelIndex &index)
 
void setPaletteModel (KisPaletteModel *model)
 
void setStorageLocation (QString location)
 
void setView (KisViewManager *view)
 
void startEditing ()
 Start editing the current palette.
 
 ~KisPaletteEditor ()
 

Private Slots

void slotGroupNameChanged (const QString &newName)
 
void slotPaletteChanged ()
 
void slotSetDocumentModified ()
 

Private Member Functions

bool duplicateExistsGroupName (const QString &name) const
 
bool duplicateExistsOriginalGroupName (const QString &name) const
 
QString filenameFromPath (const QString &path) const
 
QString newGroupName () const
 

Private Attributes

QScopedPointer< Privatem_d
 

Detailed Description

The PaletteEditor class this class manipulates a KisPaletteModel using GUI elements and communicates with KisDocument.

Changes made in this class won't be done to the palette if the palette is read only (not editable, isEditable() == false)

Definition at line 30 of file KisPaletteEditor.h.

Constructor & Destructor Documentation

◆ KisPaletteEditor()

KisPaletteEditor::KisPaletteEditor ( QObject * parent = 0)
explicit

Definition at line 62 of file KisPaletteEditor.cpp.

63 : QObject(parent)
64 , m_d(new Private)
65{
67 m_d->warnPalette.setColor(QPalette::Text, Qt::red);
68}
QScopedPointer< Private > m_d
static KoResourceServerProvider * instance()
KoResourceServer< KoColorSet > * paletteServer

References KoResourceServerProvider::instance(), m_d, and KoResourceServerProvider::paletteServer.

◆ ~KisPaletteEditor()

KisPaletteEditor::~KisPaletteEditor ( )

Definition at line 70 of file KisPaletteEditor.cpp.

71{ }

Member Function Documentation

◆ addEntry()

void KisPaletteEditor::addEntry ( const KoColor & color)

Definition at line 430 of file KisPaletteEditor.cpp.

431{
432 Q_ASSERT(m_d->model);
433 if (!m_d->view) { return; }
434 if (!m_d->view->document()) { return; }
435
437 dialog.setWindowTitle(i18nc("@title:dialog", "Add a new Color Swatch"));
438
439 QFormLayout *editableItems = new QFormLayout(dialog.mainWidget());
440
441 QComboBox *cmbGroups = new QComboBox();
442 cmbGroups->addItems(m_d->model->colorSet()->swatchGroupNames());
443 cmbGroups->setCurrentIndex(0);
444
445 QLineEdit *lnIDName = new QLineEdit();
446 lnIDName->setText(QString::number(m_d->model->colorSet()->colorCount() + 1));
447
448 QLineEdit *lnName = new QLineEdit();
449 lnName->setText(i18nc("Default name for a color swatch","Color %1", QString::number(m_d->model->colorSet()->colorCount()+1)));
450
451 KisColorButton *bnColor = new KisColorButton();
452 bnColor->setColor(color);
453
454 QCheckBox *chkSpot = new QCheckBox();
455 chkSpot->setChecked(false);
456 chkSpot->setToolTip(i18nc("@info:tooltip", "A spot color is a color that the printer is able to print without mixing the paints it has available to it. The opposite is called a process color."));
457
458 editableItems->addRow(i18n("Swatch Group:"), cmbGroups);
459 editableItems->addRow(i18n("Swatch ID:"), lnIDName);
460 editableItems->addRow(i18n("Color swatch name:"), lnName);
461 editableItems->addRow(i18nc("Color as the Color of a Swatch in a Palette", "Color:"), bnColor);
462 editableItems->addRow(i18n("Spot color:"), chkSpot);
463
464 if (dialog.exec() != KoDialog::Accepted) { return; }
465
466 QString groupName = cmbGroups->currentText();
467
468 KisSwatch newSwatch;
469 newSwatch.setColor(bnColor->color());
470 newSwatch.setName(lnName->text());
471 newSwatch.setId(lnIDName->text());
472 newSwatch.setSpotColor(chkSpot->isChecked());
473 m_d->model->addSwatch(newSwatch, groupName);
474 m_d->modifiedGroupNames.insert(groupName);
475 // TODO: This is getting called when startEditing is never called. This avoids the crash, but what is its purpose?
476 if (m_d->isEditing) {
477 KisSwatchGroupSP cs = m_d->modifiedPaletteInfo.groups.value(groupName);
478 cs->addSwatch(newSwatch);
479 if (!m_d->modifiedPaletteInfo.groups.contains(groupName)) {
480 m_d->modifiedPaletteInfo.groups.insert(groupName, cs);
481 }
482 }
483}
A pushbutton to display or allow user selection of a color.
void setColor(const KoColor &c)
void setSpotColor(bool spotColor)
Definition KisSwatch.cpp:38
void setColor(const KoColor &color)
Definition KisSwatch.cpp:32
void setId(const QString &id)
Definition KisSwatch.cpp:26
void setName(const QString &name)
Definition KisSwatch.cpp:20
A dialog base class with standard buttons and predefined layouts.
Definition KoDialog.h:116

References KisColorButton::color, m_d, KisColorButton::setColor(), KisSwatch::setColor(), KisSwatch::setId(), KisSwatch::setName(), and KisSwatch::setSpotColor().

◆ addGroup()

QString KisPaletteEditor::addGroup ( )

Stage the addition of a new swatch group.

Returns
new group's name if change accepted, empty string if cancelled

Definition at line 235 of file KisPaletteEditor.cpp.

236{
237 if (!m_d->isEditing) {
238 return QString();
239 }
241 m_d->query = &dialog;
242
243 QVBoxLayout *layout = new QVBoxLayout(dialog.mainWidget());
244
245 layout->addWidget(new QLabel(i18n("New swatch group name:")));
246 QLineEdit *leName = new QLineEdit(newGroupName());
247 connect(leName, SIGNAL(textChanged(QString)), SLOT(slotGroupNameChanged(QString)));
248 layout->addWidget(leName);
249 layout->addWidget(new QLabel(i18n("Rows of swatches in group:")));
250 QSpinBox *spxRow = new QSpinBox();
251 spxRow->setValue(20);
252 layout->addWidget(spxRow);
253
254 if (dialog.exec() != QDialog::Accepted) { return QString(); }
255 if (duplicateExistsGroupName(leName->text())) { return QString(); }
256
257 QString realName = leName->text();
258 QString name = realName;
260 name = newGroupName();
261 }
262 m_d->modifiedPaletteInfo.groups[name].reset(new KisSwatchGroup);
263 KisSwatchGroupSP newGroup = m_d->modifiedPaletteInfo.groups[name];
264 newGroup->setName(realName);
265 m_d->newGroupNames.insert(name);
266 newGroup->setRowCount(spxRow->value());
267 return realName;
268}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
QString newGroupName() const
bool duplicateExistsOriginalGroupName(const QString &name) const
bool duplicateExistsGroupName(const QString &name) const
void slotGroupNameChanged(const QString &newName)
The KisSwatchGroup class stores a matrix of color swatches swatches can accessed using (x,...
const char * name(StandardAction id)

References connect(), duplicateExistsGroupName(), duplicateExistsOriginalGroupName(), m_d, newGroupName(), and slotGroupNameChanged().

◆ addPalette()

KoColorSetSP KisPaletteEditor::addPalette ( )

Definition at line 90 of file KisPaletteEditor.cpp.

91{
92 if (!m_d->view) { return 0; }
93 if (!m_d->view->document()) { return 0; }
94
95 KoColorSetSP colorSet(new KoColorSet());
96
98 QFormLayout *layout = new QFormLayout(dialog.mainWidget());
99 QLineEdit *le = new QLineEdit(i18nc("Default name for a new palette","New Palette"));
100 layout->addRow(i18n("New palette name:"), le);
101
102 QComboBox *cmbPaletteType = new QComboBox();
103 cmbPaletteType->addItem(i18nc("Palette File Type", "Krita Palette (KPL)"));
104 cmbPaletteType->addItem(i18nc("Palette File Type", "GIMP Palette (GPL)"));
105 layout->addRow(cmbPaletteType);
106
107 QCheckBox *chkSaveInDocument = new QCheckBox(i18n("Save Palette in the Current Document"));
108 chkSaveInDocument->setChecked(false);
109 layout->addRow(chkSaveInDocument);
110
111
112 if (dialog.exec() != QDialog::Accepted) { return 0; }
113
114 QString name = le->text();
115 if (cmbPaletteType->currentIndex() == 0) {
116 colorSet->setPaletteType(KoColorSet::KPL);
117 }
118 else {
119 colorSet->setPaletteType(KoColorSet::GPL);
120 }
121 colorSet->setValid(true);
122 colorSet->setName(name);
123 colorSet->setFilename(name.split(" ").join("_")+colorSet->defaultFileExtension());
124
125 QString resourceLocation = "";
126 if (chkSaveInDocument->isChecked()) {
127 resourceLocation = m_d->view->document()->linkedResourcesStorageId();
128 }
129
130 if (KisResourceUserOperations::addResourceWithUserInput(m_d->view->mainWindowAsQWidget(), colorSet, resourceLocation)) {
131 return colorSet;
132
133 }
134
135 return 0;
136}
static bool addResourceWithUserInput(QWidget *widgetParent, KoResourceSP resource, QString storageLocation="")

References KisResourceUserOperations::addResourceWithUserInput(), KoColorSet::GPL, KoColorSet::KPL, and m_d.

◆ changeColumnCount()

void KisPaletteEditor::changeColumnCount ( int newCount)

Stage a change of the palette's column count.

Definition at line 227 of file KisPaletteEditor.cpp.

228{
229 if (!m_d->isEditing) {
230 return;
231 }
232 m_d->modifiedPaletteInfo.columnCount = newCount;
233}

References m_d.

◆ changeGroupRowCount()

void KisPaletteEditor::changeGroupRowCount ( const QString & name,
int newRowCount )

Stage a change to the row count of a group.

Parameters
name
newRowCount

Definition at line 336 of file KisPaletteEditor.cpp.

337{
338 if (!m_d->isEditing) {
339 return;
340 }
341 if (!m_d->modifiedPaletteInfo.groups.contains(name)) { return; }
342 m_d->modifiedPaletteInfo.groups[name]->setRowCount(newRowCount);
343 m_d->modifiedGroupNames.insert(name);
344}

References m_d.

◆ clearStagedChanges()

void KisPaletteEditor::clearStagedChanges ( )

Definition at line 572 of file KisPaletteEditor.cpp.

573{
574 m_d->modifiedPaletteInfo.groups.clear();
575 m_d->keepColorGroups.clear();
576 m_d->newGroupNames.clear();
577 m_d->modifiedGroupNames.clear();
578 m_d->isEditing = false;
579}

References m_d.

◆ duplicateExistsGroupName()

bool KisPaletteEditor::duplicateExistsGroupName ( const QString & name) const
private

Definition at line 194 of file KisPaletteEditor.cpp.

195{
196 if (name == m_d->groupBeingRenamed) { return false; }
197 Q_FOREACH (const KisSwatchGroupSP group, m_d->modifiedPaletteInfo.groups.values()) {
198 if (name == group->name()) { return true; }
199 }
200 return false;
201}

References m_d.

◆ duplicateExistsOriginalGroupName()

bool KisPaletteEditor::duplicateExistsOriginalGroupName ( const QString & name) const
private

Definition at line 203 of file KisPaletteEditor.cpp.

204{
205 return m_d->modifiedPaletteInfo.groups.contains(name);
206}

References m_d.

◆ endEditing()

void KisPaletteEditor::endEditing ( bool applyChanges = true)

End editing and either apply or discard staged changes.

Parameters
applyChangesIf set to false, the palette remains unchanged and staged changes are discarded.

Definition at line 519 of file KisPaletteEditor.cpp.

520{
521 if (!m_d->isEditing) {
522 qWarning("KisPaletteEditor::endEditing(): not in editing state; ignoring.");
523 return;
524 }
525
526 if (!applyChanges) {
528 return;
529 }
530
531 if (!m_d->model) return;
532 if (!m_d->model->colorSet()) return;
533 if (!m_d->view) return;
534 if (!m_d->view->document()) return;
535
536 KoColorSetSP palette = m_d->model->colorSet();
537 PaletteInfo &modified = m_d->modifiedPaletteInfo;
538
539 if (modified.columnCount != palette->columnCount()) {
540 m_d->model->setColumnCount(modified.columnCount);
541 }
542 if (modified.name != palette->name()) {
543 KisResourceUserOperations::renameResourceWithUserInput(m_d->view->mainWindowAsQWidget(), palette, m_d->modifiedPaletteInfo.name);
544 }
545 QString resourceLocation = m_d->model->colorSet()->storageLocation();
546 if (resourceLocation != m_d->modifiedPaletteInfo.storageLocation) {
547 // We need functionality for moving the resource to the new resource storage...
548 }
549
550 Q_FOREACH (const QString &groupName, palette->swatchGroupNames()) {
551 if (!modified.groups.contains(groupName)) {
552 m_d->model->removeGroup(groupName, m_d->keepColorGroups.contains(groupName));
553 }
554 }
555 Q_FOREACH (const QString &groupName, palette->swatchGroupNames()) {
556 if (m_d->modifiedGroupNames.contains(groupName)) {
557 m_d->model->setRowCountForGroup(groupName, modified.groups[groupName]->rowCount());
558 if (groupName != modified.groups[groupName]->name()) {
559 m_d->model->changeGroupName(groupName, modified.groups[groupName]->name());
560 modified.groups[modified.groups[groupName]->name()] = modified.groups[groupName];
561 modified.groups.remove(groupName);
562 }
563 }
564 }
565 Q_FOREACH (const QString &newGroupName, m_d->newGroupNames) {
566 m_d->model->addGroup(newGroupName, palette->columnCount(), m_d->modifiedPaletteInfo.groups[newGroupName]->rowCount());
567 }
568
570}
static bool renameResourceWithUserInput(QWidget *widgetParent, KoResourceSP resource, QString resourceName)
rgba palette[MAX_PALETTE]
Definition palette.c:35

References clearStagedChanges(), KisPaletteEditor::PaletteInfo::columnCount, KisPaletteEditor::PaletteInfo::groups, m_d, KisPaletteEditor::PaletteInfo::name, newGroupName(), palette, and KisResourceUserOperations::renameResourceWithUserInput().

◆ filenameFromPath()

QString KisPaletteEditor::filenameFromPath ( const QString & path) const
private

Definition at line 625 of file KisPaletteEditor.cpp.

626{
627 return QDir::fromNativeSeparators(path).section('/', -1, -1);
628}

◆ importPalette()

KoColorSetSP KisPaletteEditor::importPalette ( )

Definition at line 138 of file KisPaletteEditor.cpp.

139{
140 KoFileDialog dialog(nullptr, KoFileDialog::OpenFile, "Open Palette");
141 dialog.setCaption(i18n("Import Palette"));
142
143 dialog.setDefaultDir(QDir::homePath());
144 dialog.setMimeTypeFilters(QStringList() << "application/x-krita-palette" << "application/x-gimp-color-palette");
145
146 QString filename = dialog.filename();
147 if (filename.isEmpty()) {
148 return nullptr;
149 }
150
151 QMessageBox messageBox;
152 messageBox.setText(i18n("Do you want to store this palette in your current image?"));
153 messageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
154 QString storageLocation = "";
155 if (messageBox.exec() == QMessageBox::Yes) {
156 storageLocation = m_d->view->document()->linkedResourcesStorageId();
157 }
158 KoResourceSP resource = KisResourceUserOperations::importResourceFileWithUserInput(m_d->view->mainWindowAsQWidget(), storageLocation, ResourceType::Palettes, filename);
159
161 if (resource) {
162 palette = resource.dynamicCast<KoColorSet>();
163 }
164
165 return palette;
166}
QList< QString > QStringList
static KoResourceSP importResourceFileWithUserInput(QWidget *widgetParent, QString storageLocation, QString resourceType, QString resourceFilepath)
const QString Palettes

References KisResourceUserOperations::importResourceFileWithUserInput(), m_d, KoFileDialog::OpenFile, palette, and ResourceType::Palettes.

◆ isModified()

bool KisPaletteEditor::isModified ( ) const

Definition at line 485 of file KisPaletteEditor.cpp.

486{
487 if (m_d->model->colorSet()) {
488 return m_d->model->colorSet()->isDirty();
489 } else {
490 return false;
491 }
492}

References m_d.

◆ modifyEntry()

void KisPaletteEditor::modifyEntry ( const QModelIndex & index)

Definition at line 385 of file KisPaletteEditor.cpp.

386{
387 if (!m_d->view) { return; }
388 if (!m_d->view->document()) { return; }
389
391 dialog.setCaption(i18nc("@title:dialog", "Add a new Color Swatch"));
392 QFormLayout *editableItems = new QFormLayout(dialog.mainWidget());
393
394 QString groupName = qvariant_cast<QString>(index.data(Qt::DisplayRole));
395 if (qvariant_cast<bool>(index.data(KisPaletteModel::IsGroupNameRole))) {
396 startEditing();
397 renameGroup(groupName);
398 endEditing();
399 }
400 else {
401
402 QLineEdit *lnIDName = new QLineEdit();
403 QLineEdit *lnGroupName = new QLineEdit();
404 KisColorButton *bnColor = new KisColorButton();
405 QCheckBox *chkSpot = new QCheckBox();
406 chkSpot->setToolTip(i18nc("@info:tooltip", "A spot color is a color that the printer is able to print without mixing the paints it has available to it. The opposite is called a process color."));
407
408 KisSwatch entry = m_d->model->getSwatch(index);
409
410 editableItems->addRow(i18n("Swatch ID:"), lnIDName);
411 editableItems->addRow(i18n("Color swatch name:"), lnGroupName);
412 editableItems->addRow(i18nc("Color as the Color of a Swatch in a Palette", "Color:"), bnColor);
413 editableItems->addRow(i18n("Spot color:"), chkSpot);
414
415 lnGroupName->setText(entry.name());
416 lnIDName->setText(entry.id());
417 bnColor->setColor(entry.color());
418 chkSpot->setChecked(entry.spotColor());
419
420 if (dialog.exec() == KoDialog::Accepted) {
421 entry.setName(lnGroupName->text());
422 entry.setId(lnIDName->text());
423 entry.setColor(bnColor->color());
424 entry.setSpotColor(chkSpot->isChecked());
425 m_d->model->setSwatch(entry, index);
426 }
427 }
428}
void startEditing()
Start editing the current palette.
QString renameGroup(const QString &oldName)
Stage a rename of a group.
void endEditing(bool applyChanges=true)
End editing and either apply or discard staged changes.
KoColor color() const
Definition KisSwatch.h:30
QString name() const
Definition KisSwatch.h:24
bool spotColor() const
Definition KisSwatch.h:33
QString id() const
Definition KisSwatch.h:27

References KisSwatch::color(), KisColorButton::color, endEditing(), KisSwatch::id(), KisPaletteModel::IsGroupNameRole, m_d, KisSwatch::name(), renameGroup(), KisColorButton::setColor(), KisSwatch::setColor(), KisSwatch::setId(), KisSwatch::setName(), KisSwatch::setSpotColor(), KisSwatch::spotColor(), and startEditing().

◆ newGroupName()

QString KisPaletteEditor::newGroupName ( ) const
private

Definition at line 614 of file KisPaletteEditor.cpp.

615{
616 int i = 1;
617 QString groupname = i18nc("Default new group name", "New Group %1", QString::number(i));
618 while (m_d->modifiedPaletteInfo.groups.contains(groupname)) {
619 i++;
620 groupname = i18nc("Default new group name", "New Group %1", QString::number(i));
621 }
622 return groupname;
623}

References m_d.

◆ oldNameFromNewName()

QString KisPaletteEditor::oldNameFromNewName ( const QString & newName) const

oldNameFromNewName

Parameters
newNamethe current name of a group
Returns
the name of the group at the creation of the instance

Definition at line 208 of file KisPaletteEditor.cpp.

209{
210 Q_FOREACH (const QString &oldGroupName, m_d->modifiedPaletteInfo.groups.keys()) {
211 if (m_d->modifiedPaletteInfo.groups[oldGroupName]->name() == newName) {
212 return oldGroupName;
213 }
214 }
215 return QString();
216}

References m_d.

◆ removeEntry()

void KisPaletteEditor::removeEntry ( const QModelIndex & index)

Definition at line 371 of file KisPaletteEditor.cpp.

372{
373 Q_ASSERT(m_d->model);
374 if (!m_d->view) { return; }
375 if (!m_d->view->document()) { return; }
376 if (qvariant_cast<bool>(index.data(KisPaletteModel::IsGroupNameRole))) {
377 startEditing();
378 removeGroup(qvariant_cast<QString>(index.data(KisPaletteModel::GroupNameRole)));
379 endEditing();
380 } else {
381 m_d->model->removeSwatch(index, false);
382 }
383}
bool removeGroup(const QString &name)
Stage the removal of a group.

References endEditing(), KisPaletteModel::GroupNameRole, KisPaletteModel::IsGroupNameRole, m_d, removeGroup(), and startEditing().

◆ removeGroup()

bool KisPaletteEditor::removeGroup ( const QString & name)

Stage the removal of a group.

Parameters
nameoriginal group name
Returns
true if change accepted, false if cancelled

Definition at line 270 of file KisPaletteEditor.cpp.

271{
272 if (!m_d->isEditing) {
273 return false;
274 }
276 dialog.setWindowTitle(i18nc("@title:dialog", "Removing Swatch Group"));
277 QFormLayout *editableItems = new QFormLayout(dialog.mainWidget());
278 QCheckBox *chkKeep = new QCheckBox();
279
280 editableItems->addRow(i18nc("Shows up when deleting a swatch group", "Keep the Colors"), chkKeep);
281 if (dialog.exec() != KoDialog::Accepted) { return false; }
282
283 m_d->modifiedPaletteInfo.groups.remove(name);
284 m_d->newGroupNames.remove(name);
285 if (chkKeep->isChecked()) {
286 m_d->keepColorGroups.insert(name);
287 }
288 return true;
289}

References m_d.

◆ removePalette()

void KisPaletteEditor::removePalette ( KoColorSetSP cs)

Definition at line 168 of file KisPaletteEditor.cpp.

169{
170 if (!m_d->view) { return; }
171 if (!m_d->view->document()) { return; }
172 if (!cs) { return; }
173 m_d->rServer->removeResourceFromServer(cs);
174}

References m_d.

◆ rename()

void KisPaletteEditor::rename ( const QString & newName)

Stage a palette rename.

Parameters
newName

Definition at line 218 of file KisPaletteEditor.cpp.

219{
220 if (!m_d->isEditing) {
221 return;
222 }
223 if (newName.isEmpty()) { return; }
224 m_d->modifiedPaletteInfo.name = newName;
225}

References m_d.

◆ renameGroup()

QString KisPaletteEditor::renameGroup ( const QString & oldName)

Stage a rename of a group.

Parameters
oldName
Returns
new name if change accepted, empty string if cancelled

Definition at line 291 of file KisPaletteEditor.cpp.

292{
293 if (!m_d->isEditing) {
294 return QString();
295 }
296 if (oldName.isEmpty() || oldName == KoColorSet::GLOBAL_GROUP_NAME) { return QString(); }
297
299 m_d->query = &dialog;
300 m_d->groupBeingRenamed = m_d->modifiedPaletteInfo.groups[oldName]->name();
301
302 QFormLayout *form = new QFormLayout(dialog.mainWidget());
303
304 QLineEdit *leNewName = new QLineEdit();
305 connect(leNewName, SIGNAL(textChanged(QString)), SLOT(slotGroupNameChanged(QString)));
306 leNewName->setText(m_d->modifiedPaletteInfo.groups[oldName]->name());
307
308 form->addRow(i18n("New swatch group name:"), leNewName);
309
310 if (dialog.exec() != KoDialog::Accepted) { return QString(); }
311 if (leNewName->text().isEmpty()) { return QString(); }
312 if (duplicateExistsGroupName(leNewName->text())) { return QString(); }
313
314 m_d->modifiedPaletteInfo.groups[oldName]->setName(leNewName->text());
315 m_d->modifiedGroupNames.insert(oldName);
316
317 return leNewName->text();
318}
static const QString GLOBAL_GROUP_NAME
Definition KoColorSet.h:33

References connect(), duplicateExistsGroupName(), KoColorSet::GLOBAL_GROUP_NAME, m_d, and slotGroupNameChanged().

◆ rowCountOfGroup()

int KisPaletteEditor::rowCountOfGroup ( const QString & originalName) const

rowCountOfGroup

Parameters
originalNamethe original name of a group at the creation of the instance
Returns
newest row number of the group

Definition at line 176 of file KisPaletteEditor.cpp.

177{
178 if (!m_d->modifiedPaletteInfo.groups.contains(originalName)) {
179 KoColorSetSP colorSet = m_d->model->colorSet();
180 if (originalName.isEmpty()) {
181 return colorSet->getGlobalGroup()->rowCount();
182 }
183 else {
184 KisSwatchGroupSP group = colorSet->getGroup(originalName);
185 if (group ){
186 return group->rowCount();
187 }
188 }
189 return 0;
190 }
191 return m_d->modifiedPaletteInfo.groups[originalName]->rowCount();
192}

References m_d.

◆ saveNewPaletteVersion()

void KisPaletteEditor::saveNewPaletteVersion ( )

saveNewPaletteVersion

Definition at line 581 of file KisPaletteEditor.cpp.

582{
583 if (!m_d->model || !m_d->model->colorSet()) { return; }
584
585 QModelIndex index = m_d->rServer->resourceModel()->indexForResource(m_d->model->colorSet());
586 bool isGlobal = false;
587 if (index.isValid()) {
588 bool ok = false;
589 int storageId = m_d->rServer->resourceModel()->data(index, Qt::UserRole + KisAllResourcesModel::StorageId).toInt(&ok);
590 if (ok) {
591 KisStorageModel storageModel;
592 KisResourceStorageSP storage = storageModel.storageForId(storageId);
593 isGlobal = storage->type() != KisResourceStorage::StorageType::Memory;
594 }
595 }
596 bool res = false;
597 if (isGlobal) {
598 if (m_d->view) {
599 res = KisResourceUserOperations::updateResourceWithUserInput(m_d->view->mainWindowAsQWidget(), m_d->model->colorSet());
600 } else if (m_d->model->colorSet()->version() >= 0) {
601 //if the version is -1, then the resource should not be updated, because it was never saved to begin with...
602 res = m_d->rServer->resourceModel()->updateResource(m_d->model->colorSet());
603 dbgResources << Q_FUNC_INFO << "-- Updating resource without user input: " << m_d->model->colorSet()->name() << "Result:" << res;
604 }
605 }
606}
static bool updateResourceWithUserInput(QWidget *widgetParent, KoResourceSP resource)
KisResourceStorageSP storageForId(const int storageId) const
#define dbgResources
Definition kis_debug.h:43

References dbgResources, m_d, KisResourceStorage::Memory, KisStorageModel::storageForId(), KisAbstractResourceModel::StorageId, and KisResourceUserOperations::updateResourceWithUserInput().

◆ setEntry()

void KisPaletteEditor::setEntry ( const KoColor & color,
const QModelIndex & index )

Definition at line 351 of file KisPaletteEditor.cpp.

352{
353 Q_ASSERT(m_d->model);
354 if (!m_d->view) { return; }
355 if (!m_d->view->document()) { return; }
356 KisSwatch c = KisSwatch(color);
357 c.setId(QString::number(m_d->model->colorSet()->colorCount() + 1));
358 c.setName(i18nc("Default name for a color swatch","Color %1", QString::number(m_d->model->colorSet()->colorCount()+1)));
359 m_d->model->setSwatch(c, index);
360}

References m_d, KisSwatch::setId(), and KisSwatch::setName().

◆ setPaletteModel()

void KisPaletteEditor::setPaletteModel ( KisPaletteModel * model)

Definition at line 73 of file KisPaletteEditor.cpp.

74{
75 if (!model) { return; }
76 if (m_d->model) {
77 m_d->model->disconnect(this);
78 }
79 m_d->model = model;
81 connect(model, SIGNAL(sigPaletteChanged()), SLOT(slotPaletteChanged()));
82 connect(model, SIGNAL(sigPaletteModified()), SLOT(slotSetDocumentModified()));
83}

References connect(), m_d, slotPaletteChanged(), and slotSetDocumentModified().

◆ setStorageLocation()

void KisPaletteEditor::setStorageLocation ( QString location)

Definition at line 346 of file KisPaletteEditor.cpp.

347{
348 m_d->modifiedPaletteInfo.storageLocation = location;
349}

References m_d.

◆ setView()

void KisPaletteEditor::setView ( KisViewManager * view)

Definition at line 85 of file KisPaletteEditor.cpp.

86{
87 m_d->view = view;
88}

References m_d.

◆ slotGroupNameChanged

void KisPaletteEditor::slotGroupNameChanged ( const QString & newName)
privateslot

Definition at line 320 of file KisPaletteEditor.cpp.

321{
322 QLineEdit *leGroupName = qobject_cast<QLineEdit*>(sender());
323 if (duplicateExistsGroupName(newName) || newName == QString()) {
324 leGroupName->setPalette(m_d->warnPalette);
325 if (m_d->query->button(KoDialog::Ok)) {
326 m_d->query->button(KoDialog::Ok)->setEnabled(false);
327 }
328 return;
329 }
330 leGroupName->setPalette(m_d->normalPalette);
331 if (m_d->query->button(KoDialog::Ok)) {
332 m_d->query->button(KoDialog::Ok)->setEnabled(true);
333 }
334}
@ Ok
Show Ok button. (this button accept()s the dialog; result set to QDialog::Accepted)
Definition KoDialog.h:127

References duplicateExistsGroupName(), m_d, and KoDialog::Ok.

◆ slotPaletteChanged

void KisPaletteEditor::slotPaletteChanged ( )
privateslot

Definition at line 608 of file KisPaletteEditor.cpp.

609{
610 Q_ASSERT(m_d->model);
612}

References clearStagedChanges(), and m_d.

◆ slotSetDocumentModified

void KisPaletteEditor::slotSetDocumentModified ( )
privateslot

Definition at line 362 of file KisPaletteEditor.cpp.

363{
364 if (m_d->modifiedPaletteInfo.storageLocation == m_d->view->document()->linkedResourcesStorageId()) {
365 KisResourceUserOperations::updateResourceWithUserInput(m_d->view->mainWindowAsQWidget(), m_d->model->colorSet());
366 m_d->view->document()->setModified(true);
367 }
368 m_d->model->colorSet()->setDirty(true);
369}

References m_d, and KisResourceUserOperations::updateResourceWithUserInput().

◆ startEditing()

void KisPaletteEditor::startEditing ( )

Start editing the current palette.

This must be called before any calls that stage changes, otherwise those calls have no effect. All staged changes get applied when calling endEditing().

Adding, removing and updating swatches happens immediately

Definition at line 494 of file KisPaletteEditor.cpp.

495{
496 if (m_d->isEditing) {
497 qWarning() << "KisPaletteEditor::startEditing(): restarting palette editing.";
499 }
500
501 if (!m_d->model || !m_d->model->colorSet()) {
502 return;
503 }
504 KoColorSetSP palette = m_d->model->colorSet();
505
506 m_d->modifiedPaletteInfo.name = palette->name();
507 m_d->modifiedPaletteInfo.storageLocation = palette->storageLocation();
508 m_d->modifiedPaletteInfo.columnCount = palette->columnCount();
509 m_d->modifiedPaletteInfo.groups.clear();
510
511 Q_FOREACH (const QString &groupName, palette->swatchGroupNames()) {
512 KisSwatchGroupSP cs(new KisSwatchGroup(*palette->getGroup(groupName).data()));
513 m_d->modifiedPaletteInfo.groups.insert(groupName, cs);
514 }
515
516 m_d->isEditing = true;
517}

References clearStagedChanges(), m_d, and palette.

Member Data Documentation

◆ m_d

QScopedPointer<Private> KisPaletteEditor::m_d
private

Definition at line 147 of file KisPaletteEditor.h.


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