]> git.sesse.net Git - kdenlive/commitdiff
Fix timecode widget sometimes hard to edit
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 21 Nov 2011 18:28:42 +0000 (19:28 +0100)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 21 Nov 2011 18:29:25 +0000 (19:29 +0100)
src/clipproperties.cpp
src/projectlist.cpp
src/slideshowclip.cpp
src/timecode.cpp
src/timecode.h
src/timecodedisplay.cpp
src/timecodedisplay.h
src/titlewidget.cpp

index f0f3e05181123d62affaf61e1bf1259932b48712..b59b5ed4b3a9bfc59fbb433270cf0f1de3cd6790 100644 (file)
@@ -430,8 +430,7 @@ ClipProperties::ClipProperties(DocClipBase *clip, Timecode tc, double fps, QWidg
         m_view.clip_filesize->setHidden(true);
         m_view.label_size->setHidden(true);
     }
-    m_view.clip_duration->setInputMask("");
-    m_view.clip_duration->setValidator(tc.validator());
+    m_view.clip_duration->setInputMask(tc.mask());
     m_view.clip_duration->setText(tc.getTimecode(m_clip->duration()));
     if (t != IMAGE && t != COLOR && t != TEXT) m_view.clip_duration->setReadOnly(true);
     else {
index 04abe1c88bcefaa3a384ed85bd49860ee46bcb34..2705a62ab9b38f5ed7a2d2cffaf5703bbd4d816f 100644 (file)
@@ -1563,7 +1563,6 @@ void ProjectList::slotAddColorClip()
 
     TimecodeDisplay *t = new TimecodeDisplay(m_timecode);
     t->setValue(KdenliveSettings::color_duration());
-    t->setTimeCodeFormat(false);
     dia_ui.clip_durationBox->addWidget(t);
     dia_ui.clip_color->setColor(KdenliveSettings::colorclipcolor());
 
index c6492afa9a221aa0c3b02b2dafdb4a0fa6578c0e..dbe15e2dc7c1094bbf5742ecacd4424c4a0c92b7 100644 (file)
@@ -68,10 +68,8 @@ SlideshowClip::SlideshowClip(Timecode tc, QWidget * parent) :
     m_view.animation->addItem(i18n("Zoom"), "Zoom");
     m_view.animation->addItem(i18n("Zoom, low-pass"), "Zoom, low-pass");
 
-    m_view.clip_duration->setInputMask("");
-    m_view.clip_duration->setValidator(m_timecode.validator());
-    m_view.luma_duration->setInputMask("");
-    m_view.luma_duration->setValidator(m_timecode.validator());
+    m_view.clip_duration->setInputMask(m_timecode.mask());
+    m_view.luma_duration->setInputMask(m_timecode.mask());
     m_view.luma_duration->setText(m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))));
     m_view.folder_url->setUrl(QDir::homePath());
 
@@ -419,15 +417,15 @@ void SlideshowClip::slotUpdateDurationFormat(int ix)
     bool framesFormat = ix == 1;
     if (framesFormat) {
         // switching to frames count, update widget
+        m_view.clip_duration->setInputMask("");
         m_view.clip_duration_frames->setValue(m_timecode.getFrameCount(m_view.clip_duration->text()));
+        m_view.luma_duration->setInputMask("");
         m_view.luma_duration_frames->setValue(m_timecode.getFrameCount(m_view.luma_duration->text()));
     } else {
         // switching to timecode format
-        m_view.clip_duration->setInputMask("");
-        m_view.clip_duration->setValidator(m_timecode.validator());
+        m_view.clip_duration->setInputMask(m_timecode.mask());
         m_view.clip_duration->setText(m_timecode.getTimecodeFromFrames(m_view.clip_duration_frames->value()));
-        m_view.luma_duration->setInputMask("");
-        m_view.luma_duration->setValidator(m_timecode.validator());
+        m_view.luma_duration->setInputMask(m_timecode.mask());
         m_view.luma_duration->setText(m_timecode.getTimecodeFromFrames(m_view.luma_duration_frames->value()));
     }
     m_view.clip_duration_frames->setHidden(!framesFormat);
index 89063dd33e6e9ed2ab88623cd639552dfaeaf2d0..d60fa3554cf83404e271290f980432b2854072ab 100644 (file)
@@ -80,7 +80,6 @@ return frameNumber;
 */
 
 
-#include <QValidator>
 
 #include <KDebug>
 #include <KLocale>
