]> git.sesse.net Git - kdenlive/commitdiff
http://www.kdenlive.org/mantis/view.php?id=1607
authorSimon A. Eugster <simon.eu@gmail.com>
Mon, 24 May 2010 09:39:00 +0000 (09:39 +0000)
committerSimon A. Eugster <simon.eu@gmail.com>
Mon, 24 May 2010 09:39:00 +0000 (09:39 +0000)
Text in text items from templates is automatically selected and editable, until it changes.

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

src/titlewidget.cpp
src/titlewidget.h

index da05ed9f2ec997a2596cbf9ad1b89a087619a16c..85e230e2cb6f490a91e014dc08cb62c8597d8432 100644 (file)
@@ -553,6 +553,19 @@ void TitleWidget::templateIndexChanged(int index)
             if(KMessageBox::questionYesNo(this, i18n("Do you really want to load a new template? Changes in this title will be lost!")) == KMessageBox::No) return;
         }
         loadTitle(item);
+
+        // mbt 1607: Add property to distinguish between unchanged template titles and user titles.
+        // Text of unchanged template titles should be selected when clicked.
+        QList<QGraphicsItem *> list = graphicsView->scene()->items();
+        foreach(QGraphicsItem * qgItem, list) {
+            if(qgItem->type() == TEXTITEM) {
+                QGraphicsTextItem *i;
+                i = static_cast<QGraphicsTextItem *>(qgItem);
+                i->setProperty("isTemplate", "true");
+                i->setProperty("templateText", i->toHtml());
+            }
+
+        }
         lastDocumentHash = QCryptographicHash::hash(xml().toString().toAscii(), QCryptographicHash::Md5).toHex();
     }
 }
@@ -845,7 +858,22 @@ void TitleWidget::zIndexChanged(int v)
 void TitleWidget::selectionChanged()
 {
     if(m_scene->tool() != TITLE_SELECT) return;
-    QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
+
+    QList<QGraphicsItem *> l;
+
+    // mbt 1607: One text item might have grabbed the keyboard.
+    // Ungrab it for all items that are not selected, otherwise
+    // text input would only work for the text item that grabbed
+    // the keyboard last.
+    l = graphicsView->scene()->items();
+    foreach(QGraphicsItem * item, l) {
+        if(item->type() == TEXTITEM && !item->isSelected()) {
+            QGraphicsTextItem *i = static_cast<QGraphicsTextItem *>(item);
+            i->ungrabKeyboard();
+        }
+    }
+
+    l = graphicsView->scene()->selectedItems();
     //toolBox->setItemEnabled(2, false);
     //toolBox->setItemEnabled(3, false);
     effect_list->blockSignals(true);
@@ -998,9 +1026,15 @@ void TitleWidget::selectionChanged()
             buttonAlignNone->blockSignals(false);
             buttonAlignCenter->blockSignals(false);
 
-            // Later
-//      cur.select(QTextCursor::Document);
-//      i->setTextCursor(cur);
+            // mbt 1607: Select text if the text item is an unchanged template item.
+            if(i->property("isTemplate").isValid()) {
+                cur.setPosition(0, QTextCursor::MoveAnchor);
+                cur.select(QTextCursor::Document);
+                i->setTextCursor(cur);
+                // Make text editable now.
+                i->grabKeyboard();
+                i->setTextInteractionFlags(Qt::TextEditorInteraction);
+            }
 
             updateAxisButtons(i);
             updateCoordinates(i);
@@ -1071,6 +1105,7 @@ void TitleWidget::selectionChanged()
     // Tools working on more than one element.
     if(l.size() > 0)
         effect_list->blockSignals(false);
+
 }
 
 void TitleWidget::slotValueChanged(int type)
@@ -1453,6 +1488,18 @@ void TitleWidget::textChanged(QGraphicsTextItem *i)
              */
         }
     }
+
+    // mbt 1607: Template text has changed; don't auto-select content anymore.
+    if(i->property("isTemplate").isValid()) {
+        if(i->property("templateText").isValid()) {
+            if(i->property("templateText") == i->toHtml()) {
+                // Unchanged, do nothing.
+            } else {
+                i->setProperty("isTemplate", QVariant::Invalid);
+                i->setProperty("templateText", QVariant::Invalid);
+            }
+        }
+    }
 }
 
 void TitleWidget::slotInsertUnicode()
index 884958e603d6a1364fa798598c29c4c894949819..10ab0bb9e3ba18e1aa80b36d481b13f6825c580e 100644 (file)
@@ -225,7 +225,9 @@ public slots:
     void itemRotateX(qreal);
     void itemRotateY(qreal);
     void itemRotateZ(qreal);
+    /** Save a title to a title file */
     void saveTitle(KUrl url = KUrl());
+    /** Load a title from a title file */
     void loadTitle(KUrl url = KUrl());
 
 private slots: