Krita Source Code Documentation
Loading...
Searching...
No Matches
CssQmlUnitConverter.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6#ifndef CSSQMLUNITCONVERTER_H
7#define CSSQMLUNITCONVERTER_H
8
9#include <QObject>
10
19class CssQmlUnitConverter : public QObject
20{
21 Q_OBJECT
22
24 Q_PROPERTY(qreal dpi READ dpi WRITE setDpi NOTIFY dpiChanged)
25
26
28
30 Q_PROPERTY(qreal dataValue READ dataValue WRITE setDataValue NOTIFY dataValueChanged)
31 Q_PROPERTY(int dataUnit READ dataUnit WRITE setDataUnit NOTIFY dataUnitChanged)
32
34 Q_PROPERTY(qreal userValue READ userValue WRITE setUserValue NOTIFY userValueChanged)
35 Q_PROPERTY(int userUnit READ userUnit WRITE setUserUnit NOTIFY userUnitChanged)
36
38 Q_PROPERTY(QVariantList userUnitModel READ userUnitModel NOTIFY userUnitModelChanged)
39
41 Q_PROPERTY(QString symbol READ symbol NOTIFY userUnitChanged)
42
45
46public:
47 CssQmlUnitConverter(QObject *parent = nullptr);
48
50
51 enum UserUnits {
57 //
59 // Font Relative
66 // unique for certain properties
69 };
70
71 Q_ENUM(UserUnits)
72
73
78 Q_INVOKABLE void setDataUnitMap(const QVariantList &unitMap);
79
85 Q_INVOKABLE void setFontMetricsFromTextPropertiesModel(KoSvgTextPropertiesModel *textPropertiesModel, bool isFontSize = false, bool isLineHeight = false);
86
91 Q_INVOKABLE void setFromNormalLineHeight();
92
97 Q_INVOKABLE void setDataValueAndUnit(const qreal value, const int unit);
98
99 qreal dpi() const;
100 void setDpi(qreal newDpi);
101
102 qreal dataMultiplier() const;
103 void setDataMultiplier(qreal newDataMultiplier);
104
105 qreal dataValue() const;
106 void setDataValue(qreal newDataValue);
107
108 int dataUnit() const;
109 void setDataUnit(int newDataUnit);
110
111 qreal userValue() const;
112 void setUserValue(qreal newUserValue);
113
114 int userUnit() const;
115 void setUserUnit(int newUserUnit);
116
117 QVariantList userUnitModel() const;
118
119 QString symbol() const;
120
121 qreal percentageReference() const;
122 void setPercentageReference(qreal newPercentageReference);
123
124Q_SIGNALS:
125
128
130
132
134
136
138
140
141private:
142 // Converts from a relative value (font or percentage) to pt.
143 qreal convertFromRelativeValue(const qreal value, const UserUnits type) const;
144 // Converts from pt to the given relative value (font or percentage).
145 qreal convertToRelativeValue(const qreal value, const UserUnits type)const ;
146
147 struct Private;
148 const QScopedPointer<Private> d;
149};
150
151#endif // CSSQMLUNITCONVERTER_H
float value(const T *src, size_t ch)
The CssQmlUnitConverter class.
QString symbol
The symbol.
void setPercentageReference(qreal newPercentageReference)
@ Ic
average full-width advance
@ Lines
Used by lineHeight.
@ Px
Pixels, dpi relative.
@ Ch
average proportional advance
Q_INVOKABLE void setFontMetricsFromTextPropertiesModel(KoSvgTextPropertiesModel *textPropertiesModel, bool isFontSize=false, bool isLineHeight=false)
setFontMetricsFromTextPropertiesModel Set the current font metrics from the text properties model.
qreal convertToRelativeValue(const qreal value, const UserUnits type) const
const QScopedPointer< Private > d
qreal percentageReference
value to represent 100%
void setDataMultiplier(qreal newDataMultiplier)
QVariantList userUnitModel
A model for the available user units.
void dataMultiplierChanged()
void setDataUnit(int newDataUnit)
void setUserUnit(int newUserUnit)
qreal convertFromRelativeValue(const qreal value, const UserUnits type) const
void setDpi(qreal newDpi)
void setUserValue(qreal newUserValue)
qreal dpi
The DPI used to calculate pixel to physical properties.
void setDataValue(qreal newDataValue)
void percentageReferenceChanged()
Q_INVOKABLE void setDataUnitMap(const QVariantList &unitMap)
setDataUnitMap
Q_INVOKABLE void setFromNormalLineHeight()
setFromNormalLineHeight set the current value from line-height:normal metrics.
qreal userValue
userValue and userUnit represent the user-visible data. This can include synthetic units like px and ...
qreal dataMultiplier
Data multiplier is used if for some reason the user-value needs to be multiplied by a certain factor.
Q_INVOKABLE void setDataValueAndUnit(const qreal value, const int unit)
setDataValueAndUnit set data unit and value in one go.
qreal dataValue
dataValue and dataUnit represent the data as used by the text properties.
The KoSvgTextPropertiesModel class.