1// Copyright (C) 2021 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 QQUICKTEXTMETRICS_H
5#define QQUICKTEXTMETRICS_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#include <private/qquicktext_p.h>
20
21#include <QtCore/qobject.h>
22
23#include <QtGui/qfontmetrics.h>
24
25#include <QtQml/qqml.h>
26
27QT_BEGIN_NAMESPACE
28
29class QFont;
30
31class Q_QUICK_PRIVATE_EXPORT QQuickTextMetrics : public QObject
32{
33 Q_OBJECT
34
35 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged FINAL)
36 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged FINAL)
37 Q_PROPERTY(qreal advanceWidth READ advanceWidth NOTIFY metricsChanged FINAL)
38 Q_PROPERTY(QRectF boundingRect READ boundingRect NOTIFY metricsChanged FINAL)
39 Q_PROPERTY(qreal width READ width NOTIFY metricsChanged FINAL)
40 Q_PROPERTY(qreal height READ height NOTIFY metricsChanged FINAL)
41 Q_PROPERTY(QRectF tightBoundingRect READ tightBoundingRect NOTIFY metricsChanged FINAL)
42 Q_PROPERTY(QString elidedText READ elidedText NOTIFY metricsChanged FINAL)
43 Q_PROPERTY(Qt::TextElideMode elide READ elide WRITE setElide NOTIFY elideChanged FINAL)
44 Q_PROPERTY(qreal elideWidth READ elideWidth WRITE setElideWidth NOTIFY elideWidthChanged FINAL)
45 Q_PROPERTY(QQuickText::RenderType renderType READ renderType WRITE setRenderType
46 NOTIFY renderTypeChanged)
47 QML_NAMED_ELEMENT(TextMetrics)
48 QML_ADDED_IN_VERSION(2, 4)
49
50public:
51 explicit QQuickTextMetrics(QObject *parent = nullptr);
52
53 QFont font() const;
54 void setFont(const QFont &font);
55
56 QString text() const;
57 void setText(const QString &text);
58
59 Qt::TextElideMode elide() const;
60 void setElide(Qt::TextElideMode elide);
61
62 qreal elideWidth() const;
63 void setElideWidth(qreal elideWidth);
64
65 qreal advanceWidth() const;
66 QRectF boundingRect() const;
67 qreal width() const;
68 qreal height() const;
69 QRectF tightBoundingRect() const;
70 QString elidedText() const;
71
72 QQuickText::RenderType renderType() const;
73 void setRenderType(QQuickText::RenderType renderType);
74
75Q_SIGNALS:
76 void fontChanged();
77 void textChanged();
78 void elideChanged();
79 void elideWidthChanged();
80 void metricsChanged();
81 void renderTypeChanged();
82
83private:
84 QString m_text;
85 QFont m_font;
86 QFontMetricsF m_metrics;
87 Qt::TextElideMode m_elide;
88 qreal m_elideWidth;
89 QQuickText::RenderType m_renderType;
90};
91
92QT_END_NAMESPACE
93
94QML_DECLARE_TYPE(QQuickTextMetrics)
95
96#endif // QQUICKTEXTMETRICS_H
97

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