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 {
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());
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());
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);
*/
-#include <QValidator>
#include <KDebug>
#include <KLocale>
Timecode::Timecode(Formats format, double framesPerSecond)
{
- m_validator = new QRegExpValidator(0);
setFormat(framesPerSecond, 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
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, ':');
}
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
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));
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;
#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.
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:
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;
setTimeCodeFormat(KdenliveSettings::frametimecode(), true);
connect(lineEdit(), SIGNAL(editingFinished()), this, SLOT(slotEditingFinished()));
- connect(lineEdit(), SIGNAL(cursorPositionChanged(int, int)), this, SLOT(slotCursorPositionChanged(int, int)));
}
// virtual protected
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);
}
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()
{
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
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())) ;