@@ -89,7 +88,6 @@ return frameNumber;
 
 Timecode::Timecode(Formats format, double framesPerSecond)
 {
-    m_validator = new QRegExpValidator(0);
     setFormat(framesPerSecond, format);
 }
 
@@ -107,12 +105,6 @@ void Timecode::setFormat(double framesPerSecond, Formats format)
         m_dropFrames = round(m_realFps * .066666); //Number of frames to drop on the minute marks is the nearest integer to 6% of the framerate
         m_framesPer10Minutes = round(m_realFps * 600); //Number of frames per ten minutes
     }
-    QRegExp regExp;
-    if (m_dropFrameTimecode)
-        regExp.setPattern("^\\d{2}:\\d{2}:\\d{2};\\d{2}$");
-    else
-        regExp.setPattern("^\\d{2}:\\d{2}:\\d{2}:\\d{2}$");
-    m_validator->setRegExp(regExp);
 }
 
 double Timecode::fps() const
@@ -125,15 +117,20 @@ bool Timecode::df() const
     return m_dropFrameTimecode;
 }
 
-const QValidator *Timecode::validator() const
+const QString Timecode::mask(GenTime t) const
 {
-    return m_validator;
+    if (t < GenTime()) {
+        if (m_dropFrameTimecode) return "#99:99:99,99";
+        else return "#99:99:99:99";
+    }
+    if (m_dropFrameTimecode) return "99:99:99,99";
+    else return "99:99:99:99";
 }
 
 QString Timecode::reformatSeparators(QString duration) const
 {
     if (m_dropFrameTimecode)
-        return duration.replace(8, 1, ';');
+        return duration.replace(8, 1, ',');
     return duration.replace(8, 1, ':');
 }
 
@@ -145,31 +142,26 @@ int Timecode::getDisplayFrameCount(const QString &duration, bool frameDisplay) c
 
 int Timecode::getFrameCount(const QString &duration) const
 {
+    int hours, minutes, seconds, frames;
+    int offset = 0;
+    if (duration.at(0) == '-') {
+        offset = 1;
+        hours = duration.mid(1, 2).toInt();
+    }
+    else hours = duration.left(2).toInt();
+    minutes = duration.mid(3 + offset, 2).toInt();
+    seconds = duration.mid(6 + offset, 2).toInt();
+    frames = duration.right(2).toInt();
     if (m_dropFrameTimecode) {
-
         //CONVERT DROP FRAME TIMECODE TO A FRAME NUMBER
         //Code by David Heidelberger, adapted from Andrew Duncan
         //Given ints called hours, minutes, seconds, frames, and a double called framerate
 
-        //Get Hours, Minutes, Seconds, Frames from timecode
-        int hours, minutes, seconds, frames;
-
-        hours = duration.section(':', 0, 0).toInt();
-        minutes = duration.section(':', 1, 1).toInt();
-        if (duration.contains(';')) {
-            seconds = duration.section(';', 0, 0).section(':', 2, 2).toInt();
-            frames = duration.section(';', 1, 1).toInt();
-        } else {
-            //Handle Drop Frame timecode frame calculations, even if the timecode supplied uses incorrect "99:99:99:99" format instead of "99:99:99;99"
-            seconds = duration.section(':', 2, 2).toInt();
-            frames = duration.section(':', 3, 3).toInt();
-        }
-
         int totalMinutes = (60 * hours) + minutes; //Total number of minutes
         int frameNumber = ((m_displayedFramesPerSecond * 3600 * hours) + (m_displayedFramesPerSecond * 60 * minutes) + (m_displayedFramesPerSecond * seconds) + frames) - (m_dropFrames * (totalMinutes - floor(totalMinutes / 10)));
         return frameNumber;
     }
-    return (int)((duration.section(':', 0, 0).toInt()*3600.0 + duration.section(':', 1, 1).toInt()*60.0 + duration.section(':', 2, 2).toInt()) * m_realFps + duration.section(':', 3, 3).toInt());
+    return (int)(hours * 3600.0 + minutes * 60.0 + seconds * m_realFps + frames);
 }
 
 QString Timecode::getDisplayTimecode(const GenTime & time, bool frameDisplay) const
@@ -364,7 +356,7 @@ const QString Timecode::getTimecodeHH_MM_SS_HH(const GenTime & time) const
     text.append(':');
     text.append(QString::number(seconds).rightJustified(2, '0', false));
     if (m_dropFrameTimecode)
-        text.append(';');
+        text.append(',');
     else
         text.append(':');
     text.append(QString::number(hundredths).rightJustified(2, '0', false));
