#include <KDebug>
#include <KTemporaryFile>
#include <kio/netaccess.h>
+#include <KApplication>
+#include <KLocale>
+#include <KMessageBox>
#include <QGraphicsScene>
#include <QDomElement>
m_scene = NULL;
}
-void TitleDocument::setScene(QGraphicsScene* _scene)
+void TitleDocument::setScene(QGraphicsScene* _scene, int width, int height)
{
m_scene = _scene;
+ m_width = width;
+ m_height = height;
}
-QDomDocument TitleDocument::xml(QGraphicsPolygonItem* startv, QGraphicsPolygonItem* endv)
+QDomDocument TitleDocument::xml(QGraphicsRectItem* startv, QGraphicsRectItem* endv)
{
QDomDocument doc;
QDomElement main = doc.createElement("kdenlivetitle");
+ main.setAttribute("width", m_width);
+ main.setAttribute("height", m_height);
doc.appendChild(main);
foreach(QGraphicsItem* item, m_scene->items()) {
content.appendChild(doc.createTextNode(t->toPlainText()));
font = t->font();
content.setAttribute("font", font.family());
- content.setAttribute("font-bold", font.bold());
+ content.setAttribute("font-weight", font.weight());
content.setAttribute("font-pixel-size", font.pixelSize());
content.setAttribute("font-italic", font.italic());
content.setAttribute("font-underline", font.underline());
content.setAttribute("font-color", colorToString(t->defaultTextColor()));
+
+ // Only save when necessary.
+ if (t->data(OriginXLeft).toInt() == AxisInverted) {
+ content.setAttribute("kdenlive-axis-x-inverted", t->data(OriginXLeft).toInt());
+ }
+ if (t->data(OriginYTop).toInt() == AxisInverted) {
+ content.setAttribute("kdenlive-axis-y-inverted", t->data(OriginYTop).toInt());
+ }
if (t->textWidth() != -1) {
content.setAttribute("alignment", t->textCursor().blockFormat().alignment());
}
e.appendChild(pos);
e.appendChild(content);
- if (item->zValue() > -1100) main.appendChild(e);
+ if (item->zValue() > -1000) main.appendChild(e);
}
if (startv && endv) {
QDomElement endp = doc.createElement("endviewport");
QDomElement startp = doc.createElement("startviewport");
- endp.setAttribute("x", endv->pos().x());
- endp.setAttribute("y", endv->pos().y());
- endp.setAttribute("size", endv->sceneBoundingRect().width() / 2);
-
- startp.setAttribute("x", startv->pos().x());
- startp.setAttribute("y", startv->pos().y());
- startp.setAttribute("size", startv->sceneBoundingRect().width() / 2);
+ QRectF r(endv->pos().x(), endv->pos().y(), endv->rect().width(), endv->rect().height());
+ endp.setAttribute("rect", rectFToString(r));
+ QRectF r2(startv->pos().x(), startv->pos().y(), startv->rect().width(), startv->rect().height());
+ startp.setAttribute("rect", rectFToString(r2));
- startp.setAttribute("z-index", startv->zValue());
- endp.setAttribute("z-index", endv->zValue());
main.appendChild(startp);
main.appendChild(endp);
}
}
-bool TitleDocument::saveDocument(const KUrl& url, QGraphicsPolygonItem* startv, QGraphicsPolygonItem* endv)
+bool TitleDocument::saveDocument(const KUrl& url, QGraphicsRectItem* startv, QGraphicsRectItem* endv, int out)
{
if (!m_scene)
return false;
QDomDocument doc = xml(startv, endv);
+ doc.documentElement().setAttribute("out", out);
KTemporaryFile tmpfile;
if (!tmpfile.open()) {
kWarning() << "///// CANNOT CREATE TMP FILE in: " << tmpfile.fileName();
return KIO::NetAccess::upload(tmpfile.fileName(), url, 0);
}
-int TitleDocument::loadDocument(const KUrl& url, QGraphicsPolygonItem* startv, QGraphicsPolygonItem* endv)
+int TitleDocument::loadFromXml(QDomDocument doc, QGraphicsRectItem* startv, QGraphicsRectItem* endv, int *out)
{
- QString tmpfile;
- QDomDocument doc;
- if (!m_scene)
- return -1;
-
- if (KIO::NetAccess::download(url, tmpfile, 0)) {
- QFile file(tmpfile);
- if (file.open(QIODevice::ReadOnly)) {
- doc.setContent(&file, false);
- file.close();
- } else
- return -1;
- KIO::NetAccess::removeTempFile(tmpfile);
- return loadFromXml(doc, startv, endv);
+ QDomNodeList titles = doc.elementsByTagName("kdenlivetitle");
+ //TODO: Check if the opened title size is equal to project size, otherwise warn user and rescale
+ if (doc.documentElement().hasAttribute("width") && doc.documentElement().hasAttribute("height")) {
+ int doc_width = doc.documentElement().attribute("width").toInt();
+ int doc_height = doc.documentElement().attribute("height").toInt();
+ if (doc_width != m_width || doc_height != m_height) {
+ KMessageBox::information(kapp->activeWindow(), i18n("This title clip was created with a different frame size."), i18n("Title Profile"));
+ //TODO: convert using QTransform
+ m_width = doc_width;
+ m_height = doc_height;
+ }
}
- return -1;
-}
+ //TODO: get default title duration instead of hardcoded one
+ if (doc.documentElement().hasAttribute("out"))
+ *out = doc.documentElement().attribute("out").toInt();
+ else
+ *out = 125;
-int TitleDocument::loadFromXml(QDomDocument doc, QGraphicsPolygonItem* /*startv*/, QGraphicsPolygonItem* /*endv*/)
-{
- QDomNodeList titles = doc.elementsByTagName("kdenlivetitle");
int maxZValue = 0;
if (titles.size()) {
QDomNodeList items = titles.item(0).childNodes();
- for (int i = 0;i < items.count();i++) {
+ for (int i = 0; i < items.count(); i++) {
QGraphicsItem *gitem = NULL;
kDebug() << items.item(i).attributes().namedItem("type").nodeValue();
int zValue = items.item(i).attributes().namedItem("z-index").nodeValue().toInt();
if (items.item(i).attributes().namedItem("type").nodeValue() == "QGraphicsTextItem") {
QDomNamedNodeMap txtProperties = items.item(i).namedItem("content").attributes();
QFont font(txtProperties.namedItem("font").nodeValue());
- font.setBold(txtProperties.namedItem("font-bold").nodeValue().toInt());
+
+ QDomNode node = txtProperties.namedItem("font-bold");
+ if (!node.isNull()) {
+ // Old: Bold/Not bold.
+ font.setBold(node.nodeValue().toInt());
+ } else {
+ // New: Font weight (QFont::)
+ font.setWeight(txtProperties.namedItem("font-weight").nodeValue().toInt());
+ }
+ //font.setBold(txtProperties.namedItem("font-bold").nodeValue().toInt());
font.setItalic(txtProperties.namedItem("font-italic").nodeValue().toInt());
font.setUnderline(txtProperties.namedItem("font-underline").nodeValue().toInt());
// Older Kdenlive version did not store pixel size but point size
if (txtProperties.namedItem("font-pixel-size").isNull()) {
+ KMessageBox::information(kapp->activeWindow(), i18n("Some of your text clips were saved with size in points, which means different sizes on different displays. They will be converted to pixel size, making them portable, but you could have to adjust their size."), i18n("Text Clips Updated"));
QFont f2;
f2.setPointSize(txtProperties.namedItem("font-size").nodeValue().toInt());
font.setPixelSize(QFontInfo(f2).pixelSize());
- } else font.setPixelSize(txtProperties.namedItem("font-pixel-size").nodeValue().toInt());
+ } else
+ font.setPixelSize(txtProperties.namedItem("font-pixel-size").nodeValue().toInt());
QColor col(stringToColor(txtProperties.namedItem("font-color").nodeValue()));
QGraphicsTextItem *txt = m_scene->addText(items.item(i).namedItem("content").firstChild().nodeValue(), font);
txt->setDefaultTextColor(col);
txt->setTextCursor(cur);
}
+ if (!txtProperties.namedItem("kdenlive-axis-x-inverted").isNull()) {
+ txt->setData(OriginXLeft, txtProperties.namedItem("kdenlive-axis-x-inverted").nodeValue().toInt());
+ }
+ if (!txtProperties.namedItem("kdenlive-axis-y-inverted").isNull()) {
+ txt->setData(OriginYTop, txtProperties.namedItem("kdenlive-axis-y-inverted").nodeValue().toInt());
+ }
+
gitem = txt;
} else if (items.item(i).attributes().namedItem("type").nodeValue() == "QGraphicsRectItem") {
QString rect = items.item(i).namedItem("content").attributes().namedItem("rect").nodeValue();
break;
}
}
- } /*else if (items.item(i).nodeName() == "startviewport" && startv) {
- QPointF p(items.item(i).attributes().namedItem("x").nodeValue().toDouble(), items.item(i).attributes().namedItem("y").nodeValue().toDouble());
- double width = items.item(i).attributes().namedItem("size").nodeValue().toDouble();
- QRectF rect(-width, -width / aspect_ratio, width*2.0, width / aspect_ratio*2.0);
- kDebug() << width << rect;
- startv->setPolygon(rect);
- startv->setPos(p);
- } else if (items.item(i).nodeName() == "endviewport" && endv) {
- QPointF p(items.item(i).attributes().namedItem("x").nodeValue().toDouble(), items.item(i).attributes().namedItem("y").nodeValue().toDouble());
- double width = items.item(i).attributes().namedItem("size").nodeValue().toDouble();
- QRectF rect(-width, -width / aspect_ratio, width*2.0, width / aspect_ratio*2.0);
- kDebug() << width << rect;
- endv->setPolygon(rect);
- endv->setPos(p);
- }*/
+ } else if (items.item(i).nodeName() == "startviewport" && startv) {
+ QString rect = items.item(i).attributes().namedItem("rect").nodeValue();
+ QRectF r = stringToRect(rect);
+ startv->setRect(0, 0, r.width(), r.height());
+ startv->setPos(r.topLeft());
+ } else if (items.item(i).nodeName() == "endviewport" && endv) {
+ QString rect = items.item(i).attributes().namedItem("rect").nodeValue();
+ QRectF r = stringToRect(rect);
+ endv->setRect(0, 0, r.width(), r.height());
+ endv->setPos(r.topLeft());
+ }
}
}
return maxZValue;
QString TitleDocument::rectFToString(const QRectF& c)
{
QString ret = "%1,%2,%3,%4";
- ret = ret.arg(c.top()).arg(c.left()).arg(c.width()).arg(c.height());
+ ret = ret.arg(c.left()).arg(c.top()).arg(c.width()).arg(c.height());
return ret;
}
l.at(6).toDouble(), l.at(7).toDouble(), l.at(8).toDouble()
);
}
+
+int TitleDocument::frameWidth() const
+{
+ return m_width;
+}
+
+int TitleDocument::frameHeight() const
+{
+ return m_height;
+}
+
+