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 <QStylePainter>
26 #include <QStyleOptionSlider>
29 #include <QHBoxLayout>
31 #include <QMouseEvent>
32 #include <QToolButton>
39 TimecodeDisplay::TimecodeDisplay(Timecode t, QWidget *parent)
45 lineedit->setFont(KGlobalSettings::toolBarFont());
46 QFontMetrics fm = lineedit->fontMetrics();
47 lineedit->setMaximumWidth(fm.width("88:88:88:888"));
48 slotPrepareTimeCodeFormat(t);
49 connect(uparrow, SIGNAL(clicked()), this, SLOT(slotValueUp()));
50 connect(downarrow, SIGNAL(clicked()), this, SLOT(slotValueDown()));
51 connect(lineedit, SIGNAL(editingFinished()), this, SIGNAL(editingFinished()));
54 TimecodeDisplay::~TimecodeDisplay()
58 void TimecodeDisplay::slotValueUp()
62 if (m_maximum > -1 && val > m_maximum) val = m_maximum;
64 lineedit->clearFocus();
65 emit editingFinished();
68 void TimecodeDisplay::slotValueDown()
72 if (val < m_minimum) val = m_minimum;
74 lineedit->clearFocus();
75 emit editingFinished();
78 void TimecodeDisplay::slotPrepareTimeCodeFormat(Timecode t)
81 m_frametimecode = KdenliveSettings::frametimecode();
82 QString val = lineedit->text();
83 lineedit->setInputMask("");
84 if (m_frametimecode) {
85 int frames = m_timecode.getFrameCount(lineedit->text());
86 QIntValidator *valid = new QIntValidator(lineedit);
88 lineedit->setValidator(valid);
89 lineedit->setText(QString::number(frames));
91 int pos = lineedit->text().toInt();
92 lineedit->setValidator(m_timecode.validator());
93 lineedit->setText(m_timecode.getTimecodeFromFrames(pos));
97 void TimecodeDisplay::keyPressEvent(QKeyEvent *e)
99 if (e->key() == Qt::Key_Up) slotValueUp();
100 else if (e->key() == Qt::Key_Down) slotValueDown();
101 else QWidget::keyPressEvent(e);
104 void TimecodeDisplay::wheelEvent(QWheelEvent *e)
106 if (e->delta() > 0) slotValueUp();
107 else slotValueDown();
111 int TimecodeDisplay::maximum() const
116 int TimecodeDisplay::minimum() const
121 int TimecodeDisplay::value() const
124 if (m_frametimecode) frames = lineedit->text().toInt();
125 else frames = m_timecode.getFrameCount(lineedit->text());
129 Timecode TimecodeDisplay::timecode() const
134 void TimecodeDisplay::setRange(int min, int max)
140 void TimecodeDisplay::setValue(const QString &value)
142 if (m_frametimecode) {
143 lineedit->setText(QString::number(m_timecode.getFrameCount(value)));
144 } else lineedit->setText(value);
147 void TimecodeDisplay::setValue(int value)
149 /* if (value < m_minimum)
151 if (value > m_maximum)
153 if (m_frametimecode) lineedit->setText(QString::number(value));
154 else lineedit->setText(m_timecode.getTimecodeFromFrames(value));
156 /* setEditText(KGlobal::locale()->formatNumber(value, d->decimals));
157 d->slider->blockSignals(true);
158 d->slider->setValue(int((value - d->minimum) * 256 / (d->maximum - d->minimum) + 0.5));
159 d->slider->blockSignals(false);*/
160 //emit valueChanged(value, true);
163 #include <timecodedisplay.moc>