diff options
author | Mitch Curtis <mitch.curtis@digia.com> | 2014-08-05 17:42:54 +0200 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@digia.com> | 2014-08-08 10:42:47 +0200 |
commit | 94669499fd943fc72095afd739a21cd8e675f14f (patch) | |
tree | d902820ebbc41f75699326fa1cf887ee49fc6746 | |
parent | c0e47716c402da2333bfa4082c7b40e3b376135c (diff) |
Add declarative QQuickTextMetrics API from QQuickFontMetrics invokables
This allows use of a declarative API for the functions in QFontMetricsF
which take parameters. This solves the problem of QML expressions that
use QML methods not being re-evaluated when the internal data changes,
by allowing the user to set the arguments as properties of a
TextMetrics object, that would otherwise have to be passed to QML
methods.
For example:
FontMetrics {
id: fontMetrics
}
property rect r: fontMetrics.boundingRect("Blah")
At some point, the font of the FontMetrics object is changed, but r
will still represent the original bounding rect. Instead, the user will
now write:
TextMetrics {
id: textMetrics
text: "Blah"
}
property rect r: textMetrics.boundingRect
The QML methods remain in QQuickFontMetrics for those who need an
imperative API.
[ChangeLog][QtQuick] Added QQuickTextMetrics, which provides a
declarative API for the functions in QFontMetricsF which take
arguments.
Change-Id: I019dc4639531906fc751ba61281cc1c695742287
Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
-rw-r--r-- | src/quick/util/qquickfontmetrics.cpp | 22 | ||||
-rw-r--r-- | src/quick/util/qquicktextmetrics.cpp | 268 | ||||
-rw-r--r-- | src/quick/util/qquicktextmetrics_p.h | 111 | ||||
-rw-r--r-- | src/quick/util/qquickutilmodule.cpp | 2 | ||||
-rw-r--r-- | src/quick/util/util.pri | 6 | ||||
-rw-r--r-- | tests/auto/quick/qquicktextmetrics/qquicktextmetrics.pro | 10 | ||||
-rw-r--r-- | tests/auto/quick/qquicktextmetrics/tst_qquicktextmetrics.cpp | 161 |
7 files changed, 575 insertions, 5 deletions
diff --git a/src/quick/util/qquickfontmetrics.cpp b/src/quick/util/qquickfontmetrics.cpp index bf533995a5..47e4fc1c7e 100644 --- a/src/quick/util/qquickfontmetrics.cpp +++ b/src/quick/util/qquickfontmetrics.cpp @@ -65,12 +65,12 @@ QT_BEGIN_NAMESPACE } Rectangle { - width: fontMetrics.height() * 4 - height: fontMetrics.height() * 2 + width: fontMetrics.height * 4 + height: fontMetrics.height * 2 } \endcode - \sa QFontMetricsF + \sa QFontMetricsF, TextMetrics */ QQuickFontMetrics::QQuickFontMetrics(QObject *parent) : QObject(parent), @@ -280,6 +280,10 @@ qreal QQuickFontMetrics::lineWidth() const This is the distance from the position of the string to where the next string should be drawn. + This method is offered as an imperative alternative to the + \l {QQuickTextMetrics::advanceWidth}{advanceWidth} property of + \l {QQuickTextMetrics::advanceWidth}{TextMetrics}. + \sa {QFontMetricsF::width()}, height() */ qreal QQuickFontMetrics::advanceWidth(const QString &text) const @@ -293,6 +297,10 @@ qreal QQuickFontMetrics::advanceWidth(const QString &text) const This method returns the bounding rectangle of the characters in the string specified by \a text. + This method is offered as an imperative alternative to the + \l {QQuickTextMetrics::boundingRect}{boundingRect} property of + \l {QQuickTextMetrics::boundingRect}{TextMetrics}. + \sa {QFontMetricsF::boundingRect()}, tightBoundingRect() */ QRectF QQuickFontMetrics::boundingRect(const QString &text) const @@ -306,6 +314,10 @@ QRectF QQuickFontMetrics::boundingRect(const QString &text) const This method returns a tight bounding rectangle around the characters in the string specified by \a text. + This method is offered as an imperative alternative to the + \l {QQuickTextMetrics::tightBoundingRect}{tightBoundingRect} property of + \l {QQuickTextMetrics::tightBoundingRect}{TextMetrics}. + \sa {QFontMetricsF::tightBoundingRect()}, boundingRect() */ QRectF QQuickFontMetrics::tightBoundingRect(const QString &text) const @@ -324,6 +336,10 @@ QRectF QQuickFontMetrics::tightBoundingRect(const QString &text) const The \a flags argument is optional and currently only supports \l {Qt::TextShowMnemonic}. + This method is offered as an imperative alternative to the + \l {QQuickTextMetrics::elidedText}{elidedText} property of + \l {QQuickTextMetrics::elidedText}{TextMetrics}. + \sa {QFontMetricsF::elidedText()} */ QString QQuickFontMetrics::elidedText(const QString &text, Qt::TextElideMode mode, qreal width, int flags) const diff --git a/src/quick/util/qquicktextmetrics.cpp b/src/quick/util/qquicktextmetrics.cpp new file mode 100644 index 0000000000..09af99b82b --- /dev/null +++ b/src/quick/util/qquicktextmetrics.cpp @@ -0,0 +1,268 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtQuick module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquicktextmetrics_p.h" + +#include <QFont> + +QT_BEGIN_NAMESPACE + +/*! + \qmltype TextMetrics + \instantiates QQuickTextMetrics + \inqmlmodule QtQuick + \ingroup qtquick-text-utility + \brief Provides metrics for a given font and text + + TextMetrics calculates various properties of a given string of text for a + particular font. + + It provides a declarative API for the functions in \l QFontMetricsF which + take arguments. + + \code + TextMetrics { + id: textMetrics + font.family: "Arial" + elide: Text.ElideMiddle + elideWidth: 100 + text: "Hello World" + } + + MyItem { + text: textMetrics.elidedText + } + \endcode + + \sa QFontMetricsF, FontMetrics +*/ +QQuickTextMetrics::QQuickTextMetrics(QObject *parent) : + QObject(parent), + m_metrics(m_font), + m_elide(Qt::ElideNone), + m_elideWidth(0) +{ +} + +QQuickTextMetrics::~QQuickTextMetrics() +{ +} + +/*! + \qmlproperty font QtQuick::TextMetrics::font + + This property holds the font used for the metrics calculations. +*/ +QFont QQuickTextMetrics::font() const +{ + return m_font; +} + +void QQuickTextMetrics::setFont(const QFont &font) +{ + if (m_font != font) { + m_font = font; + m_metrics = QFontMetricsF(m_font); + emit fontChanged(); + emit metricsChanged(); + } +} + +/*! + \qmlproperty string QtQuick::TextMetrics::text + + This property holds the text used for the metrics calculations. +*/ +QString QQuickTextMetrics::text() const +{ + return m_text; +} + +void QQuickTextMetrics::setText(const QString &text) +{ + if (m_text != text) { + m_text = text; + emit textChanged(); + emit metricsChanged(); + } +} + +/*! + \qmlproperty enumeration QtQuick::TextMetrics::elide + + This property holds the elide mode of the text. This determines the + position in which the string is elided. The possible values are: + + \list + \li \c Qt::ElideNone - No eliding; this is the default value. + \li \c Qt::ElideLeft - For example: "...World" + \li \c Qt::ElideMiddle - For example: "He...ld" + \li \c Qt::ElideRight - For example: "Hello..." + \endlist + + \sa elideWidth, elidedText +*/ +Qt::TextElideMode QQuickTextMetrics::elide() const +{ + return m_elide; +} + +void QQuickTextMetrics::setElide(Qt::TextElideMode elide) +{ + if (m_elide != elide) { + m_elide = elide; + emit elideChanged(); + emit metricsChanged(); + } +} + +/*! + \qmlproperty real QtQuick::TextMetrics::elideWidth + + This property holds the largest width the text can have (in pixels) before + eliding will occur. + + \sa elide, elidedText +*/ +qreal QQuickTextMetrics::elideWidth() const +{ + return m_elideWidth; +} + +void QQuickTextMetrics::setElideWidth(qreal elideWidth) +{ + if (m_elideWidth != elideWidth) { + m_elideWidth = elideWidth; + emit elideWidthChanged(); + emit metricsChanged(); + } +} + +/*! + \qmlproperty real QtQuick::TextMetrics::advanceWidth + + This property holds the advance in pixels of the characters in \l text. + This is the distance from the position of the string to where the next + string should be drawn. + + \sa {QFontMetricsF::width()} +*/ +qreal QQuickTextMetrics::advanceWidth() const +{ + return m_metrics.width(m_text); +} + +/*! + \qmlproperty rect QtQuick::TextMetrics::boundingRect + + This property holds the bounding rectangle of the characters in the string + specified by \l text. + + \sa {QFontMetricsF::boundingRect()}, tightBoundingRect +*/ +QRectF QQuickTextMetrics::boundingRect() const +{ + return m_metrics.boundingRect(m_text); +} + +/*! + \qmlproperty real QtQuick::TextMetrics::width + + This property holds the width of the bounding rectangle of the characters + in the string specified by \l text. It is equivalent to: + + \code + textMetrics.boundingRect.width + \endcode + + \sa boundingRect +*/ +qreal QQuickTextMetrics::width() const +{ + return boundingRect().width(); +} + +/*! + \qmlproperty real QtQuick::TextMetrics::height + + This property holds the height of the bounding rectangle of the characters + in the string specified by \l text. It is equivalent to: + + \code + textMetrics.boundingRect.height + \endcode + + \sa boundingRect +*/ +qreal QQuickTextMetrics::height() const +{ + return boundingRect().height(); +} + +/*! + \qmlproperty rect QtQuick::TextMetrics::tightBoundingRect + + This property holds a tight bounding rectangle around the characters in the + string specified by \l text. + + \sa {QFontMetricsF::tightBoundingRect()}, boundingRect +*/ +QRectF QQuickTextMetrics::tightBoundingRect() const +{ + return m_metrics.tightBoundingRect(m_text); +} + +/*! + \qmlmethod string QtQuick::TextMetrics::elidedText + + This property holds an elided version of the string (i.e., a string with + "..." in it) if the string \l text is wider than \l elideWidth. If the + text is not wider than \l elideWidth, or \l elide is set to + \c Qt::ElideNone, this property will be equal to the original string. + + \sa {QFontMetricsF::elidedText()} +*/ +QString QQuickTextMetrics::elidedText() const +{ + return m_metrics.elidedText(m_text, m_elide, m_elideWidth); +} + +QT_END_NAMESPACE diff --git a/src/quick/util/qquicktextmetrics_p.h b/src/quick/util/qquicktextmetrics_p.h new file mode 100644 index 0000000000..ec993229e5 --- /dev/null +++ b/src/quick/util/qquicktextmetrics_p.h @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtQuick module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKTEXTMETRICS_H +#define QQUICKTEXTMETRICS_H + +#include <qqml.h> + +#include <QtGui/QFontMetricsF> +#include <QtCore/QObject> + +QT_BEGIN_NAMESPACE + +class QFont; + +class Q_AUTOTEST_EXPORT QQuickTextMetrics : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged FINAL) + Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged FINAL) + Q_PROPERTY(qreal advanceWidth READ advanceWidth NOTIFY metricsChanged FINAL) + Q_PROPERTY(QRectF boundingRect READ boundingRect NOTIFY metricsChanged FINAL) + Q_PROPERTY(qreal width READ width NOTIFY metricsChanged FINAL) + Q_PROPERTY(qreal height READ height NOTIFY metricsChanged FINAL) + Q_PROPERTY(QRectF tightBoundingRect READ tightBoundingRect NOTIFY metricsChanged FINAL) + Q_PROPERTY(QString elidedText READ elidedText NOTIFY metricsChanged FINAL) + Q_PROPERTY(Qt::TextElideMode elide READ elide WRITE setElide NOTIFY elideChanged FINAL) + Q_PROPERTY(qreal elideWidth READ elideWidth WRITE setElideWidth NOTIFY elideWidthChanged FINAL) + +public: + explicit QQuickTextMetrics(QObject *parent = 0); + ~QQuickTextMetrics(); + + QFont font() const; + void setFont(const QFont &font); + + QString text() const; + void setText(const QString &text); + + Qt::TextElideMode elide() const; + void setElide(Qt::TextElideMode elide); + + qreal elideWidth() const; + void setElideWidth(qreal elideWidth); + + qreal advanceWidth() const; + QRectF boundingRect() const; + qreal width() const; + qreal height() const; + QRectF tightBoundingRect() const; + QString elidedText() const; + +Q_SIGNALS: + void fontChanged(); + void textChanged(); + void elideChanged(); + void elideWidthChanged(); + void metricsChanged(); + +private: + QString m_text; + QFont m_font; + QFontMetricsF m_metrics; + Qt::TextElideMode m_elide; + qreal m_elideWidth; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQuickTextMetrics) + +#endif // QQUICKTEXTMETRICS_H diff --git a/src/quick/util/qquickutilmodule.cpp b/src/quick/util/qquickutilmodule.cpp index 1d82cfca43..8ea903b010 100644 --- a/src/quick/util/qquickutilmodule.cpp +++ b/src/quick/util/qquickutilmodule.cpp @@ -53,6 +53,7 @@ #include "qquickstate_p.h" #include "qquickstate_p_p.h" #include "qquicksystempalette_p.h" +#include "qquicktextmetrics_p.h" #include "qquicktransition_p.h" #include "qquickanimator_p.h" #include <qqmlinfo.h> @@ -109,4 +110,5 @@ void QQuickUtilModule::defineModule() qmlRegisterUncreatableType<QKeySequence, 2>("QtQuick", 2, 2, "StandardKey", QStringLiteral("Cannot create an instance of StandardKey.")); qmlRegisterType<QQuickFontMetrics>("QtQuick", 2, 4, "FontMetrics"); + qmlRegisterType<QQuickTextMetrics>("QtQuick", 2, 4, "TextMetrics"); } diff --git a/src/quick/util/util.pri b/src/quick/util/util.pri index 35553070dc..76cf1996bc 100644 --- a/src/quick/util/util.pri +++ b/src/quick/util/util.pri @@ -27,7 +27,8 @@ SOURCES += \ $$PWD/qquickanimatorjob.cpp \ $$PWD/qquickanimatorcontroller.cpp \ $$PWD/qquickprofiler.cpp \ - $$PWD/qquickfontmetrics.cpp + $$PWD/qquickfontmetrics.cpp \ + $$PWD/qquicktextmetrics.cpp HEADERS += \ $$PWD/qquickapplication_p.h\ @@ -62,4 +63,5 @@ HEADERS += \ $$PWD/qquickanimatorjob_p.h \ $$PWD/qquickanimatorcontroller_p.h \ $$PWD/qquickprofiler_p.h \ - $$PWD/qquickfontmetrics_p.h + $$PWD/qquickfontmetrics_p.h \ + $$PWD/qquicktextmetrics_p.h diff --git a/tests/auto/quick/qquicktextmetrics/qquicktextmetrics.pro b/tests/auto/quick/qquicktextmetrics/qquicktextmetrics.pro new file mode 100644 index 0000000000..6ef68db8e2 --- /dev/null +++ b/tests/auto/quick/qquicktextmetrics/qquicktextmetrics.pro @@ -0,0 +1,10 @@ +CONFIG += testcase +TARGET = tst_qquicktextmetrics +osx:CONFIG -= app_bundle + +SOURCES += tst_qquicktextmetrics.cpp + +CONFIG += parallel_test + +QT += core gui qml quick-private testlib +DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/quick/qquicktextmetrics/tst_qquicktextmetrics.cpp b/tests/auto/quick/qquicktextmetrics/tst_qquicktextmetrics.cpp new file mode 100644 index 0000000000..733b3d06b3 --- /dev/null +++ b/tests/auto/quick/qquicktextmetrics/tst_qquicktextmetrics.cpp @@ -0,0 +1,161 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QFont> +#include <QString> +#include <QtTest> +#include <QCoreApplication> +#include <QQmlComponent> +#include <QQmlEngine> +#include <QQuickItem> + +#include <QtQuick/private/qquicktextmetrics_p.h> + +#include <QFontMetricsF> + +class tst_QQuickTextMetrics : public QObject +{ + Q_OBJECT + +public: + tst_QQuickTextMetrics(); + +private Q_SLOTS: + void font(); + void functionsWithArguments_data(); + void functionsWithArguments(); +}; + +tst_QQuickTextMetrics::tst_QQuickTextMetrics() +{ +} + +void tst_QQuickTextMetrics::font() +{ + QQuickTextMetrics metrics; + + QSignalSpy fontSpy(&metrics, SIGNAL(fontChanged())); + QSignalSpy metricsSpy(&metrics, SIGNAL(metricsChanged())); + QFont font; + font.setPointSize(font.pointSize() + 1); + metrics.setFont(font); + QCOMPARE(fontSpy.count(), 1); + QCOMPARE(metricsSpy.count(), 1); +} + +Q_DECLARE_METATYPE(Qt::TextElideMode) + +void tst_QQuickTextMetrics::functionsWithArguments_data() +{ + QTest::addColumn<QString>("text"); + QTest::addColumn<Qt::TextElideMode>("mode"); + QTest::addColumn<qreal>("width"); + + QStringList strings; + strings << QString() + << QString::fromLatin1("") + << QString::fromLatin1("0") + << QString::fromLatin1("@@@@@@@") + << QString::fromLatin1("Hello"); + + QVector<Qt::TextElideMode> elideModes; + elideModes << Qt::ElideLeft << Qt::ElideMiddle << Qt::ElideRight << Qt::ElideNone; + + for (int stringIndex = 0; stringIndex < strings.size(); ++stringIndex) { + const QString string = strings.at(stringIndex); + + for (int elideModeIndex = 0; elideModeIndex < elideModes.size(); ++elideModeIndex) { + Qt::TextElideMode elideMode = static_cast<Qt::TextElideMode>(elideModes.at(elideModeIndex)); + + for (qreal width = 0; width < 100; width += 20) { + const QString tag = QString::fromLatin1("string=%1, mode=%2, width=%3").arg(string).arg(elideMode).arg(width); + QTest::newRow(qPrintable(tag)) << QString() << elideMode << width; + } + } + } +} + +void tst_QQuickTextMetrics::functionsWithArguments() +{ + QFETCH(QString, text); + QFETCH(Qt::TextElideMode, mode); + QFETCH(qreal, width); + + QQuickTextMetrics metrics; + // Ensures that the values actually change. + metrics.setText(text + "extra"); + metrics.setElideWidth(width + 1); + switch (mode) { + case Qt::ElideNone: metrics.setElide(Qt::ElideMiddle); break; + case Qt::ElideLeft: metrics.setElide(Qt::ElideRight); break; + case Qt::ElideMiddle: metrics.setElide(Qt::ElideNone); break; + case Qt::ElideRight: metrics.setElide(Qt::ElideLeft); break; + } + + QSignalSpy textSpy(&metrics, SIGNAL(textChanged())); + QSignalSpy metricsSpy(&metrics, SIGNAL(metricsChanged())); + metrics.setText(text); + QCOMPARE(textSpy.count(), 1); + QCOMPARE(metricsSpy.count(), 1); + + QSignalSpy elideSpy(&metrics, SIGNAL(elideChanged())); + metrics.setElide(mode); + QCOMPARE(elideSpy.count(), 1); + QCOMPARE(metricsSpy.count(), 2); + + QSignalSpy elideWidthSpy(&metrics, SIGNAL(elideWidthChanged())); + metrics.setElideWidth(width); + QCOMPARE(elideWidthSpy.count(), 1); + QCOMPARE(metricsSpy.count(), 3); + + QFontMetricsF expected = QFontMetricsF(QFont()); + + QCOMPARE(metrics.elidedText(), expected.elidedText(text, mode, width, 0)); + QCOMPARE(metrics.advanceWidth(), expected.width(text)); + QCOMPARE(metrics.boundingRect(), expected.boundingRect(text)); + QCOMPARE(metrics.width(), expected.boundingRect(text).width()); + QCOMPARE(metrics.height(), expected.boundingRect(text).height()); + QCOMPARE(metrics.tightBoundingRect(), expected.tightBoundingRect(text)); +} + +QTEST_MAIN(tst_QQuickTextMetrics) + +#include "tst_qquicktextmetrics.moc" |