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::Preferred);
44 setTimeCodeFormat(KdenliveSettings::frametimecode(), true);
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, bool init)
71 if (!init && m_frametimecode == frametimecode) return;
73 m_frametimecode = frametimecode;
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::updateTimeCode(Timecode t)
92 setTimeCodeFormat(KdenliveSettings::frametimecode());
95 void TimecodeDisplay::keyPressEvent(QKeyEvent *e)
97 if (e->key() == Qt::Key_Up)
99 else if (e->key() == Qt::Key_Down)
102 QWidget::keyPressEvent(e);
105 void TimecodeDisplay::wheelEvent(QWheelEvent *e)
114 int TimecodeDisplay::maximum() const
119 int TimecodeDisplay::minimum() const
124 int TimecodeDisplay::getValue() const
126 if (m_frametimecode) return lineedit->text().toInt();
127 else return m_timecode.getFrameCount(lineedit->text());
130 GenTime TimecodeDisplay::gentime() const
132 return GenTime(getValue(), m_timecode.fps());
135 Timecode TimecodeDisplay::timecode() const
140 void TimecodeDisplay::setRange(int min, int max)
146 void TimecodeDisplay::setValue(const QString &value)
148 setValue(m_timecode.getFrameCount(value));
151 void TimecodeDisplay::setValue(int value)
153 if (value < m_minimum)
155 if (m_maximum > m_minimum && value > m_maximum)
158 if (value == getValue() && !lineedit->text().isEmpty()) return;
159 downarrow->setEnabled(value > m_minimum);
160 uparrow->setEnabled(m_maximum < m_minimum || value < m_maximum);
163 lineedit->setText(QString::number(value));
165 QString v = m_timecode.getTimecodeFromFrames(value);
166 lineedit->setText(v);
170 void TimecodeDisplay::setValue(GenTime value)
172 setValue(m_timecode.getTimecode(value));
175 #include <timecodedisplay.moc>