]> git.sesse.net Git - kdenlive/commitdiff
Titler:
authorSimon A. Eugster <simon.eu@gmail.com>
Thu, 23 Jul 2009 23:14:03 +0000 (23:14 +0000)
committerSimon A. Eugster <simon.eu@gmail.com>
Thu, 23 Jul 2009 23:14:03 +0000 (23:14 +0000)
* Bug fixed: When text was selected and then a title file loaded kdenlive crashed with a SEGFAULT or so
* Fixed: Not using bold on/off anymore but font weight (QFont::Light to QFont::Black, depending on the support provided by the selected font). <http://www.kdenlive.org/mantis/view.php?id=909>

svn path=/trunk/kdenlive/; revision=3761

src/titledocument.cpp
src/titlewidget.cpp
src/titlewidget.h
src/widgets/titlewidget_ui.ui

index 73b57b0da2007f61aacd78f813940c9f5536c256..959aac69ee887db2e63b29627f3e11d296c2337b 100644 (file)
@@ -83,7 +83,7 @@ QDomDocument TitleDocument::xml(QGraphicsPolygonItem* startv, QGraphicsPolygonIt
             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());
@@ -222,7 +222,16 @@ int TitleDocument::loadFromXml(QDomDocument doc, QGraphicsPolygonItem* startv, Q
                 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
index 72c5ff984193502648876a6fc0954790bc61ba92..059fba829704966d71abbccd0142de212c2cf192 100644 (file)
@@ -69,6 +69,7 @@ TitleWidget::TitleWidget(KUrl url, QString projectTitlePath, Render *render, QWi
     connect(font_family, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(slotUpdateText())) ;
     connect(font_size, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText())) ;
     connect(textAlpha, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText()));
