| 1 |
/* This file is part of the KDE project |
| 2 |
SPDX-FileCopyrightText: 2002 Rob Buis ([email protected]) |
| 3 |
SPDX-FileCopyrightText: 2004 Nicolas GOUTTE <[email protected]> |
| 4 |
SPDX-FileCopyrightText: 2007 Thomas Zander <[email protected]> |
| 5 |
|
| 6 |
SPDX-License-Identifier: LGPL-2.0-or-later |
| 7 |
*/ |
| 8 |
|
| 9 |
#ifndef KOUNITDOUBLESPINBOX_H |
| 10 |
#define KOUNITDOUBLESPINBOX_H |
| 11 |
|
| 12 |
#include "kowidgets_export.h" |
| 13 |
|
| 14 |
#include <QDoubleSpinBox> |
| 15 |
|
| 16 |
class KoUnit; |
| 17 |
|
| 18 |
/** |
| 19 |
* Spin box for double precision numbers with unit display. |
| 20 |
* Use this widget for any value that represents a real measurable value for consistency throughout |
| 21 |
* Calligra. |
| 22 |
* This widget shows the value in the user-selected units (inch, millimeters, etc) but keeps the |
| 23 |
* calligra-widget default measurement unit internally. This has the advantage that just setting and |
| 24 |
* getting a value will not change the value due to conversions. |
| 25 |
* The KoDocument class has a unit() method for consistent (document wide) configuration of the |
| 26 |
* used unit. |
| 27 |
* 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' |
| 28 |
* This will generate code that uses this spinbox in the correct manner. |
| 29 |
*/ |
| 30 |
class KOWIDGETS_EXPORT KoUnitDoubleSpinBox : public QDoubleSpinBox |
| 31 |
{ |
| 32 |
Q_OBJECT |
| 33 |
public: |
| 34 |
/** |
| 35 |
* Constructor |
| 36 |
* Create a new spinBox with very broad range predefined. |
| 37 |
* This spinbox will have min and max borders of 10000 points and use |
| 38 |
* the default unit of points. |
| 39 |
* @param parent the parent widget |
| 40 |
*/ |
| 41 |
explicit KoUnitDoubleSpinBox(QWidget *parent = nullptr); |
| 42 |
~KoUnitDoubleSpinBox() override; |
| 43 |
|
| 44 |
/** |
| 45 |
* Set the new value in points which will then be converted to the current unit for display |
| 46 |
* @param newValue the new value |
| 47 |
* @see value() |
| 48 |
*/ |
| 49 |
virtual void changeValue(double newValue); |
| 50 |
/** |
| 51 |
* This spinbox shows the internal value after a conversion to the unit set here. |
| 52 |
*/ |
| 53 |
virtual void setUnit(const KoUnit &); |
| 54 |
|
| 55 |
/// @return the current value, converted in points |
| 56 |
double value() const; |
| 57 |
|
| 58 |
/// Set minimum value in points. |
| 59 |
void setMinimum(double min); |
| 60 |
|
| 61 |
/// Set maximum value in points. |
| 62 |
void setMaximum(double max); |
| 63 |
|
| 64 |
/// Set step size in the current unit. |
| 65 |
void setLineStep(double step); |
| 66 |
|
| 67 |
/// Set step size in points. |
| 68 |
void setLineStepPt(double step); |
| 69 |
|
| 70 |
/// Set minimum, maximum value and the step size (all in points) |
| 71 |
void setMinMaxStep(double min, double max, double step); |
| 72 |
|
| 73 |
/// reimplemented from superclass, will forward to KoUnitDoubleValidator |
| 74 |
QValidator::State validate(QString &input, int &pos) const override; |
| 75 |
|
| 76 |
/** |
| 77 |
* Transform the double in a nice text, using locale symbols |
| 78 |
* @param value the number as double |
| 79 |
* @return the resulting string |
| 80 |
*/ |
| 81 |
QString textFromValue(double value) const override; |
| 82 |
/** |
| 83 |
* Transform a string into a double, while taking care of locale specific symbols. |
| 84 |
* @param str the string to transform into a number |
| 85 |
* @return the value as double |
| 86 |
*/ |
| 87 |
double valueFromText(const QString& str) const override; |
| 88 |
|
| 89 |
|
| 90 |
Q_SIGNALS: |
| 91 |
/// emitted like valueChanged in the parent, but this one emits the point value |
| 92 |
void valueChangedPt(qreal); |
| 93 |
|
| 94 |
private: |
| 95 |
class Private; |
| 96 |
Private * const d; |
| 97 |
|
| 98 |
private Q_SLOTS: |
| 99 |
// exists to do emits for valueChangedPt |
| 100 |
void privateValueChanged(); |
| 101 |
}; |
| 102 |
|
| 103 |
#endif |
| 104 |
|