1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
18 #include "vvIntensityValueSlider.h"
20 //------------------------------------------------------------------------------
21 vvIntensityValueSlider::vvIntensityValueSlider(QWidget * parent, Qt::WindowFlags f)
22 :QWidget(parent,f), Ui::vvIntensityValueSlider()
27 mButtonPlus->setHidden(true);
28 mButtonMinus->setHidden(true);
30 // Connect signals & slots
31 connect(mSpinBox, SIGNAL(valueChanged(double)), this, SLOT(valueChangedFromSpinBox(double)));
32 connect(mSlider, SIGNAL(valueChanged(int)), this, SLOT(valueChangedFromSlider(int)));
33 connect(mButtonPlus, SIGNAL(clicked()), this, SLOT(SingleStepPlusClicked()));
34 connect(mButtonMinus, SIGNAL(clicked()), this, SLOT(SingleStepMinusClicked()));
36 //------------------------------------------------------------------------------
39 //------------------------------------------------------------------------------
40 vvIntensityValueSlider::~vvIntensityValueSlider()
43 //------------------------------------------------------------------------------
46 //------------------------------------------------------------------------------
47 void vvIntensityValueSlider::SingleStepMinusClicked()
49 mSpinBox->setSingleStep(mSpinBox->singleStep()*10);
50 mSpinBox->setDecimals(mSpinBox->decimals()-1);
52 //------------------------------------------------------------------------------
55 //------------------------------------------------------------------------------
56 void vvIntensityValueSlider::SetSingleStep(double step)
58 mSpinBox->setSingleStep(step);
60 //------------------------------------------------------------------------------
63 //------------------------------------------------------------------------------
64 void vvIntensityValueSlider::SingleStepPlusClicked()
66 mSpinBox->setSingleStep(mSpinBox->singleStep()/10);
67 mSpinBox->setDecimals(mSpinBox->decimals()+1);
69 //------------------------------------------------------------------------------
72 //------------------------------------------------------------------------------
73 void vvIntensityValueSlider::valueChangedFromSpinBox(double v)
75 if (v == mValue) return;
76 mSpinBox->setValue(v);
77 v = mSpinBox->value(); // this is needed to 'round' value according to spinBox precision
80 vv = ((v-mMin)/mWidth)/mSliderFactor;
82 mSlider->setValue(vv);
86 //------------------------------------------------------------------------------
89 //------------------------------------------------------------------------------
90 void vvIntensityValueSlider::valueChangedFromSlider(int vv)
94 v = ((double)vv*mSliderFactor)*mWidth+mMin;
99 if (mValue == v) return;
100 mSpinBox->setValue(v);
103 //------------------------------------------------------------------------------
106 //------------------------------------------------------------------------------
107 void vvIntensityValueSlider::SetText(QString t)
111 //------------------------------------------------------------------------------
114 //------------------------------------------------------------------------------
115 void vvIntensityValueSlider::SetImage(vvImage * im)
120 //------------------------------------------------------------------------------
123 //------------------------------------------------------------------------------
124 void vvIntensityValueSlider::SetValue(double v)
127 mSpinBox->setValue(v);
129 //------------------------------------------------------------------------------
132 //------------------------------------------------------------------------------
133 void vvIntensityValueSlider::SetMaximum(double max)
136 mSpinBox->setMaximum(max);
138 // If integer values : update slider max
139 if (mIsInteger == 1) {
140 mSlider->setMaximum(max);
142 double step = mWidth/1000.0;
143 mSpinBox->setSingleStep(step);
149 QString tip = QString("Min = %1 Max = %2").arg(mSpinBox->minimum()).arg(max);
152 //------------------------------------------------------------------------------
155 //------------------------------------------------------------------------------
156 void vvIntensityValueSlider::SetMinimum(double min)
159 mSpinBox->setMinimum(min);
161 if (mIsInteger == 1) {
162 mSlider->setMinimum(min);
164 double step = mWidth/1000.0;
165 mSpinBox->setSingleStep(step);
172 QString tip = QString("Min = %1 Max = %2").arg(min).arg(mSpinBox->maximum());
175 //------------------------------------------------------------------------------
178 //------------------------------------------------------------------------------
179 void vvIntensityValueSlider::Update()
182 mImage->GetFirstVTKImageData()->GetScalarRange(range);
185 double step = (mMax-mMin)/1000.0;
187 if (mImage->IsScalarTypeInteger()) {
189 mSpinBox->setSingleStep(1.0);
190 mSpinBox->setDecimals(0);
191 mSlider->setMaximum(mMax);
192 mSlider->setMinimum(mMin);
193 mSlider->setSingleStep(1);
198 mButtonPlus->setHidden(false);
199 mButtonMinus->setHidden(false);
200 mSpinBox->sizePolicy().setHorizontalPolicy(QSizePolicy::Expanding);
201 mSpinBox->setSingleStep(step);
202 mSpinBox->setDecimals(4);
203 mSlider->setMaximum(1000);
204 mSlider->setMinimum(0);
205 mSlider->setSingleStep(1);
206 mSliderFactor = 1.0/1000.0;
210 mSpinBox->setMaximum(mMax);
211 mSpinBox->setMinimum(mMin);
212 mSpinBox->setValue((mMax-mMin)/2.0+mMin);
214 QString tip = QString("Min = %1 Max = %2").arg(mMin).arg(mMax);
217 //------------------------------------------------------------------------------