diff --git a/libs/ui/widgets/kis_paintop_presets_popup.cpp b/libs/ui/widgets/kis_paintop_presets_popup.cpp --- a/libs/ui/widgets/kis_paintop_presets_popup.cpp +++ b/libs/ui/widgets/kis_paintop_presets_popup.cpp @@ -709,7 +709,7 @@ // settings and save a new copy with the same name. // there is a dialog with save options, but we don't need to show it in this situation - saveDialog->isSavingNewBrush(false); // this mostly just makes sure we keep the existing brush preset name when saving + saveDialog->useNewBrushDialog(false); // this mostly just makes sure we keep the existing brush preset name when saving saveDialog->loadExistingThumbnail(); // This makes sure we use the existing preset icon when updating the existing brush preset saveDialog->savePreset(); @@ -718,7 +718,7 @@ } void KisPaintOpPresetsPopup::slotSaveNewBrushPreset() { - saveDialog->isSavingNewBrush(true); + saveDialog->useNewBrushDialog(true); saveDialog->saveScratchPadThumbnailArea(m_d->uiWdgPaintOpPresetSettings.scratchPad->cutoutOverlay()); saveDialog->showDialog(); } diff --git a/libs/ui/widgets/kis_paintop_presets_save.h b/libs/ui/widgets/kis_paintop_presets_save.h --- a/libs/ui/widgets/kis_paintop_presets_save.h +++ b/libs/ui/widgets/kis_paintop_presets_save.h @@ -49,7 +49,8 @@ void showDialog(); - void isSavingNewBrush(bool newBrush); + /// determines if we should show the save as dialog (true) or save in the background (false) + void useNewBrushDialog(bool show); void scratchPadSetup(KisCanvasResourceProvider* resourceProvider); void saveScratchPadThumbnailArea(const QImage image); @@ -71,7 +72,7 @@ private: - bool m_isSavingNewBrush; + bool m_useNewBrushDialog; KisFavoriteResourceManager * m_favoriteResourceManager; QImage scratchPadThumbnailArea; }; diff --git a/libs/ui/widgets/kis_paintop_presets_save.cpp b/libs/ui/widgets/kis_paintop_presets_save.cpp --- a/libs/ui/widgets/kis_paintop_presets_save.cpp +++ b/libs/ui/widgets/kis_paintop_presets_save.cpp @@ -73,7 +73,7 @@ KisPaintOpPresetSP preset = m_resourceProvider->currentPreset(); // UI will look a bit different if we are saving a new brush - if (m_isSavingNewBrush) { + if (m_useNewBrushDialog) { setWindowTitle(i18n("Save New Brush Preset")); newBrushNameTexField->setVisible(true); clearBrushPresetThumbnailButton->setVisible(true); @@ -165,18 +165,18 @@ m_favoriteResourceManager->setBlockUpdates(true); - KisPaintOpPresetSP oldPreset = curPreset->clone(); + KisPaintOpPresetSP oldPreset = curPreset->clone(); // tags are not cloned with this oldPreset->load(); KisPaintOpPresetResourceServer * rServer = KisResourceServerProvider::instance()->paintOpPresetServer(); QString saveLocation = rServer->saveLocation(); // if we are saving a new brush, use what we type in for the input - QString presetName = m_isSavingNewBrush ? newBrushNameTexField->text() : curPreset->name(); - + QString presetName = m_useNewBrushDialog ? newBrushNameTexField->text() : curPreset->name(); QString currentPresetFileName = saveLocation + presetName + curPreset->defaultFileExtension(); + bool isSavingOverExistingPreset = rServer->resourceByName(presetName); - // if the preset already exists, make a back up of it - if (rServer->resourceByName(presetName)) { + // make a back up of the existing preset if we are saving over it + if (isSavingOverExistingPreset) { QString currentDate = QDate::currentDate().toString(Qt::ISODate); QString currentTime = QTime::currentTime().toString(Qt::ISODate); QString presetFilename = saveLocation + presetName + "_backup_" + currentDate + "-" + currentTime + oldPreset->defaultFileExtension(); @@ -185,10 +185,11 @@ oldPreset->setPresetDirty(false); oldPreset->setValid(true); - // add resource to the blacklist + // add backup resource to the blacklist rServer->addResource(oldPreset); rServer->removeResourceAndBlacklist(oldPreset.data()); + QStringList tags; tags = rServer->assignedTagsList(curPreset.data()); Q_FOREACH (const QString & tag, tags) { @@ -196,7 +197,8 @@ } } - if (m_isSavingNewBrush) { + + if (m_useNewBrushDialog) { KisPaintOpPresetSP newPreset = curPreset->clone(); newPreset->setFilename(currentPresetFileName); newPreset->setName(presetName); @@ -204,14 +206,24 @@ newPreset->setPresetDirty(false); newPreset->setValid(true); + + // keep tags if we are saving over existing preset + if (isSavingOverExistingPreset) { + QStringList tags; + tags = rServer->assignedTagsList(curPreset.data()); + Q_FOREACH (const QString & tag, tags) { + rServer->addTag(newPreset.data(), tag); + } + } + rServer->addResource(newPreset); // trying to get brush preset to load after it is created emit resourceSelected(newPreset.data()); + } + else { // saving a preset that is replacing an existing one - } else { - - if (curPreset->filename().contains(saveLocation)==false || curPreset->filename().contains(presetName)==false) { + if (curPreset->filename().contains(saveLocation) == false || curPreset->filename().contains(presetName) == false) { rServer->removeResourceAndBlacklist(curPreset.data()); curPreset->setFilename(currentPresetFileName); curPreset->setName(presetName); @@ -239,15 +251,17 @@ } + + void KisPresetSaveWidget::saveScratchPadThumbnailArea(QImage image) { scratchPadThumbnailArea = image; } -void KisPresetSaveWidget::isSavingNewBrush(bool newBrush) +void KisPresetSaveWidget::useNewBrushDialog(bool show) { - m_isSavingNewBrush = newBrush; + m_useNewBrushDialog = show; }