]> git.sesse.net Git - kdenlive/blob - src/doubleparameterwidget.cpp
Merge branch 'master' into effectstack
[kdenlive] / src / doubleparameterwidget.cpp
1 /**************************************************************************
2  *   Copyright (C) 2010 by Till Theato (root@ttill.de)                     *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
18  ***************************************************************************/
19
20
21 #include "doubleparameterwidget.h"
22 #include "dragvalue.h"
23
24 #include <QGridLayout>
25 #include <QLabel>
26 #include <QSpinBox>
27 #include <QToolButton>
28
29 #include <KDebug>
30 #include <KIcon>
31 #include <KLocalizedString>
32
33
34 DoubleParameterWidget::DoubleParameterWidget(const QString &name, double value, double min, double max, double defaultValue, const QString &comment, int id, const QString suffix, int decimals, QWidget *parent) :
35         QWidget(parent),
36         m_commentLabel(NULL)
37 {
38     setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);
39     QGridLayout *layout = new QGridLayout(this);
40     layout->setContentsMargins(0, 0, 0, 0);
41     layout->setSpacing(0);
42     
43     m_dragVal = new DragValue(name, defaultValue, decimals, min, max, id, suffix, this);
44     layout->addWidget(m_dragVal, 0, 1);
45
46     if (!comment.isEmpty()) {
47         m_commentLabel = new QLabel(comment, this);
48         m_commentLabel->setWordWrap(true);
49         m_commentLabel->setTextFormat(Qt::RichText);
50         m_commentLabel->setAlignment(Qt::AlignLeft | Qt::AlignTop);
51         m_commentLabel->setFrameShape(QFrame::StyledPanel);
52         m_commentLabel->setFrameShadow(QFrame::Raised);
53         m_commentLabel->setHidden(true);
54         layout->addWidget(m_commentLabel, 1, 0, 1, -1);
55     }
56     m_dragVal->setValue(value);
57     connect(m_dragVal, SIGNAL(valueChanged(double, bool)), this, SLOT(slotSetValue(double, bool)));
58     connect(m_dragVal, SIGNAL(inTimeline(int)), this, SIGNAL(setInTimeline(int)));
59 }
60
61 DoubleParameterWidget::~DoubleParameterWidget()
62 {
63     delete m_dragVal;
64     if (m_commentLabel) delete m_commentLabel;
65 }
66
67 int DoubleParameterWidget::spinSize()
68 {
69     return m_dragVal->spinSize();
70 }
71
72 void DoubleParameterWidget::setSpinSize(int width)
73 {
74     m_dragVal->setSpinSize(width);
75 }
76
77 void DoubleParameterWidget::setValue(double value)
78 {
79     m_dragVal->blockSignals(true);
80     m_dragVal->setValue(value);
81     m_dragVal->blockSignals(false);
82 }
83
84 void DoubleParameterWidget::slotSetValue(double value, bool final)
85 {
86     if (final) {
87         emit valueChanged(value);
88     }
89 }
90
91 double DoubleParameterWidget::getValue()
92 {
93     return m_dragVal->value();
94 }
95
96 void DoubleParameterWidget::slotReset()
97 {
98     m_dragVal->slotReset();
99 }
100
101 void DoubleParameterWidget::setInTimelineProperty(bool intimeline)
102 {
103     m_dragVal->setInTimelineProperty(intimeline);
104 }
105
106 void DoubleParameterWidget::slotShowComment( bool show)
107 {
108     if (m_commentLabel) {
109         m_commentLabel->setVisible(show);
110         if (show)
111             layout()->setContentsMargins(0, 0, 0, 15);
112         else
113             layout()->setContentsMargins(0, 0, 0, 0);
114     }
115 }
116
117 #include "doubleparameterwidget.moc"