-bool TitleDocument::loadDocument(const KUrl& url ,QGraphicsPolygonItem* startv, QGraphicsPolygonItem* endv) {
- QString tmpfile;
- QDomDocument doc;
- double aspect_ratio=4.0/3.0;
- if (!scene)
- return false;
-
- if (KIO::NetAccess::download(url, tmpfile, 0)) {
- QFile file(tmpfile);
- if (file.open(QIODevice::ReadOnly)) {
- doc.setContent(&file, false);
- file.close();
- }else
- return false;
- KIO::NetAccess::removeTempFile(tmpfile);
- QDomNodeList titles=doc.elementsByTagName("kdenlivetitle");
- if (titles.size()){
-
- QDomNodeList items=titles.item(0).childNodes();
- for(int i=0;i<items.count();i++){
- QGraphicsItem *gitem=NULL;
- kDebug() << items.item(i).attributes().namedItem("type").nodeValue();
- if (items.item(i).attributes().namedItem("type").nodeValue()=="QGraphicsTextItem"){
- QGraphicsTextItem *txt=scene->addText("");
- txt->setHtml(items.item(i).namedItem("content").firstChild().nodeValue());
- gitem=txt;
- }else
- if (items.item(i).attributes().namedItem("type").nodeValue()=="QGraphicsRectItem"){
- QString rect=items.item(i).namedItem("content").attributes().namedItem("rect").nodeValue();
- QString br_str=items.item(i).namedItem("content").attributes().namedItem("brushcolor").nodeValue();
- QString pen_str=items.item(i).namedItem("content").attributes().namedItem("pencolor").nodeValue();
- double penwidth=items.item(i).namedItem("content").attributes().namedItem("penwidth").nodeValue().toDouble();
- QGraphicsRectItem *rec=scene->addRect(stringToRect(rect),QPen(QBrush(stringToColor(pen_str)),penwidth),QBrush(stringToColor(br_str) ) );
- gitem=rec;
- }
- //pos and transform
- if (gitem ){
- QPointF p(items.item(i).namedItem("position").attributes().namedItem("x").nodeValue().toDouble(),
- items.item(i).namedItem("position").attributes().namedItem("y").nodeValue().toDouble());
- gitem->setPos(p);
- gitem->setTransform(stringToTransform(items.item(i).namedItem("position").firstChild().firstChild().nodeValue()));
- }
- if (items.item(i).nodeName()=="background"){
- kDebug() << items.item(i).attributes().namedItem("color").nodeValue();
- scene->setBackgroundBrush(QBrush(stringToColor(items.item(i).attributes().namedItem("color").nodeValue())));
- }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);
- }
-
- }
-
-
- }
-
-
- }
- return true;
+int TitleDocument::loadFromXml(QDomDocument doc, QGraphicsRectItem* startv, QGraphicsRectItem* endv, int *out)
+{
+ 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;
+ }
+ }
+ //TODO: get default title duration instead of hardcoded one
+ if (doc.documentElement().hasAttribute("out"))
+ *out = doc.documentElement().attribute("out").toInt();
+ else
+ *out = 125;
+
+ int maxZValue = 0;
+ if (titles.size()) {
+
+ QDomNodeList items = titles.item(0).childNodes();
+ 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 (zValue > -1000) {
+ if (items.item(i).attributes().namedItem("type").nodeValue() == "QGraphicsTextItem") {
+ QDomNamedNodeMap txtProperties = items.item(i).namedItem("content").attributes();
+ QFont font(txtProperties.namedItem("font").nodeValue());
+
+ 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());
+ QColor col(stringToColor(txtProperties.namedItem("font-color").nodeValue()));
+ QGraphicsTextItem *txt = m_scene->addText(items.item(i).namedItem("content").firstChild().nodeValue(), font);
+ QTextCursor cursor(txt->document());
+ cursor.select(QTextCursor::Document);
+ QTextCharFormat format;
+ if (txtProperties.namedItem("font-outline").nodeValue().toDouble() > 0.0) {
+ txt->setData(101, txtProperties.namedItem("font-outline").nodeValue().toDouble());
+ txt->setData(102, stringToColor(txtProperties.namedItem("font-outline-color").nodeValue()));
+ format.setTextOutline(
+ QPen(QColor(stringToColor(txtProperties.namedItem("font-outline-color").nodeValue())),
+ txtProperties.namedItem("font-outline").nodeValue().toDouble(),
+ Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)
+ );
+
+ }
+ format.setForeground(QBrush(col));
+ cursor.mergeCharFormat(format);
+ txt->setTextInteractionFlags(Qt::NoTextInteraction);
+ if (txtProperties.namedItem("alignment").isNull() == false) {
+ txt->setTextWidth(txt->boundingRect().width());
+ QTextCursor cur = txt->textCursor();
+ QTextBlockFormat format = cur.blockFormat();
+ format.setAlignment((Qt::Alignment) txtProperties.namedItem("alignment").nodeValue().toInt());
+ cur.select(QTextCursor::Document);
+ cur.setBlockFormat(format);
+ txt->setTextCursor(cur);
+ cur.clearSelection();
+ 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());
+ }
+
+ // Effects
+ if (!txtProperties.namedItem("typewriter").isNull()) {
+ QStringList effData = QStringList() << "typewriter" << txtProperties.namedItem("typewriter").nodeValue();
+ txt->setData(100, effData);
+ }
+
+ gitem = txt;
+ } else if (items.item(i).attributes().namedItem("type").nodeValue() == "QGraphicsRectItem") {
+ QString rect = items.item(i).namedItem("content").attributes().namedItem("rect").nodeValue();
+ QString br_str = items.item(i).namedItem("content").attributes().namedItem("brushcolor").nodeValue();
+ QString pen_str = items.item(i).namedItem("content").attributes().namedItem("pencolor").nodeValue();
+ double penwidth = items.item(i).namedItem("content").attributes().namedItem("penwidth").nodeValue().toDouble();
+ QGraphicsRectItem *rec = m_scene->addRect(stringToRect(rect), QPen(QBrush(stringToColor(pen_str)), penwidth, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin), QBrush(stringToColor(br_str)));
+ gitem = rec;
+ } else if (items.item(i).attributes().namedItem("type").nodeValue() == "QGraphicsPixmapItem") {
+ QString url = items.item(i).namedItem("content").attributes().namedItem("url").nodeValue();
+ QPixmap pix(url);
+ QGraphicsPixmapItem *rec = m_scene->addPixmap(pix);
+ rec->setData(Qt::UserRole, url);
+ gitem = rec;
+ } else if (items.item(i).attributes().namedItem("type").nodeValue() == "QGraphicsSvgItem") {
+ QString url = items.item(i).namedItem("content").attributes().namedItem("url").nodeValue();
+ QGraphicsSvgItem *rec = new QGraphicsSvgItem(url);
+ m_scene->addItem(rec);
+ rec->setData(Qt::UserRole, url);
+ gitem = rec;
+ }
+ }
+ //pos and transform
+ if (gitem) {
+ QPointF p(items.item(i).namedItem("position").attributes().namedItem("x").nodeValue().toDouble(),
+ items.item(i).namedItem("position").attributes().namedItem("y").nodeValue().toDouble());
+ gitem->setPos(p);
+ QDomElement trans = items.item(i).namedItem("position").firstChild().toElement();
+ gitem->setTransform(stringToTransform(trans.firstChild().nodeValue()));
+ QString rotate = trans.attribute("rotation");
+ if (!rotate.isEmpty()) gitem->setData(ROTATEFACTOR, stringToList(rotate));
+ QString zoom = trans.attribute("zoom");
+ if (!zoom.isEmpty()) gitem->setData(ZOOMFACTOR, zoom.toInt());
+ int zValue = items.item(i).attributes().namedItem("z-index").nodeValue().toInt();
+ if (zValue > maxZValue) maxZValue = zValue;
+ gitem->setZValue(zValue);
+ gitem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
+
+#if QT_VERSION >= 0x040600
+ // effects
+ QDomNode eff = items.item(i).namedItem("effect");
+ if (!eff.isNull()) {
+ QDomElement e = eff.toElement();
+ if (e.attribute("type") == "blur") {
+ QGraphicsBlurEffect *blur = new QGraphicsBlurEffect();
+ blur->setBlurRadius(e.attribute("blurradius").toInt());
+ gitem->setGraphicsEffect(blur);
+ } else if (e.attribute("type") == "shadow") {
+ QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect();
+ shadow->setBlurRadius(e.attribute("blurradius").toInt());
+ shadow->setOffset(e.attribute("xoffset").toInt(), e.attribute("yoffset").toInt());
+ gitem->setGraphicsEffect(shadow);
+ }
+ }
+#endif
+ }
+
+ if (items.item(i).nodeName() == "background") {
+ kDebug() << items.item(i).attributes().namedItem("color").nodeValue();
+ QColor color = QColor(stringToColor(items.item(i).attributes().namedItem("color").nodeValue()));
+ //color.setAlpha(items.item(i).attributes().namedItem("alpha").nodeValue().toInt());
+ QList<QGraphicsItem *> items = m_scene->items();
+ for (int i = 0; i < items.size(); i++) {
+ if (items.at(i)->zValue() == -1100) {
+ ((QGraphicsRectItem *)items.at(i))->setBrush(QBrush(color));
+ break;
+ }
+ }
+ } 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;