From e85e7d429540978be45387387509767a83247f32 Mon Sep 17 00:00:00 2001 From: Alberto Villa Date: Tue, 16 Jun 2009 03:31:04 +0000 Subject: [PATCH] convert font-size to font-pixel-size in old documents (almost complete) svn path=/trunk/kdenlive/; revision=3545 --- src/documentvalidator.cpp | 49 +++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/src/documentvalidator.cpp b/src/documentvalidator.cpp index fd10011e..5391f7ec 100644 --- a/src/documentvalidator.cpp +++ b/src/documentvalidator.cpp @@ -26,6 +26,7 @@ #include #include +#include #include DocumentValidator::DocumentValidator(QDomDocument doc): @@ -45,7 +46,7 @@ bool DocumentValidator::validate(const double currentVersion) if (!upgrade(kdenlivedocElm.attribute("version").toDouble(), currentVersion)) return false; - /* + /* * Check the syntax (this will be replaced by XSD validation with Qt 4.6) * and correct some errors */ @@ -126,8 +127,10 @@ bool DocumentValidator::upgrade(double version, const double currentVersion) kDebug() << "Opening a document with version " << version; // No conversion needed - if (version == currentVersion) - return true; + if (version == currentVersion) { + if (!m_doc.toString().contains("font-size")) // TODO: remove when currentVersion == 0.84 + return true; + } // The document is too new if (version > currentVersion) { @@ -136,10 +139,6 @@ bool DocumentValidator::upgrade(double version, const double currentVersion) return false; } - // - QDomNode infoXmlNode = m_doc.elementsByTagName("kdenlivedoc").at(0); - QDomElement infoXml = infoXmlNode.toElement(); - // Unsupported document versions if (version == 0.5 || version == 0.7) { kDebug() << "Unable to open document with version " << version; @@ -147,6 +146,10 @@ bool DocumentValidator::upgrade(double version, const double currentVersion) return false; } + // + QDomNode infoXmlNode = m_doc.elementsByTagName("kdenlivedoc").at(0); + QDomElement infoXml = infoXmlNode.toElement(); + if (version <= 0.6) { QDomElement infoXml_old = infoXmlNode.cloneNode(true).toElement(); // Needed for folders QDomNode westley = m_doc.elementsByTagName("westley").at(1); @@ -669,6 +672,38 @@ bool DocumentValidator::upgrade(double version, const double currentVersion) } } + if (version <= 0.83) { + // Replace point size with pixel size in text titles + if (m_doc.toString().contains("font-size")) { + QDomNodeList kproducerNodes = m_doc.elementsByTagName("kdenlive_producer"); + for (int i = 0; i < kproducerNodes.count(); ++i) { + QDomElement kproducer = kproducerNodes.at(i).toElement(); + if (kproducer.attribute("type").toInt() == TEXT) { + QDomDocument data; + data.setContent(kproducer.attribute("xmldata")); + QDomNodeList items = data.firstChild().childNodes(); + for (int j = 0; j < items.count(); ++j) { + if (items.at(j).attributes().namedItem("type").nodeValue() == "QGraphicsTextItem") { + QDomNamedNodeMap textProperties = items.at(j).namedItem("content").attributes(); + if (textProperties.namedItem("font-pixel-size").isNull()) { + QFont font; + font.setPointSize(textProperties.namedItem("font-size").nodeValue().toInt()); + QDomElement content = items.at(j).namedItem("content").toElement(); + content.setAttribute("font-pixel-size", QFontInfo(font).pixelSize()); + content.removeAttribute("font-size"); + kproducer.setAttribute("xmldata", data.toString()); + QString resource = kproducer.attribute("resource"); + if (QFile::exists(resource)) { + // TODO: delete the preview file + } + } + } + } + } + } + } + } + // The document has been converted: mark it as modified infoXml.setAttribute("version", currentVersion); m_modified = true; -- 2.39.2