positionedit.cpp 2.95 KB
Newer Older
1
/***************************************************************************
Vincent PINON's avatar
Vincent PINON committed
2
                          positionedit.cpp  -  description
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
                             -------------------
    begin                : 03 Aug 2008
    copyright            : (C) 2008 by Marco Gittler
    email                : g.marco@freenet.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

Vincent PINON's avatar
Vincent PINON committed
18 19
#include "positionedit.h"

Till Theato's avatar
Till Theato committed
20
#include "timecodedisplay.h"
21 22
#include "kdenlivesettings.h"

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
23
#include <QDebug>
24

25 26
#include <QLabel>
#include <QSlider>
27
#include <QHBoxLayout>
28

Laurent Montel's avatar
Laurent Montel committed
29
PositionEdit::PositionEdit(const QString &name, int pos, int min, int max, const Timecode&tc, QWidget* parent) :
Laurent Montel's avatar
Laurent Montel committed
30
    QWidget(parent)
31
{
Till Theato's avatar
Till Theato committed
32 33 34
    QHBoxLayout *layout = new QHBoxLayout(this);

    QLabel *label = new QLabel(name, this);
35 36 37

    m_slider = new QSlider(Qt::Horizontal);
    m_slider->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred));
Till Theato's avatar
Till Theato committed
38 39 40
    m_slider->setRange(min, max);

    m_display = new TimecodeDisplay(tc, this);
41 42
    m_display->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred));
    m_display->setRange(min, max);
Till Theato's avatar
Till Theato committed
43 44 45 46 47

    layout->addWidget(label);
    layout->addWidget(m_slider);
    layout->addWidget(m_display);

48
    connect(m_slider, SIGNAL(valueChanged(int)), m_display, SLOT(setValue(int)));
49
    connect(m_slider, SIGNAL(valueChanged(int)), this, SIGNAL(parameterChanged(int)));
50
    connect(m_display, SIGNAL(timeCodeEditingFinished()), this, SLOT(slotUpdatePosition()));
51
    m_slider->setValue(pos);
52 53
}

54
PositionEdit::~PositionEdit()
55
{
56 57 58 59
    m_display->blockSignals(true);
    m_slider->blockSignals(true);
    delete m_slider;
    delete m_display;
60 61
}

62
void PositionEdit::updateTimecodeFormat()
63
{
Till Theato's avatar
Till Theato committed
64
    m_display->slotUpdateTimeCodeFormat();
65 66
}

67
int PositionEdit::getPosition() const
68
{
69
    return m_slider->value();
70 71
}

72 73 74 75 76
void PositionEdit::setPosition(int pos)
{
    m_slider->setValue(pos);
}

77 78
void PositionEdit::slotUpdatePosition()
{
79
    m_slider->blockSignals(true);
80
    m_slider->setValue(m_display->getValue());
81
    m_slider->blockSignals(false);
82 83 84
    emit parameterChanged(m_display->getValue());
}

85
void PositionEdit::setRange(int min, int max, bool absolute)
86
{
87
    if (absolute) {
Laurent Montel's avatar
Laurent Montel committed
88 89
        m_slider->setRange(min, max);
        m_display->setRange(min, max);
90
    } else {
Laurent Montel's avatar
Laurent Montel committed
91 92
        m_slider->setRange(0, max - min);
        m_display->setRange(0, max - min);
93
    }
94 95
}

96