X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Ftimecodedisplay.cpp;h=a98659ed9b832de832a8cd74608cd9db9e42ea22;hb=c3302003093710ee247ad84c0fe2ef3c579d417f;hp=f3e98203449847e27013ea6d718cd527ed1db1fa;hpb=f8fc9aef061d85a6a86c1cd834307917db79c57d;p=kdenlive diff --git a/src/timecodedisplay.cpp b/src/timecodedisplay.cpp index f3e98203..a98659ed 100644 --- a/src/timecodedisplay.cpp +++ b/src/timecodedisplay.cpp @@ -27,58 +27,68 @@ #include #include #include +#include +#include +#include - -TimecodeDisplay::TimecodeDisplay(Timecode t, QWidget *parent) - : QWidget(parent), +TimecodeDisplay::TimecodeDisplay(const Timecode& t, QWidget *parent) + : QAbstractSpinBox(parent), m_timecode(t), + m_frametimecode(false), m_minimum(0), m_maximum(-1) { - setupUi(this); - lineedit->setFont(KGlobalSettings::toolBarFont()); - QFontMetrics fm = lineedit->fontMetrics(); - lineedit->setMaximumWidth(fm.width("88:88:88:888")); - setSizePolicy(QSizePolicy::Maximum, QSizePolicy::MinimumExpanding); + lineEdit()->setFont(KGlobalSettings::toolBarFont()); + lineEdit()->setAlignment(Qt::AlignRight | Qt::AlignVCenter); + QFontMetrics fm = lineEdit()->fontMetrics(); +#if QT_VERSION >= 0x040600 + setMinimumWidth(fm.width("88:88:88:88888888") + contentsMargins().right() + contentsMargins().right()); +#else + int left, top, right, bottom; + getContentsMargins(&left, &top, &right, &bottom); + setMinimumWidth(fm.width("88:88:88:88888888") + left + right); +#endif + setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); + setAccelerated(true); + + setValue(m_minimum); - slotUpdateTimeCodeFormat(); + 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(editingFinished()), this, SLOT(slotEditingFinished())); } -void TimecodeDisplay::slotValueUp() +// virtual protected +QAbstractSpinBox::StepEnabled TimecodeDisplay::stepEnabled () const { - int val = value(); - val++; - setValue(val); - lineedit->clearFocus(); - emit editingFinished(); + QAbstractSpinBox::StepEnabled result = QAbstractSpinBox::StepNone; + if (m_value > m_minimum) result |= QAbstractSpinBox::StepDownEnabled; + if (m_maximum == -1 || m_value < m_maximum) result |= QAbstractSpinBox::StepUpEnabled; + return result; } -void TimecodeDisplay::slotValueDown() +// virtual +void TimecodeDisplay::stepBy(int steps) { - int val = value(); - val--; + int val = m_value + steps; setValue(val); - lineedit->clearFocus(); - emit editingFinished(); } -void TimecodeDisplay::setTimeCodeFormat(bool frametimecode) +void TimecodeDisplay::setTimeCodeFormat(bool frametimecode, bool init) { - int val = value(); + if (!init && m_frametimecode == frametimecode) return; m_frametimecode = frametimecode; - lineedit->setInputMask(""); + lineEdit()->clear(); if (m_frametimecode) { - QIntValidator *valid = new QIntValidator(lineedit); + QIntValidator *valid = new QIntValidator(lineEdit()); valid->setBottom(0); - lineedit->setValidator(valid); + 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() @@ -86,22 +96,35 @@ void TimecodeDisplay::slotUpdateTimeCodeFormat() setTimeCodeFormat(KdenliveSettings::frametimecode()); } +void TimecodeDisplay::updateTimeCode(const Timecode &t) +{ + m_timecode = t; + setTimeCodeFormat(KdenliveSettings::frametimecode()); +} + void TimecodeDisplay::keyPressEvent(QKeyEvent *e) { - if (e->key() == Qt::Key_Up) - slotValueUp(); - else if (e->key() == Qt::Key_Down) - slotValueDown(); + if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) { + e->setAccepted(true); + clearFocus(); + } else - QWidget::keyPressEvent(e); + QAbstractSpinBox::keyPressEvent(e); } +void TimecodeDisplay::mouseReleaseEvent(QMouseEvent *e) +{ + QAbstractSpinBox::mouseReleaseEvent(e); + if (!lineEdit()->underMouse()) { + clearFocus(); + } +} + + void TimecodeDisplay::wheelEvent(QWheelEvent *e) { - if (e->delta() > 0) - slotValueUp(); - else - slotValueDown(); + QAbstractSpinBox::wheelEvent(e); + clearFocus(); } @@ -115,17 +138,14 @@ int TimecodeDisplay::minimum() const return m_minimum; } -int TimecodeDisplay::value() const +int TimecodeDisplay::getValue() const { - int frames; - if (m_frametimecode) frames = lineedit->text().toInt(); - else frames = m_timecode.getFrameCount(lineedit->text()); - return frames; + return m_value; } GenTime TimecodeDisplay::gentime() const { - return GenTime(value(), m_timecode.fps()); + return GenTime(m_value, m_timecode.fps()); } Timecode TimecodeDisplay::timecode() const @@ -151,20 +171,31 @@ void TimecodeDisplay::setValue(int value) if (m_maximum > m_minimum && value > m_maximum) value = m_maximum; - downarrow->setEnabled(value > m_minimum); - uparrow->setEnabled(m_maximum < m_minimum || value < m_maximum); - - if (m_frametimecode) - lineedit->setText(QString::number(value)); - else - lineedit->setText(m_timecode.getTimecodeFromFrames(value)); + 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); + } +} - //emit valueChanged(value, true); +void TimecodeDisplay::setValue(const GenTime &value) +{ + setValue((int) value.frames(m_timecode.fps())); } -void TimecodeDisplay::setValue(GenTime value) + +void TimecodeDisplay::slotEditingFinished() { - setValue(m_timecode.getTimecode(value)); + lineEdit()->deselect(); + if (m_frametimecode) setValue(lineEdit()->text().toInt()); + else setValue(lineEdit()->text()); + emit timeCodeEditingFinished(); } #include