Fraxinus  16.5.0-fx-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxDoubleSpanSlider.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 #ifndef CXDOUBLESPANSLIDER_H_
33 #define CXDOUBLESPANSLIDER_H_
34 
35 #include "cxResourceWidgetsExport.h"
36 
37 #include <QWidget>
38 #include "cxDoubleRange.h"
39 #include "qxtspanslider.h"
40 #include "cxDoubleWidgets.h"
43 class QDoubleSpinBox;
44 
45 namespace cx
46 {
47 
53 class cxResourceWidgets_EXPORT DoubleSpanSlider : public QxtSpanSlider
54 {
55  Q_OBJECT
56 
57 public:
58  virtual ~DoubleSpanSlider() {}
59  DoubleSpanSlider(QWidget* parent = 0) : QxtSpanSlider(parent)
60  {
61  connect(this, SIGNAL(spanChanged(int,int)), this, SLOT(spanChangedSlot(int,int)));
62  this->setDoubleRange(DoubleRange(0,1,0.1));
63  }
64  void setDoubleRange(const DoubleRange& range)
65  {
66  mRange = range;
67  this->setRange(0, mRange.resolution());
68  this->setSingleStep(mRange.step());
69  }
71  {
72  return mRange;
73  }
74  void setDoubleSpan(double lower, double upper)
75  {
76  int lower_i = (lower-mRange.min())/mRange.step();
77  int upper_i = (upper-mRange.min())/mRange.step();
78  this->setSpan(lower_i, upper_i);
79  }
80  void setDoubleLowerValue(double val)
81  {
82  int v_i = (val-mRange.min())/mRange.step();
83  this->setLowerValue(v_i);
84  }
85  double getDoubleLowerValue() const
86  {
87  double v_d = mRange.step()*(double)(this->lowerValue()) + mRange.min();
88  return v_d;
89  }
90  void setDoubleUpperValue(double val)
91  {
92  int v_i = (val-mRange.min())/mRange.step();
93  this->setUpperValue(v_i);
94  }
95  double getDoubleUpperValue() const
96  {
97  double v_d = mRange.step()*(double)(this->upperValue()) + mRange.min();
98  return v_d;
99  }
100  void setDoubleTickInterval(double interval)
101  {
102  this->setTickInterval(interval/mRange.step());
103  }
104 
105 signals:
106  void doubleSpanChanged(double lower, double upper);
107 
108 private slots:
109  void spanChangedSlot(int lower, int upper)
110  {
111  emit doubleSpanChanged(getDoubleLowerValue(), getDoubleUpperValue());
112  }
113 
114 private:
115  DoubleRange mRange;
116 };
117 
122 class cxResourceWidgets_EXPORT SliderRangeGroupWidget : public OptimizedUpdateWidget
123 {
124  Q_OBJECT
125 public:
126  SliderRangeGroupWidget(QWidget* parent, DoublePairPropertyBasePtr dataInterface, QGridLayout* gridLayout = 0, int row = 0);
127 
128  void addToGridLayout(QGridLayout* gridLayout, int row);
129  void setRange(const DoubleRange& range);
130  void setDecimals(int decimals);
131  std::pair<double,double> getValue() const;
132  bool setValue(double lower, double upper);
133 
134 signals:
135  void valueChanged(double lower, double upper);
136 
137 private slots:
138  void doubleSpanChangedSlot(double lower, double upper);
139  void textEditedSlot();
140  void dataChanged();
141 
142 private:
144  void init(QGridLayout *gridLayout, int row);
145  void updateGuiRange();
146  QLabel* mLabel;
147  QDoubleSpinBox* mLowerEdit;
148  QDoubleSpinBox* mUpperEdit;
149  DoubleSpanSlider* mSpanSlider;
150 
152 };
153 
154 
155 } // namespace cx
156 
157 #endif /* CXDOUBLESPANSLIDER_H_ */
void setDoubleSpan(double lower, double upper)
double getDoubleLowerValue() const
double getDoubleUpperValue() const
Utility class for describing a bounded numeric range.
Definition: cxDoubleRange.h:53
void setDoubleTickInterval(double interval)
boost::shared_ptr< DoublePairPropertyBase > DoublePairPropertyBasePtr
Custom widget for display of double-valued data.Use the double-named methods instead of qslider's int...
DoubleRange getDoubleRange() const
Interface for all classes following the modified/prepaint paradigm.
DoubleSpanSlider(QWidget *parent=0)
void setDoubleRange(const DoubleRange &range)
void setDoubleUpperValue(double val)
void setDoubleLowerValue(double val)