]> git.sesse.net Git - kdenlive/blob - src/doubleparameterwidget.cpp
Allow adding comments to bool parameters
[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
23 #include <QGridLayout>
24 #include <QLabel>
25 #include <QSlider>
26 #include <QSpinBox>
27 #include <QToolButton>
28
29 #include <KIcon>
30 #include <KLocalizedString>
31
32
33 DoubleParameterWidget::DoubleParameterWidget(const QString &name, int value, int min, int max, int defaultValue, const QString &comment, const QString suffix, QWidget *parent) :
34         QWidget(parent),
35         m_default(defaultValue)
36 {
37     QGridLayout *layout = new QGridLayout(this);
38     layout->setContentsMargins(0, 0, 0, 0);
39     layout->setSpacing(0);
40
41     m_name = new QLabel(name, this);
42     layout->addWidget(m_name, 0, 0);
43
44     m_slider = new QSlider(Qt::Horizontal, this);
45     m_slider->setRange(min, max);
46     //m_slider->setPageStep((max - min) / 10);
47     layout->addWidget(m_slider, 0, 1);
48
49     m_spinBox = new QSpinBox(this);
50     m_spinBox->setRange(min, max);
51     m_spinBox->setKeyboardTracking(false);
52     if (!suffix.isEmpty())
53         m_spinBox->setSuffix(suffix);
54     layout->addWidget(m_spinBox, 0, 2);
55
56     QToolButton *reset = new QToolButton(this);
57     reset->setAutoRaise(true);
58     reset->setIcon(KIcon("edit-undo"));
59     reset->setToolTip(i18n("Reset to default value"));
60     layout->addWidget(reset, 0, 3);
61
62     m_commentLabel = new QLabel(comment, this);
63     m_commentLabel->setWordWrap(true);
64     m_commentLabel->setTextFormat(Qt::RichText);
65     m_commentLabel->setAlignment(Qt::AlignLeft | Qt::AlignTop);
66     m_commentLabel->setFrameShape(QFrame::StyledPanel);
67     m_commentLabel->setFrameShadow(QFrame::Raised);
68     m_commentLabel->setBackgroundRole(QPalette::AlternateBase);
69     m_commentLabel->setHidden(true);
70     layout->addWidget(m_commentLabel, 1, 0, 1, -1);
71
72     connect(m_slider,  SIGNAL(valueChanged(int)), this, SLOT(setValue(int)));
73     connect(m_spinBox, SIGNAL(valueChanged(int)), this, SLOT(setValue(int)));
74     connect(reset,     SIGNAL(clicked(bool)),     this, SLOT(slotReset()));
75
76     m_spinBox->setValue(value);
77 }
78
79 void DoubleParameterWidget::setValue(int value)
80 {
81     m_slider->blockSignals(true);
82     m_spinBox->blockSignals(true);
83
84     m_slider->setValue(value);
85     m_spinBox->setValue(value);
86
87     m_slider->blockSignals(false);
88     m_spinBox->blockSignals(false);
89
90     emit valueChanged(value);
91 }
92
93 int DoubleParameterWidget::getValue()
94 {
95     return m_spinBox->value();
96 }
97
98 void DoubleParameterWidget::setName(const QString& name)
99 {
100     m_name->setText(name);
101 }
102
103 void DoubleParameterWidget::slotReset()
104 {
105     setValue(m_default);
106 }
107
108 void DoubleParameterWidget::slotShowComment( bool show)
109 {
110     if (m_commentLabel->text() != QString()) {
111         m_commentLabel->setVisible(show);
112         if (show)
113             layout()->setContentsMargins(0, 0, 0, 15);
114         else
115             layout()->setContentsMargins(0, 0, 0, 0);
116     }
117 }
118
119 #include "doubleparameterwidget.moc"