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#include <QVariant>
11
20class CssQmlUnitConverter : public QObject
21{
22 Q_OBJECT
23
25 Q_PROPERTY(qreal dpi READ dpi WRITE setDpi NOTIFY dpiChanged)
26
27
29
31 Q_PROPERTY(qreal dataValue READ dataValue WRITE setDataValue NOTIFY dataValueChanged)
32 Q_PROPERTY(int dataUnit READ dataUnit WRITE setDataUnit NOTIFY dataUnitChanged)
33
35 Q_PROPERTY(qreal userValue READ userValue WRITE setUserValue NOTIFY userValueChanged)
36 Q_PROPERTY(int userUnit READ userUnit WRITE setUserUnit NOTIFY userUnitChanged)
37
39 Q_PROPERTY(QVariantList userUnitModel READ userUnitModel NOTIFY userUnitModelChanged)
40
42 Q_PROPERTY(QString symbol READ symbol NOTIFY userUnitChanged)
43
46
47public:
48 CssQmlUnitConverter(QObject *parent = nullptr);
49
51
52 enum UserUnits {
58 //
60 // Font Relative
67 // unique for certain properties
70 };
71
72 Q_ENUM(UserUnits)
73
74
79 Q_INVOKABLE void setDataUnitMap(const QVariantList &unitMap);
80
86 Q_INVOKABLE void setFontMetricsFromTextPropertiesModel(KoSvgTextPropertiesModel *textPropertiesModel, bool isFontSize = false, bool isLineHeight = false);
87
92 Q_INVOKABLE void setFromNormalLineHeight();
93
98 Q_INVOKABLE void setDataValueAndUnit(const qreal value, const int unit);
99
100 qreal dpi() const;
101 void setDpi(qreal newDpi);
102
103 qreal dataMultiplier() const;
104 void setDataMultiplier(qreal newDataMultiplier);
105
106 qreal dataValue() const;
107 void setDataValue(qreal newDataValue);
108
109 int dataUnit() const;
110 void setDataUnit(int newDataUnit);
111
112 qreal userValue() const;
113 void setUserValue(qreal newUserValue);
114
115 int userUnit() const;
116 void setUserUnit(int newUserUnit);
117
118 QVariantList userUnitModel() const;
119
120 QString symbol() const;
121
122 qreal percentageReference() const;
123 void setPercentageReference(qreal newPercentageReference);
124
125Q_SIGNALS:
126
129
131
133
135
137
139
141
142private:
143 // Converts from a relative value (font or percentage) to pt.
144 qreal convertFromRelativeValue(const qreal value, const UserUnits type) const;
145 // Converts from pt to the given relative value (font or percentage).
146 qreal convertToRelativeValue(const qreal value, const UserUnits type)const ;
147
148 struct Private;
149 const QScopedPointer<Private> d;
150};
151
152#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.