itom  3.0.0
doubleSpinBox.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2016, Institut fuer Technische Optik (ITO),
5  Universitaet Stuttgart, Germany
6 
7  This file is part of itom and its software development toolkit (SDK).
8 
9  itom is free software; you can redistribute it and/or modify it
10  under the terms of the GNU Library General Public Licence as published by
11  the Free Software Foundation; either version 2 of the Licence, or (at
12  your option) any later version.
13 
14  In addition, as a special exception, the Institut fuer Technische
15  Optik (ITO) gives you certain additional rights.
16  These rights are described in the ITO LGPL Exception version 1.0,
17  which can be found in the file LGPL_EXCEPTION.txt in this package.
18 
19  itom is distributed in the hope that it will be useful, but
20  WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
22  General Public Licence for more details.
23 
24  You should have received a copy of the GNU Library General Public License
25  along with itom. If not, see <http://www.gnu.org/licenses/>.
26 
27  This file is a port and modified version of the
28  Common framework (http://www.commontk.org)
29 *********************************************************************** */
30 
31 #ifndef DOUBLESPINBOX_H
32 #define DOUBLESPINBOX_H
33 
34 // Qt includes
35 #include <QMetaType>
36 #include <QString>
37 #include <QWidget>
38 
39 class QDoubleSpinBox;
40 class QEvent;
41 class QKeyEvent;
42 class QLineEdit;
43 class QObject;
44 
45 #include "commonWidgets.h"
46 
48 class ValueProxy;
49 
54 class ITOMWIDGETS_EXPORT DoubleSpinBox : public QWidget
55 {
56  Q_OBJECT
57 
58 #if QT_VERSION < 0x050500
59  //for >= Qt 5.5.0 see Q_ENUM definition below
60  Q_ENUMS(SetMode)
61  Q_ENUMS(SizeHintPolicy)
62  Q_FLAGS(DecimalsOption DecimalsOptions)
63 #endif
64 
65  Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment)
66  Q_PROPERTY(bool frame READ hasFrame WRITE setFrame)
67  Q_PROPERTY(QString prefix READ prefix WRITE setPrefix)
68  Q_PROPERTY(QString suffix READ suffix WRITE setSuffix)
69  Q_PROPERTY(QString cleanText READ cleanText)
80  Q_PROPERTY(int decimals READ decimals WRITE setDecimals NOTIFY decimalsChanged)
85  Q_PROPERTY(DecimalsOptions decimalsOption READ decimalsOption WRITE setDecimalsOption)
86  Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
87  Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
88  Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep)
90  Q_PROPERTY(double value READ value WRITE setValue NOTIFY valueChanged USER true)
93  Q_PROPERTY(SetMode setMode READ setMode WRITE setSetMode)
99  Q_PROPERTY(bool invertedControls READ invertedControls WRITE setInvertedControls)
103  Q_PROPERTY(SizeHintPolicy sizeHintPolicy READ sizeHintPolicy WRITE setSizeHintPolicy)
105  Q_PROPERTY(bool keyboardTracking READ keyboardTracking WRITE setKeyboardTracking)
106 
107 public:
108 
119  enum SetMode
120  {
121  SetAlways,
122  SetIfDifferent,
123  };
124 
129  {
132  FixedDecimals = 0x000,
137  DecimalsByShortcuts = 0x001,
141  DecimalsByKey = 0x002,
144  DecimalsByValue = 0x004,
149  InsertDecimals = 0x008,
155  ReplaceDecimals = 0x010,
158  DecimalsAsMax = 0x020,
161  DecimalsAsMin = 0x040,
165  DecimalPointAlwaysVisible = 0x080
166  };
167  Q_DECLARE_FLAGS(DecimalsOptions, DecimalsOption)
168 
169  enum SizeHintPolicy
170  {
171  SizeHintByMinMax,
172  SizeHintByValue
173  };
174 
175 #if QT_VERSION >= 0x050500
176  //Q_ENUM exposes a meta object to the enumeration types, such that the key names for the enumeration
177  //values are always accessible.
178  Q_ENUM(SetMode)
179  Q_ENUM(SizeHintPolicy)
180  Q_FLAG(DecimalsOptions)
181 #endif
182 
183  typedef QWidget Superclass;
184 
187  explicit DoubleSpinBox(QWidget* parent = 0);
188  explicit DoubleSpinBox(DoubleSpinBox::SetMode mode, QWidget* parent = 0);
189  virtual ~DoubleSpinBox();
190 
193  double value() const;
194 
197  double displayedValue() const;
198 
204  void setDisplayedValue(double displayValue);
205 
208  QString text() const;
209 
212  QString cleanText() const;
213 
215  Qt::Alignment alignment () const;
216  void setAlignment (Qt::Alignment flag);
217 
219  void setFrame(bool frame);
220  bool hasFrame() const;
221 
225  QString prefix() const;
226  void setPrefix(const QString &prefix);
227 
231  QString suffix() const;
232  void setSuffix(const QString &suffix);
233 
238  double singleStep() const;
239  void setSingleStep(double value);
240 
242  double minimum() const;
243  void setMinimum(double min);
244  double maximum() const;
245  void setMaximum(double max);
246  void setRange(double min, double max);
247 
251  int decimals() const;
252 
256  double round(double value) const;
257 
261  QDoubleSpinBox* spinBox() const;
262 
265  QLineEdit* lineEdit()const;
266 
269  DoubleSpinBox::SetMode setMode() const;
270  void setSetMode(SetMode mode);
271 
274  DoubleSpinBox::DecimalsOptions decimalsOption();
275  void setDecimalsOption(DoubleSpinBox::DecimalsOptions option);
276 
282  void setInvertedControls(bool invertedControls);
283  bool invertedControls() const;
284 
287  void setSizeHintPolicy(SizeHintPolicy newSizeHintPolicy);
290  SizeHintPolicy sizeHintPolicy()const;
291 
300  void setValueProxy(ValueProxy* proxy);
301  ValueProxy* valueProxy() const;
302 
305  virtual QSize sizeHint()const;
308  virtual QSize minimumSizeHint()const;
309 
310  void setKeyboardTracking(bool kt);
311  bool keyboardTracking() const;
312 
313 public slots:
316  void setValue(double value);
317 
320  void setValueIfDifferent(double value);
321 
324  void setValueAlways(double value);
325 
328  void stepUp();
329  void stepDown();
330 
333  void setDecimals(int decimal);
334 
335 signals:
338  void valueChanged(double);
339  void valueChanged(const QString &);
340 
343  void editingFinished();
344 
346  void decimalsChanged(int);
347 
348 protected:
349  DoubleSpinBoxPrivate* const d_ptr;
350 
352  virtual void keyPressEvent(QKeyEvent* event);
354  virtual bool eventFilter(QObject *obj, QEvent *event);
355 
356  friend class CoordinatesWidgetPrivate;
357 private:
358  Q_DECLARE_PRIVATE(DoubleSpinBox);
359  Q_DISABLE_COPY(DoubleSpinBox);
360 };
361 
362 Q_DECLARE_METATYPE(DoubleSpinBox::SetMode)
363 Q_DECLARE_OPERATORS_FOR_FLAGS(DoubleSpinBox::DecimalsOptions)
364 
365 #endif //__DoubleSpinBox_h
Custom SpinBox The DoubleSpinBox internaly uses a QDoubleSpinBox while it retain controls over it...
Definition: doubleSpinBox.h:54
DecimalsOption
Definition: doubleSpinBox.h:128
Base class for value proxies. Value proxy allows to decouple the displayed value from the values acce...
Definition: valueProxy.h:45
SetMode
Definition: doubleSpinBox.h:119
Definition: doubleSpinBox_p.h:90