From: Jean-Baptiste Mardelle Date: Mon, 21 Nov 2011 18:28:42 +0000 (+0100) Subject: Fix timecode widget sometimes hard to edit X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=3f792a879e99ee97e1cf3bb2ce09e19ed820ed41;p=kdenlive Fix timecode widget sometimes hard to edit --- diff --git a/src/clipproperties.cpp b/src/clipproperties.cpp index f0f3e051..b59b5ed4 100644 --- a/src/clipproperties.cpp +++ b/src/clipproperties.cpp @@ -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 { diff --git a/src/projectlist.cpp b/src/projectlist.cpp index 04abe1c8..2705a62a 100644 --- a/src/projectlist.cpp +++ b/src/projectlist.cpp @@ -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()); diff --git a/src/slideshowclip.cpp b/src/slideshowclip.cpp index c6492afa..dbe15e2d 100644 --- a/src/slideshowclip.cpp +++ b/src/slideshowclip.cpp @@ -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); diff --git a/src/timecode.cpp b/src/timecode.cpp index 89063dd3..d60fa355 100644 --- a/src/timecode.cpp +++ b/src/timecode.cpp @@ -80,7 +80,6 @@ return frameNumber; */ -#include #include #include @@ -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; diff --git a/src/timecode.h b/src/timecode.h index 7c2d2692..c98ac209 100644 --- a/src/timecode.h +++ b/src/timecode.h @@ -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; diff --git a/src/timecodedisplay.cpp b/src/timecodedisplay.cpp index c4b77a4a..fa67d290 100644 --- a/src/timecodedisplay.cpp +++ b/src/timecodedisplay.cpp @@ -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() { diff --git a/src/timecodedisplay.h b/src/timecodedisplay.h index a18f757f..05fab240 100644 --- a/src/timecodedisplay.h +++ b/src/timecodedisplay.h @@ -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 diff --git a/src/titlewidget.cpp b/src/titlewidget.cpp index 5a00bd44..74f27ac3 100644 --- a/src/titlewidget.cpp +++ b/src/titlewidget.cpp @@ -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())) ;