1 /* This file is part of the KDE project
2 Copyright (c) 2010 Jean-Baptiste Mardelle <jb@kdenlive.org>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 #include "timecodedisplay.h"
21 #include "kdenlivesettings.h"
25 #include <QMouseEvent>
32 TimecodeDisplay::TimecodeDisplay(Timecode t, QWidget *parent)
39 lineedit->setFont(KGlobalSettings::toolBarFont());
40 QFontMetrics fm = lineedit->fontMetrics();
41 lineedit->setMaximumWidth(fm.width("88:88:88:888"));
42 setSizePolicy(QSizePolicy::Maximum, QSizePolicy::MinimumExpanding);
44 slotUpdateTimeCodeFormat();
46 connect(uparrow, SIGNAL(clicked()), this, SLOT(slotValueUp()));
47 connect(downarrow, SIGNAL(clicked()), this, SLOT(slotValueDown()));
48 connect(lineedit, SIGNAL(editingFinished()), this, SIGNAL(editingFinished()));
51 void TimecodeDisplay::slotValueUp()
56 lineedit->clearFocus();
57 emit editingFinished();
60 void TimecodeDisplay::slotValueDown()
65 lineedit->clearFocus();
66 emit editingFinished();
69 void TimecodeDisplay::setTimeCodeFormat(bool frametimecode)
72 m_frametimecode = frametimecode;
73 lineedit->setInputMask("");
74 if (m_frametimecode) {
75 QIntValidator *valid = new QIntValidator(lineedit);
77 lineedit->setValidator(valid);
79 lineedit->setValidator(m_timecode.validator());
84 void TimecodeDisplay::slotUpdateTimeCodeFormat()
86 setTimeCodeFormat(KdenliveSettings::frametimecode());
89 void TimecodeDisplay::keyPressEvent(QKeyEvent *e)
91 if (e->key() == Qt::Key_Up)
93 else if (e->key() == Qt::Key_Down)
96 QWidget::keyPressEvent(e);
99 void TimecodeDisplay::wheelEvent(QWheelEvent *e)
108 int TimecodeDisplay::maximum() const
113 int TimecodeDisplay::minimum() const
118 int TimecodeDisplay::value() const
121 if (m_frametimecode) frames = lineedit->text().toInt();
122 else frames = m_timecode.getFrameCount(lineedit->text());
126 GenTime TimecodeDisplay::gentime() const
128 return GenTime(value(), m_timecode.fps());
131 Timecode TimecodeDisplay::timecode() const
136 void TimecodeDisplay::setRange(int min, int max)
142 void TimecodeDisplay::setValue(const QString &value)
144 setValue(m_timecode.getFrameCount(value));
147 void TimecodeDisplay::setValue(int value)
149 if (value < m_minimum)
151 if (m_maximum > m_minimum && value > m_maximum)
154 downarrow->setEnabled(value > m_minimum);
155 uparrow->setEnabled(m_maximum < m_minimum || value < m_maximum);
158 lineedit->setText(QString::number(value));
160 lineedit->setText(m_timecode.getTimecodeFromFrames(value));
162 //emit valueChanged(value, true);
165 void TimecodeDisplay::setValue(GenTime value)
167 setValue(m_timecode.getTimecode(value));
170 #include <timecodedisplay.moc>