15#include <klocalizedstring.h>
36 return i18n(
"Millimeters (mm)");
38 return i18n(
"Centimeters (cm)");
40 return i18n(
"Decimeters (dm)");
42 return i18n(
"Inches (in)");
44 return i18n(
"Pica (pi)");
46 return i18n(
"Cicero (cc)");
48 return i18n(
"Points (pt)");
50 return i18n(
"Pixels (px)");
52 return i18n(
"Unsupported unit");
116 result = i - skipped;
129 qreal rounding = 1.0;
158 return floor(userValue * rounding) / rounding;
231 if (_value.isEmpty())
234 QString
value(_value.simplified());
235 value.remove(QLatin1Char(
' '));
237 int firstLetter = -1;
238 for (
int i = 0; i <
value.length(); ++i) {
239 if (
value.at(i).isLetter()) {
240 if (
value.at(i) == QLatin1Char(
'e'))
247 if (firstLetter == -1)
248 return value.toDouble();
251 value.truncate(firstLetter);
252 const qreal val =
value.toDouble();
254 if (
symbol == QLatin1String(
"pt"))
260 return u.fromUserValue(val);
262 if (
symbol == QLatin1String(
"m"))
264 else if (
symbol == QLatin1String(
"km"))
275 if (
symbol == QLatin1String(
"inch") ) {
285 result =
static_cast<Type>(i);
298 switch (fromUnit.
type()) {
325 switch (toUnit.
type()) {
354 if (_value.isEmpty())
357 QString
value(_value.simplified());
358 value.remove(QLatin1Char(
' '));
360 int firstLetter = -1;
361 for (
int i = 0; i <
value.length(); ++i) {
362 if (
value.at(i).isLetter()) {
363 if (
value.at(i) == QLatin1Char(
'e'))
370 if (firstLetter == -1)
371 return value.toDouble();
373 const QString
type =
value.mid(firstLetter);
374 value.truncate(firstLetter);
375 const qreal val =
value.toDouble();
377 if (
type == QLatin1String(
"deg"))
379 else if (
type == QLatin1String(
"rad"))
380 return val * 180 /
M_PI;
381 else if (
type == QLatin1String(
"grad"))
389 return std::sqrt(qAbs(t.determinant()));
397#ifndef QT_NO_DEBUG_STREAM
401 debug.nospace() << unit.
symbol();
405 return debug.space();
float value(const T *src, size_t ch)
static const KoUnit::Type typesInUi[KoUnit::TypeCount]
QDebug operator<<(QDebug debug, const KoUnit &unit)
static const char *const unitNameList[KoUnit::TypeCount]
constexpr qreal POINT_TO_CM(qreal px)
constexpr qreal POINT_TO_DM(qreal px)
constexpr qreal CC_TO_POINT(qreal cc)
constexpr qreal POINT_TO_MM(qreal px)
constexpr qreal POINT_TO_INCH(qreal px)
constexpr qreal CM_TO_POINT(qreal cm)
static const qreal IN_ROUNDING
static const qreal PT_ROUNDING
constexpr qreal INCH_TO_POINT(qreal inch)
static const qreal MM_ROUNDING
constexpr qreal POINT_TO_PI(qreal px)
static const qreal CM_ROUNDING
static const qreal DM_ROUNDING
constexpr qreal PI_TO_POINT(qreal pi)
constexpr qreal POINT_TO_CC(qreal px)
constexpr qreal MM_TO_POINT(qreal mm)
static const qreal CC_ROUNDING
static const qreal PI_ROUNDING
constexpr qreal DM_TO_POINT(qreal dm)
static qreal parseAngle(const QString &value, qreal defaultVal=0.0)
parse an angle to its value in degrees
QString toUserStringValue(qreal ptValue) const
static qreal convertFromUnitToUnit(const qreal value, const KoUnit &fromUnit, const KoUnit &toUnit, qreal factor=1.0)
static QString unitDescription(KoUnit::Type type)
Get the description string of the given unit.
static qreal parseValue(const QString &value, qreal defaultVal=0.0)
parse common Krita and Odf values, like "10cm", "5mm" to pt
qreal fromUserValue(qreal value) const
static qreal approxTransformScale(const QTransform &t)
KoUnit::Type type() const
qreal toUserValuePrecise(const qreal ptValue) const
static KoUnit fromSymbol(const QString &symbol, bool *ok=0)
static KoUnit fromListForUi(int index, ListOptions listOptions=ListAll, qreal factor=1.0)
qreal toUserValueRounded(const qreal value) const
QString symbol() const
Get the symbol string of the unit.
KoUnit(Type unit=Point, qreal factor=1.0)
@ Point
Postscript point, 1/72th of an Inco.
void adjustByPixelTransform(const QTransform &t)
static QStringList listOfUnitNameForUi(ListOptions listOptions=ListAll)
Returns the list of unit types for the UI, controlled with the given listOptions.
qreal toUserValue(qreal ptValue, bool rounding=true) const
int indexInListForUi(ListOptions listOptions=ListAll) const