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< Private > m_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 432 of file KisPaletteEditor.cpp.

433{
434 Q_ASSERT(m_d->model);
435 if (!m_d->view) { return; }
436 if (!m_d->view->document()) { return; }
437
439 dialog.setWindowTitle(i18nc("@title:dialog", "Add a new Color Swatch"));
440
441 QFormLayout *editableItems = new QFormLayout(dialog.mainWidget());
442
443 QComboBox *cmbGroups = new QComboBox();
444 cmbGroups->addItems(m_d->model->colorSet()->swatchGroupNames());
445 cmbGroups->setCurrentIndex(0);
446
447 QLineEdit *lnIDName = new QLineEdit();
448 lnIDName->setText(QString::number(m_d->model->colorSet()->colorCount() + 1));
449
450 QLineEdit *lnName = new QLineEdit();
451 lnName->setText(i18nc("Default name for a color swatch","Color %1", QString::number(m_d->model->colorSet()->colorCount()+1)));
452
453 KisColorButton *bnColor = new KisColorButton();
454 bnColor->setColor(color);
455
456 QCheckBox *chkSpot = new QCheckBox();
457 chkSpot->setChecked(false);
458 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."));
459
460 editableItems->addRow(i18n("Swatch Group:"), cmbGroups);
461 editableItems->addRow(i18n("Swatch ID:"), lnIDName);
462 editableItems->addRow(i18n("Color swatch name:"), lnName);
463 editableItems->addRow(i18nc("Color as the Color of a Swatch in a Palette", "Color:"), bnColor);
464 editableItems->addRow(i18n("Spot color:"), chkSpot);
465
466 if (dialog.exec() != KoDialog::Accepted) { return; }
467
468 QString groupName = cmbGroups->currentText();
469
470 KisSwatch newSwatch;
471 newSwatch.setColor(bnColor->color());
472 newSwatch.setName(lnName->text());
473 newSwatch.setId(lnIDName->text());
474 newSwatch.setSpotColor(chkSpot->isChecked());
475 m_d->model->addSwatch(newSwatch, groupName);
476 m_d->modifiedGroupNames.insert(groupName);
477 // TODO: This is getting called when startEditing is never called. This avoids the crash, but what is its purpose?
478 if (m_d->isEditing) {
479 KisSwatchGroupSP cs = m_d->modifiedPaletteInfo.groups.value(groupName);
480 cs->addSwatch(newSwatch);
481 if (!m_d->modifiedPaletteInfo.groups.contains(groupName)) {
482 m_d->modifiedPaletteInfo.groups.insert(groupName, cs);
483 }
484 }
485}
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}
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 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 574 of file KisPaletteEditor.cpp.

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

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 521 of file KisPaletteEditor.cpp.

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

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

◆ filenameFromPath()

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

Definition at line 630 of file KisPaletteEditor.cpp.

631{
632 return QDir::fromNativeSeparators(path).section('/', -1, -1);
633}

◆ 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
160 KoColorSetSP palette;
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, and ResourceType::Palettes.

◆ isModified()

bool KisPaletteEditor::isModified ( ) const

Definition at line 487 of file KisPaletteEditor.cpp.

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

References m_d.

◆ modifyEntry()

void KisPaletteEditor::modifyEntry ( const QModelIndex & index)

Definition at line 386 of file KisPaletteEditor.cpp.

387{
388 if (!m_d->view) { return; }
389 if (!m_d->view->document()) { return; }
390 if (!m_d->model->colorSet()) { return; }
391
393 dialog.setCaption(i18nc("@title:dialog", "Add a new Color Swatch"));
394 QFormLayout *editableItems = new QFormLayout(dialog.mainWidget());
395
396 QString groupName = qvariant_cast<QString>(index.data(Qt::DisplayRole));
397 if (qvariant_cast<bool>(index.data(KisPaletteModel::IsGroupNameRole))) {
398 startEditing();
399 renameGroup(groupName);
400 endEditing();
401 }
402 else {
403
404 QLineEdit *lnIDName = new QLineEdit();
405 QLineEdit *lnGroupName = new QLineEdit();
406 KisColorButton *bnColor = new KisColorButton();
407 QCheckBox *chkSpot = new QCheckBox();
408 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."));
409
410 KisSwatch entry = m_d->model->getSwatch(index);
411
412 editableItems->addRow(i18n("Swatch ID:"), lnIDName);
413 editableItems->addRow(i18n("Color swatch name:"), lnGroupName);
414 editableItems->addRow(i18nc("Color as the Color of a Swatch in a Palette", "Color:"), bnColor);
415 editableItems->addRow(i18n("Spot color:"), chkSpot);
416
417 lnGroupName->setText(entry.name());
418 lnIDName->setText(entry.id());
419 bnColor->setColor(entry.color());
420 chkSpot->setChecked(entry.spotColor());
421
422 if (dialog.exec() == KoDialog::Accepted) {
423 entry.setName(lnGroupName->text());
424 entry.setId(lnIDName->text());
425 entry.setColor(bnColor->color());
426 entry.setSpotColor(chkSpot->isChecked());
427 m_d->model->setSwatch(entry, index);
428 }
429 }
430}
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 619 of file KisPaletteEditor.cpp.

620{
621 int i = 1;
622 QString groupname = i18nc("Default new group name", "New Group %1", QString::number(i));
623 while (m_d->modifiedPaletteInfo.groups.contains(groupname)) {
624 i++;
625 groupname = i18nc("Default new group name", "New Group %1", QString::number(i));
626 }
627 return groupname;
628}

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 372 of file KisPaletteEditor.cpp.

373{
374 Q_ASSERT(m_d->model);
375 if (!m_d->view) { return; }
376 if (!m_d->view->document()) { return; }
377 if (qvariant_cast<bool>(index.data(KisPaletteModel::IsGroupNameRole))) {
378 startEditing();
379 removeGroup(qvariant_cast<QString>(index.data(KisPaletteModel::GroupNameRole)));
380 endEditing();
381 } else {
382 m_d->model->removeSwatch(index, false);
383 }
384}
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 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 583 of file KisPaletteEditor.cpp.

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

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 if (!m_d->model->colorSet()) { return; }
357 KisSwatch c = KisSwatch(color);
358 c.setId(QString::number(m_d->model->colorSet()->colorCount() + 1));
359 c.setName(i18nc("Default name for a color swatch","Color %1", QString::number(m_d->model->colorSet()->colorCount()+1)));
360 m_d->model->setSwatch(c, index);
361}

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 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 610 of file KisPaletteEditor.cpp.

611{
612 Q_ASSERT(m_d->model);
614
615 const KoColorSetSP colorSet = m_d->model->colorSet();
616 m_d->modifiedPaletteInfo.storageLocation = colorSet ? colorSet->storageLocation() : "";
617}

References clearStagedChanges(), and m_d.

◆ slotSetDocumentModified

void KisPaletteEditor::slotSetDocumentModified ( )
privateslot

Definition at line 363 of file KisPaletteEditor.cpp.

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

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 496 of file KisPaletteEditor.cpp.

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

References clearStagedChanges(), and m_d.

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: