Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
QmitkSliderNavigatorWidget.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
14 
15 QmitkSliderNavigatorWidget::QmitkSliderNavigatorWidget(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f)
16 {
17  this->setupUi(this);
18 
19  m_Slider->setOrientation(Qt::Horizontal);
20  m_Slider->setMinimum(0);
21  m_Slider->setMaximum(0);
22  m_Slider->setValue(0);
23  m_Slider->setSingleStep(1);
24  m_Slider->setPageStep(10);
25 
26  m_SpinBox->setMinimum( 0 );
27  m_SpinBox->setMaximum(0);
28  m_SpinBox->setValue(0);
29  m_SpinBox->setDecimals(0);
30  m_SpinBox->setSingleStep(1);
31 
32  this->connect(m_Slider, SIGNAL(valueChanged(double)), SLOT(slider_valueChanged(double)));
33  this->connect(m_SpinBox, SIGNAL(valueChanged(double)), SLOT(spinBox_valueChanged(double)));
34 
35  // this avoids trying to use m_Stepper until it is set to something != nullptr
36  // (additionally to the avoiding recursions during refetching)
37  m_InRefetch = true;
38 
39  // Hide slider labeling -- until it is explicitly activated
40  this->ShowLabels(false);
41 
42  // Set label values as invalid (N/A)
43  this->SetLabelValuesValid(false, false);
44 
45  m_HasLabels = false;
46  m_HasLabelUnit = true;
47  m_InverseDirection = false;
48  m_InvertedControls = false;
49 }
50 
52 {
53  if (!m_InRefetch)
54  {
55  m_InRefetch = true;
56 
57  if (m_Stepper->GetSteps() == 0)
58  {
59  m_Slider->setMaximum(0);
60  m_Slider->setValue(0);
61  m_SpinBox->setMaximum(0);
62  m_SpinBox->setValue(0);
63  }
64  else
65  {
66  m_Slider->setMaximum(m_Stepper->GetSteps() - 1);
68  {
69  m_Slider->setValue(m_Stepper->GetSteps() - 1 - m_Stepper->GetPos());
70  }
71  else
72  {
73  m_Slider->setValue(m_Stepper->GetPos());
74  }
75 
76  m_SpinBox->setMaximum(m_Stepper->GetSteps() - 1);
78  {
79  m_SpinBox->setValue(m_Stepper->GetSteps() - 1 - m_Stepper->GetPos());
80  }
81  else
82  {
83  m_SpinBox->setValue(m_Stepper->GetPos());
84  }
85  }
86 
87  if (m_Stepper->HasRange() && m_HasLabels)
88  {
89  // Show slider with labels according to below settings
90  m_SliderLabelLeft->setHidden(false);
91  m_SliderLabelRight->setHidden(false);
92 
93  if (m_Stepper->HasValidRange())
94  {
95  this->SetLabelValuesValid(true, true);
96  this->SetLabelValues(m_Stepper->GetRangeMin(), m_Stepper->GetRangeMax());
97  }
98  else
99  {
100  this->SetLabelValuesValid(false, false);
101  }
102 
103  if (m_Stepper->HasUnitName())
104  {
105  this->SetLabelUnit(m_Stepper->GetUnitName());
106  }
107  }
108  else
109  {
110  // Show slider without any labels
111  m_SliderLabelLeft->setHidden(true);
112  m_SliderLabelRight->setHidden(true);
113  }
114 
115  // Update GUI according to above settings
116  this->SetLabels();
117 
118  m_InRefetch = false;
119  }
120 }
121 
123 {
124  m_Stepper = stepper;
125 
126  // this avoids trying to use m_Stepper until it is set to something != nullptr
127  // (additionally to the avoiding recursions during refetching)
128  m_InRefetch = (stepper == nullptr);
129 }
130 
131 
133 {
134  if (!m_InRefetch)
135  {
136  if (m_InverseDirection)
137  {
138  m_Stepper->SetPos(m_Stepper->GetSteps() - 1 - m_Slider->value());
139  }
140  else
141  {
142  m_Stepper->SetPos(m_Slider->value());
143  }
144  this->Refetch();
145  }
146 }
147 
149 {
150  m_HasLabels = show;
151 }
152 
154 {
155  m_HasLabelUnit = show;
156 }
157 
159 {
160  m_MinValue = min;
161  m_MaxValue = max;
162 }
163 
164 void QmitkSliderNavigatorWidget::SetLabelValuesValid(bool minValid, bool maxValid)
165 {
166  m_MinValueValid = minValid;
167  m_MaxValueValid = maxValid;
168 }
169 
171 {
172  m_LabelUnit = unit;
173 }
174 
176 {
177  return m_LabelUnit;
178 }
179 
181 {
182  if (value < -10000000.0)
183  {
184  return "-INF";
185  }
186  else if (value > 10000000.0)
187  {
188  return "+INF";
189  }
190  else
191  {
192  return QString::number(value, 'f', 2);
193  }
194 }
195 
197 {
198  if (m_MinValueValid)
199  {
200  return this->ClippedValueToString(m_MinValue);
201  }
202  else
203  {
204  return "N/A";
205  }
206 }
207 
209 {
210  if (m_MaxValueValid)
211  {
212  return this->ClippedValueToString(m_MaxValue);
213  }
214  else
215  {
216  return "N/A";
217  }
218 }
219 
221 {
222  QString minText = "<p align='center'><font size='2'>" + this->GetMinValueLabel();
223 
224  QString maxText = "<p align='center'><font size='2'>" + this->GetMaxValueLabel();
225 
226  if (m_HasLabelUnit)
227  {
228  minText += "&nbsp;" + this->GetLabelUnit();
229  maxText += "&nbsp;" + this->GetLabelUnit();
230  }
231 
232  if (m_MinValueValid)
233  {
234  minText += "<br>(pos&nbsp;0)";
235  }
236 
237  if (m_MaxValueValid)
238  {
239  maxText += "<br>(pos&nbsp;" + QString::number(m_Stepper->GetSteps() - 1) + ")";
240  }
241 
242  minText += "</font></p>";
243  maxText += "</font></p>";
244 
245  m_SliderLabelLeft->setText(minText);
246  m_SliderLabelRight->setText(maxText);
247 }
248 
250 {
251  if (!m_InRefetch)
252  {
253  if (m_InverseDirection)
254  {
255  m_Stepper->SetPos(m_Stepper->GetSteps() - 1 - m_SpinBox->value());
256  }
257  else
258  {
259  m_Stepper->SetPos(m_SpinBox->value());
260  }
261  this->Refetch();
262  }
263 }
264 
266 {
267  return m_Stepper->GetPos();
268 }
269 
271 {
272  if (!m_InRefetch)
273  {
274  m_Stepper->SetPos(val);
275  }
276 }
277 
279 {
280  return m_InverseDirection;
281 }
282 
284 {
285  if (inverseDirection != m_InverseDirection)
286  {
287  m_InverseDirection = inverseDirection;
288  this->Refetch();
289  }
290 }
291 
293 {
294  return m_InvertedControls;
295 }
296 
298 {
299  if (invertedControls != m_InvertedControls)
300  {
301  m_InvertedControls = invertedControls;
302  m_Slider->setInvertedAppearance(invertedControls);
303  m_Slider->setInvertedControls(invertedControls);
304  m_SpinBox->setInvertedControls(invertedControls);
305  }
306 }
307 
void SetInverseDirection(bool inverseDirection)
void SetStepper(mitk::Stepper *stepper)
void SetLabels()
Configure slider with labels according to range and unit settings.
void SetLabelValuesValid(bool minValid, bool maxValid)
void Refetch()
Updates the slider with the recent changes applied to the navigator.
QString ClippedValueToString(float value)
Converts the passed value to a QString representation.
QmitkSliderNavigatorWidget(QWidget *parent=nullptr, Qt::WindowFlags f=nullptr)
static T max(T x, T y)
Definition: svm.cpp:56
QString GetMinValueLabel()
Returns range-minimum (displayed as label left of slider if enabled)
void SetLabelValues(float min, float max)
Set range minimum and maximum (displayed as labels left and right of slider if enabled) ...
void SetInvertedControls(bool invertedControls)
static T min(T x, T y)
Definition: svm.cpp:53
Helper class to step through a list.
Definition: mitkStepper.h:47
void SetLabelUnit(const char *unit)
Set range unit (e.g. mm or ms) which will be displayed below range labels if enabled.
void ShowLabelUnit(bool show)
En-/disables displaying of the unit label (range will be displayed without unit if enabled)...