CustusX  15.3.4-beta
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
165 private slots:
166  void textEditedSlot();
167  void doubleValueChanged(double val);
168  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)
169  void infiniteSliderMouseMoved(QPointF delta);
170 
171 protected:
172  virtual void prePaintEvent();
174 
175 private:
176  void enableAll(bool);
177 
178  DoubleSlider* mSlider;
179  QDial* mDial;
180  QDoubleSpinBox* mSpinBox;
181  QLabel* mLabel;
182  DoubleLineEdit* mEdit;
183  MousePadWidget* mInfiniteSlider;
184 };
185 
193 class cxResourceWidgets_EXPORT SliderGroupWidget: public ScalarInteractionWidget
194 {
195 Q_OBJECT
196 public:
197  SliderGroupWidget(QWidget* parent, DoublePropertyBasePtr, QGridLayout* gridLayout = 0, int row = 0);
198 };
199 
209 class cxResourceWidgets_EXPORT SpinBoxGroupWidget: public ScalarInteractionWidget
210 {
211 Q_OBJECT
212 public:
213  SpinBoxGroupWidget(QWidget* parent, DoublePropertyBasePtr, QGridLayout* gridLayout = 0, int row = 0);
214 };
215 
225 class cxResourceWidgets_EXPORT SpinBoxAndSliderGroupWidget: public ScalarInteractionWidget
226 {
227 Q_OBJECT
228 public:
229  SpinBoxAndSliderGroupWidget(QWidget* parent, DoublePropertyBasePtr, QGridLayout* gridLayout = 0, int row = 0);
230 };
231 typedef boost::shared_ptr<SpinBoxAndSliderGroupWidget> SpinBoxAndSliderGroupWidgetPtr;
232 
242 class cxResourceWidgets_EXPORT SpinBoxAndDialGroupWidget: public ScalarInteractionWidget
243 {
244 Q_OBJECT
245 public:
246 SpinBoxAndDialGroupWidget(QWidget* parent, DoublePropertyBasePtr, QGridLayout* gridLayout = 0, int row = 0);
247 };
248 typedef boost::shared_ptr<SpinBoxAndDialGroupWidget> SpinBoxAndDialGroupWidgetPtr;
249 
250 
260 class cxResourceWidgets_EXPORT SpinBoxInfiniteSliderGroupWidget: public ScalarInteractionWidget
261 {
262 Q_OBJECT
263 public:
264  SpinBoxInfiniteSliderGroupWidget(QWidget* parent, DoublePropertyBasePtr, QGridLayout* gridLayout = 0, int row = 0);
265 };
266 
267 } //namespace cx
268 
269 
270 #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)