]> git.sesse.net Git - kdenlive/blobdiff - src/titlewidget.cpp
Re-use KOffice widget in the titler to gain space (spin box with popup slider)
[kdenlive] / src / titlewidget.cpp
index 931b5d8f55055736dd2cdd78380f8cbda0265abf..7ccffdf05f99b46d693d0012e0579027c9ad3723 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "titlewidget.h"
 #include "kdenlivesettings.h"
+#include "KoSliderCombo.h"
 
 #include <cmath>
 
@@ -71,6 +72,25 @@ TitleWidget::TitleWidget(KUrl url, Timecode tc, QString projectTitlePath, Render
     frame_properties->setEnabled(false);
     frame_properties->setFixedHeight(frame_toolbar->height());
 
+    // Set combo sliders values
+    textAlpha->setMinimum(0);
+    textAlpha->setMaximum(255);
+    textAlpha->setDecimals(0);
+    textAlpha->setValue(255);
+    textAlpha->setToolTip(i18n("Font color opacity"));
+
+    textOutlineAlpha->setMinimum(0);
+    textOutlineAlpha->setMaximum(255);
+    textOutlineAlpha->setDecimals(0);
+    textOutlineAlpha->setValue(255);
+    textOutlineAlpha->setToolTip(i18n("Outline color opacity"));
+    
+    textOutline->setMinimum(0);
+    textOutline->setMaximum(200);
+    textOutline->setDecimals(0);
+    textOutline->setValue(0);
+    textOutline->setToolTip(i18n("Outline width"));
+    
     itemzoom->setSuffix(i18n("%"));
     m_frameWidth = render->renderWidth();
     m_frameHeight = render->renderHeight();
@@ -83,9 +103,12 @@ TitleWidget::TitleWidget(KUrl url, Timecode tc, QString projectTitlePath, Render
     connect(horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(slotChangeBackground())) ;
 
     connect(fontColorButton, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ;
+    connect(textOutlineColor, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ;
     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(textAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
+    connect(textOutline, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
+    connect(textOutlineAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
     connect(font_weight_box, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateText()));
 
     connect(font_family, SIGNAL(editTextChanged(const QString &)), this, SLOT(slotFontText(const QString&)));
@@ -187,31 +210,31 @@ TitleWidget::TitleWidget(KUrl url, Timecode tc, QString projectTitlePath, Render
     m_unicodeAction->setToolTip(i18n("Insert Unicode character") + ' ' + m_unicodeAction->shortcut().toString());
     connect(m_unicodeAction, SIGNAL(triggered()), this, SLOT(slotInsertUnicode()));
     buttonInsertUnicode->setDefaultAction(m_unicodeAction);
-    
+
     m_zUp = new QAction(KIcon("kdenlive-zindex-up"), QString(), this);
     m_zUp->setShortcut(Qt::Key_PageUp);
     m_zUp->setToolTip(i18n("Raise object"));
     connect(m_zUp, SIGNAL(triggered()), this, SLOT(slotZIndexUp()));
     zUp->setDefaultAction(m_zUp);
-    
+
     m_zDown = new QAction(KIcon("kdenlive-zindex-down"), QString(), this);
     m_zDown->setShortcut(Qt::Key_PageDown);
     m_zDown->setToolTip(i18n("Lower object"));
     connect(m_zDown, SIGNAL(triggered()), this, SLOT(slotZIndexDown()));
     zDown->setDefaultAction(m_zDown);
-    
+
     m_zTop = new QAction(KIcon("kdenlive-zindex-top"), QString(), this);
     m_zTop->setShortcut(Qt::Key_Home);
     m_zTop->setToolTip(i18n("Raise object to top"));
     connect(m_zTop, SIGNAL(triggered()), this, SLOT(slotZIndexTop()));
     zTop->setDefaultAction(m_zTop);
-    
+
     m_zBottom = new QAction(KIcon("kdenlive-zindex-bottom"), QString(), this);
     m_zBottom->setShortcut(Qt::Key_End);
     m_zBottom->setToolTip(i18n("Lower object to bottom"));
     connect(m_zBottom, SIGNAL(triggered()), this, SLOT(slotZIndexBottom()));
     zBottom->setDefaultAction(m_zBottom);
-    
+
     zDown->setIcon(KIcon("kdenlive-zindex-down"));
     zTop->setIcon(KIcon("kdenlive-zindex-top"));
     zBottom->setIcon(KIcon("kdenlive-zindex-bottom"));
@@ -295,6 +318,7 @@ TitleWidget::TitleWidget(KUrl url, Timecode tc, QString projectTitlePath, Render
     graphicsView->setScene(m_scene);
     m_titledocument.setScene(m_scene, m_frameWidth, m_frameHeight);
     connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(slotChanged()));
+    connect(font_size, SIGNAL(valueChanged(int)), m_scene, SLOT(slotUpdateFontSize(int)));
 
     // a gradient background
     /*QRadialGradient *gradient = new QRadialGradient(0, 0, 10);
@@ -664,6 +688,23 @@ void TitleWidget::slotNewText(QGraphicsTextItem *tt)
     QColor color = fontColorButton->color();
     color.setAlpha(textAlpha->value());
     tt->setDefaultTextColor(color);
+
+    QTextCursor cur(tt->document());
+    cur.select(QTextCursor::Document);
+    QTextBlockFormat format = cur.blockFormat();
+    QTextCharFormat cformat = cur.charFormat();
+    QColor outlineColor = textOutlineColor->color();
+    outlineColor.setAlpha(textOutlineAlpha->value());
+    double outlineWidth = textOutline->value() / 10.0;
+
+    tt->setData(101, outlineWidth);
+    tt->setData(102, outlineColor);
+    if (outlineWidth > 0.0) cformat.setTextOutline(QPen(outlineColor, outlineWidth));
+
+    cformat.setForeground(QBrush(color));
+    cur.setCharFormat(cformat);
+    cur.setBlockFormat(format);
+    tt->setTextCursor(cur);
     tt->setZValue(m_count++);
     setCurrentItem(tt);
 }
@@ -771,7 +812,7 @@ void TitleWidget::selectionChanged()
                     effect_stack->setHidden(true);
                 }
 #else
-               effect_list->blockSignals(true);
+                effect_list->blockSignals(true);
                 effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
                 effect_list->blockSignals(false);
                 effect_stack->setHidden(true);
@@ -795,14 +836,30 @@ void TitleWidget::selectionChanged()
             QFont font = i->font();
             font_family->setCurrentFont(font);
             font_size->setValue(font.pixelSize());
+            m_scene->slotUpdateFontSize(font.pixelSize());
             buttonItalic->setChecked(font.italic());
             buttonUnder->setChecked(font.underline());
             setFontBoxWeight(font.weight());
 
-            QColor color = i->defaultTextColor();
+            QTextCursor cursor(i->document());
+            cursor.select(QTextCursor::Document);
+            QColor color = cursor.charFormat().foreground().color();
             fontColorButton->setColor(color);
             textAlpha->setValue(color.alpha());
 
+            if (!i->data(101).isNull()) {
+                textOutline->blockSignals(true);
+                textOutline->setValue(i->data(101).toDouble()*10);
+                textOutline->blockSignals(false);
+            }
+            if (!i->data(102).isNull()) {
+                textOutlineColor->blockSignals(true);
+                textOutlineAlpha->blockSignals(true);
+                textOutlineColor->setColor(i->data(102).toString());
+                textOutlineAlpha->setValue(QColor(i->data(102).toString()).alpha());
+                textOutlineColor->blockSignals(false);
+                textOutlineAlpha->blockSignals(false);
+            }
             QTextCursor cur = i->textCursor();
             QTextBlockFormat format = cur.blockFormat();
             if (i->textWidth() == -1) buttonAlignNone->setChecked(true);
@@ -966,7 +1023,7 @@ void TitleWidget::updateDimension(QGraphicsItem *i)
     value_h->blockSignals(true);
     zValue->blockSignals(true);
 
-       zValue->setValue((int) i->zValue());
+    zValue->setValue((int) i->zValue());
     if (i->type() == IMAGEITEM) {
         // Get multipliers for rotation/scaling
 
@@ -989,7 +1046,7 @@ void TitleWidget::updateDimension(QGraphicsItem *i)
         value_h->setValue((int) t->boundingRect().height());
     }
 
-       zValue->blockSignals(false);
+    zValue->blockSignals(false);
     value_w->blockSignals(false);
     value_h->blockSignals(false);
 }
@@ -1291,6 +1348,9 @@ void TitleWidget::slotUpdateText()
     QColor color = fontColorButton->color();
     color.setAlpha(textAlpha->value());
 
+    QColor outlineColor = textOutlineColor->color();
+    outlineColor.setAlpha(textOutlineAlpha->value());
+    double outlineWidth = textOutline->value() / 10.0;
     QGraphicsTextItem* item = NULL;
     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
     if (l.size() == 1 && l.at(0)->type() == TEXTITEM) {
@@ -1298,7 +1358,8 @@ void TitleWidget::slotUpdateText()
     }
     if (!item) return;
     //if (item->textCursor().selection ().isEmpty())
-    QTextCursor cur = item->textCursor();
+    QTextCursor cur(item->document());
+    cur.select(QTextCursor::Document);
     QTextBlockFormat format = cur.blockFormat();
     if (buttonAlignLeft->isChecked() || buttonAlignCenter->isChecked() || buttonAlignRight->isChecked()) {
         item->setTextWidth(item->boundingRect().width());
@@ -1310,16 +1371,19 @@ void TitleWidget::slotUpdateText()
         item->setTextWidth(-1);
     }
 
-    {
-        item->setFont(font);
-        item->setDefaultTextColor(color);
-        cur.select(QTextCursor::Document);
-        cur.setBlockFormat(format);
-        item->setTextCursor(cur);
-        cur.clearSelection();
-        item->setTextCursor(cur);
+    item->setFont(font);
+    QTextCharFormat cformat = cur.charFormat();
 
-    }
+    item->setData(101, outlineWidth);
+    item->setData(102, outlineColor);
+    if (outlineWidth > 0.0) cformat.setTextOutline(QPen(outlineColor, outlineWidth));
+
+    cformat.setForeground(QBrush(color));
+    cur.setCharFormat(cformat);
+    cur.setBlockFormat(format);
+    item->setTextCursor(cur);
+    cur.clearSelection();
+    item->setTextCursor(cur);
 }
 
 void TitleWidget::rectChanged()
@@ -1643,6 +1707,7 @@ void TitleWidget::readChoices()
     // read the entries
     font_family->setCurrentFont(titleConfig.readEntry("font_family", font_family->currentFont()));
     font_size->setValue(titleConfig.readEntry("font_pixel_size", font_size->value()));
+    m_scene->slotUpdateFontSize(font_size->value());
     fontColorButton->setColor(titleConfig.readEntry("font_color", fontColorButton->color()));
     textAlpha->setValue(titleConfig.readEntry("font_alpha", textAlpha->value()));
     int weight;
@@ -1841,7 +1906,7 @@ void TitleWidget::slotAddEffect(int ix)
     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
     int effect = effect_list->itemData(ix).toInt();
     if (effect == NOEFFECT) {
-       if (l.size() == 1) l[0]->setData(100, QVariant());
+        if (l.size() == 1) l[0]->setData(100, QVariant());
         effect_stack->setHidden(true);
         return;
     }
@@ -1927,83 +1992,83 @@ void TitleWidget::slotEditShadow()
 
 qreal TitleWidget::zIndexBounds(bool maxBound)
 {
-       qreal bound = maxBound? -99 : 99;
-       QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
-       if (l.size() > 0) {
-               QList<QGraphicsItem*> lItems = graphicsView->scene()->items(l[0]->sceneBoundingRect(), Qt::IntersectsItemShape);
-               if (lItems.size() > 0) {
-                       int n = lItems.size();
-                       qreal z;
-                       if (maxBound) {
-                               for (int i = 0; i < n; i++) {
-                                       z = lItems[i]->zValue();
-                                       if (z > bound && !lItems[i]->isSelected()) {
-                                               bound = z;
-                                       }
-                               }
-                       } else {
-                               // Get minimum z index.
-                               for (int i = 0; i < n; i++) {
-                                       z = lItems[i]->zValue();
-                                       if (z < bound && !lItems[i]->isSelected() && z > -999) {
-                                               // There are items at the very bottom (background e.g.) with z-index < -1000.
-                                               bound = z;
-                                       }
-                               }
-                       }
-               }
-       }
-       return bound;
-}
-
-void TitleWidget::slotZIndexUp() 
+    qreal bound = maxBound ? -99 : 99;
+    QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
+    if (l.size() > 0) {
+        QList<QGraphicsItem*> lItems = graphicsView->scene()->items(l[0]->sceneBoundingRect(), Qt::IntersectsItemShape);
+        if (lItems.size() > 0) {
+            int n = lItems.size();
+            qreal z;
+            if (maxBound) {
+                for (int i = 0; i < n; i++) {
+                    z = lItems[i]->zValue();
+                    if (z > bound && !lItems[i]->isSelected()) {
+                        bound = z;
+                    }
+                }
+            } else {
+                // Get minimum z index.
+                for (int i = 0; i < n; i++) {
+                    z = lItems[i]->zValue();
+                    if (z < bound && !lItems[i]->isSelected() && z > -999) {
+                        // There are items at the very bottom (background e.g.) with z-index < -1000.
+                        bound = z;
+                    }
+                }
+            }
+        }
+    }
+    return bound;
+}
+
+void TitleWidget::slotZIndexUp()
 {
     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
     if (l.size() >= 1) {
-               qreal currentZ = l[0]->zValue();
-           qreal max = zIndexBounds(true);
-               if (currentZ <= max) {
-                       l[0]->setZValue(currentZ+1);
-                   updateDimension(l[0]);
-               }
+        qreal currentZ = l[0]->zValue();
+        qreal max = zIndexBounds(true);
+        if (currentZ <= max) {
+            l[0]->setZValue(currentZ + 1);
+            updateDimension(l[0]);
+        }
     }
 }
 
-void TitleWidget::slotZIndexTop() 
+void TitleWidget::slotZIndexTop()
 {
     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
     if (l.size() >= 1) {
-               qreal currentZ = l[0]->zValue();
-           qreal max = zIndexBounds(true);
-               if (currentZ <= max) {
-                       l[0]->setZValue(max+1);
-                   updateDimension(l[0]);
-               }
+        qreal currentZ = l[0]->zValue();
+        qreal max = zIndexBounds(true);
+        if (currentZ <= max) {
+            l[0]->setZValue(max + 1);
+            updateDimension(l[0]);
+        }
     }
 }
 
-void TitleWidget::slotZIndexDown() 
+void TitleWidget::slotZIndexDown()
 {
     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
     if (l.size() >= 1) {
-               qreal currentZ = l[0]->zValue();
-           qreal min = zIndexBounds(false);
-               if (currentZ >= min) {
-                       l[0]->setZValue(currentZ-1);
-                   updateDimension(l[0]);
-               }
+        qreal currentZ = l[0]->zValue();
+        qreal min = zIndexBounds(false);
+        if (currentZ >= min) {
+            l[0]->setZValue(currentZ - 1);
+            updateDimension(l[0]);
+        }
     }
 }
 
-void TitleWidget::slotZIndexBottom() 
+void TitleWidget::slotZIndexBottom()
 {
     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
     if (l.size() >= 1) {
-               qreal currentZ = l[0]->zValue();
-           qreal min = zIndexBounds(false);
-               if (currentZ >= min) {
-                       l[0]->setZValue(min-1);
-                   updateDimension(l[0]);
-               }
+        qreal currentZ = l[0]->zValue();
+        qreal min = zIndexBounds(false);
+        if (currentZ >= min) {
+            l[0]->setZValue(min - 1);
+            updateDimension(l[0]);
+        }
     }
 }