]> git.sesse.net Git - kdenlive/blob - src/positionedit.cpp
New improved widget for position parameter in effects (for example with fade effects)
[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     m_ui.krestrictedline->setText(m_tc.getTimecodeFromFrames(pos));
34 }
35
36 int PositionEdit::getPosition() const
37 {
38     return m_ui.horizontalSlider->value();
39 }
40
41 void PositionEdit::setPosition(int pos)
42 {
43     m_ui.horizontalSlider->setValue(pos);
44     m_ui.krestrictedline->setText(m_tc.getTimecodeFromFrames(pos));
45 }
46
47 void PositionEdit::slotUpdateTimecode()
48 {
49     m_ui.krestrictedline->setText(m_tc.getTimecodeFromFrames(m_ui.horizontalSlider->value()));
50     emit parameterChanged();
51 }
52
53 void PositionEdit::slotUpdatePosition()
54 {
55     m_ui.horizontalSlider->blockSignals(true);
56     int pos = m_tc.getFrameCount(m_ui.krestrictedline->text(), KdenliveSettings::project_fps());
57     m_ui.horizontalSlider->setValue(pos);
58     if (pos != m_ui.horizontalSlider->value()) {
59         // Value out of range
60         m_ui.krestrictedline->setText(m_tc.getTimecodeFromFrames(m_ui.horizontalSlider->value()));
61     }
62     m_ui.horizontalSlider->blockSignals(false);
63     emit parameterChanged();
64 }
65