Now we can use PNG, JPG, JPEG and BMP images
--HG-- branch : feature
This commit is contained in:
parent
2efe06f444
commit
1d959cb747
|
@ -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))
|
||||
|
|
|
@ -5,7 +5,15 @@
|
|||
<xs:complexType>
|
||||
<xs:sequence minOccurs="1" maxOccurs="unbounded">
|
||||
<xs:element name="version" type="formatVersion"></xs:element>
|
||||
<xs:element name="image" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element>
|
||||
<xs:element name="image" minOccurs="0" maxOccurs="1">
|
||||
<xs:complexType>
|
||||
<xs:simpleContent>
|
||||
<xs:extension base="xs:string">
|
||||
<xs:attribute name="extension" type="xs:string"></xs:attribute>
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="unit" type="units"></xs:element>
|
||||
<xs:element name="author" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element>
|
||||
<xs:element name="description" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user