From 846a908b73ed3392c3f80a5c425c9ccf3c1e6a04 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Fri, 10 Mar 2017 14:39:49 +0100 Subject: Add Imagine style The Imagine style is based on image assets. The style comes with a default set of images, but the images can be easily changed by providing a directory with images using a predefined naming convention. [ChangeLog][Controls] Added the Imagine style, which is based on image assets that can be provided using a predefined naming convention. Task-number: QTPM-517 Change-Id: I550d7dac9a9686d60bec15655ac92dea9f36149c Reviewed-by: Mitch Curtis --- tests/auto/auto.pro | 3 +- tests/auto/controls/controls.pro | 1 + tests/auto/controls/imagine/dependencies.qml | 6 + tests/auto/controls/imagine/imagine.pro | 15 ++ tests/auto/controls/imagine/tst_imagine.cpp | 47 ++++ tests/auto/font/tst_font.cpp | 8 +- tests/auto/palette/tst_palette.cpp | 2 +- tests/auto/qquickninepatchimage/data/foo.9.png | Bin 0 -> 213 bytes tests/auto/qquickninepatchimage/data/foo@2x.9.png | Bin 0 -> 295 bytes tests/auto/qquickninepatchimage/data/foo@3x.9.png | Bin 0 -> 377 bytes tests/auto/qquickninepatchimage/data/foo@4x.9.png | Bin 0 -> 482 bytes .../auto/qquickninepatchimage/data/inset-all.9.png | Bin 0 -> 245 bytes .../qquickninepatchimage/data/inset-all@2x.9.png | Bin 0 -> 341 bytes .../qquickninepatchimage/data/inset-all@3x.9.png | Bin 0 -> 470 bytes .../qquickninepatchimage/data/inset-all@4x.9.png | Bin 0 -> 577 bytes .../data/inset-bottomright.9.png | Bin 0 -> 246 bytes .../data/inset-bottomright@2x.9.png | Bin 0 -> 348 bytes .../data/inset-bottomright@3x.9.png | Bin 0 -> 460 bytes .../data/inset-bottomright@4x.9.png | Bin 0 -> 565 bytes .../qquickninepatchimage/data/inset-topleft.9.png | Bin 0 -> 227 bytes .../data/inset-topleft@2x.9.png | Bin 0 -> 305 bytes .../data/inset-topleft@3x.9.png | Bin 0 -> 420 bytes .../data/inset-topleft@4x.9.png | Bin 0 -> 516 bytes .../qquickninepatchimage/data/ninepatchimage.qml | 7 + tests/auto/qquickninepatchimage/data/padding.9.png | Bin 0 -> 226 bytes .../qquickninepatchimage/data/padding@2x.9.png | Bin 0 -> 298 bytes .../qquickninepatchimage/data/padding@3x.9.png | Bin 0 -> 381 bytes .../qquickninepatchimage/data/padding@4x.9.png | Bin 0 -> 485 bytes .../qquickninepatchimage/qquickninepatchimage.pro | 14 ++ .../tst_qquickninepatchimage.cpp | 241 +++++++++++++++++++++ tests/benchmarks/creationtime/tst_creationtime.cpp | 15 ++ 31 files changed, 354 insertions(+), 5 deletions(-) create mode 100644 tests/auto/controls/imagine/dependencies.qml create mode 100644 tests/auto/controls/imagine/imagine.pro create mode 100644 tests/auto/controls/imagine/tst_imagine.cpp create mode 100644 tests/auto/qquickninepatchimage/data/foo.9.png create mode 100644 tests/auto/qquickninepatchimage/data/foo@2x.9.png create mode 100644 tests/auto/qquickninepatchimage/data/foo@3x.9.png create mode 100644 tests/auto/qquickninepatchimage/data/foo@4x.9.png create mode 100644 tests/auto/qquickninepatchimage/data/inset-all.9.png create mode 100644 tests/auto/qquickninepatchimage/data/inset-all@2x.9.png create mode 100644 tests/auto/qquickninepatchimage/data/inset-all@3x.9.png create mode 100644 tests/auto/qquickninepatchimage/data/inset-all@4x.9.png create mode 100644 tests/auto/qquickninepatchimage/data/inset-bottomright.9.png create mode 100644 tests/auto/qquickninepatchimage/data/inset-bottomright@2x.9.png create mode 100644 tests/auto/qquickninepatchimage/data/inset-bottomright@3x.9.png create mode 100644 tests/auto/qquickninepatchimage/data/inset-bottomright@4x.9.png create mode 100644 tests/auto/qquickninepatchimage/data/inset-topleft.9.png create mode 100644 tests/auto/qquickninepatchimage/data/inset-topleft@2x.9.png create mode 100644 tests/auto/qquickninepatchimage/data/inset-topleft@3x.9.png create mode 100644 tests/auto/qquickninepatchimage/data/inset-topleft@4x.9.png create mode 100644 tests/auto/qquickninepatchimage/data/ninepatchimage.qml create mode 100644 tests/auto/qquickninepatchimage/data/padding.9.png create mode 100644 tests/auto/qquickninepatchimage/data/padding@2x.9.png create mode 100644 tests/auto/qquickninepatchimage/data/padding@3x.9.png create mode 100644 tests/auto/qquickninepatchimage/data/padding@4x.9.png create mode 100644 tests/auto/qquickninepatchimage/qquickninepatchimage.pro create mode 100644 tests/auto/qquickninepatchimage/tst_qquickninepatchimage.cpp (limited to 'tests') diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 935fa178..87cda7dc 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -19,6 +19,7 @@ SUBDIRS += \ qquickmaterialstyle \ qquickmaterialstyleconf \ qquickmenubar \ + qquickninepatchimage \ qquickstyle \ qquickstyleselector \ qquickuniversalstyle \ @@ -32,4 +33,4 @@ boot2qt: SUBDIRS -= applicationwindow calendar controls cursor \ drawer focus font menu platform palette popup \ qquickmaterialstyle qquickmaterialstyleconf \ qquickuniversalstyle qquickuniversalstyleconf \ - snippets qquickmenubar + snippets qquickmenubar qquickninepatchimage diff --git a/tests/auto/controls/controls.pro b/tests/auto/controls/controls.pro index c61dff0e..fd852c4b 100644 --- a/tests/auto/controls/controls.pro +++ b/tests/auto/controls/controls.pro @@ -2,5 +2,6 @@ TEMPLATE = subdirs SUBDIRS += \ default \ fusion \ + imagine \ material \ universal diff --git a/tests/auto/controls/imagine/dependencies.qml b/tests/auto/controls/imagine/dependencies.qml new file mode 100644 index 00000000..3811fec0 --- /dev/null +++ b/tests/auto/controls/imagine/dependencies.qml @@ -0,0 +1,6 @@ +import QtTest 1.0 +import QtQuick 2.10 +import QtQuick.Controls 2.3 +import QtQuick.Controls.Imagine 2.3 + +TestCase { } diff --git a/tests/auto/controls/imagine/imagine.pro b/tests/auto/controls/imagine/imagine.pro new file mode 100644 index 00000000..ab521c98 --- /dev/null +++ b/tests/auto/controls/imagine/imagine.pro @@ -0,0 +1,15 @@ +TEMPLATE = app +TARGET = tst_imagine +CONFIG += qmltestcase +QT += quickcontrols2 + +DEFINES += TST_CONTROLS_DATA=\\\"$$QQC2_SOURCE_TREE/tests/auto/controls/data\\\" + +SOURCES += \ + $$PWD/tst_imagine.cpp + +OTHER_FILES += \ + $$PWD/../data/*.qml + +TESTDATA += \ + $$PWD/../data/tst_* diff --git a/tests/auto/controls/imagine/tst_imagine.cpp b/tests/auto/controls/imagine/tst_imagine.cpp new file mode 100644 index 00000000..9777c9c9 --- /dev/null +++ b/tests/auto/controls/imagine/tst_imagine.cpp @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +int main(int argc, char *argv[]) +{ + QTEST_ADD_GPU_BLACKLIST_SUPPORT + QTEST_SET_MAIN_SOURCE_PATH + qputenv("QML_NO_TOUCH_COMPRESSION", "1"); + QQuickStyle::setStyle("Imagine"); + return quick_test_main(argc, argv, "tst_controls::Imagine", TST_CONTROLS_DATA); +} diff --git a/tests/auto/font/tst_font.cpp b/tests/auto/font/tst_font.cpp index 6f04a8c0..b05cdcd8 100644 --- a/tests/auto/font/tst_font.cpp +++ b/tests/auto/font/tst_font.cpp @@ -252,7 +252,7 @@ void tst_font::defaultFont_data() QTest::newRow("ToolButton") << "ToolButton" << QPlatformTheme::ToolButtonFont; QTest::newRow("ToolSeparator") << "ToolSeparator" << QPlatformTheme::SystemFont; QTest::newRow("ToolTip") << "ToolTip" << QPlatformTheme::TipLabelFont; - QTest::newRow("Tumbler") << "Tumbler" << QPlatformTheme::SystemFont; + QTest::newRow("Tumbler") << "Tumbler" << QPlatformTheme::ItemViewFont; } void tst_font::defaultFont() @@ -260,12 +260,14 @@ void tst_font::defaultFont() QFETCH(QString, control); QFETCH(QPlatformTheme::Font, fontType); - TestFontTheme theme(QGuiApplicationPrivate::platform_theme); - QQmlEngine engine; QQmlComponent component(&engine); component.setData(QString("import QtQuick.Controls 2.2; %1 { }").arg(control).toUtf8(), QUrl()); + // The call to setData() above causes QQuickDefaultTheme to be set as the platform theme, + // so we must make sure we only set our theme afterwards. + TestFontTheme theme(QGuiApplicationPrivate::platform_theme); + QScopedPointer object(component.create()); QVERIFY2(!object.isNull(), qPrintable(component.errorString())); diff --git a/tests/auto/palette/tst_palette.cpp b/tests/auto/palette/tst_palette.cpp index 0bf0bcb0..66e93ae4 100644 --- a/tests/auto/palette/tst_palette.cpp +++ b/tests/auto/palette/tst_palette.cpp @@ -315,7 +315,7 @@ void tst_palette::defaultPalette_data() QTest::newRow("ToolButton") << "ToolButton" << QPlatformTheme::ToolButtonPalette; QTest::newRow("ToolSeparator") << "ToolSeparator" << QPlatformTheme::ToolButtonPalette; QTest::newRow("ToolTip") << "ToolTip" << QPlatformTheme::ToolTipPalette; - QTest::newRow("Tumbler") << "Tumbler" << QPlatformTheme::SystemPalette; + QTest::newRow("Tumbler") << "Tumbler" << QPlatformTheme::ItemViewPalette; } void tst_palette::defaultPalette() diff --git a/tests/auto/qquickninepatchimage/data/foo.9.png b/tests/auto/qquickninepatchimage/data/foo.9.png new file mode 100644 index 00000000..51246990 Binary files /dev/null and b/tests/auto/qquickninepatchimage/data/foo.9.png differ diff --git a/tests/auto/qquickninepatchimage/data/foo@2x.9.png b/tests/auto/qquickninepatchimage/data/foo@2x.9.png new file mode 100644 index 00000000..c8dc30a3 Binary files /dev/null and b/tests/auto/qquickninepatchimage/data/foo@2x.9.png differ diff --git a/tests/auto/qquickninepatchimage/data/foo@3x.9.png b/tests/auto/qquickninepatchimage/data/foo@3x.9.png new file mode 100644 index 00000000..00ea4e05 Binary files /dev/null and b/tests/auto/qquickninepatchimage/data/foo@3x.9.png differ diff --git a/tests/auto/qquickninepatchimage/data/foo@4x.9.png b/tests/auto/qquickninepatchimage/data/foo@4x.9.png new file mode 100644 index 00000000..ea73340a Binary files /dev/null and b/tests/auto/qquickninepatchimage/data/foo@4x.9.png differ diff --git a/tests/auto/qquickninepatchimage/data/inset-all.9.png b/tests/auto/qquickninepatchimage/data/inset-all.9.png new file mode 100644 index 00000000..e08ef9c7 Binary files /dev/null and b/tests/auto/qquickninepatchimage/data/inset-all.9.png differ diff --git a/tests/auto/qquickninepatchimage/data/inset-all@2x.9.png b/tests/auto/qquickninepatchimage/data/inset-all@2x.9.png new file mode 100644 index 00000000..96d1c0e8 Binary files /dev/null and b/tests/auto/qquickninepatchimage/data/inset-all@2x.9.png differ diff --git a/tests/auto/qquickninepatchimage/data/inset-all@3x.9.png b/tests/auto/qquickninepatchimage/data/inset-all@3x.9.png new file mode 100644 index 00000000..215ce27e Binary files /dev/null and b/tests/auto/qquickninepatchimage/data/inset-all@3x.9.png differ diff --git a/tests/auto/qquickninepatchimage/data/inset-all@4x.9.png b/tests/auto/qquickninepatchimage/data/inset-all@4x.9.png new file mode 100644 index 00000000..35e53101 Binary files /dev/null and b/tests/auto/qquickninepatchimage/data/inset-all@4x.9.png differ diff --git a/tests/auto/qquickninepatchimage/data/inset-bottomright.9.png b/tests/auto/qquickninepatchimage/data/inset-bottomright.9.png new file mode 100644 index 00000000..c4c37dff Binary files /dev/null and b/tests/auto/qquickninepatchimage/data/inset-bottomright.9.png differ diff --git a/tests/auto/qquickninepatchimage/data/inset-bottomright@2x.9.png b/tests/auto/qquickninepatchimage/data/inset-bottomright@2x.9.png new file mode 100644 index 00000000..3d64036f Binary files /dev/null and b/tests/auto/qquickninepatchimage/data/inset-bottomright@2x.9.png differ diff --git a/tests/auto/qquickninepatchimage/data/inset-bottomright@3x.9.png b/tests/auto/qquickninepatchimage/data/inset-bottomright@3x.9.png new file mode 100644 index 00000000..115184d9 Binary files /dev/null and b/tests/auto/qquickninepatchimage/data/inset-bottomright@3x.9.png differ diff --git a/tests/auto/qquickninepatchimage/data/inset-bottomright@4x.9.png b/tests/auto/qquickninepatchimage/data/inset-bottomright@4x.9.png new file mode 100644 index 00000000..2ec7cbef Binary files /dev/null and b/tests/auto/qquickninepatchimage/data/inset-bottomright@4x.9.png differ diff --git a/tests/auto/qquickninepatchimage/data/inset-topleft.9.png b/tests/auto/qquickninepatchimage/data/inset-topleft.9.png new file mode 100644 index 00000000..9cc5f43d Binary files /dev/null and b/tests/auto/qquickninepatchimage/data/inset-topleft.9.png differ diff --git a/tests/auto/qquickninepatchimage/data/inset-topleft@2x.9.png b/tests/auto/qquickninepatchimage/data/inset-topleft@2x.9.png new file mode 100644 index 00000000..a4ca2b12 Binary files /dev/null and b/tests/auto/qquickninepatchimage/data/inset-topleft@2x.9.png differ diff --git a/tests/auto/qquickninepatchimage/data/inset-topleft@3x.9.png b/tests/auto/qquickninepatchimage/data/inset-topleft@3x.9.png new file mode 100644 index 00000000..73f3595a Binary files /dev/null and b/tests/auto/qquickninepatchimage/data/inset-topleft@3x.9.png differ diff --git a/tests/auto/qquickninepatchimage/data/inset-topleft@4x.9.png b/tests/auto/qquickninepatchimage/data/inset-topleft@4x.9.png new file mode 100644 index 00000000..78baa463 Binary files /dev/null and b/tests/auto/qquickninepatchimage/data/inset-topleft@4x.9.png differ diff --git a/tests/auto/qquickninepatchimage/data/ninepatchimage.qml b/tests/auto/qquickninepatchimage/data/ninepatchimage.qml new file mode 100644 index 00000000..7ef07a1c --- /dev/null +++ b/tests/auto/qquickninepatchimage/data/ninepatchimage.qml @@ -0,0 +1,7 @@ +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Controls.Imagine 2.3 +import QtQuick.Controls.Imagine.impl 2.3 + +NinePatchImage { +} diff --git a/tests/auto/qquickninepatchimage/data/padding.9.png b/tests/auto/qquickninepatchimage/data/padding.9.png new file mode 100644 index 00000000..5b4f0960 Binary files /dev/null and b/tests/auto/qquickninepatchimage/data/padding.9.png differ diff --git a/tests/auto/qquickninepatchimage/data/padding@2x.9.png b/tests/auto/qquickninepatchimage/data/padding@2x.9.png new file mode 100644 index 00000000..44eb1943 Binary files /dev/null and b/tests/auto/qquickninepatchimage/data/padding@2x.9.png differ diff --git a/tests/auto/qquickninepatchimage/data/padding@3x.9.png b/tests/auto/qquickninepatchimage/data/padding@3x.9.png new file mode 100644 index 00000000..d1563448 Binary files /dev/null and b/tests/auto/qquickninepatchimage/data/padding@3x.9.png differ diff --git a/tests/auto/qquickninepatchimage/data/padding@4x.9.png b/tests/auto/qquickninepatchimage/data/padding@4x.9.png new file mode 100644 index 00000000..e86cce69 Binary files /dev/null and b/tests/auto/qquickninepatchimage/data/padding@4x.9.png differ diff --git a/tests/auto/qquickninepatchimage/qquickninepatchimage.pro b/tests/auto/qquickninepatchimage/qquickninepatchimage.pro new file mode 100644 index 00000000..b40a5f4c --- /dev/null +++ b/tests/auto/qquickninepatchimage/qquickninepatchimage.pro @@ -0,0 +1,14 @@ +CONFIG += testcase +macos:CONFIG -= app_bundle +TARGET = tst_qquickninepatchimage + +QT += core gui qml quick testlib +QT_PRIVATE += gui-private quick-private quickcontrols2-private + +include (../shared/util.pri) + +SOURCES += tst_qquickninepatchimage.cpp + +TESTDATA += \ + $$PWD/data/*.qml \ + $$PWD/data/*.png diff --git a/tests/auto/qquickninepatchimage/tst_qquickninepatchimage.cpp b/tests/auto/qquickninepatchimage/tst_qquickninepatchimage.cpp new file mode 100644 index 00000000..c7710199 --- /dev/null +++ b/tests/auto/qquickninepatchimage/tst_qquickninepatchimage.cpp @@ -0,0 +1,241 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../shared/util.h" +#include "../shared/visualtestutil.h" + +using namespace QQuickVisualTestUtil; + +class tst_qquickninepatchimage : public QQmlDataTest +{ + Q_OBJECT + +private slots: + void ninePatch_data(); + void ninePatch(); + void padding_data(); + void padding(); + void inset_data(); + void inset(); + void implicitSize_data(); + void implicitSize(); +}; + +static QImage grabItemToImage(QQuickItem *item) +{ + QSharedPointer result = item->grabToImage(); + QSignalSpy spy(result.data(), SIGNAL(ready())); + spy.wait(); + return result->image(); +} + +void tst_qquickninepatchimage::ninePatch_data() +{ + QTest::addColumn("dpr"); + QTest::addColumn("size"); + + // original size, downsized, stretched + const QList sizes = QList() + << QSize(40, 40) // original + << QSize(10, 40) // downsized (h) + << QSize(40, 10) // downsized (v) + << QSize(10, 10) // downsized (h & v) + << QSize(80, 40) // stretched (h) + << QSize(40, 80) // stretched (v) + << QSize(80, 80) // stretched (h & v) + << QSize(8, 8); // minimal (borders only) + + for (const QSize &sz : sizes) { + for (int dpr = 1; dpr <= 4; ++dpr) + QTest::newRow(qPrintable(QString::fromLatin1("DPR=%1, %2x%3").arg(dpr).arg(sz.width()).arg(sz.height()))) << dpr << sz; + } +} + +void tst_qquickninepatchimage::ninePatch() +{ + QFETCH(int, dpr); + QFETCH(QSize, size); + + QHighDpiScaling::setGlobalFactor(dpr); + + QQuickView view(testFileUrl("ninepatchimage.qml")); + QCOMPARE(view.status(), QQuickView::Ready); + view.show(); + view.requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(&view)); + + QQuickImage *ninePatchImage = qobject_cast(view.rootObject()); + QVERIFY(ninePatchImage); + ninePatchImage->setSource(testFileUrl("foo.9.png")); + ninePatchImage->setSize(size); + + const QImage ninePatchImageGrab = grabItemToImage(ninePatchImage).scaled(size * dpr); + + // Generate an image to compare against the actual 9-patch image. + QImage generatedImage(size * dpr, ninePatchImageGrab.format()); + generatedImage.fill(Qt::red); + + QImage blueRect(4 * dpr, 4 * dpr, ninePatchImageGrab.format()); + blueRect.fill(Qt::blue); + + QPainter painter(&generatedImage); + // Top-left + painter.drawImage(0, 0, blueRect); + // Top-right + painter.drawImage(generatedImage.width() - blueRect.width(), 0, blueRect); + // Bottom-right + painter.drawImage(generatedImage.width() - blueRect.width(), generatedImage.height() - blueRect.height(), blueRect); + // Bottom-left + painter.drawImage(0, generatedImage.height() - blueRect.height(), blueRect); + + QCOMPARE(ninePatchImageGrab, generatedImage); +} + +void tst_qquickninepatchimage::padding_data() +{ + QTest::addColumn("dpr"); + + for (int dpr = 1; dpr <= 4; ++dpr) + QTest::newRow(qPrintable(QString::fromLatin1("DPR=%1").arg(dpr))) << dpr; +} + +void tst_qquickninepatchimage::padding() +{ + QFETCH(int, dpr); + + QHighDpiScaling::setGlobalFactor(dpr); + + QQuickView view(testFileUrl("ninepatchimage.qml")); + QCOMPARE(view.status(), QQuickView::Ready); + view.show(); + view.requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(&view)); + + QQuickImage *ninePatchImage = qobject_cast(view.rootObject()); + QVERIFY(ninePatchImage); + ninePatchImage->setSource(testFileUrl("padding.9.png")); + + QCOMPARE(ninePatchImage->property("topPadding").toReal(), 8); + QCOMPARE(ninePatchImage->property("leftPadding").toReal(), 18); + QCOMPARE(ninePatchImage->property("rightPadding").toReal(), 20); + QCOMPARE(ninePatchImage->property("bottomPadding").toReal(), 10); +} + +void tst_qquickninepatchimage::inset_data() +{ + QTest::addColumn("dpr"); + QTest::addColumn("file"); + QTest::addColumn("insets"); + + const QStringList files = QStringList() << "inset-all.9.png" << "inset-topleft.9.png" << "inset-bottomright.9.png"; + const QList insets = QList() << QMarginsF(2, 1, 3, 4) << QMarginsF(2, 1, 0, 0) << QMarginsF(0, 0, 3, 4); + + for (int i = 0; i < files.count(); ++i) { + QString file = files.at(i); + for (int dpr = 1; dpr <= 4; ++dpr) + QTest::newRow(qPrintable(QString::fromLatin1("%1 DPR=%2").arg(file).arg(dpr))) << dpr << file << insets.at(i); + } +} + +Q_DECLARE_METATYPE(QMarginsF) + +void tst_qquickninepatchimage::inset() +{ + QFETCH(int, dpr); + QFETCH(QString, file); + QFETCH(QMarginsF, insets); + + QHighDpiScaling::setGlobalFactor(dpr); + + QQuickView view(testFileUrl("ninepatchimage.qml")); + QCOMPARE(view.status(), QQuickView::Ready); + view.show(); + view.requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(&view)); + + QQuickImage *ninePatchImage = qobject_cast(view.rootObject()); + QVERIFY(ninePatchImage); + ninePatchImage->setSource(testFileUrl(file)); + + QCOMPARE(ninePatchImage->property("topInset").toReal(), insets.top()); + QCOMPARE(ninePatchImage->property("leftInset").toReal(), insets.left()); + QCOMPARE(ninePatchImage->property("rightInset").toReal(), insets.right()); + QCOMPARE(ninePatchImage->property("bottomInset").toReal(), insets.bottom()); +} + +void tst_qquickninepatchimage::implicitSize_data() +{ + QTest::addColumn("dpr"); + QTest::addColumn("file"); + QTest::addColumn("implicitSize"); + + const QStringList files = QStringList() << "foo.9.png" << "padding.9.png" << "inset-all.9.png" << "inset-topleft.9.png" << "inset-bottomright.9.png"; + + for (const QString &file : files) { + for (int dpr = 1; dpr <= 4; ++dpr) + QTest::newRow(qPrintable(QString::fromLatin1("%1 DPR=%2").arg(file).arg(dpr))) << dpr << file << QSizeF(40, 40); + } +} + +void tst_qquickninepatchimage::implicitSize() +{ + QFETCH(int, dpr); + QFETCH(QString, file); + QFETCH(QSizeF, implicitSize); + + QHighDpiScaling::setGlobalFactor(dpr); + + QQuickView view(testFileUrl("ninepatchimage.qml")); + QCOMPARE(view.status(), QQuickView::Ready); + view.show(); + view.requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(&view)); + + QQuickImage *ninePatchImage = qobject_cast(view.rootObject()); + QVERIFY(ninePatchImage); + ninePatchImage->setSource(testFileUrl(file)); + + QCOMPARE(ninePatchImage->implicitWidth(), implicitSize.width()); + QCOMPARE(ninePatchImage->implicitHeight(), implicitSize.height()); +} + +QTEST_MAIN(tst_qquickninepatchimage) + +#include "tst_qquickninepatchimage.moc" diff --git a/tests/benchmarks/creationtime/tst_creationtime.cpp b/tests/benchmarks/creationtime/tst_creationtime.cpp index 4909f080..25533e95 100644 --- a/tests/benchmarks/creationtime/tst_creationtime.cpp +++ b/tests/benchmarks/creationtime/tst_creationtime.cpp @@ -47,6 +47,9 @@ private slots: void controls(); void controls_data(); + void imagine(); + void imagine_data(); + void material(); void material_data(); @@ -125,6 +128,18 @@ void tst_CreationTime::controls_data() addTestRows(&engine, "controls", "QtQuick/Controls.2", QStringList() << "CheckIndicator" << "RadioIndicator" << "SwitchIndicator"); } +void tst_CreationTime::imagine() +{ + QFETCH(QUrl, url); + doBenchmark(&engine, url); +} + +void tst_CreationTime::imagine_data() +{ + QTest::addColumn("url"); + addTestRows(&engine, "controls/imagine", "QtQuick/Controls.2/Imagine"); +} + void tst_CreationTime::material() { QFETCH(QUrl, url); -- cgit v1.2.3