|
Krita Source Code Documentation
|
#include <KoUnit.h>
Inheritance diagram for KoUnit:Public Types | |
| enum | ListOption { ListAll = 0 , HidePixel = 1 , HideMask = HidePixel } |
| Used to control the scope of the unit types listed in the UI. More... | |
| enum | Type { Millimeter = 0 , Point , Inch , Centimeter , Decimeter , Pica , Cicero , Pixel , TypeCount } |
Public Member Functions | |
| void | adjustByPixelTransform (const QTransform &t) |
| qreal | fromUserValue (const QString &value, bool *ok=0) const |
| qreal | fromUserValue (qreal value) const |
| int | indexInListForUi (ListOptions listOptions=ListAll) const |
| KoUnit (Type unit=Point, qreal factor=1.0) | |
| KoUnit & | operator= (Type unit) |
| bool | operator== (const KoUnit &other) const |
| void | setFactor (qreal factor) |
| QString | symbol () const |
| Get the symbol string of the unit. | |
| QString | toString () const |
| QString | toUserStringValue (qreal ptValue) const |
| qreal | toUserValue (qreal ptValue, bool rounding=true) const |
| qreal | toUserValuePrecise (const qreal ptValue) const |
| qreal | toUserValueRounded (const qreal value) const |
| KoUnit::Type | type () const |
Static Public Member Functions | |
| static qreal | approxTransformScale (const QTransform &t) |
| static qreal | convertFromUnitToUnit (const qreal value, const KoUnit &fromUnit, const KoUnit &toUnit, qreal factor=1.0) |
| static KoUnit | fromListForUi (int index, ListOptions listOptions=ListAll, qreal factor=1.0) |
| static KoUnit | fromSymbol (const QString &symbol, bool *ok=0) |
| static QStringList | listOfUnitNameForUi (ListOptions listOptions=ListAll) |
Returns the list of unit types for the UI, controlled with the given listOptions. | |
| static qreal | parseAngle (const QString &value, qreal defaultVal=0.0) |
| parse an angle to its value in degrees | |
| static qreal | parseValue (const QString &value, qreal defaultVal=0.0) |
| parse common Krita and Odf values, like "10cm", "5mm" to pt | |
| static QString | unitDescription (KoUnit::Type type) |
| Get the description string of the given unit. | |
Private Attributes | |
| qreal | m_pixelConversion |
| Type | m_type |
Krita stores everything in pt (using "qreal") internally. When displaying a value to the user, the value is converted to the user's unit of choice, and rounded to a reasonable precision to avoid 0.999999
For implementing the selection of a unit type in the UI use the *ForUi() methods. They ensure the same order of the unit types in all places, with the order not bound to the order in the enum (so ABI-compatible extension is possible) and with the order and scope of listed types controlled by the ListOptions parameter.
| enum KoUnit::ListOption |
| enum KoUnit::Type |
Length units supported by Krita.
| Enumerator | |
|---|---|
| Millimeter | |
| Point | Postscript point, 1/72th of an Inco. |
| Inch | |
| Centimeter | |
| Decimeter | |
| Pica | |
| Cicero | |
| Pixel | |
| TypeCount | |
Definition at line 74 of file KoUnit.h.
Construction requires initialization. The factor is for variable factor units like pixel
| void KoUnit::adjustByPixelTransform | ( | const QTransform & | t | ) |
Adjust the unit by pixel transformation applied to the describing object. It multiplies the pixel coefficient by the average scale of the matrix.
Definition at line 392 of file KoUnit.cpp.
References approxTransformScale(), and m_pixelConversion.
|
static |
Get an approximate scale of a unit vector that was converted by the transformation.
Please note that exact values are guaranteed only for combinations of Translate, Rotation and Uniform Scale matrices. For combinations having shears and perspective the value will be average for the point near CS origin.
Definition at line 387 of file KoUnit.cpp.
|
static |
convert the given value directly from one unit to another
Definition at line 295 of file KoUnit.cpp.
References CC_TO_POINT(), Centimeter, Cicero, CM_TO_POINT(), Decimeter, DM_TO_POINT(), Inch, INCH_TO_POINT(), Millimeter, MM_TO_POINT(), PI_TO_POINT(), Pica, Pixel, Point, POINT_TO_CC(), POINT_TO_CM(), POINT_TO_DM(), POINT_TO_INCH(), POINT_TO_MM(), POINT_TO_PI(), type(), and value().
|
static |
Returns a KoUnit instance with the type at the index of the UI list with the given listOptions.
Definition at line 80 of file KoUnit.cpp.
References HidePixel, KoUnit(), Pixel, Point, type(), TypeCount, and typesInUi.
|
static |
Convert a unit symbol string into a KoUnit
| symbol | symbol to convert |
| ok | if set, it will be true if the unit was known, false if unknown |
Definition at line 271 of file KoUnit.cpp.
References Inch, KoUnit(), Point, symbol(), TypeCount, and unitNameList.
| qreal KoUnit::fromUserValue | ( | const QString & | value, |
| bool * | ok = 0 ) const |
This method is the one to use to read a value from a dialog
| value | value entered by the user |
| ok | if set, the pointed bool is set to true if the value could be converted to a qreal, and to false otherwise. |
Definition at line 224 of file KoUnit.cpp.
References fromUserValue(), toDouble(), and value().
| qreal KoUnit::fromUserValue | ( | qreal | value | ) | const |
This method is the one to use to read a value from a dialog
Definition at line 201 of file KoUnit.cpp.
References CC_TO_POINT(), Centimeter, Cicero, CM_TO_POINT(), Decimeter, DM_TO_POINT(), Inch, INCH_TO_POINT(), m_pixelConversion, m_type, Millimeter, MM_TO_POINT(), PI_TO_POINT(), Pica, Pixel, Point, and value().
| int KoUnit::indexInListForUi | ( | ListOptions | listOptions = ListAll | ) | const |
Get the index of this unit in the list of unit types for the UI, if it is controlled with the given listOptions.
Definition at line 101 of file KoUnit.cpp.
References HidePixel, m_type, Pixel, TypeCount, and typesInUi.
|
static |
Returns the list of unit types for the UI, controlled with the given listOptions.
Definition at line 69 of file KoUnit.cpp.
References HideMask, ListAll, Pixel, type(), TypeCount, typesInUi, and unitDescription().
|
inline |
Definition at line 112 of file KoUnit.h.
References m_pixelConversion, m_type, and qFuzzyCompare().
|
static |
parse an angle to its value in degrees
Definition at line 352 of file KoUnit.cpp.
|
static |
parse common Krita and Odf values, like "10cm", "5mm" to pt
Definition at line 229 of file KoUnit.cpp.
References DM_TO_POINT(), fromSymbol(), symbol(), u, and value().
|
inline |
| QString KoUnit::symbol | ( | ) | const |
Get the symbol string of the unit.
Definition at line 347 of file KoUnit.cpp.
References m_type, and unitNameList.
|
inline |
| QString KoUnit::toUserStringValue | ( | qreal | ptValue | ) | const |
This method is the one to use to display a value in a dialog
ptValue converted the unit and rounded, ready to be displayed Definition at line 196 of file KoUnit.cpp.
References toUserValue().
| qreal KoUnit::toUserValue | ( | qreal | ptValue, |
| bool | rounding = true ) const |
Convert the value ptValue with or with rounding as indicated by rounding. This method is a proxy to toUserValuePrecise and toUserValueRounded.
ptValue converted to unit Definition at line 186 of file KoUnit.cpp.
References toUserValuePrecise(), and toUserValueRounded().
| qreal KoUnit::toUserValuePrecise | ( | const qreal | ptValue | ) | const |
Convert the value ptValue to the unit (without rounding) This method is meant to be used in complex calculations.
Definition at line 161 of file KoUnit.cpp.
References Centimeter, Cicero, Decimeter, Inch, m_pixelConversion, m_type, Millimeter, Pica, Pixel, Point, POINT_TO_CC(), POINT_TO_CM(), POINT_TO_DM(), POINT_TO_INCH(), POINT_TO_MM(), and POINT_TO_PI().
| qreal KoUnit::toUserValueRounded | ( | const qreal | value | ) | const |
Convert the value ptValue to the unit and round it. This method is meant to be used to display a value in a dialog.
Definition at line 126 of file KoUnit.cpp.
References CC_ROUNDING, Centimeter, Cicero, CM_ROUNDING, Decimeter, DM_ROUNDING, IN_ROUNDING, Inch, m_type, Millimeter, MM_ROUNDING, PI_ROUNDING, Pica, Pixel, Point, PT_ROUNDING, toUserValuePrecise(), and value().
|
inline |
|
static |
Get the description string of the given unit.
Definition at line 32 of file KoUnit.cpp.
References Centimeter, Cicero, Decimeter, Inch, Millimeter, Pica, Pixel, Point, and type().