]> git.sesse.net Git - kdenlive/blob - src/positionedit.cpp
Fix compilation with Qt < 4.6:
[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         m_frameDisplay(KdenliveSettings::frametimecode())
27 {
28     m_ui.setupUi(this);
29     m_ui.label->setText(name);
30     m_ui.horizontalSlider->setRange(min, max);
31     connect(m_ui.horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateTimecode()));
32     connect(m_ui.krestrictedline, SIGNAL(editingFinished()), this, SLOT(slotUpdatePosition()));
33     m_ui.horizontalSlider->setValue(pos);
34     if (m_frameDisplay) {
35         QValidator *valid = new QIntValidator(this);
36         m_ui.krestrictedline->setInputMask("");
37         m_ui.krestrictedline->setValidator(valid);
38     }
39     m_ui.krestrictedline->setText(m_tc.getDisplayTimecodeFromFrames(pos, m_frameDisplay));
40 }
41
42 int PositionEdit::getPosition() const
43 {
44     return m_ui.horizontalSlider->value();
45 }
46
47 void PositionEdit::setPosition(int pos)
48 {
49     m_ui.horizontalSlider->setValue(pos);
50     m_ui.krestrictedline->setText(m_tc.getDisplayTimecodeFromFrames(pos, m_frameDisplay));
51 }
52
53 void PositionEdit::slotUpdateTimecode()
54 {
55     m_ui.krestrictedline->setText(m_tc.getDisplayTimecodeFromFrames(m_ui.horizontalSlider->value(), m_frameDisplay));
56     emit parameterChanged();
57 }
58
59 void PositionEdit::slotUpdatePosition()
60 {
61     m_ui.horizontalSlider->blockSignals(true);
62     int pos = m_tc.getDisplayFrameCount(m_ui.krestrictedline->text(), m_frameDisplay);
63     m_ui.horizontalSlider->setValue(pos);
64     if (pos != m_ui.horizontalSlider->value()) {
65         // Value out of range
66         m_ui.krestrictedline->setText(m_tc.getDisplayTimecodeFromFrames(m_ui.horizontalSlider->value(), m_frameDisplay));
67     }
68     m_ui.horizontalSlider->blockSignals(false);
69     emit parameterChanged();
70 }
71