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"
22 #include "dragvalue.h"
24 #include <QGridLayout>
28 #include <QToolButton>
31 #include <KLocalizedString>
34 DoubleParameterWidget::DoubleParameterWidget(const QString &name, int value, int min, int max, int defaultValue, const QString &comment, const QString suffix, QWidget *parent) :
36 m_default(defaultValue)
38 QGridLayout *layout = new QGridLayout(this);
39 layout->setContentsMargins(0, 0, 0, 0);
40 layout->setSpacing(0);
42 m_name = new QLabel(name, this);
43 layout->addWidget(m_name, 0, 0);
45 m_slider = new QSlider(Qt::Horizontal, this);
46 m_slider->setRange(min, max);
47 //m_slider->setPageStep((max - min) / 10);
48 layout->addWidget(m_slider, 0, 1);
50 m_dragVal = new DragValue(this);
51 m_dragVal->setRange(min, max);
52 m_dragVal->setPrecision(0);
53 layout->addWidget(m_dragVal, 0, 2);
55 m_spinBox = new QSpinBox(this);
56 m_spinBox->setRange(min, max);
57 m_spinBox->setKeyboardTracking(false);
58 if (!suffix.isEmpty())
59 m_spinBox->setSuffix(suffix);
60 //layout->addWidget(m_spinBox, 0, 2);
61 m_spinBox->setHidden(true);
63 QToolButton *reset = new QToolButton(this);
64 reset->setAutoRaise(true);
65 reset->setIcon(KIcon("edit-undo"));
66 reset->setToolTip(i18n("Reset to default value"));
67 layout->addWidget(reset, 0, 3);
69 m_commentLabel = new QLabel(comment, this);
70 m_commentLabel->setWordWrap(true);
71 m_commentLabel->setTextFormat(Qt::RichText);
72 m_commentLabel->setAlignment(Qt::AlignLeft | Qt::AlignTop);
73 m_commentLabel->setFrameShape(QFrame::StyledPanel);
74 m_commentLabel->setFrameShadow(QFrame::Raised);
75 m_commentLabel->setHidden(true);
76 layout->addWidget(m_commentLabel, 1, 0, 1, -1);
78 connect(m_slider, SIGNAL(valueChanged(int)), this, SLOT(setValue(int)));
79 connect(m_dragVal, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotSetValue(qreal, bool)));
80 connect(m_spinBox, SIGNAL(valueChanged(int)), this, SLOT(setValue(int)));
81 connect(reset, SIGNAL(clicked(bool)), this, SLOT(slotReset()));
83 //m_spinBox->setValue(value);
84 m_dragVal->setValue(value);
87 void DoubleParameterWidget::setValue(int value)
89 m_slider->blockSignals(true);
90 m_spinBox->blockSignals(true);
91 m_dragVal->blockSignals(true);
93 m_slider->setValue(value);
94 m_spinBox->setValue(value);
95 m_dragVal->setValue(value);
97 m_slider->blockSignals(false);
98 m_spinBox->blockSignals(false);
99 m_dragVal->blockSignals(false);
101 emit valueChanged(value);
104 void DoubleParameterWidget::slotSetValue(qreal value, bool final)
107 setValue((int)value);
110 int DoubleParameterWidget::getValue()
112 return m_spinBox->value();
115 void DoubleParameterWidget::setName(const QString& name)
117 m_name->setText(name);
120 void DoubleParameterWidget::slotReset()
125 void DoubleParameterWidget::slotShowComment( bool show)
127 if (m_commentLabel->text() != QString()) {
128 m_commentLabel->setVisible(show);
130 layout()->setContentsMargins(0, 0, 0, 15);
132 layout()->setContentsMargins(0, 0, 0, 0);
136 #include "doubleparameterwidget.moc"