CTK  0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
ctkDoubleSpinBox.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Library: CTK
4 
5  Copyright (c) Kitware Inc.
6 
7  Licensed under the Apache License, Version 2.0 (the "License");
8  you may not use this file except in compliance with the License.
9  You may obtain a copy of the License at
10 
11  http://www.apache.org/licenses/LICENSE-2.0.txt
12 
13  Unless required by applicable law or agreed to in writing, software
14  distributed under the License is distributed on an "AS IS" BASIS,
15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  See the License for the specific language governing permissions and
17  limitations under the License.
18 
19 =========================================================================*/
20 
21 #ifndef __ctkDoubleSpinBox_h
22 #define __ctkDoubleSpinBox_h
23 
24 // Qt includes
25 #include <QMetaType>
26 #include <QString>
27 #include <QWidget>
28 
29 class QDoubleSpinBox;
30 class QEvent;
31 class QKeyEvent;
32 class QLineEdit;
33 class QObject;
34 
35 // CTK includes
36 #include "ctkWidgetsExport.h"
37 
38 class ctkDoubleSpinBoxPrivate;
39 class ctkValueProxy;
40 
45 class CTK_WIDGETS_EXPORT ctkDoubleSpinBox : public QWidget
46 {
47  Q_OBJECT
48  Q_ENUMS(SetMode)
49  Q_FLAGS(DecimalsOption DecimalsOptions)
50  Q_ENUMS(SizeHintPolicy)
51 
52  Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment)
53  Q_PROPERTY(bool frame READ hasFrame WRITE setFrame)
54  Q_PROPERTY(QString prefix READ prefix WRITE setPrefix)
55  Q_PROPERTY(QString suffix READ suffix WRITE setSuffix)
56  Q_PROPERTY(QString cleanText READ cleanText)
67  Q_PROPERTY(int decimals READ decimals WRITE setDecimals NOTIFY decimalsChanged)
72  Q_PROPERTY(DecimalsOptions decimalsOption READ decimalsOption WRITE setDecimalsOption)
73  Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
74  Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
75  Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep)
77  Q_PROPERTY(double value READ value WRITE setValue NOTIFY valueChanged USER true)
80  Q_PROPERTY(SetMode setMode READ setMode WRITE setSetMode)
86  Q_PROPERTY(bool invertedControls READ invertedControls WRITE setInvertedControls)
90  Q_PROPERTY(SizeHintPolicy sizeHintPolicy READ sizeHintPolicy WRITE setSizeHintPolicy)
91 
92 public:
93 
104  enum SetMode
105  {
108  };
109 
114  {
117  FixedDecimals = 0x000,
122  DecimalsByShortcuts = 0x001,
126  DecimalsByKey = 0x002,
129  DecimalsByValue = 0x004,
134  InsertDecimals = 0x008,
140  ReplaceDecimals = 0x010,
143  DecimalsAsMax = 0x020,
146  DecimalsAsMin = 0x040,
150  DecimalPointAlwaysVisible = 0x080
151  };
152  Q_DECLARE_FLAGS(DecimalsOptions, DecimalsOption)
153 
155  {
157  SizeHintByValue
158  };
159 
160  typedef QWidget Superclass;
161 
164  explicit ctkDoubleSpinBox(QWidget* parent = 0);
165  explicit ctkDoubleSpinBox(ctkDoubleSpinBox::SetMode mode, QWidget* parent = 0);
166  virtual ~ctkDoubleSpinBox();
167 
170  double value() const;
171 
174  double displayedValue() const;
175 
181  void setDisplayedValue(double displayValue);
182 
185  QString text() const;
186 
189  QString cleanText() const;
190 
192  Qt::Alignment alignment () const;
193  void setAlignment (Qt::Alignment flag);
194 
196  void setFrame(bool frame);
197  bool hasFrame() const;
198 
202  QString prefix() const;
203  void setPrefix(const QString &prefix);
204 
208  QString suffix() const;
209  void setSuffix(const QString &suffix);
210 
215  double singleStep() const;
216  void setSingleStep(double value);
217 
219  double minimum() const;
220  void setMinimum(double min);
221  double maximum() const;
222  void setMaximum(double max);
223  void setRange(double min, double max);
224 
228  int decimals() const;
229 
233  double round(double value) const;
234 
238  QDoubleSpinBox* spinBox() const;
239 
242  QLineEdit* lineEdit()const;
243 
247  void setSetMode(SetMode mode);
248 
251  ctkDoubleSpinBox::DecimalsOptions decimalsOption();
252  void setDecimalsOption(ctkDoubleSpinBox::DecimalsOptions option);
253 
259  void setInvertedControls(bool invertedControls);
260  bool invertedControls() const;
261 
264  void setSizeHintPolicy(SizeHintPolicy newSizeHintPolicy);
268 
279 
282  virtual QSize sizeHint()const;
285  virtual QSize minimumSizeHint()const;
286 
287 public Q_SLOTS:
290  void setValue(double value);
291 
294  void setValueIfDifferent(double value);
295 
298  void setValueAlways(double value);
299 
302  void stepUp();
303  void stepDown();
304 
307  void setDecimals(int decimal);
308 
309 Q_SIGNALS:
312  void valueChanged(double);
313  void valueChanged(const QString &);
314 
318 
320  void decimalsChanged(int);
321 
322 protected:
323  ctkDoubleSpinBoxPrivate* const d_ptr;
324 
326  virtual void keyPressEvent(QKeyEvent* event);
328  virtual bool eventFilter(QObject *obj, QEvent *event);
329 
330  friend class ctkCoordinatesWidgetPrivate;
331 private:
332  Q_DECLARE_PRIVATE(ctkDoubleSpinBox);
333  Q_DISABLE_COPY(ctkDoubleSpinBox);
334 };
335 
337 Q_DECLARE_OPERATORS_FOR_FLAGS(ctkDoubleSpinBox::DecimalsOptions)
338 
339 #endif //__ctkDoubleSpinBox_h
ctkDoubleSpinBox::valueChanged
void valueChanged(const QString &)
ctkDoubleSpinBox::text
QString text() const
ctkDoubleSpinBox::setDecimalsOption
void setDecimalsOption(ctkDoubleSpinBox::DecimalsOptions option)
ctkDoubleSpinBox::~ctkDoubleSpinBox
virtual ~ctkDoubleSpinBox()
ctkDoubleSpinBox::minimum
double minimum() const
Set/Get the range of the spinbox. Default range is [0.0, 9.9].
ctkDoubleSpinBox::d_ptr
ctkDoubleSpinBoxPrivate *const d_ptr
Definition: ctkDoubleSpinBox.h:323
ctkDoubleSpinBox::ctkDoubleSpinBox
ctkDoubleSpinBox(QWidget *parent=0)
Q_DECLARE_OPERATORS_FOR_FLAGS
Q_DECLARE_OPERATORS_FOR_FLAGS(ctkVTKDataSetModel::AttributeTypes)
ctkDoubleSpinBox::valueChanged
void valueChanged(double)
ctkDoubleSpinBox::DecimalsOption
DecimalsOption
Definition: ctkDoubleSpinBox.h:114
ctkDoubleSpinBox::valueProxy
ctkValueProxy * valueProxy() const
ctkDoubleSpinBox::setAlignment
void setAlignment(Qt::Alignment flag)
ctkDoubleSpinBox::setInvertedControls
void setInvertedControls(bool invertedControls)
ctkDoubleSpinBox::setValue
void setValue(double value)
ctkDoubleSpinBox::SetAlways
@ SetAlways
Definition: ctkDoubleSpinBox.h:106
ctkDoubleSpinBox::ctkDoubleSpinBox
ctkDoubleSpinBox(ctkDoubleSpinBox::SetMode mode, QWidget *parent=0)
ctkDoubleSpinBox::setPrefix
void setPrefix(const QString &prefix)
ctkDoubleSpinBox::setMinimum
void setMinimum(double min)
ctkDoubleSpinBox::setSingleStep
void setSingleStep(double value)
ctkDoubleSpinBox::SizeHintByMinMax
@ SizeHintByMinMax
Definition: ctkDoubleSpinBox.h:156
ctkDoubleSpinBox
Custom SpinBox The ctkDoubleSpinBox internaly uses a QDoubleSpinBox while it retain controls over it.
Definition: ctkDoubleSpinBox.h:46
ctkDoubleSpinBox::stepDown
void stepDown()
ctkDoubleSpinBox::decimals
int decimals() const
ctkDoubleSpinBox::lineEdit
QLineEdit * lineEdit() const
ctkDoubleSpinBox::editingFinished
void editingFinished()
ctkDoubleSpinBox::prefix
QString prefix() const
ctkDoubleSpinBox::invertedControls
bool invertedControls() const
ctkDoubleSpinBox::setDecimals
void setDecimals(int decimal)
ctkDoubleSpinBox::SetIfDifferent
@ SetIfDifferent
Definition: ctkDoubleSpinBox.h:107
ctkDoubleSpinBox::keyPressEvent
virtual void keyPressEvent(QKeyEvent *event)
Reimplemented to support shortcuts.
ctkDoubleSpinBox::SetMode
SetMode
Definition: ctkDoubleSpinBox.h:105
ctkDoubleSpinBox::setSizeHintPolicy
void setSizeHintPolicy(SizeHintPolicy newSizeHintPolicy)
ctkDoubleSpinBox::setFrame
void setFrame(bool frame)
Set/Get the frame.
ctkDoubleSpinBox::value
double value() const
ctkDoubleSpinBox::decimalsChanged
void decimalsChanged(int)
Signal emitted when the decimals of the displayed are changed.
ctkDoubleSpinBox::setValueAlways
void setValueAlways(double value)
ctkDoubleSpinBox::maximum
double maximum() const
ctkDoubleSpinBox::sizeHintPolicy
SizeHintPolicy sizeHintPolicy() const
ctkDoubleSpinBox::setDisplayedValue
void setDisplayedValue(double displayValue)
ctkDoubleSpinBox::setMode
ctkDoubleSpinBox::SetMode setMode() const
Set the spinbox mode when using a set*() method. /.
ctkDoubleSpinBox::setValueProxy
void setValueProxy(ctkValueProxy *proxy)
ctkDoubleSpinBox::sizeHint
virtual QSize sizeHint() const
ctkDoubleSpinBox::setRange
void setRange(double min, double max)
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(ctkDICOMPersonName)
ctkDoubleSpinBox::SizeHintPolicy
SizeHintPolicy
Definition: ctkDoubleSpinBox.h:155
ctkDoubleSpinBox::minimumSizeHint
virtual QSize minimumSizeHint() const
ctkDoubleSpinBox::round
double round(double value) const
ctkValueProxy
Base class for value proxies. Value proxy allows to decouple the displayed value from the values acce...
Definition: ctkValueProxy.h:47
ctkDoubleSpinBox::Superclass
QWidget Superclass
Definition: ctkDoubleSpinBox.h:160
ctkDoubleSpinBox::setSuffix
void setSuffix(const QString &suffix)
ctkDoubleSpinBox::eventFilter
virtual bool eventFilter(QObject *obj, QEvent *event)
Reimplemented to support shortcuts on the double spinbox.
ctkDoubleSpinBox::alignment
Qt::Alignment alignment() const
Set/Get the spinbox alignement.
ctkDoubleSpinBox::suffix
QString suffix() const
ctkDoubleSpinBox::singleStep
double singleStep() const
ctkDoubleSpinBox::setValueIfDifferent
void setValueIfDifferent(double value)
ctkDoubleSpinBox::displayedValue
double displayedValue() const
ctkDoubleSpinBox::cleanText
QString cleanText() const
ctkDoubleSpinBox::setSetMode
void setSetMode(SetMode mode)
ctkDoubleSpinBox::spinBox
QDoubleSpinBox * spinBox() const
ctkDoubleSpinBox::decimalsOption
ctkDoubleSpinBox::DecimalsOptions decimalsOption()
ctkDoubleSpinBox::setMaximum
void setMaximum(double max)
ctkDoubleSpinBox::stepUp
void stepUp()
ctkDoubleSpinBox::hasFrame
bool hasFrame() const