File indexing completed on 2024-05-12 16:02:12
0001 /* This file is part of the KDE project 0002 SPDX-FileCopyrightText: 2002 Rob Buis (buis@kde.org) 0003 SPDX-FileCopyrightText: 2004 Nicolas GOUTTE <goutte@kde.org> 0004 SPDX-FileCopyrightText: 2007 Thomas Zander <zander@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #ifndef KOUNITDOUBLESPINBOX_H 0010 #define KOUNITDOUBLESPINBOX_H 0011 0012 #include "kritawidgets_export.h" 0013 0014 #include <QDoubleSpinBox> 0015 0016 class KoUnit; 0017 0018 /** 0019 * Spin box for double precision numbers with unit display. 0020 * Use this widget for any value that represents a real measurable value for consistency throughout 0021 * Krita. 0022 * This widget shows the value in the user-selected units (inch, millimeters, etc) but keeps the 0023 * Krita-widget default measurement unit internally. This has the advantage that just setting and 0024 * getting a value will not change the value due to conversions. 0025 * The KoDocument class has a unit() method for consistent (document wide) configuration of the 0026 * used unit. 0027 * It is advised to use a QDoubleSpinBox in QtDesigner and then use the context-menu item: 'Promote to Custom Widget' and use the values: 'classname=KoUnitDoubleSpinBox', 'headerfile=KoUnitDoubleSpinBox.h' 0028 * This will generate code that uses this spinbox in the correct manner. 0029 * 0030 * This class need to be replaced as much as possible with \see KisDoubleParseUnitSpinBox to add math parsing ability. 0031 */ 0032 class KRITAWIDGETS_EXPORT KoUnitDoubleSpinBox : public QDoubleSpinBox 0033 { 0034 Q_OBJECT 0035 public: 0036 /** 0037 * Constructor 0038 * Create a new spinBox with very broad range predefined. 0039 * This spinbox will have min and max borders of 10000 points and use 0040 * the default unit of points. 0041 * @param parent the parent widget 0042 */ 0043 explicit KoUnitDoubleSpinBox( QWidget *parent = 0); 0044 ~KoUnitDoubleSpinBox() override; 0045 0046 /** 0047 * Set the new value in points which will then be converted to the current unit for display 0048 * @param newValue the new value 0049 * @see value() 0050 */ 0051 virtual void changeValue( double newValue ); 0052 /** 0053 * This spinbox shows the internal value after a conversion to the unit set here. 0054 */ 0055 virtual void setUnit( const KoUnit &); 0056 0057 /// @return the current value, converted in points 0058 double value( ) const; 0059 0060 /// Set minimum value in points. 0061 void setMinimum(double min); 0062 0063 /// Set maximum value in points. 0064 void setMaximum(double max); 0065 0066 /// Set step size in the current unit. 0067 void setLineStep(double step); 0068 0069 /// Set step size in points. 0070 void setLineStepPt(double step); 0071 0072 /// Set minimum, maximum value and the step size (all in points) 0073 void setMinMaxStep( double min, double max, double step ); 0074 0075 /// reimplemented from superclass, will forward to KoUnitDoubleValidator 0076 QValidator::State validate(QString &input, int &pos) const override; 0077 0078 /** 0079 * Transform the double in a nice text, using locale symbols 0080 * @param value the number as double 0081 * @return the resulting string 0082 */ 0083 QString textFromValue( double value ) const override; 0084 /** 0085 * Transform a string into a double, while taking care of locale specific symbols. 0086 * @param str the string to transform into a number 0087 * @return the value as double 0088 */ 0089 double valueFromText( const QString& str ) const override; 0090 0091 0092 Q_SIGNALS: 0093 /// emitted like valueChanged in the parent, but this one emits the point value 0094 void valueChangedPt( qreal ); 0095 0096 private: 0097 class Private; 0098 Private * const d; 0099 0100 private Q_SLOTS: 0101 // exists to do emits for valueChangedPt 0102 void privateValueChanged(); 0103 }; 0104 0105 #endif 0106