1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQUICKFONTMETRICS_H
5#define QQUICKFONTMETRICS_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <private/qtquickglobal_p.h>
19
20#include <QtQml/qqml.h>
21
22#include <QtGui/qfontmetrics.h>
23
24#include <QtCore/qobject.h>
25
26QT_BEGIN_NAMESPACE
27
28class QFont;
29
30class Q_QUICK_PRIVATE_EXPORT QQuickFontMetrics : public QObject
31{
32 Q_OBJECT
33
34 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged FINAL)
35 Q_PROPERTY(qreal ascent READ ascent NOTIFY fontChanged FINAL)
36 Q_PROPERTY(qreal descent READ descent NOTIFY fontChanged FINAL)
37 Q_PROPERTY(qreal height READ height NOTIFY fontChanged FINAL)
38 Q_PROPERTY(qreal leading READ leading NOTIFY fontChanged FINAL)
39 Q_PROPERTY(qreal lineSpacing READ lineSpacing NOTIFY fontChanged FINAL)
40 Q_PROPERTY(qreal minimumLeftBearing READ minimumLeftBearing NOTIFY fontChanged FINAL)
41 Q_PROPERTY(qreal minimumRightBearing READ minimumRightBearing NOTIFY fontChanged FINAL)
42 Q_PROPERTY(qreal maximumCharacterWidth READ maximumCharacterWidth NOTIFY fontChanged FINAL)
43 Q_PROPERTY(qreal xHeight READ xHeight NOTIFY fontChanged FINAL)
44 Q_PROPERTY(qreal averageCharacterWidth READ averageCharacterWidth NOTIFY fontChanged FINAL)
45 Q_PROPERTY(qreal underlinePosition READ underlinePosition NOTIFY fontChanged FINAL)
46 Q_PROPERTY(qreal overlinePosition READ overlinePosition NOTIFY fontChanged FINAL)
47 Q_PROPERTY(qreal strikeOutPosition READ strikeOutPosition NOTIFY fontChanged FINAL)
48 Q_PROPERTY(qreal lineWidth READ lineWidth NOTIFY fontChanged FINAL)
49 QML_NAMED_ELEMENT(FontMetrics)
50 QML_ADDED_IN_VERSION(2, 4)
51public:
52 explicit QQuickFontMetrics(QObject *parent = nullptr);
53
54 QFont font() const;
55 void setFont(const QFont &font);
56
57 qreal ascent() const;
58 qreal descent() const;
59 qreal height() const;
60 qreal leading() const;
61 qreal lineSpacing() const;
62 qreal minimumLeftBearing() const;
63 qreal minimumRightBearing() const;
64 qreal maximumCharacterWidth() const;
65
66 qreal xHeight() const;
67 qreal averageCharacterWidth() const;
68
69 qreal underlinePosition() const;
70 qreal overlinePosition() const;
71 qreal strikeOutPosition() const;
72 qreal lineWidth() const;
73
74 Q_INVOKABLE qreal advanceWidth(const QString &text) const;
75 Q_INVOKABLE QRectF boundingRect(const QString &text) const;
76 Q_INVOKABLE QRectF tightBoundingRect(const QString &text) const;
77 Q_INVOKABLE QString elidedText(const QString &text, Qt::TextElideMode mode, qreal width, int flags = 0) const;
78
79Q_SIGNALS:
80 void fontChanged(const QFont &font);
81
82private:
83 QFont m_font;
84 QFontMetricsF m_metrics;
85};
86
87QT_END_NAMESPACE
88
89QML_DECLARE_TYPE(QQuickFontMetrics)
90
91#endif // QQUICKFONTMETRICS_H
92

source code of qtdeclarative/src/quick/util/qquickfontmetrics_p.h