itom 2.2.1
K:/git-itom/sources/itom/itomWidgets/doubleSpinBox.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     Common framework (http://www.commontk.org)
00029 *********************************************************************** */
00030 
00031 #ifndef DOUBLESPINBOX_H
00032 #define DOUBLESPINBOX_H
00033 
00034 // Qt includes
00035 #include <QMetaType>
00036 #include <QString>
00037 #include <QWidget>
00038 
00039 class QDoubleSpinBox;
00040 class QEvent;
00041 class QKeyEvent;
00042 class QLineEdit;
00043 class QObject;
00044 
00045 #include "commonWidgets.h"
00046 
00047 class DoubleSpinBoxPrivate;
00048 class ValueProxy;
00049 
00054 class ITOMWIDGETS_EXPORT DoubleSpinBox : public QWidget
00055 {
00056   Q_OBJECT
00057   Q_ENUMS(SetMode)
00058   Q_FLAGS(DecimalsOption DecimalsOptions)
00059   Q_ENUMS(SizeHintPolicy)
00060 
00061   Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment)
00062   Q_PROPERTY(bool frame READ hasFrame WRITE setFrame)
00063   Q_PROPERTY(QString prefix READ prefix WRITE setPrefix)
00064   Q_PROPERTY(QString suffix READ suffix WRITE setSuffix)
00065   Q_PROPERTY(QString cleanText READ cleanText)
00076   Q_PROPERTY(int decimals READ decimals WRITE setDecimals NOTIFY decimalsChanged)
00081   Q_PROPERTY(DecimalsOptions decimalsOption READ decimalsOption WRITE setDecimalsOption)
00082   Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
00083   Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
00084   Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep)
00086   Q_PROPERTY(double value READ value WRITE setValue NOTIFY valueChanged USER true)
00089   Q_PROPERTY(SetMode setMode READ setMode WRITE setSetMode)
00095   Q_PROPERTY(bool invertedControls READ invertedControls WRITE setInvertedControls)
00099   Q_PROPERTY(SizeHintPolicy sizeHintPolicy READ sizeHintPolicy WRITE setSizeHintPolicy)
00101   Q_PROPERTY(bool keyboardTracking READ keyboardTracking WRITE setKeyboardTracking)
00102 
00103 public:
00104 
00115   enum SetMode
00116     {
00117     SetAlways,
00118     SetIfDifferent,
00119     };
00120 
00124   enum DecimalsOption
00125     {
00128     FixedDecimals = 0x000,
00133     DecimalsByShortcuts = 0x001,
00137     DecimalsByKey = 0x002,
00140     DecimalsByValue = 0x004,
00145     InsertDecimals = 0x008,
00151     ReplaceDecimals = 0x010,
00154     DecimalsAsMax = 0x020,
00157     DecimalsAsMin = 0x040,
00161     DecimalPointAlwaysVisible = 0x080
00162     };
00163   Q_DECLARE_FLAGS(DecimalsOptions, DecimalsOption)
00164 
00165   enum SizeHintPolicy
00166     {
00167     SizeHintByMinMax,
00168     SizeHintByValue
00169     };
00170 
00171   typedef QWidget Superclass;
00172 
00175   explicit DoubleSpinBox(QWidget* parent = 0);
00176   explicit DoubleSpinBox(DoubleSpinBox::SetMode mode, QWidget* parent = 0);
00177   virtual ~DoubleSpinBox();
00178 
00181   double value() const;
00182 
00185   double displayedValue() const;
00186 
00192   void setDisplayedValue(double displayValue);
00193 
00196   QString text() const;
00197 
00200   QString cleanText() const;
00201 
00203   Qt::Alignment alignment () const;
00204   void setAlignment (Qt::Alignment flag);
00205 
00207   void setFrame(bool frame);
00208   bool hasFrame() const;
00209 
00213   QString prefix() const;
00214   void setPrefix(const QString &prefix);
00215 
00219   QString suffix() const;
00220   void setSuffix(const QString &suffix);
00221 
00226   double singleStep() const;
00227   void setSingleStep(double value);
00228 
00230   double minimum() const;
00231   void setMinimum(double min);
00232   double maximum() const;
00233   void setMaximum(double max);
00234   void setRange(double min, double max);
00235 
00239   int decimals() const;
00240 
00244   double round(double value) const;
00245 
00249   QDoubleSpinBox* spinBox() const;
00250 
00253   QLineEdit* lineEdit()const;
00254 
00257   DoubleSpinBox::SetMode setMode() const;
00258   void setSetMode(SetMode mode);
00259 
00262   DoubleSpinBox::DecimalsOptions decimalsOption();
00263   void setDecimalsOption(DoubleSpinBox::DecimalsOptions option);
00264 
00270   void setInvertedControls(bool invertedControls);
00271   bool invertedControls() const;
00272 
00275   void setSizeHintPolicy(SizeHintPolicy newSizeHintPolicy);
00278   SizeHintPolicy sizeHintPolicy()const;
00279 
00288   void setValueProxy(ValueProxy* proxy);
00289   ValueProxy* valueProxy() const;
00290 
00293   virtual QSize sizeHint()const;
00296   virtual QSize minimumSizeHint()const;
00297 
00298   void setKeyboardTracking(bool kt);
00299   bool keyboardTracking() const;
00300 
00301 public slots:
00304   void setValue(double value);
00305 
00308   void setValueIfDifferent(double value);
00309 
00312   void setValueAlways(double value);
00313 
00316   void stepUp();
00317   void stepDown();
00318 
00321   void setDecimals(int decimal);
00322 
00323 signals:
00326   void valueChanged(double);
00327   void valueChanged(const QString &);
00328 
00331   void editingFinished();
00332 
00334   void decimalsChanged(int);
00335 
00336 protected:
00337   DoubleSpinBoxPrivate* const d_ptr;
00338 
00340   virtual void keyPressEvent(QKeyEvent* event);
00342   virtual bool eventFilter(QObject *obj, QEvent *event);
00343 
00344   friend class CoordinatesWidgetPrivate;
00345 private:
00346   Q_DECLARE_PRIVATE(DoubleSpinBox);
00347   Q_DISABLE_COPY(DoubleSpinBox);
00348 };
00349 
00350 Q_DECLARE_METATYPE(DoubleSpinBox::SetMode)
00351 Q_DECLARE_OPERATORS_FOR_FLAGS(DoubleSpinBox::DecimalsOptions)
00352 
00353 #endif //__DoubleSpinBox_h
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Properties Friends