#include "timecodedisplay.h"
#include "kdenlivesettings.h"
-#include <QSize>
-#include <QStyle>
-#include <QStylePainter>
-#include <QStyleOptionSlider>
#include <QLineEdit>
#include <QValidator>
-#include <QHBoxLayout>
-#include <QFrame>
#include <QMouseEvent>
-#include <QToolButton>
#include <kglobal.h>
#include <klocale.h>
TimecodeDisplay::TimecodeDisplay(Timecode t, QWidget *parent)
: QWidget(parent),
+ m_timecode(t),
m_minimum(0),
m_maximum(-1)
{
lineedit->setFont(KGlobalSettings::toolBarFont());
QFontMetrics fm = lineedit->fontMetrics();
lineedit->setMaximumWidth(fm.width("88:88:88:888"));
- slotPrepareTimeCodeFormat(t);
+ setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
+
+ 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()));
}
-TimecodeDisplay::~TimecodeDisplay()
-{
-}
-
void TimecodeDisplay::slotValueUp()
{
- int val = value();
+ int val = getValue();
val++;
- if (m_maximum > -1 && val > m_maximum) val = m_maximum;
setValue(val);
lineedit->clearFocus();
emit editingFinished();
void TimecodeDisplay::slotValueDown()
{
- int val = value();
+ int val = getValue();
val--;
- if (val < m_minimum) val = m_minimum;
setValue(val);
lineedit->clearFocus();
emit editingFinished();
}
-void TimecodeDisplay::slotPrepareTimeCodeFormat(Timecode t)
+void TimecodeDisplay::setTimeCodeFormat(bool frametimecode, bool init)
{
- m_timecode = t;
- m_frametimecode = KdenliveSettings::frametimecode();
- QString val = lineedit->text();
- lineedit->setInputMask("");
+ if (!init && m_frametimecode == frametimecode) return;
+ int val = getValue();
+ m_frametimecode = frametimecode;
if (m_frametimecode) {
- int frames = m_timecode.getFrameCount(lineedit->text());
QIntValidator *valid = new QIntValidator(lineedit);
valid->setBottom(0);
lineedit->setValidator(valid);
- lineedit->setText(QString::number(frames));
} else {
- int pos = lineedit->text().toInt();
lineedit->setValidator(m_timecode.validator());
- lineedit->setText(m_timecode.getTimecodeFromFrames(pos));
}
+ setValue(val);
+}
+
+void TimecodeDisplay::slotUpdateTimeCodeFormat()
+{
+ setTimeCodeFormat(KdenliveSettings::frametimecode());
+}
+
+void TimecodeDisplay::updateTimeCode(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();
- else QWidget::keyPressEvent(e);
+ if (e->key() == Qt::Key_Up)
+ slotValueUp();
+ else if (e->key() == Qt::Key_Down)
+ slotValueDown();
+ else
+ QWidget::keyPressEvent(e);
}
void TimecodeDisplay::wheelEvent(QWheelEvent *e)
{
- if (e->delta() > 0) slotValueUp();
- else slotValueDown();
+ if (e->delta() > 0)
+ slotValueUp();
+ else
+ slotValueDown();
}
return m_minimum;
}
-int TimecodeDisplay::value() const
+int TimecodeDisplay::getValue() const
+{
+ if (m_frametimecode) return lineedit->text().toInt();
+ else return m_timecode.getFrameCount(lineedit->text());
+}
+
+GenTime TimecodeDisplay::gentime() const
{
- int frames;
- if (m_frametimecode) frames = lineedit->text().toInt();
- else frames = m_timecode.getFrameCount(lineedit->text());
- return frames;
+ return GenTime(getValue(), m_timecode.fps());
}
Timecode TimecodeDisplay::timecode() const
void TimecodeDisplay::setValue(const QString &value)
{
- if (m_frametimecode) {
- lineedit->setText(QString::number(m_timecode.getFrameCount(value)));
- } else lineedit->setText(value);
+ setValue(m_timecode.getFrameCount(value));
}
void TimecodeDisplay::setValue(int value)
{
- /* if (value < m_minimum)
- value = m_minimum;
- if (value > m_maximum)
- value = m_maximum;*/
- if (m_frametimecode) lineedit->setText(QString::number(value));
- else lineedit->setText(m_timecode.getTimecodeFromFrames(value));
-
- /* setEditText(KGlobal::locale()->formatNumber(value, d->decimals));
- d->slider->blockSignals(true);
- d->slider->setValue(int((value - d->minimum) * 256 / (d->maximum - d->minimum) + 0.5));
- d->slider->blockSignals(false);*/
- //emit valueChanged(value, true);
+ if (value < m_minimum)
+ value = m_minimum;
+ 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)
+ lineedit->setText(QString::number(value));
+ else {
+ QString v = m_timecode.getTimecodeFromFrames(value);
+ lineedit->setText(v);
+ }
+}
+
+void TimecodeDisplay::setValue(GenTime value)
+{
+ setValue(m_timecode.getTimecode(value));
}
#include <timecodedisplay.moc>