1 /***************************************************************************
2 * Copyright (C) 2010 by Till Theato (root@ttill.de) *
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. *
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. *
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 ***************************************************************************/
21 #include "doubleparameterwidget.h"
23 #include <QHBoxLayout>
27 #include <QToolButton>
30 #include <KLocalizedString>
33 DoubleParameterWidget::DoubleParameterWidget(const QString &name, int value, int min, int max, int defaultValue, const QString suffix, QWidget *parent) :
35 m_default(defaultValue)
37 QHBoxLayout *layout = new QHBoxLayout(this);
38 layout->setContentsMargins(0, 0, 0, 0);
40 m_name = new QLabel(name, this);
41 layout->addWidget(m_name);
43 m_slider = new QSlider(Qt::Horizontal, this);
44 m_slider->setRange(min, max);
45 //m_slider->setPageStep((max - min) / 10);
46 layout->addWidget(m_slider);
48 m_spinBox = new QSpinBox(this);
49 m_spinBox->setRange(min, max);
50 m_spinBox->setKeyboardTracking(false);
51 if (!suffix.isEmpty())
52 m_spinBox->setSuffix(suffix);
53 layout->addWidget(m_spinBox);
55 QToolButton *reset = new QToolButton(this);
56 reset->setAutoRaise(true);
57 reset->setIcon(KIcon("edit-undo"));
58 reset->setToolTip(i18n("Reset to default value"));
59 layout->addWidget(reset);
61 connect(m_slider, SIGNAL(valueChanged(int)), this, SLOT(setValue(int)));
62 connect(m_spinBox, SIGNAL(valueChanged(int)), this, SLOT(setValue(int)));
63 connect(reset, SIGNAL(clicked(bool)), this, SLOT(slotReset()));
65 m_spinBox->setValue(value);
68 void DoubleParameterWidget::setValue(int value)
70 m_slider->blockSignals(true);
71 m_spinBox->blockSignals(true);
73 m_slider->setValue(value);
74 m_spinBox->setValue(value);
76 m_slider->blockSignals(false);
77 m_spinBox->blockSignals(false);
79 emit valueChanged(value);
82 int DoubleParameterWidget::getValue()
84 return m_spinBox->value();
87 void DoubleParameterWidget::setName(const QString& name)
89 m_name->setText(name);
92 void DoubleParameterWidget::slotReset()
97 #include "doubleparameterwidget.moc"