itom  3.0.0
doubleSpinBox_p.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  CTK Common Toolkit (http://www.commontk.org)
29 *********************************************************************** */
30 
31 // includes
32 #include "doubleSpinBox.h"
33 
34 // Qt includes
35 #include <QDoubleSpinBox>
36 #include <QPointer>
38 class ValueProxy;
39 class QFocusEvent;
40 
41 //-----------------------------------------------------------------------------
42 class itomQDoubleSpinBox: public QDoubleSpinBox
43 {
44  Q_OBJECT
50  Q_PROPERTY(bool invertedControls READ invertedControls WRITE setInvertedControls)
51 public:
52  typedef QDoubleSpinBox Superclass;
53  itomQDoubleSpinBox(DoubleSpinBoxPrivate* pimpl, QWidget* widget);
54  void setInvertedControls(bool invertedControls);
55  bool invertedControls() const;
56 
59  virtual void stepBy(int steps);
60 
63  virtual QLineEdit* lineEdit()const;
64 
65  virtual double valueFromText(const QString &text) const;
66  virtual QString textFromValue(double value) const;
67  virtual int decimalsFromText(const QString &text) const;
68  virtual QValidator::State validate(QString& input, int& pos)const;
69 
71  void initStyleOptionSpinBox(QStyleOptionSpinBox* option);
72 protected:
73  DoubleSpinBoxPrivate* const d_ptr;
74 
75  void focusOutEvent(QFocusEvent * event);
76 
81  virtual StepEnabled stepEnabled () const;
82 
83  bool InvertedControls;
84 private:
85  Q_DECLARE_PRIVATE(DoubleSpinBox);
86  Q_DISABLE_COPY(itomQDoubleSpinBox);
87 };
88 
89 //-----------------------------------------------------------------------------
90 class DoubleSpinBoxPrivate: public QObject
91 {
92  Q_OBJECT
93  Q_DECLARE_PUBLIC(DoubleSpinBox);
94 protected:
95  DoubleSpinBox* const q_ptr;
96 public:
98 
99  itomQDoubleSpinBox* SpinBox;
101  int DefaultDecimals;
102  DoubleSpinBox::DecimalsOptions DOption;
103  bool InvertedControls;
104  DoubleSpinBox::SizeHintPolicy SizeHintPolicy;
105 
106  double InputValue;
107  double InputRange[2];
108 
109  mutable QString CachedText;
110  mutable double CachedValue;
111  mutable QValidator::State CachedState;
112  mutable int CachedDecimals;
113  mutable QSize CachedSizeHint;
114  bool ForceInputValueUpdate;
115 
116  QPointer<ValueProxy> Proxy;
117 
118  void init();
120  bool compare(double x1, double x2) const;
122  double round(double value, int decimals)const;
123 
125  QString stripped(const QString& text, int* pos)const;
126 
130  int boundDecimals(int decimals)const;
134  int decimalsForValue(double value)const;
137  void setDecimals(int dec);
140  void setValue(double value, int dec = -1);
141 
145  double validateAndInterpret(QString &input, int &pos,
146  QValidator::State &state, int &decimals) const;
147 
148  void connectSpinBoxValueChanged();
149  void disconnectSpinBoxValueChanged();
150 
151 public slots:
152  void editorTextChanged(const QString& text);
153  void onValueChanged();
154 
155  void onValueProxyAboutToBeModified();
156  void onValueProxyModified();
157 };
virtual StepEnabled stepEnabled() const
Definition: doubleSpinBox.cpp:103
virtual QLineEdit * lineEdit() const
Definition: doubleSpinBox.cpp:61
bool invertedControls
Definition: doubleSpinBox_p.h:50
virtual void stepBy(int steps)
Definition: doubleSpinBox.cpp:84
Definition: doubleSpinBox_p.h:42
Custom SpinBox The DoubleSpinBox internaly uses a QDoubleSpinBox while it retain controls over it...
Definition: doubleSpinBox.h:54
void initStyleOptionSpinBox(QStyleOptionSpinBox *option)
Expose publicly QAbstractSpinBox::initStyleOption()
Definition: doubleSpinBox.cpp:66
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