From: Jean-Baptiste Mardelle Date: Wed, 25 Mar 2009 23:45:12 +0000 (+0000) Subject: Use pixel size for titles font instead of point size (hope it doesn't mess up existin... X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=660f9a62a5a4aa983903a9caa01f5d952582fe41;p=kdenlive Use pixel size for titles font instead of point size (hope it doesn't mess up existing titles): http://www.kdenlive.org:80/mantis/view.php?id=732 svn path=/trunk/kdenlive/; revision=3185 --- diff --git a/src/titledocument.cpp b/src/titledocument.cpp index da81c62b..1f02b7e3 100644 --- a/src/titledocument.cpp +++ b/src/titledocument.cpp @@ -14,17 +14,22 @@ * (at your option) any later version. * * * ***************************************************************************/ + #include "titledocument.h" + +#include +#include +#include + #include #include #include #include #include #include -#include +#include #include -#include -#include + TitleDocument::TitleDocument() { scene = NULL; @@ -65,12 +70,14 @@ QDomDocument TitleDocument::xml(QGraphicsPolygonItem* startv, QGraphicsPolygonIt case 8: e.setAttribute("type", "QGraphicsTextItem"); t = static_cast(item); + // Don't save empty text nodes + if (t->toPlainText().simplified().isEmpty()) continue; //content.appendChild(doc.createTextNode(((QGraphicsTextItem*)item)->toHtml())); content.appendChild(doc.createTextNode(t->toPlainText())); font = t->font(); content.setAttribute("font", font.family()); content.setAttribute("font-bold", font.bold()); - content.setAttribute("font-size", font.pointSize()); + 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())); @@ -183,12 +190,19 @@ int TitleDocument::loadFromXml(QDomDocument doc, QGraphicsPolygonItem* /*startv* int zValue = items.item(i).attributes().namedItem("z-index").nodeValue().toInt(); if (zValue > -1000) if (items.item(i).attributes().namedItem("type").nodeValue() == "QGraphicsTextItem") { - QFont font(items.item(i).namedItem("content").attributes().namedItem("font").nodeValue()); - font.setBold(items.item(i).namedItem("content").attributes().namedItem("font-bold").nodeValue().toInt()); - font.setItalic(items.item(i).namedItem("content").attributes().namedItem("font-italic").nodeValue().toInt()); - font.setUnderline(items.item(i).namedItem("content").attributes().namedItem("font-underline").nodeValue().toInt()); - font.setPointSize(items.item(i).namedItem("content").attributes().namedItem("font-size").nodeValue().toInt()); - QColor col(stringToColor(items.item(i).namedItem("content").attributes().namedItem("font-color").nodeValue())); + QDomNamedNodeMap txtProperties = items.item(i).namedItem("content").attributes(); + QFont font(txtProperties.namedItem("font").nodeValue()); + 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()) { + 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 = scene->addText(items.item(i).namedItem("content").firstChild().nodeValue(), font); txt->setDefaultTextColor(col); txt->setTextInteractionFlags(Qt::NoTextInteraction); diff --git a/src/titlewidget.cpp b/src/titlewidget.cpp index 4612961b..1505adb8 100644 --- a/src/titlewidget.cpp +++ b/src/titlewidget.cpp @@ -374,7 +374,7 @@ void TitleWidget::slotNewRect(QGraphicsRectItem * rect) { void TitleWidget::slotNewText(QGraphicsTextItem *tt) { QFont font = font_family->currentFont(); - font.setPointSize(font_size->value()); + font.setPixelSize(font_size->value()); // mbd: issue 551: font.setBold(buttonBold->isChecked()); font.setItalic(buttonItalic->isChecked()); @@ -428,7 +428,7 @@ void TitleWidget::selectionChanged() { QFont font = i->font(); font_family->setCurrentFont(font); - font_size->setValue(font.pointSize()); + font_size->setValue(font.pixelSize()); buttonBold->setChecked(font.bold()); buttonItalic->setChecked(font.italic()); buttonUnder->setChecked(font.underline()); @@ -523,7 +523,7 @@ void TitleWidget::textChanged() { void TitleWidget::slotUpdateText() { QFont font = font_family->currentFont(); - font.setPointSize(font_size->value()); + font.setPixelSize(font_size->value()); font.setBold(buttonBold->isChecked()); font.setItalic(buttonItalic->isChecked()); font.setUnderline(buttonUnder->isChecked()); @@ -721,7 +721,8 @@ void TitleWidget::writeChoices() { KConfigGroup titleConfig(config, "TitleWidget"); // Write the entries titleConfig.writeEntry("font_family", font_family->currentFont()); - titleConfig.writeEntry("font_size", font_size->value()); + //titleConfig.writeEntry("font_size", font_size->value()); + titleConfig.writeEntry("font_pixel_size", font_size->value()); titleConfig.writeEntry("font_color", fontColorButton->color()); titleConfig.writeEntry("font_alpha", textAlpha->value()); titleConfig.writeEntry("font_bold", buttonBold->isChecked()); @@ -748,7 +749,7 @@ void TitleWidget::readChoices() { KConfigGroup titleConfig(config, "TitleWidget"); // read the entries font_family->setCurrentFont(titleConfig.readEntry("font_family", font_family->currentFont())); - font_size->setValue(titleConfig.readEntry("font_size", font_size->value())); + font_size->setValue(titleConfig.readEntry("font_pixel_size", font_size->value())); fontColorButton->setColor(titleConfig.readEntry("font_color", fontColorButton->color())); textAlpha->setValue(titleConfig.readEntry("font_alpha", textAlpha->value())); buttonBold->setChecked(titleConfig.readEntry("font_bold", buttonBold->isChecked()));