1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7 /***************************************************************************
8  *   Craig Bradney, cbradney@zip.com.au                                    *
9  ***************************************************************************/
10 
11 #ifndef SCRSPINBOX
12 #define SCRSPINBOX
13 
14 #include <QDoubleSpinBox>
15 #include <QLineEdit>
16 #include <QWidget>
17 
18 #include "scribusapi.h"
19 
20 //!\brief ScrSpinBox is a Qt4 replacement for our old ScrSpinBox using Qt3
21 class SCRIBUS_API ScrSpinBox : public QDoubleSpinBox
22 {
23 	Q_OBJECT
24 	public:
25 		ScrSpinBox(QWidget *parent, int unitIndex=0);
26 		ScrSpinBox(double minValue, double maxValue, QWidget *pa, int unitIndex=0);
27 		~ScrSpinBox() override;
28 
29 		//overridden members
30 		double valueFromText (const QString & text) const override;
31 		QString textFromValue (double value) const override;
32 		QValidator::State validate (QString & input, int & pos) const override;
33 		void fixup (QString & input) const override;
34 
35 		// call QDoubleSpinBox::setValue() without emitting valueChanged() signal
36 		void showValue(double val);
37 
38 		//custom
39 		void init(int unitIndex);
40 		void setConstants(const QMap<QString, double>* constants);
41 		void setNewUnit(int unitIndex);
42 		double getValue(int unitIndex=0) const;
43 
unitIndex()44 		uint unitIndex() const { return m_unitIndex; }
45 		double unitRatio() const;
46 
47 		// Reimplement QDoubleSpinBox::stepBy() for angle wrapping
48 		void stepBy(int steps) override;
49 
50 	public slots:
51 		void getValues(double *min, double *max, int *deci, double *val) const;
52 		void setValue(int val);
53 		void setValue(double val);
54 		void setValues(double min, double max, int deci, double val);
55 
56 	protected:
57 		uint m_unitIndex { 0 };
58 		const QMap<QString, double>* m_constants;
59 
60 		void setParameters(int s);
61 		bool eventFilter ( QObject * watched, QEvent * event ) override;
62 
63 	protected slots:
64 		void textChanged();
65 
66 };
67 #endif
68