CustusX  2023.01.05-dev+develop.0da12
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) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 
13 #ifndef CXDOUBLEWIDGETS_H_
14 #define CXDOUBLEWIDGETS_H_
15 
16 #include "cxResourceWidgetsExport.h"
17 
18 #include <QWidget>
19 #include <QSlider>
20 #include <QLineEdit>
21 #include <QDoubleSpinBox>
22 #include <QLabel>
23 #include <QGridLayout>
24 #include <QDial>
25 
26 #include "cxDoubleRange.h"
27 #include "cxDoublePropertyBase.h"
29 
30 namespace cx
31 {
32 class MousePadWidget;
33 
40 class cxResourceWidgets_EXPORT DoubleSlider: public QSlider
41 {
42 Q_OBJECT
43 
44 public:
45  virtual ~DoubleSlider()
46  {
47  }
48  DoubleSlider(QWidget* parent = 0) :
49  QSlider(parent)
50  {
51  connect(this, SIGNAL(valueChanged(int)), this, SLOT(valueChangedSlot(int)));
52  setDoubleRange(DoubleRange(0, 1, 0.1));
53  }
54  void setDoubleRange(const DoubleRange& range)
55  {
56  mRange = range;
57  setRange(0, mRange.resolution());
58  setSingleStep(mRange.step());
59  }
60  void setDoubleValue(double val)
61  {
62  int v_i = (val - mRange.min()) / mRange.step();
63  setValue(v_i);
64  }
65  double getDoubleValue() const
66  {
67  double v_d = mRange.step() * (double) value() + mRange.min();
68  return v_d;
69  }
70  void setDoubleTickInterval(double interval)
71  {
72  setTickInterval(interval / mRange.step());
73  }
74 
75 signals:
76  void doubleValueChanged(double value);
77 
78 private slots:
79  void valueChangedSlot(int val)
80  {
81  emit doubleValueChanged(getDoubleValue());
82  }
83 
84 private:
85  DoubleRange mRange;
86 };
87 
92 class cxResourceWidgets_EXPORT DoubleLineEdit: public QLineEdit
93 {
94 public:
95  DoubleLineEdit(QWidget* parent = 0) :
96  QLineEdit(parent)
97  {
98  }
99  virtual QSize sizeHint() const;
100  virtual QSize minimumSizeHint() const;
101  double getDoubleValue(double defVal = 0.0) const
102  {
103  bool ok;
104  double newVal = this->text().toDouble(&ok);
105  if (!ok)
106  return defVal;
107  return newVal;
108  }
109  void setDoubleValue(double val)
110  {
111  this->setText(QString::number(val, 'g', 4));
112  }
113 };
114 
126 class cxResourceWidgets_EXPORT ScalarInteractionWidget: public OptimizedUpdateWidget
127 {
128 Q_OBJECT
129 public:
131 
132  void enableLabel();
133  void enableSlider();
134  void enableDial();
135  void enableEdit();
136  void enableSpinBox();
137  void enableInfiniteSlider();
138 
139  void addToOwnLayout();
140  void addToGridLayout(QGridLayout* gridLayout = 0, int row = 0);
141  void build(QGridLayout* gridLayout = 0, int row = 0);
142 
143  void showLabel(bool on);
144 
145 private slots:
146  void textEditedSlot();
147  void doubleValueChanged(double val);
148  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)
149  void infiniteSliderMouseMoved(QPointF delta);
150 
151 protected:
152  virtual void prePaintEvent();
154 
155 private:
156  void enableAll(bool);
157 
158  DoubleSlider* mSlider;
159  QDial* mDial;
160  QDoubleSpinBox* mSpinBox;
161  QLabel* mLabel;
162  DoubleLineEdit* mEdit;
163  MousePadWidget* mInfiniteSlider;
164 };
165 
173 class cxResourceWidgets_EXPORT SliderGroupWidget: public ScalarInteractionWidget
174 {
175 Q_OBJECT
176 public:
177  SliderGroupWidget(QWidget* parent, DoublePropertyBasePtr, QGridLayout* gridLayout = 0, int row = 0);
178 };
179 
189 class cxResourceWidgets_EXPORT SpinBoxGroupWidget: public ScalarInteractionWidget
190 {
191 Q_OBJECT
192 public:
193  SpinBoxGroupWidget(QWidget* parent, DoublePropertyBasePtr, QGridLayout* gridLayout = 0, int row = 0);
194 };
195 
205 class cxResourceWidgets_EXPORT SpinBoxAndSliderGroupWidget: public ScalarInteractionWidget
206 {
207 Q_OBJECT
208 public:
209  SpinBoxAndSliderGroupWidget(QWidget* parent, DoublePropertyBasePtr, QGridLayout* gridLayout = 0, int row = 0);
210 };
211 typedef boost::shared_ptr<SpinBoxAndSliderGroupWidget> SpinBoxAndSliderGroupWidgetPtr;
212 
222 class cxResourceWidgets_EXPORT SpinBoxAndDialGroupWidget: public ScalarInteractionWidget
223 {
224 Q_OBJECT
225 public:
226 SpinBoxAndDialGroupWidget(QWidget* parent, DoublePropertyBasePtr, QGridLayout* gridLayout = 0, int row = 0);
227 };
228 typedef boost::shared_ptr<SpinBoxAndDialGroupWidget> SpinBoxAndDialGroupWidgetPtr;
229 
230 
240 class cxResourceWidgets_EXPORT SpinBoxInfiniteSliderGroupWidget: public ScalarInteractionWidget
241 {
242 Q_OBJECT
243 public:
244  SpinBoxInfiniteSliderGroupWidget(QWidget* parent, DoublePropertyBasePtr, QGridLayout* gridLayout = 0, int row = 0);
245 };
246 
247 } //namespace cx
248 
249 
250 #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:32
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.