X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Ftimecodedisplay.cpp;h=a98659ed9b832de832a8cd74608cd9db9e42ea22;hb=c3302003093710ee247ad84c0fe2ef3c579d417f;hp=acd1515a80b2b23e3c5858532c0b7f983dfea83b;hpb=f062174e87e6f3c034b77f34069350e6f462a474;p=kdenlive diff --git a/src/timecodedisplay.cpp b/src/timecodedisplay.cpp index acd1515a..a98659ed 100644 --- a/src/timecodedisplay.cpp +++ b/src/timecodedisplay.cpp @@ -31,7 +31,7 @@ #include #include -TimecodeDisplay::TimecodeDisplay(Timecode t, QWidget *parent) +TimecodeDisplay::TimecodeDisplay(const Timecode& t, QWidget *parent) : QAbstractSpinBox(parent), m_timecode(t), m_frametimecode(false), @@ -51,43 +51,44 @@ TimecodeDisplay::TimecodeDisplay(Timecode t, QWidget *parent) setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); setAccelerated(true); + setValue(m_minimum); + setTimeCodeFormat(KdenliveSettings::frametimecode(), true); - connect(lineEdit(), SIGNAL(returnPressed()), this, SLOT(slotEditingFinished())); - connect(lineEdit(), SIGNAL(cursorPositionChanged(int, int)), this, SLOT(slotCursorPositionChanged(int, int))); + connect(lineEdit(), SIGNAL(editingFinished()), this, SLOT(slotEditingFinished())); } // virtual protected QAbstractSpinBox::StepEnabled TimecodeDisplay::stepEnabled () const { QAbstractSpinBox::StepEnabled result = QAbstractSpinBox::StepNone; - if (getValue() > m_minimum) result |= QAbstractSpinBox::StepDownEnabled; - if (m_maximum == -1 || getValue() < m_maximum) result |= QAbstractSpinBox::StepUpEnabled; + if (m_value > m_minimum) result |= QAbstractSpinBox::StepDownEnabled; + if (m_maximum == -1 || m_value < m_maximum) result |= QAbstractSpinBox::StepUpEnabled; return result; } // virtual void TimecodeDisplay::stepBy(int steps) { - int val = getValue(); - val += steps; + int val = m_value + steps; setValue(val); - emit editingFinished(); } void TimecodeDisplay::setTimeCodeFormat(bool frametimecode, bool init) { if (!init && m_frametimecode == frametimecode) return; - int val = getValue(); m_frametimecode = frametimecode; + lineEdit()->clear(); if (m_frametimecode) { 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_value); } void TimecodeDisplay::slotUpdateTimeCodeFormat() @@ -95,7 +96,7 @@ void TimecodeDisplay::slotUpdateTimeCodeFormat() setTimeCodeFormat(KdenliveSettings::frametimecode()); } -void TimecodeDisplay::updateTimeCode(Timecode t) +void TimecodeDisplay::updateTimeCode(const Timecode &t) { m_timecode = t; setTimeCodeFormat(KdenliveSettings::frametimecode()); @@ -103,8 +104,10 @@ void TimecodeDisplay::updateTimeCode(Timecode t) void TimecodeDisplay::keyPressEvent(QKeyEvent *e) { - if (e->key() == Qt::Key_Return) - slotEditingFinished(); + if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) { + e->setAccepted(true); + clearFocus(); + } else QAbstractSpinBox::keyPressEvent(e); } @@ -117,14 +120,12 @@ void TimecodeDisplay::mouseReleaseEvent(QMouseEvent *e) } } -/* + void TimecodeDisplay::wheelEvent(QWheelEvent *e) { - if (e->delta() > 0) - slotValueUp(); - else - slotValueDown(); -}*/ + QAbstractSpinBox::wheelEvent(e); + clearFocus(); +} int TimecodeDisplay::maximum() const @@ -139,13 +140,12 @@ int TimecodeDisplay::minimum() const int TimecodeDisplay::getValue() const { - if (m_frametimecode) return lineEdit()->text().toInt(); - else return m_timecode.getFrameCount(lineEdit()->text()); + return m_value; } GenTime TimecodeDisplay::gentime() const { - return GenTime(getValue(), m_timecode.fps()); + return GenTime(m_value, m_timecode.fps()); } Timecode TimecodeDisplay::timecode() const @@ -171,51 +171,31 @@ void TimecodeDisplay::setValue(int value) if (m_maximum > m_minimum && value > m_maximum) value = m_maximum; - if (value == getValue() && !lineEdit()->text().isEmpty()) return; - //downarrow->setEnabled(value > m_minimum); - //uparrow->setEnabled(m_maximum < m_minimum || value < m_maximum); - - if (m_frametimecode) + if (m_frametimecode) { + if (value == m_value && !lineEdit()->text().isEmpty()) return; + m_value = value; lineEdit()->setText(QString::number(value)); + } else { + if (value == m_value && lineEdit()->text() != ":::") return; + m_value = value; QString v = m_timecode.getTimecodeFromFrames(value); lineEdit()->setText(v); } } -void TimecodeDisplay::setValue(GenTime value) +void TimecodeDisplay::setValue(const GenTime &value) { - setValue(m_timecode.getTimecode(value)); + setValue((int) value.frames(m_timecode.fps())); } -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() { - clearFocus(); lineEdit()->deselect(); - emit editingFinished(); + if (m_frametimecode) setValue(lineEdit()->text().toInt()); + else setValue(lineEdit()->text()); + emit timeCodeEditingFinished(); } #include