diff --git a/libs/global/kis_dom_utils.h b/libs/global/kis_dom_utils.h --- a/libs/global/kis_dom_utils.h +++ b/libs/global/kis_dom_utils.h @@ -26,6 +26,7 @@ #include #include #include +#include #include @@ -110,6 +111,26 @@ } + inline QString qColorToQString(QColor color) + { + // color channels will usually have 0-255 + QString customColor = QString::number(color.red()).append(",") + .append(QString::number(color.green())).append(",") + .append(QString::number(color.blue())).append(",") + .append(QString::number(color.alpha())); + + return customColor; + } + + inline QColor qStringToQColor(QString colorString) + { + QStringList colorComponents = colorString.split(','); + return QColor(colorComponents[0].toInt(), colorComponents[1].toInt(), colorComponents[2].toInt(), colorComponents[3].toInt()); + } + + + + /** * Save a value of type QRect into an XML tree. A child for \p parent * is created and assigned a tag \p tag. The corresponding value can diff --git a/libs/ui/KisDocument.h b/libs/ui/KisDocument.h --- a/libs/ui/KisDocument.h +++ b/libs/ui/KisDocument.h @@ -590,6 +590,12 @@ /// @replace the current list of assistants with @param value void setAssistants(const QList &value); + + void setAssistantsGlobalColor(QColor color); + QColor assistantsGlobalColor(); + + + /** * Get existing reference images layer or null if none exists. */ diff --git a/libs/ui/KisDocument.cpp b/libs/ui/KisDocument.cpp --- a/libs/ui/KisDocument.cpp +++ b/libs/ui/KisDocument.cpp @@ -266,6 +266,7 @@ , preActivatedNode(0) // the node is from another hierarchy! , imageIdleWatcher(2000 /*ms*/) , assistants(rhs.assistants) // WARNING: assistants should not store pointers to the document! + , globalAssistantsColor(rhs.globalAssistantsColor) , gridConfig(rhs.gridConfig) , savingLock(&savingMutex) , batchMode(rhs.batchMode) @@ -324,6 +325,8 @@ QList assistants; + QColor globalAssistantsColor; + KisSharedPtr referenceImagesLayer; KisGridConfig gridConfig; @@ -1790,3 +1793,13 @@ { return errorMessage.isEmpty() ? KisImportExportFilter::conversionStatusString(status) : errorMessage; } + +void KisDocument::setAssistantsGlobalColor(QColor color) +{ + d->globalAssistantsColor = color; +} + +QColor KisDocument::assistantsGlobalColor() +{ + return d->globalAssistantsColor; +} diff --git a/libs/ui/KisView.cpp b/libs/ui/KisView.cpp --- a/libs/ui/KisView.cpp +++ b/libs/ui/KisView.cpp @@ -250,6 +250,9 @@ d->canvas.addDecoration(d->paintingAssistantsDecoration); d->paintingAssistantsDecoration->setVisible(true); + d->canvas.paintingAssistantsDecoration()->setGlobalAssistantsColor(d->document->assistantsGlobalColor()); + + d->canvas.addDecoration(d->referenceImagesDecoration); d->referenceImagesDecoration->setVisible(true); diff --git a/libs/ui/kis_painting_assistant.cc b/libs/ui/kis_painting_assistant.cc --- a/libs/ui/kis_painting_assistant.cc +++ b/libs/ui/kis_painting_assistant.cc @@ -22,6 +22,7 @@ #include "kis_painting_assistant.h" #include "kis_coordinates_converter.h" #include "kis_debug.h" +#include "kis_dom_utils.h" #include #include "kis_tool.h" @@ -365,7 +366,7 @@ xml.writeAttribute("type",d->id); xml.writeAttribute("active", QString::number(d->isSnappingActive)); xml.writeAttribute("useCustomColor", QString::number(d->useCustomColor)); - xml.writeAttribute("customColor", KisPaintingAssistantsDecoration::qColorToQString(d->assistantCustomColor)); + xml.writeAttribute("customColor", KisDomUtils::qColorToQString(d->assistantCustomColor)); @@ -420,13 +421,13 @@ usingColor = true; } + setUseCustomColor(usingColor); } if ( xml.attributes().hasAttribute("customColor")) { QStringRef customColor = xml.attributes().value("customColor"); - - setAssistantCustomColor( KisPaintingAssistantsDecoration::qStringToQColor(customColor.toString()) ); + setAssistantCustomColor( KisDomUtils::qStringToQColor(customColor.toString()) ); } diff --git a/libs/ui/kis_painting_assistants_decoration.h b/libs/ui/kis_painting_assistants_decoration.h --- a/libs/ui/kis_painting_assistants_decoration.h +++ b/libs/ui/kis_painting_assistants_decoration.h @@ -116,10 +116,6 @@ int handleSize(); void setHandleSize(int handleSize); - /// helper functions when converting between QColor when saving to XML - static QString qColorToQString(QColor color); - static QColor qStringToQColor(QString colorString); - Q_SIGNALS: void assistantChanged(); void selectedAssistantChanged(); diff --git a/libs/ui/kis_painting_assistants_decoration.cpp b/libs/ui/kis_painting_assistants_decoration.cpp --- a/libs/ui/kis_painting_assistants_decoration.cpp +++ b/libs/ui/kis_painting_assistants_decoration.cpp @@ -42,18 +42,20 @@ , snapOnlyOneAssistant(true) , firstAssistant(0) , aFirstStroke(false) + , m_globalAssistantsColor(QColor(176, 176, 176, 255)), + m_handleSize(14) {} bool assistantVisible; bool outlineVisible; bool snapOnlyOneAssistant; KisPaintingAssistantSP firstAssistant; KisPaintingAssistantSP selectedAssistant; bool aFirstStroke; - QColor m_globalAssistantsColor = QColor(176, 176, 176, 255); // kis_assistant_tool has same default color specified + QColor m_globalAssistantsColor; bool m_isEditingAssistants = false; bool m_outlineVisible = false; - int m_handleSize = 14; // size of editor handles on assistants + int m_handleSize; // size of editor handles on assistants // move, visibility, delete icons for each assistant. These only display while the assistant tool is active // these icons will be covered by the kis_paintint_assistant_decoration with things like the perspective assistant @@ -359,6 +361,11 @@ void KisPaintingAssistantsDecoration::setGlobalAssistantsColor(QColor color) { d->m_globalAssistantsColor = color; + + + // view()->document() is referenced multiple times in this class + // it is used to later store things in the KRA file when saving. + view()->document()->setAssistantsGlobalColor(color); uncache(); } @@ -474,21 +481,3 @@ } - -QString KisPaintingAssistantsDecoration::qColorToQString(QColor color) -{ - // color channels will usually have 0-255 - QString customColor = QString::number(color.red()).append(",") - .append(QString::number(color.blue())).append(",") - .append(QString::number(color.green())).append(",") - .append(QString::number(color.alpha())); - - return customColor; -} - -QColor KisPaintingAssistantsDecoration::qStringToQColor(QString colorString) -{ - QStringList colorComponents = colorString.split(','); - return QColor(colorComponents[0].toInt(), colorComponents[1].toInt(), colorComponents[2].toInt(), colorComponents[3].toInt()); -} - diff --git a/plugins/assistants/Assistants/kis_assistant_tool.cc b/plugins/assistants/Assistants/kis_assistant_tool.cc --- a/plugins/assistants/Assistants/kis_assistant_tool.cc +++ b/plugins/assistants/Assistants/kis_assistant_tool.cc @@ -29,6 +29,7 @@ #include #include #include +#include "kis_dom_utils.h" #include #include @@ -74,12 +75,13 @@ m_internalMode = MODE_CREATION; m_assistantHelperYOffset = 10; - m_canvas->paintingAssistantsDecoration()->setHandleSize(17); + m_handleSize = 17; + m_canvas->paintingAssistantsDecoration()->setHandleSize(m_handleSize); + if (m_optionsWidget) { m_canvas->paintingAssistantsDecoration()->deselectAssistant(); - updateToolOptionsUI(); } @@ -768,7 +770,8 @@ if ( xml.attributes().hasAttribute("useCustomColor")) { QStringRef customColor = xml.attributes().value("customColor"); - assistant->setAssistantCustomColor( KisPaintingAssistantsDecoration::qStringToQColor(customColor.toString()) ); + assistant->setAssistantCustomColor( KisDomUtils::qStringToQColor(customColor.toString()) ); + } } @@ -832,7 +835,7 @@ QXmlStreamWriter xml(&data); xml.writeStartDocument(); xml.writeStartElement("paintingassistant"); - xml.writeAttribute("color", KisPaintingAssistantsDecoration::qColorToQString(m_canvas->paintingAssistantsDecoration()->globalAssistantsColor()) ); // global color if no custom color used + xml.writeAttribute("color", KisDomUtils::qColorToQString(m_canvas->paintingAssistantsDecoration()->globalAssistantsColor()) ); // global color if no custom color used xml.writeStartElement("handles"); @@ -855,7 +858,8 @@ xml.writeStartElement("assistant"); xml.writeAttribute("type", assistant->id()); xml.writeAttribute("useCustomColor", QString::number(assistant->useCustomColor())); - xml.writeAttribute("customColor", KisPaintingAssistantsDecoration::qColorToQString(assistant->assistantCustomColor())); + xml.writeAttribute("customColor", KisDomUtils::qColorToQString(assistant->assistantCustomColor())); + // custom assistant properties like angle density on vanishing point @@ -923,11 +927,22 @@ connect(m_options.vanishingPointAngleSpinbox, SIGNAL(valueChanged(double)), this, SLOT(slotChangeVanishingPointAngle(double))); + // initialize UI elements with existing data if possible + if (m_canvas && m_canvas->paintingAssistantsDecoration()) { + QColor newColor = m_canvas->paintingAssistantsDecoration()->globalAssistantsColor(); + m_options.assistantsColor->setColor(newColor); // grey default for all assistants + int startingAlpha = (float)newColor.alpha()/255.0 * 100; + m_options.assistantsGlobalOpacitySlider->setValue(startingAlpha); + + } else { + m_options.assistantsColor->setColor(QColor(176, 176, 176, 255)); // grey default for all assistants + m_options.assistantsGlobalOpacitySlider->setValue(100); // 100% + } - m_options.assistantsColor->setColor(QColor(176, 176, 176, 255)); // grey default for all assistants - m_options.assistantsGlobalOpacitySlider->setValue(100); // 100% m_options.assistantsGlobalOpacitySlider->setPrefix(i18n("Opacity: ")); m_options.assistantsGlobalOpacitySlider->setSuffix(" %"); + + m_assistantsGlobalOpacity = m_options.assistantsGlobalOpacitySlider->value()*0.01; @@ -941,11 +956,6 @@ connect(m_options.customAssistantColorButton, SIGNAL(changed(QColor)), this, SLOT(slotUpdateCustomColor())); connect(m_options.customColorOpacitySlider, SIGNAL(valueChanged(int)), SLOT(slotcustomOpacityChanged())); - - QColor newColor = m_options.assistantsColor->color(); - newColor.setAlpha(m_assistantsGlobalOpacity*255); - m_canvas->paintingAssistantsDecoration()->setGlobalAssistantsColor(newColor); - m_options.vanishingPointAngleSpinbox->setPrefix(i18n("Density: ")); m_options.vanishingPointAngleSpinbox->setSuffix(QChar(Qt::Key_degree)); m_options.vanishingPointAngleSpinbox->setRange(1.0, 180.0); diff --git a/plugins/impex/kra/kra_converter.cpp b/plugins/impex/kra/kra_converter.cpp --- a/plugins/impex/kra/kra_converter.cpp +++ b/plugins/impex/kra/kra_converter.cpp @@ -285,7 +285,6 @@ m_kraLoader = new KisKraLoader(m_doc, syntaxVersion); - // Legacy from the multi-image .kra file period. for (node = root.firstChild(); !node.isNull(); node = node.nextSibling()) { if (node.isElement()) { if (node.nodeName() == "IMAGE") { diff --git a/plugins/impex/libkra/kis_kra_loader.cpp b/plugins/impex/libkra/kis_kra_loader.cpp --- a/plugins/impex/libkra/kis_kra_loader.cpp +++ b/plugins/impex/libkra/kis_kra_loader.cpp @@ -206,6 +206,7 @@ QString colorspacename; const KoColorSpace * cs; + if ((attr = element.attribute(MIME)) == NATIVE_MIMETYPE) { if ((m_d->imageName = element.attribute(NAME)).isNull()) { @@ -306,14 +307,24 @@ KoXmlNode child; for (child = element.lastChild(); !child.isNull(); child = child.previousSibling()) { KoXmlElement e = child.toElement(); + if(e.tagName() == CANVASPROJECTIONCOLOR) { if (e.hasAttribute(COLORBYTEDATA)) { QByteArray colorData = QByteArray::fromBase64(e.attribute(COLORBYTEDATA).toLatin1()); KoColor color((const quint8*)colorData.data(), image->colorSpace()); image->setDefaultProjectionColor(color); } } + + if(e.tagName() == GLOBALASSISTANTSCOLOR) { + if (e.hasAttribute(SIMPLECOLORDATA)) { + QString colorData = e.attribute(SIMPLECOLORDATA); + m_d->document->setAssistantsGlobalColor(KisDomUtils::qStringToQColor(colorData)); + } + } + + if(e.tagName()== PROOFINGWARNINGCOLOR) { QDomDocument dom; KoXml::asQDomElement(dom, e); @@ -503,6 +514,8 @@ QString location; QMap handleMap; KisPaintingAssistant* assistant = 0; + QColor globalColor = m_d->document->assistantsGlobalColor(); + QMap::const_iterator loadedAssistant = m_d->assistantsFilenames.constBegin(); while (loadedAssistant != m_d->assistantsFilenames.constEnd()){ const KisPaintingAssistantFactory* factory = KisPaintingAssistantFactoryRegistry::instance()->get(loadedAssistant.value()); @@ -512,6 +525,7 @@ location += m_d->imageName + ASSISTANTS_PATH; file_path = location + loadedAssistant.key(); assistant->loadXml(store, handleMap, file_path); + assistant->setAssistantGlobalColor(globalColor); //If an assistant has too few handles than it should according to it's own setup, just don't load it// if (assistant->handles().size()==assistant->numHandles()){ diff --git a/plugins/impex/libkra/kis_kra_saver.h b/plugins/impex/libkra/kis_kra_saver.h --- a/plugins/impex/libkra/kis_kra_saver.h +++ b/plugins/impex/libkra/kis_kra_saver.h @@ -49,6 +49,7 @@ private: void saveBackgroundColor(QDomDocument& doc, QDomElement& element, KisImageSP image); + void saveAssistantsGlobalColor(QDomDocument& doc, QDomElement& element); void saveWarningColor(QDomDocument& doc, QDomElement& element, KisImageSP image); void saveCompositions(QDomDocument& doc, QDomElement& element, KisImageSP image); bool saveAssistants(KoStore *store,QString uri, bool external); diff --git a/plugins/impex/libkra/kis_kra_saver.cpp b/plugins/impex/libkra/kis_kra_saver.cpp --- a/plugins/impex/libkra/kis_kra_saver.cpp +++ b/plugins/impex/libkra/kis_kra_saver.cpp @@ -91,7 +91,7 @@ QDomElement KisKraSaver::saveXML(QDomDocument& doc, KisImageSP image) { - QDomElement imageElement = doc.createElement("IMAGE"); // Legacy! + QDomElement imageElement = doc.createElement("IMAGE"); Q_ASSERT(image); imageElement.setAttribute(NAME, m_d->imageName); @@ -126,6 +126,7 @@ m_d->keyframeFilenames = visitor.keyframeFileNames(); saveBackgroundColor(doc, imageElement, image); + saveAssistantsGlobalColor(doc, imageElement); saveWarningColor(doc, imageElement, image); saveCompositions(doc, imageElement, image); saveAssistantsList(doc, imageElement); @@ -302,6 +303,14 @@ element.appendChild(e); } +void KisKraSaver::saveAssistantsGlobalColor(QDomDocument& doc, QDomElement& element) +{ + QDomElement e = doc.createElement(GLOBALASSISTANTSCOLOR); + QString colorString = KisDomUtils::qColorToQString(m_d->doc->assistantsGlobalColor()); + e.setAttribute(SIMPLECOLORDATA, QString(colorString)); + element.appendChild(e); +} + void KisKraSaver::saveWarningColor(QDomDocument& doc, QDomElement& element, KisImageSP image) { if (image->proofingConfiguration()) { @@ -328,16 +337,19 @@ QString location; QMap assistantcounters; QByteArray data; + QList assistants = m_d->doc->assistants(); QMap handlemap; if (!assistants.isEmpty()) { + Q_FOREACH (KisPaintingAssistantSP assist, assistants){ if (!assistantcounters.contains(assist->id())){ assistantcounters.insert(assist->id(),0); } location = external ? QString() : uri; location += m_d->imageName + ASSISTANTS_PATH; location += QString(assist->id()+"%1.assistant").arg(assistantcounters[assist->id()]); + data = assist->saveXml(handlemap); store->open(location); store->write(data); diff --git a/plugins/impex/libkra/kis_kra_tags.h b/plugins/impex/libkra/kis_kra_tags.h --- a/plugins/impex/libkra/kis_kra_tags.h +++ b/plugins/impex/libkra/kis_kra_tags.h @@ -132,6 +132,8 @@ const QString ICCPROOFINGPROFILE ="icc-proofing-profile"; const QString CANVASPROJECTIONCOLOR = "ProjectionBackgroundColor"; const QString COLORBYTEDATA = "ColorData"; +const QString SIMPLECOLORDATA = "SimpleColorData"; // easier 8-bit color data that works well with XML +const QString GLOBALASSISTANTSCOLOR = "GlobalAssistantsColor"; }