]> git.sesse.net Git - kdenlive/blob - src/positionedit.cpp
When user wants to display timecode in frames, use frames for all timecode display...
[kdenlive] / src / positionedit.cpp
1 /***************************************************************************
2                           geomeytrval.cpp  -  description
3                              -------------------
4     begin                : 03 Aug 2008
5     copyright            : (C) 2008 by Marco Gittler
6     email                : g.marco@freenet.de
7  ***************************************************************************/
8
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17
18 #include "positionedit.h"
19 #include "kdenlivesettings.h"
20
21 #include <KDebug>
22
23 PositionEdit::PositionEdit(const QString name, int pos, int min, int max, const Timecode tc, QWidget* parent) :
24         QWidget(parent),
25         m_tc(tc)
26 {
27     m_ui.setupUi(this);
28     m_ui.label->setText(name);
29     m_ui.horizontalSlider->setRange(min, max);
30     connect(m_ui.horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateTimecode()));
31     connect(m_ui.krestrictedline, SIGNAL(editingFinished()), this, SLOT(slotUpdatePosition()));
32     m_ui.horizontalSlider->setValue(pos);
33     if (KdenliveSettings::frametimecode()) {
34         m_ui.krestrictedline->setInputMask("000000000000");
35         m_ui.krestrictedline->setText(QString::number(pos));
36     } else m_ui.krestrictedline->setText(m_tc.getTimecodeFromFrames(pos));
37 }
38
39 int PositionEdit::getPosition() const
40 {
41     return m_ui.horizontalSlider->value();
42 }
43
44 void PositionEdit::setPosition(int pos)
45 {
46     m_ui.horizontalSlider->setValue(pos);
47     if (KdenliveSettings::frametimecode()) m_ui.krestrictedline->setText(QString::number(pos));
48     else m_ui.krestrictedline->setText(m_tc.getTimecodeFromFrames(pos));
49 }
50
51 void PositionEdit::slotUpdateTimecode()
52 {
53     if (KdenliveSettings::frametimecode()) m_ui.krestrictedline->setText(QString::number(m_ui.horizontalSlider->value()));
54     else m_ui.krestrictedline->setText(m_tc.getTimecodeFromFrames(m_ui.horizontalSlider->value()));
55     emit parameterChanged();
56 }
57
58 void PositionEdit::slotUpdatePosition()
59 {
60     m_ui.horizontalSlider->blockSignals(true);
61     int pos;
62     if (KdenliveSettings::frametimecode()) pos = m_ui.krestrictedline->text().toInt();
63     else pos = m_tc.getFrameCount(m_ui.krestrictedline->text());
64     m_ui.horizontalSlider->setValue(pos);
65     if (pos != m_ui.horizontalSlider->value()) {
66         // Value out of range
67         if (KdenliveSettings::frametimecode()) m_ui.krestrictedline->setText(QString::number(m_ui.horizontalSlider->value()));
68         else m_ui.krestrictedline->setText(m_tc.getTimecodeFromFrames(m_ui.horizontalSlider->value()));
69     }
70     m_ui.horizontalSlider->blockSignals(false);
71     emit parameterChanged();
72 }
73