00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <qhbox.h>
00023 #include <qlayout.h>
00024 #include <qslider.h>
00025
00026 #include <knuminput.h>
00027
00028 #include "kis_double_widget.h"
00029
00030 KisDoubleWidget::KisDoubleWidget(QWidget* parent, const char* name)
00031 : super(parent, name)
00032 {
00033 init(0, 1);
00034 }
00035
00036 KisDoubleWidget::KisDoubleWidget(double min, double max, QWidget* parent, const char* name)
00037 : super(parent, name)
00038 {
00039 init(min, max);
00040 }
00041
00042 KisDoubleWidget::~KisDoubleWidget()
00043 {
00044 }
00045
00046 void KisDoubleWidget::init(double min, double max)
00047 {
00048 m_spinBox = new KDoubleSpinBox(min, max, 0.05, 0, 2, this, "spinbox");
00049 connect(m_spinBox, SIGNAL(valueChanged(double)), this, SLOT(setSliderValue(double)));
00050
00051 m_slider = new QSlider(static_cast<int>(min * 100 + 0.5), static_cast<int>(max * 100 + 0.5), 1, 0, QSlider::Horizontal, this, "sld");
00052 connect(m_slider, SIGNAL(valueChanged(int)), this, SLOT(sliderValueChanged(int)));
00053 connect(m_slider, SIGNAL(sliderPressed()), SIGNAL(sliderPressed()));
00054 connect(m_slider, SIGNAL(sliderReleased()), SIGNAL(sliderReleased()));
00055
00056 m_layout = new QHBoxLayout(this, 0, -1, "hbox layout");
00057
00058 m_layout->addWidget(m_slider);
00059 m_layout->addSpacing(5);
00060 m_layout->addWidget(m_spinBox);
00061 m_layout->addItem(new QSpacerItem(5,1,QSizePolicy::Expanding, QSizePolicy::Minimum));
00062 }
00063
00064 double KisDoubleWidget::value() const
00065 {
00066 return m_spinBox->value();
00067 }
00068
00069 void KisDoubleWidget::setValue(double value)
00070 {
00071 int intValue;
00072
00073 if (value < 0) {
00074 intValue = static_cast<int>(value * 100 - 0.5);
00075 } else {
00076 intValue = static_cast<int>(value * 100 + 0.5);
00077 }
00078 m_slider->setValue(intValue);
00079 }
00080
00081 void KisDoubleWidget::setRange(double min, double max)
00082 {
00083 m_spinBox->setRange(min, max);
00084 m_slider->setRange(static_cast<int>(min * 100 + 0.5), static_cast<int>(max * 100 + 0.5));
00085 }
00086
00087 void KisDoubleWidget::setTickmarks(QSlider::TickSetting tickSetting)
00088 {
00089 m_slider->setTickmarks(tickSetting);
00090 }
00091
00092 void KisDoubleWidget::setTickInterval(double value)
00093 {
00094 m_slider->setTickInterval(static_cast<int>(value * 100 + 0.5));
00095 }
00096
00097 double KisDoubleWidget::tickInterval() const
00098 {
00099 return m_slider->tickInterval() / 100.0;
00100 }
00101
00102 void KisDoubleWidget::setSliderValue(double value)
00103 {
00104 int intValue;
00105
00106 if (value < 0) {
00107 intValue = static_cast<int>(value * 100 - 0.5);
00108 } else {
00109 intValue = static_cast<int>(value * 100 + 0.5);
00110 }
00111 m_slider->setValue(intValue);
00112 emit valueChanged(value);
00113 }
00114
00115 void KisDoubleWidget::sliderValueChanged(int value)
00116 {
00117 m_spinBox->setValue(value / 100.0);
00118 }
00119
00120 void KisDoubleWidget::setPrecision(int precision)
00121 {
00122 m_spinBox->setPrecision(precision);
00123 }
00124
00125 void KisDoubleWidget::setLineStep(double step)
00126 {
00127 m_spinBox->setLineStep(step);
00128 m_slider->setLineStep(static_cast<int>(step * 100));
00129 }
00130
00131 void KisDoubleWidget::setPageStep(double step)
00132 {
00133 m_slider->setPageStep(static_cast<int>(step * 100));
00134 }
00135
00136 void KisDoubleWidget::setTracking(bool tracking)
00137 {
00138 m_slider->setTracking(tracking);
00139 }
00140
00141 bool KisDoubleWidget::tracking() const
00142 {
00143 return m_slider->tracking();
00144 }
00145
00146 #include "kis_double_widget.moc"
00147