From 12a08ee8eaa27be7dc500b1c15348e8f692949dc Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Wed, 25 Jul 2018 08:40:07 +0200 Subject: QQuickIconImage: prevent color from being applied twice QQuickIconImage::componentComplete() calls QQuickIconImagePrivate::updateIcon(), which loads the icon's image via QQuickImageBase::load(). That eventually calls QQuickImageBase::requestFinished(), which calls QQuickIconImage::pixmapChange(). That then calls QQuickIconImagePrivate::updateFillMode(), which can in turn cause QQuickIconImage::pixmapChange() to be called again, causing recursion. This recursion resulted in icon.color being applied twice. We already have a recursion check in place in QQuickIconImagePrivate::updateFillMode(), so we can reuse that in QQuickIconImage::pixmapChange() to know whether or not we should apply the color to the image. Task-number: QTBUG-69506 Change-Id: I5cd9edaa524c7ceb9c41c53a9efefcc4c647e246 Reviewed-by: Richard Moe Gustavsen --- .../qquickiconimage/data/translucentColors.qml | 67 ++++++++++++++++++++++ tests/auto/qquickiconimage/tst_qquickiconimage.cpp | 33 ++++++++++- 2 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 tests/auto/qquickiconimage/data/translucentColors.qml (limited to 'tests/auto') diff --git a/tests/auto/qquickiconimage/data/translucentColors.qml b/tests/auto/qquickiconimage/data/translucentColors.qml new file mode 100644 index 00000000..49178d76 --- /dev/null +++ b/tests/auto/qquickiconimage/data/translucentColors.qml @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2018 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:BSD$ +** 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. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.10 +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 + +ApplicationWindow { + width: 500 + height: 500 + visible: true + + IconImage { + width: Math.min(250, parent.width) + height: Math.min(250, parent.height) + source: "qrc:/icons/testtheme/22x22/actions/color-test-original.png" + sourceSize: Qt.size(250, 0) + color: Qt.rgba(0, 0, 0, 0.5) + } +} diff --git a/tests/auto/qquickiconimage/tst_qquickiconimage.cpp b/tests/auto/qquickiconimage/tst_qquickiconimage.cpp index 1dab0784..bc24c4fb 100644 --- a/tests/auto/qquickiconimage/tst_qquickiconimage.cpp +++ b/tests/auto/qquickiconimage/tst_qquickiconimage.cpp @@ -1,4 +1,4 @@ -/**************************************************************************** +/**************************************************************************** ** ** Copyright (C) 2017 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -69,6 +70,7 @@ private slots: void color(); void fileSelectors(); void imageProvider(); + void translucentColors(); private: void setTheme(); @@ -528,6 +530,35 @@ void tst_qquickiconimage::imageProvider() QCOMPARE(image.pixelColor(image.width() / 2, image.height() / 2), QColor(Qt::red)); } +/* + QQuickIconImage::componentComplete() calls QQuickIconImagePrivate::updateIcon(), + which loads the icon's image via QQuickImageBase::load(). That eventually calls + QQuickImageBase::requestFinished(), which calls QQuickIconImage::pixmapChange(). + That then calls QQuickIconImagePrivate::updateFillMode(), which can in turn + cause QQuickIconImage::pixmapChange() to be called again, causing recursion. + + This was a problem because it resulted in icon.color being applied twice. + + This test checks that that doesn't happen. +*/ +void tst_qquickiconimage::translucentColors() +{ + if (QGuiApplication::platformName() == QLatin1String("offscreen")) + QSKIP("grabToImage() doesn't work on the \"offscreen\" platform plugin (QTBUG-63185)"); + + // Doesn't reproduce with QQuickView. + QQmlApplicationEngine engine; + engine.load(testFileUrl("translucentColors.qml")); + QQuickWindow *window = qobject_cast(engine.rootObjects().first()); + + QQuickIconImage *iconImage = qobject_cast(window->findChild()); + QVERIFY(iconImage); + + const QImage image = grabItemToImage(iconImage); + QVERIFY(!image.isNull()); + QCOMPARE(image.pixelColor(image.width() / 2, image.height() / 2), QColor::fromRgba(0x80000000)); +} + int main(int argc, char *argv[]) { QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); -- cgit v1.2.3