itom
Loading...
Searching...
No Matches
doubleSpinBox.h
1/* ********************************************************************
2 itom software
3 URL: http://www.uni-stuttgart.de/ito
4 Copyright (C) 2020, Institut für Technische Optik (ITO),
5 Universität 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 für 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
39class QDoubleSpinBox;
40class QEvent;
41class QKeyEvent;
42class QLineEdit;
43class QObject;
44
45#include "commonWidgets.h"
46
48class ValueProxy;
49
54class ITOMWIDGETS_EXPORT DoubleSpinBox : public QWidget
55{
56 Q_OBJECT
57
58 Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment)
59 Q_PROPERTY(bool frame READ hasFrame WRITE setFrame)
60 Q_PROPERTY(QString prefix READ prefix WRITE setPrefix)
61 Q_PROPERTY(QString suffix READ suffix WRITE setSuffix)
62 Q_PROPERTY(QString cleanText READ cleanText)
73 Q_PROPERTY(int decimals READ decimals WRITE setDecimals NOTIFY decimalsChanged)
78 Q_PROPERTY(DecimalsOptions decimalsOption READ decimalsOption WRITE setDecimalsOption)
79 Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
80 Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
81 Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep)
83 Q_PROPERTY(double value READ value WRITE setValue NOTIFY valueChanged USER true)
86 Q_PROPERTY(SetMode setMode READ setMode WRITE setSetMode)
92 Q_PROPERTY(bool invertedControls READ invertedControls WRITE setInvertedControls)
96 Q_PROPERTY(SizeHintPolicy sizeHintPolicy READ sizeHintPolicy WRITE setSizeHintPolicy)
98 Q_PROPERTY(bool keyboardTracking READ keyboardTracking WRITE setKeyboardTracking)
99
100public:
101
113 {
114 SetAlways,
115 SetIfDifferent,
116 };
117
122 {
125 FixedDecimals = 0x000,
130 DecimalsByShortcuts = 0x001,
134 DecimalsByKey = 0x002,
137 DecimalsByValue = 0x004,
142 InsertDecimals = 0x008,
148 ReplaceDecimals = 0x010,
151 DecimalsAsMax = 0x020,
154 DecimalsAsMin = 0x040,
158 DecimalPointAlwaysVisible = 0x080
159 };
160 Q_DECLARE_FLAGS(DecimalsOptions, DecimalsOption)
161
162 enum SizeHintPolicy
163 {
164 SizeHintByMinMax,
165 SizeHintByValue
166 };
167
168 //Q_ENUM exposes a meta object to the enumeration types, such that the key names for the enumeration
169 //values are always accessible.
170 Q_ENUM(SetMode)
171 Q_ENUM(SizeHintPolicy)
172 Q_FLAG(DecimalsOptions)
173
174 typedef QWidget Superclass;
175
178 explicit DoubleSpinBox(QWidget* parent = 0);
179 explicit DoubleSpinBox(DoubleSpinBox::SetMode mode, QWidget* parent = 0);
180 virtual ~DoubleSpinBox();
181
184 double value() const;
185
188 double displayedValue() const;
189
195 void setDisplayedValue(double displayValue);
196
199 QString text() const;
200
203 QString cleanText() const;
204
206 Qt::Alignment alignment () const;
207 void setAlignment (Qt::Alignment flag);
208
210 void setFrame(bool frame);
211 bool hasFrame() const;
212
216 QString prefix() const;
217 void setPrefix(const QString &prefix);
218
222 QString suffix() const;
223 void setSuffix(const QString &suffix);
224
229 double singleStep() const;
230 void setSingleStep(double value);
231
233 double minimum() const;
234 void setMinimum(double min);
235 double maximum() const;
236 void setMaximum(double max);
237 void setRange(double min, double max);
238
242 int decimals() const;
243
247 double round(double value) const;
248
252 QDoubleSpinBox* spinBox() const;
253
256 QLineEdit* lineEdit()const;
257
260 DoubleSpinBox::SetMode setMode() const;
261 void setSetMode(SetMode mode);
262
265 DoubleSpinBox::DecimalsOptions decimalsOption();
266 void setDecimalsOption(DoubleSpinBox::DecimalsOptions option);
267
273 void setInvertedControls(bool invertedControls);
274 bool invertedControls() const;
275
278 void setSizeHintPolicy(SizeHintPolicy newSizeHintPolicy);
281 SizeHintPolicy sizeHintPolicy()const;
282
291 void setValueProxy(ValueProxy* proxy);
292 ValueProxy* valueProxy() const;
293
296 virtual QSize sizeHint()const;
299 virtual QSize minimumSizeHint()const;
300
301 void setKeyboardTracking(bool kt);
302 bool keyboardTracking() const;
303
304public slots:
307 void setValue(double value);
308
311 void setValueIfDifferent(double value);
312
315 void setValueAlways(double value);
316
319 void stepUp();
320 void stepDown();
321
324 void setDecimals(int decimal);
325
326signals:
329 void valueChanged(double);
330 void valueChanged(const QString &);
331
335
338
339protected:
340 DoubleSpinBoxPrivate* const d_ptr;
341
343 virtual void keyPressEvent(QKeyEvent* event);
345 virtual bool eventFilter(QObject *obj, QEvent *event);
346
347 friend class CoordinatesWidgetPrivate;
348private:
349 Q_DECLARE_PRIVATE(DoubleSpinBox);
350 Q_DISABLE_COPY(DoubleSpinBox);
351};
352
353Q_DECLARE_METATYPE(DoubleSpinBox::SetMode)
354Q_DECLARE_OPERATORS_FOR_FLAGS(DoubleSpinBox::DecimalsOptions)
355
356#endif //__DoubleSpinBox_h
Custom SpinBox The DoubleSpinBox internally uses a QDoubleSpinBox while it retain controls over it.
Definition doubleSpinBox.h:55
void editingFinished()
DecimalsOption
Definition doubleSpinBox.h:122
SetMode
Definition doubleSpinBox.h:113
void valueChanged(double)
void decimalsChanged(int)
Signal emitted when the decimals of the displayed are changed.
DoubleSpinBox::DecimalsOptions decimalsOption()
Definition doubleSpinBox_p.h:91
Base class for value proxies. Value proxy allows to decouple the displayed value from the values acce...
Definition valueProxy.h:46