]> git.sesse.net Git - kdenlive/blobdiff - src/timecodedisplay.cpp
Make it possible to add a comment explaining effect parameters (for now only double...
[kdenlive] / src / timecodedisplay.cpp
index 7916ebdd784bdad15986e460a8bcb47e7d6bca05..55d5fd08525d8a6f3ea6fd8067e388164616e925 100644 (file)
@@ -39,13 +39,14 @@ TimecodeDisplay::TimecodeDisplay(Timecode t, QWidget *parent)
     lineedit->setFont(KGlobalSettings::toolBarFont());
     QFontMetrics fm = lineedit->fontMetrics();
     lineedit->setMaximumWidth(fm.width("88:88:88:888"));
-    setSizePolicy(QSizePolicy::Maximum, QSizePolicy::MinimumExpanding);
+    setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
 
     setTimeCodeFormat(KdenliveSettings::frametimecode(), true);
 
     connect(uparrow, SIGNAL(clicked()), this, SLOT(slotValueUp()));
     connect(downarrow, SIGNAL(clicked()), this, SLOT(slotValueDown()));
     connect(lineedit, SIGNAL(editingFinished()), this, SIGNAL(editingFinished()));
+    connect(lineedit, SIGNAL(cursorPositionChanged(int, int)), this, SLOT(slotCursorPositionChanged(int, int)));
 }
 
 void TimecodeDisplay::slotValueUp()
@@ -155,7 +156,7 @@ void TimecodeDisplay::setValue(int value)
     if (m_maximum > m_minimum && value > m_maximum)
         value = m_maximum;
 
-    if (value == getValue()) return;
+    if (value == getValue() && !lineedit->text().isEmpty()) return;
     downarrow->setEnabled(value > m_minimum);
     uparrow->setEnabled(m_maximum < m_minimum || value < m_maximum);
 
@@ -163,7 +164,6 @@ void TimecodeDisplay::setValue(int value)
         lineedit->setText(QString::number(value));
     else {
         QString v = m_timecode.getTimecodeFromFrames(value);
-        kDebug() << "// SETTING TO: " << value << " = " << v << "( " << m_timecode.fps();
         lineedit->setText(v);
     }
 }
@@ -173,4 +173,26 @@ void TimecodeDisplay::setValue(GenTime value)
     setValue(m_timecode.getTimecode(value));
 }
 
+void TimecodeDisplay::slotCursorPositionChanged(int oldPos, int newPos)
+{
+    lineedit->blockSignals(true);
+    QString text = lineedit->text();
+
+    if (newPos < text.size() && !text.at(newPos).isDigit()) {
+        // char at newPos is a separator (':' or ';')
+
+        // make it possible move the cursor backwards at separators
+        if (newPos == oldPos - 1)
+            lineedit->setSelection(newPos, -1);
+        else
+            lineedit->setSelection(newPos + 2, -1);
+    } else if (newPos < text.size()) {
+        lineedit->setSelection(newPos + 1, -1);
+    } else {
+        lineedit->setSelection(newPos, -1);
+    }
+
+    lineedit->blockSignals(false);
+}
+
 #include <timecodedisplay.moc>