13#include <QRegularExpression>
17#include <klocalizedstring.h>
26 Private(
double low,
double up,
double step)
41 : QDoubleSpinBox( parent ),
44 QDoubleSpinBox::setDecimals( 2 );
47 setAlignment( Qt::AlignRight );
60 debugWidgets <<
"KoUnitDoubleSpinBox::validate :" << input <<
" at" << pos;
65 QRegularExpression regexp (
"([ a-zA-Z]+)$");
66 QRegularExpressionMatch match;
67 const int res = input.indexOf(regexp, 0, &match);
75 return QValidator::Intermediate;
79 const QString number ( input.left( res ).trimmed() );
80 const QString unitName ( match.captured( 1 ).trimmed().toLower() );
83 debugWidgets <<
"Split:" << number <<
":" << unitName <<
":";
99 return QValidator::Intermediate;
105 return QValidator::Invalid;
107 newVal =
d->unit.toUserValuePrecise(newVal);
110 return QValidator::Acceptable;
115 QDoubleSpinBox::setValue(
d->unit.toUserValue( val ) );
127 if (
unit ==
d->unit)
return;
129 double oldvalue =
d->unit.fromUserValue( QDoubleSpinBox::value() );
137 step = qMax(qreal(1.0), step);
140 QDoubleSpinBox::setSingleStep( step );
143 setSuffix(
unit.
symbol().prepend(QLatin1Char(
' ')));
148 return d->unit.fromUserValue( QDoubleSpinBox::value() );
153 d->lowerInPoints = min;
154 QDoubleSpinBox::setMinimum(
d->unit.toUserValue( min ) );
159 d->upperInPoints = max;
160 QDoubleSpinBox::setMaximum(
d->unit.toUserValue( max ) );
166 QDoubleSpinBox::setSingleStep( step );
171 d->stepInPoints = step;
172 QDoubleSpinBox::setSingleStep(
d->unit.toUserValue( step ) );
187 return QLocale().toString(
value,
'f', decimals() );
193 str2.remove(
d->unit.symbol());
194 return QLocale().toDouble(str2);
float value(const T *src, size_t ch)
double stepInPoints
step in points
QString textFromValue(double value) const override
virtual void changeValue(double newValue)
void setLineStep(double step)
Set step size in the current unit.
Private(double low, double up, double step)
virtual void setUnit(const KoUnit &)
void valueChangedPt(qreal)
emitted like valueChanged in the parent, but this one emits the point value
double valueFromText(const QString &str) const override
double lowerInPoints
lowest value in points
double upperInPoints
highest value in points
void setMaximum(double max)
Set maximum value in points.
void privateValueChanged()
QValidator::State validate(QString &input, int &pos) const override
reimplemented from superclass, will forward to KoUnitDoubleValidator
void setMinMaxStep(double min, double max, double step)
Set minimum, maximum value and the step size (all in points)
KoUnitDoubleSpinBox(QWidget *parent=0)
void setLineStepPt(double step)
Set step size in points.
void setMinimum(double min)
Set minimum value in points.
~KoUnitDoubleSpinBox() override
qreal fromUserValue(qreal value) const
KoUnit::Type type() const
qreal toUserValuePrecise(const qreal ptValue) const
static KoUnit fromSymbol(const QString &symbol, bool *ok=0)
QString symbol() const
Get the symbol string of the unit.
@ Point
Postscript point, 1/72th of an Inco.
qreal toUserValue(qreal ptValue, bool rounding=true) const