]> git.sesse.net Git - kdenlive/blob - src/positionedit.cpp
Fix label
[kdenlive] / src / positionedit.cpp
1 /***************************************************************************
2                           positionedit.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 "timecodedisplay.h"
20 #include "kdenlivesettings.h"
21
22 #include <KDebug>
23
24 #include <QLabel>
25 #include <QSlider>
26 #include <QHBoxLayout>
27
28 PositionEdit::PositionEdit(const QString &name, int pos, int min, int max, const Timecode&tc, QWidget* parent) :
29     QWidget(parent)
30 {
31     QHBoxLayout *layout = new QHBoxLayout(this);
32
33     QLabel *label = new QLabel(name, this);
34
35     m_slider = new QSlider(Qt::Horizontal);
36     m_slider->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred));
37     m_slider->setRange(min, max);
38
39     m_display = new TimecodeDisplay(tc, this);
40     m_display->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred));
41     m_display->setRange(min, max);
42
43     layout->addWidget(label);
44     layout->addWidget(m_slider);
45     layout->addWidget(m_display);
46
47     connect(m_slider, SIGNAL(valueChanged(int)), m_display, SLOT(setValue(int)));
48     connect(m_slider, SIGNAL(valueChanged(int)), this, SIGNAL(parameterChanged(int)));
49     connect(m_display, SIGNAL(timeCodeEditingFinished()), this, SLOT(slotUpdatePosition()));
50     m_slider->setValue(pos);
51 }
52
53 PositionEdit::~PositionEdit()
54 {
55     m_display->blockSignals(true);
56     m_slider->blockSignals(true);
57     delete m_slider;
58     delete m_display;
59 }
60
61 void PositionEdit::updateTimecodeFormat()
62 {
63     m_display->slotUpdateTimeCodeFormat();
64 }
65
66 int PositionEdit::getPosition() const
67 {
68     return m_slider->value();
69 }
70
71 void PositionEdit::setPosition(int pos)
72 {
73     m_slider->setValue(pos);
74 }
75
76 void PositionEdit::slotUpdatePosition()
77 {
78     m_slider->blockSignals(true);
79     m_slider->setValue(m_display->getValue());
80     m_slider->blockSignals(false);
81     emit parameterChanged(m_display->getValue());
82 }
83
84 void PositionEdit::setRange(int min, int max, bool absolute)
85 {
86     if (absolute) {
87         m_slider->setRange(min, max);
88         m_display->setRange(min, max);
89     } else {
90         m_slider->setRange(0, max - min);
91         m_display->setRange(0, max - min);
92     }
93 }
94
95 #include "positionedit.moc"