Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Allow cloning style presets and put in some guard rails for saving.

Wolthera van Hövell tot Westerflier8c0cc5396707
diff --git a/libs/flake/resources/KoCssStylePreset.cpp b/libs/flake/resources/KoCssStylePreset.cpp
index 8223d4fd0a..52eb3a9c6d 100644
--- a/libs/flake/resources/KoCssStylePreset.cpp
+++ b/libs/flake/resources/KoCssStylePreset.cpp
@@ -98,7 +98,10 @@ QString KoCssStylePreset::description() const
void KoCssStylePreset::setDescription(QString description)
{
d->shape->setAdditionalAttribute(DESC, description);
+ QMap<QString, QVariant> m = metadata();
+ if (m[DESCRIPTION].toString() == description) return;
addMetaData(DESCRIPTION, description);
+ setDirty(true);
}
QString KoCssStylePreset::styleType() const
diff --git a/plugins/dockers/textproperties/CssStylePresetEditDialog.cpp b/plugins/dockers/textproperties/CssStylePresetEditDialog.cpp
index f3413ab104..a4c17d80c7 100644
--- a/plugins/dockers/textproperties/CssStylePresetEditDialog.cpp
+++ b/plugins/dockers/textproperties/CssStylePresetEditDialog.cpp
@@ -8,6 +8,7 @@
#include <QQmlContext>
#include <QQuickItem>
#include <QColorDialog>
+#include <QPushButton>
#include <KoResourcePaths.h>
#include <KLocalizedContext>
#include <KLocalizedString>
@@ -94,6 +95,7 @@ void CssStylePresetEditDialog::setCurrentResource(KoCssStylePresetSP resource)
QMetaObject::invokeMethod(m_quickWidget->rootObject(), "setProperties");
m_blockUpdates = false;
+ slotUpdateDirty();
}
KoCssStylePresetSP CssStylePresetEditDialog::currentResource()
@@ -133,6 +135,7 @@ void CssStylePresetEditDialog::slotUpdateTextProperties()
m_quickWidget->rootObject()->setProperty("presetSample", m_currentResource->sampleSvg());
m_quickWidget->rootObject()->setProperty("presetSampleAlignment", variantFromAlignment(m_currentResource->alignSample()));
QMetaObject::invokeMethod(m_quickWidget->rootObject(), "setProperties");
+ slotUpdateDirty();
}
}
}
@@ -151,3 +154,15 @@ QString CssStylePresetEditDialog::wwsFontFamilyName(QString familyName)
}
return name.value();
}
+
+void CssStylePresetEditDialog::slotUpdateDirty() {
+ bool isDirty = m_currentResource->isDirty();
+ const QString title = m_quickWidget->rootObject()->property("presetTitle").toString();
+ if (!isDirty) {
+ const QString description = m_quickWidget->rootObject()->property("presetDescription").toString();
+ if (title != m_currentResource->name() || description != m_currentResource->description()) {
+ isDirty = true;
+ }
+ }
+ this->button(KoDialog::Ok)->setEnabled(isDirty && !title.isEmpty());
+}
diff --git a/plugins/dockers/textproperties/CssStylePresetEditDialog.h b/plugins/dockers/textproperties/CssStylePresetEditDialog.h
index 64394cbf5c..39afbc9e60 100644
--- a/plugins/dockers/textproperties/CssStylePresetEditDialog.h
+++ b/plugins/dockers/textproperties/CssStylePresetEditDialog.h
@@ -28,6 +28,7 @@ public Q_SLOTS:
void slotUpdateTextProperties();
QColor modalColorDialog(QColor oldColor);
QString wwsFontFamilyName(QString familyName);
+ void slotUpdateDirty();
private:
QQuickWidget *m_quickWidget {0};
diff --git a/plugins/dockers/textproperties/TextPropertiesDock.cpp b/plugins/dockers/textproperties/TextPropertiesDock.cpp
index 04a484b0b7..fdc56d4ad8 100644
--- a/plugins/dockers/textproperties/TextPropertiesDock.cpp
+++ b/plugins/dockers/textproperties/TextPropertiesDock.cpp
@@ -279,6 +279,7 @@ bool TextPropertiesDock::createNewPresetFromSettings()
KoCssStylePresetSP preset(new KoCssStylePreset(QString()));
KoSvgTextPropertyData textData = d->textModel->textData.get();
preset->setProperties(textData.commonProperties);
+ preset->setName(i18nc("@info:placeholder", "New Style Preset"));
CssStylePresetEditDialog *dialog = new CssStylePresetEditDialog(this);
dialog->setDpi(d->currentDpi);
@@ -303,3 +304,19 @@ void TextPropertiesDock::editPreset(KoResourceSP resource)
KisResourceUserOperations::updateResourceWithUserInput(this, dialog->currentResource());
}
}
+
+void TextPropertiesDock::cloneAndEditPreset(KoResourceSP resource)
+{
+ KoResourceSP newResource = resource->clone();
+ KoCssStylePresetSP preset = newResource.staticCast<KoCssStylePreset>();
+ if (!preset) return;
+
+ CssStylePresetEditDialog *dialog = new CssStylePresetEditDialog(this);
+ dialog->setCurrentResource(preset);
+
+ if (dialog->exec() == QDialog::Accepted) {
+ preset = dialog->currentResource();
+ preset->setFilename(preset->name().replace(' ', '_').replace('.', '_') + preset->defaultFileExtension());
+ KisResourceUserOperations::addResourceWithUserInput(this, preset);
+ }
+}
diff --git a/plugins/dockers/textproperties/TextPropertiesDock.h b/plugins/dockers/textproperties/TextPropertiesDock.h
index 716fbeed8f..96e2796b2b 100644
--- a/plugins/dockers/textproperties/TextPropertiesDock.h
+++ b/plugins/dockers/textproperties/TextPropertiesDock.h
@@ -41,6 +41,7 @@ public Q_SLOTS:
bool createNewPresetFromSettings();
void editPreset(KoResourceSP resource);
+ void cloneAndEditPreset(KoResourceSP resource);
private:
diff --git a/plugins/dockers/textproperties/qml/CssStylePresetEdit.qml b/plugins/dockers/textproperties/qml/CssStylePresetEdit.qml
index 832fa1fc48..2e741e9075 100644
--- a/plugins/dockers/textproperties/qml/CssStylePresetEdit.qml
+++ b/plugins/dockers/textproperties/qml/CssStylePresetEdit.qml
@@ -77,6 +77,7 @@ Control {
id: presetTitleField;
Layout.fillWidth: true;
placeholderText: i18nc("info:placeholder", "Style Name");
+ onTextChanged: mainWindow.slotUpdateDirty();
}
Label {
Layout.minimumWidth: implicitWidth;
@@ -94,6 +95,7 @@ Control {
wrapMode: TextInput.Wrap;
placeholderText: i18nc("info:placeholder", "Style Description.");
+ onTextChanged: mainWindow.slotUpdateDirty();
}
background: Rectangle {
diff --git a/plugins/dockers/textproperties/qml/TextProperties.qml b/plugins/dockers/textproperties/qml/TextProperties.qml
index 8b72a56c44..f46d7043e1 100644
--- a/plugins/dockers/textproperties/qml/TextProperties.qml
+++ b/plugins/dockers/textproperties/qml/TextProperties.qml
@@ -178,6 +178,25 @@ Rectangle {
}
palette: editPalette.palette;
+ enabled: presetView.currentIndex >= 0;
+ ToolTip.visible: hovered;
+ ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval;
+ ToolTip.text: text;
+ }
+ ToolButton {
+ text: i18nc("@label:button", "Clone Style Preset");
+ display: AbstractButton.IconOnly;
+ icon.source: "qrc:///light_edit-copy.svg";
+ icon.color: palette.text;
+ icon.width: 16;
+ icon.height: 16;
+ onClicked: mainWindow.cloneAndEditPreset(presetView.currentResource);
+ hoverEnabled: true;
+ PaletteControl {
+ id: cloneButtonPalette;
+ }
+ palette: cloneButtonPalette.palette;
+
enabled: presetView.currentIndex >= 0;
ToolTip.visible: hovered;
ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval;