Changeset View
Changeset View
Standalone View
Standalone View
libs/widgets/kis_double_parse_spin_box.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (c) 2016 Laurent Valentin Jospin <laurent.valentin@famillejospin.ch> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or modify | ||||
5 | * it under the terms of the GNU General Public License as published by | ||||
6 | * the Free Software Foundation; either version 2 of the License, or | ||||
7 | * (at your option) any later version. | ||||
8 | * | ||||
9 | * This program is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
12 | * GNU General Public License for more details. | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU General Public License | ||||
15 | * along with this program; if not, write to the Free Software | ||||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
17 | */ | ||||
18 | | ||||
19 | #ifndef KISDOUBLEPARSESPINBOX_H | ||||
20 | #define KISDOUBLEPARSESPINBOX_H | ||||
21 | | ||||
22 | #include <QDoubleSpinBox> | ||||
23 | | ||||
24 | #include "kritawidgets_export.h" | ||||
25 | | ||||
26 | class QLabel; | ||||
27 | | ||||
28 | /*! | ||||
29 | * \brief The KisDoubleParseSpinBox class is a cleverer doubleSpinBox, able to parse arithmetic expressions. | ||||
30 | * | ||||
31 | * Use this spinbox instead of the basic one from Qt if you want it to be able to parse arithmetic expressions. | ||||
32 | */ | ||||
33 | class KRITAWIDGETS_EXPORT KisDoubleParseSpinBox : public QDoubleSpinBox | ||||
34 | { | ||||
35 | | ||||
36 | Q_OBJECT | ||||
37 | public: | ||||
38 | KisDoubleParseSpinBox(QWidget* parent = 0); | ||||
39 | ~KisDoubleParseSpinBox(); | ||||
40 | | ||||
41 | virtual double valueFromText(const QString & text) const; | ||||
42 | virtual QString textFromValue(double val) const; | ||||
43 | virtual QValidator::State validate ( QString & input, int & pos ) const; | ||||
44 | | ||||
45 | virtual void stepBy(int steps); | ||||
46 | | ||||
47 | void setValue(double value); //polymorphism won't work directly, we use a signal/slot hack to do so but if signals are disabled this function will still be useful. | ||||
48 | | ||||
49 | bool isLastValid() const{ return boolLastValid; } | ||||
50 | | ||||
51 | Q_SIGNALS: | ||||
52 | | ||||
53 | //! \brief signal emmitted when the last parsed expression create an error. | ||||
54 | void errorWhileParsing(QString expr) const; | ||||
55 | //! \brief signal emmitted when the last parsed expression is valid. | ||||
56 | void noMoreParsingError() const; | ||||
57 | | ||||
58 | public Q_SLOTS: | ||||
59 | | ||||
60 | //! \brief useful to let the widget change it's stylesheet when an error occured in the last expression. | ||||
61 | void setErrorStyle(); | ||||
62 | //! \brief useful to let the widget reset it's stylesheet when there's no more error. | ||||
63 | void clearErrorStyle(); | ||||
64 | //! \brief say the widget to return to an error free state. | ||||
65 | void clearError(); | ||||
66 | | ||||
67 | protected: | ||||
68 | | ||||
69 | mutable QString* lastExprParsed; | ||||
70 | mutable bool boolLastValid; | ||||
71 | mutable double oldValue; | ||||
72 | | ||||
73 | QLabel* warningIcon; | ||||
74 | | ||||
75 | QPalette oldPalette; | ||||
76 | bool isOldPaletteSaved; | ||||
77 | | ||||
78 | QMargins oldMargins; | ||||
79 | bool areOldMarginsSaved; | ||||
80 | }; | ||||
81 | | ||||
82 | #endif // KISDOUBLEPARSESPINBOX_H |