Fraxinus  17.12-rc2
An IGT application
cxDoubleWidgets.h
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 
34 #ifndef CXDOUBLEWIDGETS_H_
35 #define CXDOUBLEWIDGETS_H_
36 
37 #include "cxResourceWidgetsExport.h"
38 
39 #include <QWidget>
40 #include <QSlider>
41 #include <QLineEdit>
42 #include <QDoubleSpinBox>
43 #include <QLabel>
44 #include <QGridLayout>
45 #include <QDial>
46 
47 #include "cxDoubleRange.h"
48 #include "cxDoublePropertyBase.h"
50 
51 namespace cx
52 {
53 class MousePadWidget;
54 
61 class cxResourceWidgets_EXPORT DoubleSlider: public QSlider
62 {
63 Q_OBJECT
64 
65 public:
66  virtual ~DoubleSlider()
67  {
68  }
69  DoubleSlider(QWidget* parent = 0) :
70  QSlider(parent)
71  {
72  connect(this, SIGNAL(valueChanged(int)), this, SLOT(valueChangedSlot(int)));
73  setDoubleRange(DoubleRange(0, 1, 0.1));
74  }
75  void setDoubleRange(const DoubleRange& range)
76  {
77  mRange = range;
78  setRange(0, mRange.resolution());
79  setSingleStep(mRange.step());
80  }
81  void setDoubleValue(double val)
82  {
83  int v_i = (val - mRange.min()) / mRange.step();
84  setValue(v_i);
85  }
86  double getDoubleValue() const
87  {
88  double v_d = mRange.step() * (double) value() + mRange.min();
89  return v_d;
90  }
91  void setDoubleTickInterval(double interval)
92  {
93  setTickInterval(interval / mRange.step());
94  }
95 
96 signals:
97  void doubleValueChanged(double value);
98 
99 private slots:
100  void valueChangedSlot(int val)
101  {
102  emit doubleValueChanged(getDoubleValue());
103  }
104 
105 private:
106  DoubleRange mRange;
107 };
108 
113 class cxResourceWidgets_EXPORT DoubleLineEdit: public QLineEdit
114 {
115 public:
116  DoubleLineEdit(QWidget* parent = 0) :
117  QLineEdit(parent)
118  {
119  }
120  virtual QSize sizeHint() const;
121  virtual QSize minimumSizeHint() const;
122  double getDoubleValue(double defVal = 0.0) const
123  {
124  bool ok;
125  double newVal = this->text().toDouble(&ok);
126  if (!ok)
127  return defVal;
128  return newVal;
129  }
130  void setDoubleValue(double val)
131  {
132  this->setText(QString::number(val, 'g', 4));
133  }
134 };
135 
147 class cxResourceWidgets_EXPORT ScalarInteractionWidget: public OptimizedUpdateWidget
148 {
149 Q_OBJECT
150 public:
152 
153  void enableLabel();
154  void enableSlider();
155  void enableDial();
156  void enableEdit();
157  void enableSpinBox();
158  void enableInfiniteSlider();
159 
160  void addToOwnLayout();
161  void addToGridLayout(QGridLayout* gridLayout = 0, int row = 0);
162  void build(QGridLayout* gridLayout = 0, int row = 0);
163 
164  void showLabel(bool on);
165 
166 private slots:
167  void textEditedSlot();
168  void doubleValueChanged(double val);
169  void intValueChanged(int val); //expecting a value that is 100 times as big as the double value (because QDial uses ints, not double, we scale)
170  void infiniteSliderMouseMoved(QPointF delta);
171 
172 protected:
173  virtual void prePaintEvent();
175 
176 private:
177  void enableAll(bool);
178 
179  DoubleSlider* mSlider;
180  QDial* mDial;
181  QDoubleSpinBox* mSpinBox;
182  QLabel* mLabel;
183  DoubleLineEdit* mEdit;
184  MousePadWidget* mInfiniteSlider;
185 };
186 
194 class cxResourceWidgets_EXPORT SliderGroupWidget: public ScalarInteractionWidget
195 {
196 Q_OBJECT
197 public:
198  SliderGroupWidget(QWidget* parent, DoublePropertyBasePtr, QGridLayout* gridLayout = 0, int row = 0);
199 };
200 
210 class cxResourceWidgets_EXPORT SpinBoxGroupWidget: public ScalarInteractionWidget
211 {
212 Q_OBJECT
213 public:
214  SpinBoxGroupWidget(QWidget* parent, DoublePropertyBasePtr, QGridLayout* gridLayout = 0, int row = 0);
215 };
216 
226 class cxResourceWidgets_EXPORT SpinBoxAndSliderGroupWidget: public ScalarInteractionWidget
227 {
228 Q_OBJECT
229 public:
230  SpinBoxAndSliderGroupWidget(QWidget* parent, DoublePropertyBasePtr, QGridLayout* gridLayout = 0, int row = 0);
231 };
232 typedef boost::shared_ptr<SpinBoxAndSliderGroupWidget> SpinBoxAndSliderGroupWidgetPtr;
233 
243 class cxResourceWidgets_EXPORT SpinBoxAndDialGroupWidget: public ScalarInteractionWidget
244 {
245 Q_OBJECT
246 public:
247 SpinBoxAndDialGroupWidget(QWidget* parent, DoublePropertyBasePtr, QGridLayout* gridLayout = 0, int row = 0);
248 };
249 typedef boost::shared_ptr<SpinBoxAndDialGroupWidget> SpinBoxAndDialGroupWidgetPtr;
250 
251 
261 class cxResourceWidgets_EXPORT SpinBoxInfiniteSliderGroupWidget: public ScalarInteractionWidget
262 {
263 Q_OBJECT
264 public:
265  SpinBoxInfiniteSliderGroupWidget(QWidget* parent, DoublePropertyBasePtr, QGridLayout* gridLayout = 0, int row = 0);
266 };
267 
268 } //namespace cx
269 
270 
271 #endif /* CXDOUBLEWIDGETS_H_ */
double getDoubleValue() const
void setDoubleValue(double val)
Composite widget for scalar data manipulation.
boost::shared_ptr< SpinBoxAndSliderGroupWidget > SpinBoxAndSliderGroupWidgetPtr
Utility class for describing a bounded numeric range.
Definition: cxDoubleRange.h:53
DoublePropertyBasePtr mData
virtual ~DoubleSlider()
A touchpad-friendly area for performing 1D/2D scroll operations.
Composite widget for scalar data manipulation.
boost::shared_ptr< SpinBoxAndDialGroupWidget > SpinBoxAndDialGroupWidgetPtr
double getDoubleValue(double defVal=0.0) const
Composite widget for scalar data manipulation.
void setDoubleRange(const DoubleRange &range)
DoubleSlider(QWidget *parent=0)
Custom widget for display of double-valued data.
boost::shared_ptr< class DoublePropertyBase > DoublePropertyBasePtr
A QLineEdit specialized to deal with double data.
void setDoubleValue(double val)
Composite widget for scalar data manipulation.
Interface for all classes following the modified/prepaint paradigm.
Composite widget for scalar data manipulation.
Composite widget for scalar data manipulation.
void setDoubleTickInterval(double interval)
DoubleLineEdit(QWidget *parent=0)
Namespace for all CustusX production code.