(node.data()));
+}
+
+void GamutMaskDock::slotGamutMaskSave()
+{
+ QString newTitle = m_dockerUI->maskTitleEdit->text();
+ // was this mask previously set to selectors?
+ bool setToSelectors = (m_resourceProvider->currentGamutMask() == m_selectedMask);
+
+ if (m_selectedMask->title() != newTitle) {
+ // title has changed, rename
+ if (!m_selectedMask) {
+ return;
+ }
+
+ // construct a copy
+ KoGamutMask* newMask = addDuplicateResource(newTitle);
+
+ // delete old mask and select new
+ slotGamutMaskDelete();
+ m_selectedMask = newMask;
+ }
+
+ saveSelectedMaskResource();
+ finalizeMaskSave();
+
+ if (setToSelectors) {
+ emit sigGamutMaskSet(m_selectedMask);
+ }
+}
+
+void GamutMaskDock::slotGamutMaskCancelEdit()
+{
+ if (!m_selectedMask) {
+ return;
+ }
+
+ bool cancelApproved = false;
+ if (m_maskDocument->isModified()) {
+ int res = QMessageBox::warning(this,
+ i18nc("@title:window", "Krita"),
+ i18n("Gamut mask '%1' has been modified.
Discard changes?
"
+ , m_selectedMask->title()),
+ QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
+
+ switch (res) {
+ case QMessageBox::Yes : {
+ cancelApproved = true;
+ break;
+ }
+ case QMessageBox::No : {
+ cancelApproved = false;
+ break;
+ }
+ }
+ } else {
+ cancelApproved = true;
+ }
+
+ if (cancelApproved) {
+ cancelMaskEdit();
+ closeMaskDocument();
+ }
+}
+
+void GamutMaskDock::slotGamutMaskPreview()
+{
+ if (!m_selectedMask) {
+ return;
+ }
+
+ m_selectedMask->setPreviewMaskShapes(getShapesFromLayer());
+ emit sigGamutMaskPreviewUpdate();
+}
+
+void GamutMaskDock::slotGamutMaskSelected(KoGamutMask *mask)
+{
+ m_selectedMask = mask;
+
+ if (m_selectedMask) {
+ m_dockerUI->labelMaskName->setText(m_selectedMask->title());
+ } else {
+ m_dockerUI->labelMaskName->setText(i18n("Select a mask"));
+ }
+}
+
+void GamutMaskDock::setCanvas(KoCanvasBase *canvas)
+{
+ setEnabled(canvas != 0);
+}
+
+void GamutMaskDock::unsetCanvas()
+{
+ setEnabled(false);
+}
+
+
+void GamutMaskDock::unsetResourceServer()
+{
+ KoResourceServer* rServer = KoResourceServerProvider::instance()->gamutMaskServer();
+ rServer->removeObserver(this);
+}
+
+void GamutMaskDock::removingResource(KoGamutMask *resource)
+{
+}
+
+void GamutMaskDock::resourceChanged(KoGamutMask *resource)
+{
+}
+
+void GamutMaskDock::slotGamutMaskSaveNew()
+{
+ if (!m_selectedMask) {
+ return;
+ }
+
+ KoGamutMask* newMask = addDuplicateResource(m_dockerUI->maskTitleEdit->text());
+ m_selectedMask = newMask;
+
+ saveSelectedMaskResource();
+ finalizeMaskSave();
+}
+
+void GamutMaskDock::slotGamutMaskDelete()
+{
+ if (!m_selectedMask) {
+ return;
+ }
+
+ int res = QMessageBox::warning(this,
+ i18nc("@title:window", "Krita"),
+ i18n("Are you sure you want to delete mask '%1'?"
+ , m_selectedMask->title()),
+ QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
+
+ // delete only if user confirms
+ if (res == QMessageBox::Yes) {
+ // if deleting previously set mask, notify selectors to unset their mask
+ if (m_selectedMask == m_resourceProvider->currentGamutMask()) {
+ emit sigGamutMaskUnset();
+ }
+
+ QString resourceFile = m_selectedMask->filename();
+
+ KoResourceServer* rServer = KoResourceServerProvider::instance()->gamutMaskServer();
+ // TODO: other resources do it this way, but the files stay on disk
+ rServer->removeResourceAndBlacklist(m_selectedMask);
+
+ m_selectedMask = nullptr;
+ m_dockerUI->labelMaskName->setText(i18n("Select a mask"));
+ }
+}
+
+void GamutMaskDock::slotGamutMaskSet()
+{
+ if (!m_selectedMask) {
+ return;
+ }
+
+ emit sigGamutMaskSet(m_selectedMask);
+}
+
+void GamutMaskDock::slotDocumentRemoved(QString filename)
+{
+ if (!m_maskDocument) {
+ return;
+ }
+
+ // HACK: we do not want to run this if it is we who close the file
+ if (!m_selfClosingMaskFile) {
+ // KisPart called, that a document will be removed
+ // if it's ours, cancel the mask edit operation
+ if (m_maskDocument->url().toLocalFile() == filename) {
+ cancelMaskEdit();
+ }
+ }
+}
Index: plugins/dockers/gamutmask/gamutmask_plugin.h
===================================================================
--- /dev/null
+++ plugins/dockers/gamutmask/gamutmask_plugin.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2018 Anna Medonosova
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef H_GAMUT_MASK_PLUGIN_H
+#define H_GAMUT_MASK_PLUGIN_H
+
+#include
+#include
+
+class GamutMaskPlugin: public QObject
+{
+public:
+ GamutMaskPlugin(QObject *parent, const QVariantList &);
+};
+
+#endif // H_GAMUT_MASK_PLUGIN_H
Index: plugins/dockers/gamutmask/gamutmask_plugin.cpp
===================================================================
--- /dev/null
+++ plugins/dockers/gamutmask/gamutmask_plugin.cpp
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2018 Anna Medonosova
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "gamutmask_plugin.h"
+#include "gamutmask_dock.h"
+
+#include
+#include
+#include
+#include
+
+K_PLUGIN_FACTORY_WITH_JSON(PaletteDockPluginFactory, "krita_gamutmask.json", registerPlugin();)
+
+class GamutMaskDockFactory: public KoDockFactoryBase
+{
+public:
+ QString id() const override {
+ return QString("GamutMask");
+ }
+
+ virtual Qt::DockWidgetArea defaultDockWidgetArea() const {
+ return Qt::RightDockWidgetArea;
+ }
+
+ QDockWidget* createDockWidget() override {
+ GamutMaskDock* dockWidget = new GamutMaskDock();
+ dockWidget->setObjectName(id());
+ return dockWidget;
+ }
+
+ DockPosition defaultDockPosition() const override {
+ return DockMinimized;
+ }
+};
+
+
+GamutMaskPlugin::GamutMaskPlugin(QObject* parent, const QVariantList &):
+ QObject(parent)
+{
+ KoDockRegistry::instance()->add(new GamutMaskDockFactory());
+}
+
+#include "gamutmask_plugin.moc"
Index: plugins/dockers/gamutmask/krita_gamutmask.json
===================================================================
--- /dev/null
+++ plugins/dockers/gamutmask/krita_gamutmask.json
@@ -0,0 +1,9 @@
+{
+ "Id": "Gamut masks",
+ "Type": "Service",
+ "X-KDE-Library": "kritagamutmask",
+ "X-KDE-ServiceTypes": [
+ "Krita/Dock"
+ ],
+ "X-Krita-Version": "28"
+}