diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index 84d1e4a94..50ecacea1 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -619,7 +619,12 @@ void DialogPatternProperties::InitImage() QByteArray ba = QByteArray::fromBase64(byteArray); QBuffer buffer(&ba); buffer.open(QIODevice::ReadOnly); - image.load(&buffer, "PNG"); // writes image into ba in PNG format + QString extension = doc->GetImageExtension(); + if (extension.isEmpty()) + { + extension = "PNG"; + } + image.load(&buffer, extension.toLatin1().data()); // writes image into ba in PNG format ui->imageLabel->setPixmap(QPixmap::fromImage(image)); ui->imageLabel->setContextMenuPolicy(Qt::CustomContextMenu); @@ -641,7 +646,8 @@ void DialogPatternProperties::InitImage() //--------------------------------------------------------------------------------------------------------------------- void DialogPatternProperties::SetNewImage() { - const QString fileName = QFileDialog::getOpenFileName(this, tr("Image for pattern"), QString(), tr("Images (*.png)")); + const QString fileName = QFileDialog::getOpenFileName(this, tr("Image for pattern"), QString(), + tr("Images (*.png *.jpg *.jpeg *.bmp)")); QImage image; if (fileName.isEmpty()) { @@ -654,15 +660,24 @@ void DialogPatternProperties::SetNewImage() return; } ui->imageLabel->setPixmap(QPixmap::fromImage(image)); + QFileInfo f(fileName); + QString extension = f.suffix().toUpper(); - QByteArray byteArray; - QBuffer buffer(&byteArray); - buffer.open(QIODevice::WriteOnly); - image.save(&buffer, "PNG"); // writes the image in PNG format inside the buffer - QString iconBase64 = QString::fromLatin1(byteArray.toBase64().data()); + if (extension == "JPEG") + { + extension = "JPG"; + } + if (extension == "PNG" || extension == "JPG" || extension == "BMP") + { + QByteArray byteArray; + QBuffer buffer(&byteArray); + buffer.open(QIODevice::WriteOnly); + image.save(&buffer, extension.toLatin1().data()); // writes the image in 'extension' format inside the buffer + QString iconBase64 = QString::fromLatin1(byteArray.toBase64().data()); - // save our image to file.val - doc->SetImage(iconBase64); + // save our image to file.val + doc->SetImage(iconBase64, extension); + } } } @@ -680,7 +695,7 @@ void DialogPatternProperties::SaveImage() byteArray.append(doc->GetImage().toUtf8()); QByteArray ba = QByteArray::fromBase64(byteArray); - QString extension = ".PNG"; + QString extension = "." + doc->GetImageExtension(); QString filename = QFileDialog::getSaveFileName(this, tr("Save File")); QFile file(filename + extension); if (file.open(QIODevice::WriteOnly)) diff --git a/src/libs/ifc/schema/pattern/v0.2.7.xsd b/src/libs/ifc/schema/pattern/v0.2.7.xsd index 807f16b77..f7e6a556e 100644 --- a/src/libs/ifc/schema/pattern/v0.2.7.xsd +++ b/src/libs/ifc/schema/pattern/v0.2.7.xsd @@ -5,7 +5,15 @@ - + + + + + + + + + diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 424d4dd9f..5e38b33b7 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -924,10 +924,48 @@ QString VAbstractPattern::GetImage() const } //--------------------------------------------------------------------------------------------------------------------- -void VAbstractPattern::SetImage(const QString &text) +QString VAbstractPattern::GetImageExtension() const +{ + const QString defExt = "PNG"; + const QDomNodeList nodeList = this->elementsByTagName(TagImage); + if (nodeList.isEmpty()) + { + return defExt; + } + else + { + const QDomNode domNode = nodeList.at(0); + if (domNode.isNull() == false && domNode.isElement()) + { + const QDomElement domElement = domNode.toElement(); + if (domElement.isNull() == false) + { + const QString ext = domElement.attribute(QString("extension"), ""); + if (ext.isEmpty()) + { + return defExt; + } + else + { + return ext; + } + } + } + } + return defExt; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractPattern::SetImage(const QString &text, const QString &extension) { CheckTagExists(TagImage); setTagText(TagImage, text); + QDomNodeList list = elementsByTagName(TagImage); + for (int i=0; i < list.size(); ++i) + { + QDomElement dom = list.at(i).toElement(); + dom.setAttribute(QString("extension"), extension); + } modified = true; emit patternChanged(false); } diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index 6cb575803..aeb0a9d97 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -107,7 +107,8 @@ public: void SetNotes(const QString &text); QString GetImage() const; - void SetImage(const QString &text); + QString GetImageExtension() const; + void SetImage(const QString &text, const QString &extension); void DeleteImage(); QString GetVersion() const;