@@ -423,7 +415,7 @@ const QString Timecode::getTimecodeDropFrame(int framenumber) const
     text.append(QString::number(minutes).rightJustified(2, '0', false));
     text.append(':');
     text.append(QString::number(seconds).rightJustified(2, '0', false));
-    text.append(';');
+    text.append(',');
     text.append(QString::number(frames).rightJustified(2, '0', false));
 
     return text;
index 7c2d26921f7ac7bf7ef26e001fec18988e238047..c98ac209589e700651ff3976bb499c1967b664be 100644 (file)
@@ -21,9 +21,6 @@
 
 #include "gentime.h"
 
-class QValidator;
-class QRegExpValidator;
-
 /**
 Handles the conversion of a GenTime into a nicely formatted string, taking into account things such as drop frame if necessary. Handles multiple formats, such as HH:MM:SS:FF, HH:MM:SS:F, All Frames, All Seconds, etc.
 
@@ -58,7 +55,7 @@ public:
     const QString getTimecodeFromFrames(int frames) const;
     double fps() const;
     bool df() const;
-    const QValidator *validator() const;
+    const QString mask(GenTime t = GenTime()) const;
     QString reformatSeparators(QString duration) const;
 
 private:
@@ -68,7 +65,6 @@ private:
     double m_realFps;
     double m_dropFrames;
     int m_framesPer10Minutes;
-    QRegExpValidator *m_validator;
 
     const QString getTimecodeHH_MM_SS_FF(const GenTime & time) const;
     const QString getTimecodeHH_MM_SS_FF(int frames) const;
index c4b77a4a3a15a9475583dfcd016965ff86accded..fa67d29006e6efed79217cdf3f72051d70131e24 100644 (file)
@@ -54,7 +54,6 @@ TimecodeDisplay::TimecodeDisplay(Timecode t, QWidget *parent)
     setTimeCodeFormat(KdenliveSettings::frametimecode(), true);
 
     connect(lineEdit(), SIGNAL(editingFinished()), this, SLOT(slotEditingFinished()));
-    connect(lineEdit(), SIGNAL(cursorPositionChanged(int, int)), this, SLOT(slotCursorPositionChanged(int, int)));
 }
 
 // virtual protected
@@ -84,8 +83,10 @@ void TimecodeDisplay::setTimeCodeFormat(bool frametimecode, bool init)
         QIntValidator *valid = new QIntValidator(lineEdit());
         valid->setBottom(0);
         lineEdit()->setValidator(valid);
+        lineEdit()->setInputMask(QString());
     } else {
-        lineEdit()->setValidator(m_timecode.validator());
+        lineEdit()->setValidator(0);
+        lineEdit()->setInputMask(m_timecode.mask());
     }
     setValue(val);
 }
@@ -188,28 +189,6 @@ void TimecodeDisplay::setValue(GenTime value)
     setValue(m_timecode.getTimecode(value));
 }
 
-void TimecodeDisplay::slotCursorPositionChanged(int oldPos, int newPos)
-{
-    if (!lineEdit()->hasFocus()) return;
-    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);
-}
 
 void TimecodeDisplay::slotEditingFinished()
 {
index a18f757f08ddb464db497d33b7c06375be83bb61..05fab240ade385b66e9c88026feaea81700efd7c 100644 (file)
@@ -99,11 +99,6 @@ public slots:
 private slots:
     void slotEditingFinished();
 
-    /** @brief Updates the selection when the cursor position changed.
-     * The digit after the cursor will be selected.
-     * This makes it easier to edit the timecode. */
-    void slotCursorPositionChanged(int oldPos, int newPos);
-
 signals:
     /**
      * Emitted every time the value changes (by calling setValue() or
index 5a00bd44077f27038df4f335e848c44fc9fc666a..74f27ac38ffa37476fce63508700e77eb736449c 100644 (file)
@@ -148,8 +148,7 @@ TitleWidget::TitleWidget(KUrl url, Timecode tc, QString projectTitlePath, Render
     splitter->setStretchFactor(0, 20);
 
     //If project is drop frame, set the input mask as such.
-    title_duration->setInputMask("");
-    title_duration->setValidator(m_tc.validator());
+    title_duration->setInputMask(m_tc.mask());
     title_duration->setText(m_tc.reformatSeparators(KdenliveSettings::title_duration()));
 
     connect(backgroundColor, SIGNAL(clicked()), this, SLOT(slotChangeBackground())) ;