itom 2.2.1
K:/git-itom/sources/itom/itomWidgets/doubleSpinBox_p.h
00001 /* ********************************************************************
00002     itom software
00003     URL: http://www.uni-stuttgart.de/ito
00004     Copyright (C) 2016, Institut fuer Technische Optik (ITO),
00005     Universitaet Stuttgart, Germany
00006 
00007     This file is part of itom and its software development toolkit (SDK).
00008 
00009     itom is free software; you can redistribute it and/or modify it
00010     under the terms of the GNU Library General Public Licence as published by
00011     the Free Software Foundation; either version 2 of the Licence, or (at
00012     your option) any later version.
00013    
00014     In addition, as a special exception, the Institut fuer Technische
00015     Optik (ITO) gives you certain additional rights.
00016     These rights are described in the ITO LGPL Exception version 1.0,
00017     which can be found in the file LGPL_EXCEPTION.txt in this package.
00018 
00019     itom is distributed in the hope that it will be useful, but
00020     WITHOUT ANY WARRANTY; without even the implied warranty of
00021     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library
00022     General Public Licence for more details.
00023 
00024     You should have received a copy of the GNU Library General Public License
00025     along with itom. If not, see <http://www.gnu.org/licenses/>.
00026 
00027     This file is a port and modified version of the 
00028     CTK Common Toolkit (http://www.commontk.org)
00029 *********************************************************************** */
00030 
00031 //  includes
00032 #include "doubleSpinBox.h"
00033 
00034 // Qt includes
00035 #include <QDoubleSpinBox>
00036 #include <QPointer>
00037 class DoubleSpinBoxPrivate;
00038 class ValueProxy;
00039 class QFocusEvent;
00040 
00041 //-----------------------------------------------------------------------------
00042 class itomQDoubleSpinBox: public QDoubleSpinBox
00043 {
00044   Q_OBJECT
00050   Q_PROPERTY(bool invertedControls READ invertedControls WRITE setInvertedControls)
00051 public:
00052   typedef QDoubleSpinBox Superclass;
00053   itomQDoubleSpinBox(DoubleSpinBoxPrivate* pimpl, QWidget* widget);
00054   void setInvertedControls(bool invertedControls);
00055   bool invertedControls() const;
00056 
00059   virtual void stepBy(int steps);
00060 
00063   virtual QLineEdit* lineEdit()const;
00064 
00065   virtual double valueFromText(const QString &text) const;
00066   virtual QString textFromValue(double value) const;
00067   virtual int decimalsFromText(const QString &text) const;
00068   virtual QValidator::State validate(QString& input, int& pos)const;
00069 
00071   void initStyleOptionSpinBox(QStyleOptionSpinBox* option);
00072 protected:
00073   DoubleSpinBoxPrivate* const d_ptr;
00074 
00075   void focusOutEvent(QFocusEvent * event);
00076 
00081   virtual StepEnabled stepEnabled () const;
00082 
00083   bool InvertedControls;
00084 private:
00085   Q_DECLARE_PRIVATE(DoubleSpinBox);
00086   Q_DISABLE_COPY(itomQDoubleSpinBox);
00087 };
00088 
00089 //-----------------------------------------------------------------------------
00090 class DoubleSpinBoxPrivate: public QObject
00091 {
00092   Q_OBJECT
00093   Q_DECLARE_PUBLIC(DoubleSpinBox);
00094 protected:
00095   DoubleSpinBox* const q_ptr;
00096 public:
00097   DoubleSpinBoxPrivate(DoubleSpinBox& object);
00098 
00099   itomQDoubleSpinBox* SpinBox;
00100   DoubleSpinBox::SetMode Mode;
00101   int DefaultDecimals;
00102   DoubleSpinBox::DecimalsOptions DOption;
00103   bool InvertedControls;
00104   DoubleSpinBox::SizeHintPolicy SizeHintPolicy;
00105 
00106   double InputValue;
00107   double InputRange[2];
00108 
00109   mutable QString CachedText;
00110   mutable double CachedValue;
00111   mutable QValidator::State CachedState;
00112   mutable int CachedDecimals;
00113   mutable QSize CachedSizeHint;
00114   bool ForceInputValueUpdate;
00115 
00116   QPointer<ValueProxy> Proxy;
00117 
00118   void init();
00120   bool compare(double x1, double x2) const;
00122   double round(double value, int decimals)const;
00123 
00125   QString stripped(const QString& text, int* pos)const;
00126 
00130   int boundDecimals(int decimals)const;
00134   int decimalsForValue(double value)const;
00137   void setDecimals(int dec);
00140   void setValue(double value, int dec = -1);
00141 
00145   double validateAndInterpret(QString &input, int &pos,
00146                               QValidator::State &state, int &decimals) const;
00147 
00148   void connectSpinBoxValueChanged();
00149   void disconnectSpinBoxValueChanged();
00150 
00151 public slots:
00152   void editorTextChanged(const QString& text);
00153   void onValueChanged();
00154 
00155   void onValueProxyAboutToBeModified();
00156   void onValueProxyModified();
00157 };
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Properties Friends