| 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 | |
| 26 | QT_BEGIN_NAMESPACE |
| 27 | |
| 28 | class QFont; |
| 29 | |
| 30 | class Q_QUICK_EXPORT QQuickFontMetrics : public QObject |
| 31 | { |
| 32 | Q_OBJECT |
| 33 | |
| 34 | Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged) |
| 35 | Q_PROPERTY(qreal ascent READ ascent NOTIFY fontChanged) |
| 36 | Q_PROPERTY(qreal descent READ descent NOTIFY fontChanged) |
| 37 | Q_PROPERTY(qreal height READ height NOTIFY fontChanged) |
| 38 | Q_PROPERTY(qreal leading READ leading NOTIFY fontChanged) |
| 39 | Q_PROPERTY(qreal lineSpacing READ lineSpacing NOTIFY fontChanged) |
| 40 | Q_PROPERTY(qreal minimumLeftBearing READ minimumLeftBearing NOTIFY fontChanged) |
| 41 | Q_PROPERTY(qreal minimumRightBearing READ minimumRightBearing NOTIFY fontChanged) |
| 42 | Q_PROPERTY(qreal maximumCharacterWidth READ maximumCharacterWidth NOTIFY fontChanged) |
| 43 | Q_PROPERTY(qreal xHeight READ xHeight NOTIFY fontChanged) |
| 44 | Q_PROPERTY(qreal averageCharacterWidth READ averageCharacterWidth NOTIFY fontChanged) |
| 45 | Q_PROPERTY(qreal underlinePosition READ underlinePosition NOTIFY fontChanged) |
| 46 | Q_PROPERTY(qreal overlinePosition READ overlinePosition NOTIFY fontChanged) |
| 47 | Q_PROPERTY(qreal strikeOutPosition READ strikeOutPosition NOTIFY fontChanged) |
| 48 | Q_PROPERTY(qreal lineWidth READ lineWidth NOTIFY fontChanged) |
| 49 | QML_NAMED_ELEMENT(FontMetrics) |
| 50 | QML_ADDED_IN_VERSION(2, 4) |
| 51 | public: |
| 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 | |
| 79 | Q_SIGNALS: |
| 80 | void fontChanged(const QFont &font); |
| 81 | |
| 82 | private: |
| 83 | QFont m_font; |
| 84 | QFontMetricsF m_metrics; |
| 85 | }; |
| 86 | |
| 87 | QT_END_NAMESPACE |
| 88 | |
| 89 | #endif // QQUICKFONTMETRICS_H |
| 90 |
