40 QHash<QString, KisSwatchGroupSP>
groups;
67 m_d->warnPalette.setColor(QPalette::Text, Qt::red);
75 if (!model) {
return; }
77 m_d->model->disconnect(
this);
92 if (!
m_d->view) {
return 0; }
93 if (!
m_d->view->document()) {
return 0; }
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);
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);
107 QCheckBox *chkSaveInDocument =
new QCheckBox(i18n(
"Save Palette in the Current Document"));
108 chkSaveInDocument->setChecked(
false);
109 layout->addRow(chkSaveInDocument);
112 if (dialog.exec() != QDialog::Accepted) {
return 0; }
114 QString name = le->text();
115 if (cmbPaletteType->currentIndex() == 0) {
121 colorSet->setValid(
true);
122 colorSet->setName(name);
123 colorSet->setFilename(name.split(
" ").join(
"_")+colorSet->defaultFileExtension());
125 QString resourceLocation =
"";
126 if (chkSaveInDocument->isChecked()) {
127 resourceLocation =
m_d->view->document()->linkedResourcesStorageId();
141 dialog.setCaption(i18n(
"Import Palette"));
143 dialog.setDefaultDir(QDir::homePath());
144 dialog.setMimeTypeFilters(
QStringList() <<
"application/x-krita-palette" <<
"application/x-gimp-color-palette");
146 QString filename = dialog.filename();
147 if (filename.isEmpty()) {
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();
170 if (!
m_d->view) {
return; }
171 if (!
m_d->view->document()) {
return; }
173 m_d->rServer->removeResourceFromServer(cs);
178 if (!
m_d->modifiedPaletteInfo.groups.contains(originalName)) {
180 if (originalName.isEmpty()) {
181 return colorSet->getGlobalGroup()->rowCount();
186 return group->rowCount();
191 return m_d->modifiedPaletteInfo.groups[originalName]->rowCount();
196 if (name ==
m_d->groupBeingRenamed) {
return false; }
198 if (name == group->name()) {
return true; }
205 return m_d->modifiedPaletteInfo.groups.contains(name);
210 Q_FOREACH (
const QString &oldGroupName,
m_d->modifiedPaletteInfo.groups.keys()) {
211 if (
m_d->modifiedPaletteInfo.groups[oldGroupName]->name() == newName) {
220 if (!
m_d->isEditing) {
223 if (newName.isEmpty()) {
return; }
224 m_d->modifiedPaletteInfo.name = newName;
229 if (!
m_d->isEditing) {
232 m_d->modifiedPaletteInfo.columnCount = newCount;
237 if (!
m_d->isEditing) {
241 m_d->query = &dialog;
243 QVBoxLayout *layout =
new QVBoxLayout(dialog.mainWidget());
245 layout->addWidget(
new QLabel(i18n(
"New swatch group name:")));
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);
254 if (dialog.exec() != QDialog::Accepted) {
return QString(); }
257 QString realName = leName->text();
258 QString name = realName;
264 newGroup->setName(realName);
265 m_d->newGroupNames.insert(name);
266 newGroup->setRowCount(spxRow->value());
272 if (!
m_d->isEditing) {
276 dialog.setWindowTitle(i18nc(
"@title:dialog",
"Removing Swatch Group"));
277 QFormLayout *editableItems =
new QFormLayout(dialog.mainWidget());
278 QCheckBox *chkKeep =
new QCheckBox();
280 editableItems->addRow(i18nc(
"Shows up when deleting a swatch group",
"Keep the Colors"), chkKeep);
281 if (dialog.exec() != KoDialog::Accepted) {
return false; }
283 m_d->modifiedPaletteInfo.groups.remove(name);
284 m_d->newGroupNames.remove(name);
285 if (chkKeep->isChecked()) {
286 m_d->keepColorGroups.insert(name);
293 if (!
m_d->isEditing) {
299 m_d->query = &dialog;
300 m_d->groupBeingRenamed =
m_d->modifiedPaletteInfo.groups[oldName]->name();
302 QFormLayout *form =
new QFormLayout(dialog.mainWidget());
304 QLineEdit *leNewName =
new QLineEdit();
306 leNewName->setText(
m_d->modifiedPaletteInfo.groups[oldName]->name());
308 form->addRow(i18n(
"New swatch group name:"), leNewName);
310 if (dialog.exec() != KoDialog::Accepted) {
return QString(); }
311 if (leNewName->text().isEmpty()) {
return QString(); }
314 m_d->modifiedPaletteInfo.groups[oldName]->setName(leNewName->text());
315 m_d->modifiedGroupNames.insert(oldName);
317 return leNewName->text();
322 QLineEdit *leGroupName = qobject_cast<QLineEdit*>(sender());
324 leGroupName->setPalette(
m_d->warnPalette);
330 leGroupName->setPalette(
m_d->normalPalette);
338 if (!
m_d->isEditing) {
341 if (!
m_d->modifiedPaletteInfo.groups.contains(name)) {
return; }
342 m_d->modifiedPaletteInfo.groups[name]->setRowCount(newRowCount);
343 m_d->modifiedGroupNames.insert(name);
348 m_d->modifiedPaletteInfo.storageLocation = location;
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; }
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);
365 if (
m_d->modifiedPaletteInfo.storageLocation ==
m_d->view->document()->linkedResourcesStorageId()) {
367 m_d->view->document()->setModified(
true);
369 m_d->model->colorSet()->setDirty(
true);
374 Q_ASSERT(
m_d->model);
375 if (!
m_d->view) {
return; }
376 if (!
m_d->view->document()) {
return; }
382 m_d->model->removeSwatch(index,
false);
388 if (!
m_d->view) {
return; }
389 if (!
m_d->view->document()) {
return; }
390 if (!
m_d->model->colorSet()) {
return; }
393 dialog.setCaption(i18nc(
"@title:dialog",
"Add a new Color Swatch"));
394 QFormLayout *editableItems =
new QFormLayout(dialog.mainWidget());
396 QString groupName = qvariant_cast<QString>(index.data(Qt::DisplayRole));
404 QLineEdit *lnIDName =
new QLineEdit();
405 QLineEdit *lnGroupName =
new QLineEdit();
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."));
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);
417 lnGroupName->setText(entry.
name());
418 lnIDName->setText(entry.
id());
422 if (dialog.exec() == KoDialog::Accepted) {
423 entry.
setName(lnGroupName->text());
424 entry.
setId(lnIDName->text());
427 m_d->model->setSwatch(entry, index);
434 Q_ASSERT(
m_d->model);
435 if (!
m_d->view) {
return; }
436 if (!
m_d->view->document()) {
return; }
439 dialog.setWindowTitle(i18nc(
"@title:dialog",
"Add a new Color Swatch"));
441 QFormLayout *editableItems =
new QFormLayout(dialog.mainWidget());
443 QComboBox *cmbGroups =
new QComboBox();
444 cmbGroups->addItems(
m_d->model->colorSet()->swatchGroupNames());
445 cmbGroups->setCurrentIndex(0);
447 QLineEdit *lnIDName =
new QLineEdit();
448 lnIDName->setText(QString::number(
m_d->model->colorSet()->colorCount() + 1));
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)));
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."));
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);
466 if (dialog.exec() != KoDialog::Accepted) {
return; }
468 QString groupName = cmbGroups->currentText();
472 newSwatch.
setName(lnName->text());
473 newSwatch.
setId(lnIDName->text());
475 m_d->model->addSwatch(newSwatch, groupName);
476 m_d->modifiedGroupNames.insert(groupName);
478 if (
m_d->isEditing) {
480 cs->addSwatch(newSwatch);
481 if (!
m_d->modifiedPaletteInfo.groups.contains(groupName)) {
482 m_d->modifiedPaletteInfo.groups.insert(groupName, cs);
489 if (
m_d->model->colorSet()) {
490 return m_d->model->colorSet()->isDirty();
498 if (
m_d->isEditing) {
499 qWarning() <<
"KisPaletteEditor::startEditing(): restarting palette editing.";
503 if (!
m_d->model || !
m_d->model->colorSet()) {
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();
513 Q_FOREACH (
const QString &groupName, palette->swatchGroupNames()) {
515 m_d->modifiedPaletteInfo.groups.insert(groupName, cs);
518 m_d->isEditing =
true;
523 if (!
m_d->isEditing) {
524 qWarning(
"KisPaletteEditor::endEditing(): not in editing state; ignoring.");
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;
541 if (modified.
columnCount != palette->columnCount()) {
544 if (modified.
name != palette->name()) {
547 QString resourceLocation =
m_d->model->colorSet()->storageLocation();
548 if (resourceLocation !=
m_d->modifiedPaletteInfo.storageLocation) {
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));
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());
563 modified.
groups.remove(groupName);
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;
585 if (!
m_d->model || !
m_d->model->colorSet()) {
return; }
587 QModelIndex index =
m_d->rServer->resourceModel()->indexForResource(
m_d->model->colorSet());
588 bool isGlobal =
false;
589 if (index.isValid()) {
602 }
else if (
m_d->model->colorSet()->version() >= 0) {
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;
612 Q_ASSERT(
m_d->model);
616 m_d->modifiedPaletteInfo.storageLocation = colorSet ? colorSet->storageLocation() :
"";
622 QString groupname = i18nc(
"Default new group name",
"New Group %1", QString::number(i));
623 while (
m_d->modifiedPaletteInfo.groups.contains(groupname)) {
625 groupname = i18nc(
"Default new group name",
"New Group %1", QString::number(i));
632 return QDir::fromNativeSeparators(path).section(
'/', -1, -1);
QList< QString > QStringList
void setPaletteModel(KisPaletteModel *model)
KoColorSetSP addPalette()
void rename(const QString &newName)
Stage a palette rename.
KisPaletteEditor(QObject *parent=0)
void startEditing()
Start editing the current palette.
void modifyEntry(const QModelIndex &index)
QString newGroupName() const
void removePalette(KoColorSetSP)
void changeColumnCount(int)
Stage a change of the palette's column count.
bool duplicateExistsOriginalGroupName(const QString &name) const
KoColorSetSP importPalette()
QString filenameFromPath(const QString &path) const
void changeGroupRowCount(const QString &name, int newRowCount)
Stage a change to the row count of a group.
QString renameGroup(const QString &oldName)
Stage a rename of a group.
void saveNewPaletteVersion()
saveNewPaletteVersion
QString addGroup()
Stage the addition of a new swatch group.
QScopedPointer< Private > m_d
bool removeGroup(const QString &name)
Stage the removal of a group.
int rowCountOfGroup(const QString &originalName) const
rowCountOfGroup
void setView(KisViewManager *view)
void slotSetDocumentModified()
void removeEntry(const QModelIndex &index)
void endEditing(bool applyChanges=true)
End editing and either apply or discard staged changes.
QString oldNameFromNewName(const QString &newName) const
oldNameFromNewName
void setStorageLocation(QString location)
bool duplicateExistsGroupName(const QString &name) const
void setEntry(const KoColor &color, const QModelIndex &index)
void slotPaletteChanged()
void slotGroupNameChanged(const QString &newName)
void clearStagedChanges()
void addEntry(const KoColor &color)
The KisPaletteModel class This, together with KisPaletteView and KisPaletteDelegate forms a mvc way t...
static KoResourceSP importResourceFileWithUserInput(QWidget *widgetParent, QString storageLocation, QString resourceType, QString resourceFilepath)
static bool renameResourceWithUserInput(QWidget *widgetParent, KoResourceSP resource, QString resourceName)
static bool addResourceWithUserInput(QWidget *widgetParent, KoResourceSP resource, QString storageLocation="")
static bool updateResourceWithUserInput(QWidget *widgetParent, KoResourceSP resource)
KisResourceStorageSP storageForId(const int storageId) const
The KisSwatchGroup class stores a matrix of color swatches swatches can accessed using (x,...
void setSpotColor(bool spotColor)
void setColor(const KoColor &color)
void setId(const QString &id)
void setName(const QString &name)
static const QString GLOBAL_GROUP_NAME
A dialog base class with standard buttons and predefined layouts.
@ Ok
Show Ok button. (this button accept()s the dialog; result set to QDialog::Accepted)
QHash< QString, KisSwatchGroupSP > groups
QPointer< KisViewManager > view
QSet< QString > pathsToRemove
KoResourceServer< KoColorSet > * rServer
QPointer< KoDialog > query
QSet< QString > modifiedGroupNames
QSet< QString > newGroupNames
QSet< QString > keepColorGroups
QPointer< KisPaletteModel > model
KisPaletteEditor::PaletteInfo modifiedPaletteInfo
QString groupBeingRenamed
static KoResourceServerProvider * instance()
KoResourceServer< KoColorSet > * paletteServer