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,11 @@ /// @replace the current list of assistants with @param value void setAssistants(const QList &value); + + /// get and set assistantsconfiguration + void setAssistantsGlobalColor(QColor color); + QColor assistantsGlobalColor(); + /** * Get existing reference images layer or create new 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) @@ -323,6 +324,7 @@ QScopedPointer imageIdleConnection; QList assistants; + QColor globalAssistantsColor = QColor(127, 127, 127, 255); KisSharedPtr referenceImagesLayer; @@ -1702,6 +1704,18 @@ d->assistants = value; } +void KisDocument::setAssistantsGlobalColor(QColor color) +{ + d->globalAssistantsColor = color; +} + +QColor KisDocument::assistantsGlobalColor() +{ + return d->globalAssistantsColor; +} + + + KisSharedPtr KisDocument::getOrCreateReferenceImagesLayer(KisImageSP targetImage) { if (!d->referenceImagesLayer) { 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 @@ -420,6 +420,7 @@ usingColor = true; } + setUseCustomColor(usingColor); } 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,6 +42,8 @@ , snapOnlyOneAssistant(true) , firstAssistant(0) , aFirstStroke(false) + , m_globalAssistantsColor(QColor(176, 176, 176, 255)), + m_handleSize(14) {} bool assistantVisible; @@ -50,10 +52,10 @@ 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(); } @@ -479,8 +486,8 @@ { // 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.blue())).append(",") .append(QString::number(color.alpha())); return customColor; 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 @@ -74,12 +74,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(); } @@ -923,11 +924,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 +953,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,6 +307,7 @@ 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()); @@ -314,6 +316,16 @@ } } + + if(e.tagName() == GLOBALASSISTANTSCOLOR) { + if (e.hasAttribute(COLORBYTEDATA)) { + QByteArray colorData = QByteArray::fromBase64(e.attribute(COLORBYTEDATA).toLatin1()); + KoColor color((const quint8*)colorData.data(), image->colorSpace()); + m_d->document->setAssistantsGlobalColor(color.toQColor()); + } + } + + if(e.tagName()== PROOFINGWARNINGCOLOR) { QDomDocument dom; KoXml::asQDomElement(dom, e); @@ -503,6 +515,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 +526,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,16 @@ element.appendChild(e); } +void KisKraSaver::saveAssistantsGlobalColor(QDomDocument& doc, QDomElement& element) +{ + QDomElement e = doc.createElement(GLOBALASSISTANTSCOLOR); + KoColor color = KoColor(m_d->doc->assistantsGlobalColor(), m_d->doc->image()->colorSpace()) ; + + QByteArray colorData = QByteArray::fromRawData((const char*)color.data(), color.colorSpace()->pixelSize()); + e.setAttribute(COLORBYTEDATA, QString(colorData.toBase64())); + element.appendChild(e); +} + void KisKraSaver::saveWarningColor(QDomDocument& doc, QDomElement& element, KisImageSP image) { if (image->proofingConfiguration()) { @@ -328,9 +339,11 @@ 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); @@ -338,6 +351,7 @@ 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,7 @@ const QString ICCPROOFINGPROFILE ="icc-proofing-profile"; const QString CANVASPROJECTIONCOLOR = "ProjectionBackgroundColor"; const QString COLORBYTEDATA = "ColorData"; +const QString GLOBALASSISTANTSCOLOR = "GlobalAssistantsColor"; }