+    connect(font_weight_box, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateText()));
 
     connect(rectFAlpha, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
     connect(rectBAlpha, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
@@ -105,7 +106,6 @@ TitleWidget::TitleWidget(KUrl url, QString projectTitlePath, Render *render, QWi
     connect(value_h, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
     connect(buttonFitZoom, SIGNAL(clicked()), this, SLOT(slotAdjustZoom()));
     connect(buttonRealSize, SIGNAL(clicked()), this, SLOT(slotZoomOneToOne()));
-    connect(buttonBold, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
     connect(buttonItalic, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
     connect(buttonUnder, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
     connect(buttonAlignLeft, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
@@ -120,9 +120,18 @@ TitleWidget::TitleWidget(KUrl url, QString projectTitlePath, Render *render, QWi
     // mbd
     connect(this, SIGNAL(accepted()), this, SLOT(slotAccepted()));
 
+    font_weight_box->blockSignals(true);
+    font_weight_box->addItem(i18nc("Font style", "Light"), QFont::Light);
+    font_weight_box->addItem(i18nc("Font style", "Normal"), QFont::Normal);
+    font_weight_box->addItem(i18nc("Font style", "Demi-Bold"), QFont::DemiBold);
+    font_weight_box->addItem(i18nc("Font style", "Bold"), QFont::Bold);
+    font_weight_box->addItem(i18nc("Font style", "Black"), QFont::Black);
+    font_weight_box->setToolTip(i18n("Font weight"));
+    font_weight_box->setCurrentIndex(1);
+    font_weight_box->blockSignals(false);
+
     buttonFitZoom->setIcon(KIcon("zoom-fit-best"));
     buttonRealSize->setIcon(KIcon("zoom-original"));
-    buttonBold->setIcon(KIcon("format-text-bold"));
     buttonItalic->setIcon(KIcon("format-text-italic"));
     buttonUnder->setIcon(KIcon("format-text-underline"));
     buttonAlignCenter->setIcon(KIcon("format-justify-center"));
@@ -584,7 +593,7 @@ void TitleWidget::slotNewText(QGraphicsTextItem *tt)
     QFont font = font_family->currentFont();
     font.setPixelSize(font_size->value());
     // mbd: issue 551:
-    font.setBold(buttonBold->isChecked());
+    font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
     font.setItalic(buttonItalic->isChecked());
     font.setUnderline(buttonUnder->isChecked());
 
@@ -596,6 +605,15 @@ void TitleWidget::slotNewText(QGraphicsTextItem *tt)
     setCurrentItem(tt);
 }
 
+void TitleWidget::setFontBoxWeight(int weight)
+{
+    int index = font_weight_box->findData(weight);
+    if (index < 0) {
+        index = font_weight_box->findData(QFont::Normal);
+    }
+    font_weight_box->setCurrentIndex(index);
+}
+
 void TitleWidget::setCurrentItem(QGraphicsItem *item)
 {
     m_scene->setSelectedItem(item);
@@ -642,7 +660,7 @@ void TitleWidget::selectionChanged()
             //toolBox->setItemEnabled(2, true);
             font_size->blockSignals(true);
             font_family->blockSignals(true);
-            buttonBold->blockSignals(true);
+            font_weight_box->blockSignals(true);
             buttonItalic->blockSignals(true);
             buttonUnder->blockSignals(true);
             fontColorButton->blockSignals(true);
@@ -655,9 +673,9 @@ void TitleWidget::selectionChanged()
             QFont font = i->font();
             font_family->setCurrentFont(font);
             font_size->setValue(font.pixelSize());
-            buttonBold->setChecked(font.bold());
             buttonItalic->setChecked(font.italic());
             buttonUnder->setChecked(font.underline());
+            setFontBoxWeight(font.weight());
 
             QColor color = i->defaultTextColor();
             fontColorButton->setColor(color);
@@ -672,7 +690,7 @@ void TitleWidget::selectionChanged()
 
             font_size->blockSignals(false);
             font_family->blockSignals(false);
-            buttonBold->blockSignals(false);
+            font_weight_box->blockSignals(false);
             buttonItalic->blockSignals(false);
             buttonUnder->blockSignals(false);
             fontColorButton->blockSignals(false);
@@ -1136,9 +1154,9 @@ void TitleWidget::slotUpdateText()
 {
     QFont font = font_family->currentFont();
     font.setPixelSize(font_size->value());
-    font.setBold(buttonBold->isChecked());
     font.setItalic(buttonItalic->isChecked());
     font.setUnderline(buttonUnder->isChecked());
+    font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
     QColor color = fontColorButton->color();
     color.setAlpha(textAlpha->value());
 
@@ -1282,6 +1300,7 @@ void TitleWidget::loadTitle()
         for (int i = 0; i < items.size(); i++) {
             if (items.at(i)->zValue() > -1000) delete items.at(i);
         }
+        m_scene->clearTextSelection();
         m_count = m_titledocument.loadDocument(url, m_startViewport, m_endViewport) + 1;
         insertingValues = true;
         startViewportX->setValue(m_startViewport->data(0).toInt());
@@ -1408,7 +1427,7 @@ void TitleWidget::writeChoices()
     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());
+    titleConfig.writeEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
     titleConfig.writeEntry("font_italic", buttonItalic->isChecked());
     titleConfig.writeEntry("font_underlined", buttonUnder->isChecked());
 
@@ -1439,7 +1458,10 @@ void TitleWidget::readChoices()
     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()));
+    int weight;
+    if (titleConfig.readEntry("font_bold", false)) weight = QFont::Bold;
+    else weight = titleConfig.readEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
+    setFontBoxWeight(weight);
     buttonItalic->setChecked(titleConfig.readEntry("font_italic", buttonItalic->isChecked()));
     buttonUnder->setChecked(titleConfig.readEntry("font_underlined", buttonUnder->isChecked()));
 
index ecbc887612572d5312450094ef888f6e0aee2628..d4a5fa826b7ba75c7f29a5cf3f1f60e162a3db2e 100644 (file)
@@ -108,6 +108,9 @@ private:
 
     enum ValueType { ValueWidth = 0, ValueHeight = 1 };
 
+    /** \brief Sets the font weight value in the combo box. (#909) */
+    void setFontBoxWeight(int weight);
+
     /** \brief Store the current choices of font, background and rect values */
     void writeChoices();
     /** \brief Read the last stored choices into the dialog */
index 2b6bce23a7e1255dbf9428110001035b21a13c97..ec68de6e8e60d02a3653c9d99caff55d497d464a 100644 (file)
          </widget>
         </item>
         <item>
-         <widget class="QToolButton" name="buttonBold">
-          <property name="text">
-           <string>...</string>
-          </property>
-          <property name="checkable">
-           <bool>true</bool>
-          </property>
-          <property name="checked">
-           <bool>false</bool>
-          </property>
-         </widget>
+         <widget class="QComboBox" name="font_weight_box"/>
         </item>
         <item>
          <widget class="QToolButton" name="buttonItalic">
         <rect>
          <x>0</x>
          <y>0</y>
-         <width>450</width>
-         <height>122</height>
+         <width>139</width>
+         <height>100</height>
         </rect>
        </property>
        <attribute name="label">
         <rect>
          <x>0</x>
          <y>0</y>
-         <width>450</width>
-         <height>122</height>
+         <width>301</width>
+         <height>183</height>
         </rect>
        </property>
        <attribute name="label">
         <rect>
          <x>0</x>
          <y>0</y>
-         <width>434</width>
-         <height>230</height>
+         <width>232</width>
+         <height>198</height>
         </rect>
        </property>
        <attribute name="label">