diff options
author | Ruslan Nigmatullin <euroelessar@yandex.ru> | 2014-03-31 03:54:06 +0400 |
---|---|---|
committer | Konstantin Ritt <ritt.ks@gmail.com> | 2015-02-02 23:28:19 +0000 |
commit | a40d390a3bbc1919843000b427a168180b83a344 (patch) | |
tree | 05121f7154fed3bc8a167460f9cc8aca0687995f /tests/auto/gui | |
parent | a9066ecf646134009494f68a0365d4549d999c66 (diff) |
Fixed icons lookup in QIcon::fromTheme
This commit fixes incorrect logic of icons' lookup if there are
fallbacks or more than one theme's directory.
According to Icon Theme Specification, Directory Layout section, theme
can be spread across several base directories by having subdirectories
of the same name. This makes possible to extend system themes by
application-specific icons without making of collisions with other
applications.
According to Icon Naming Specification, Icon Naming Guidelines section,
icon name may contain dashes to separate levels of specificity in icon
names. This makes possible to set in application very specific icon
which may be not in every theme. So it can fallback to less specific one.
Change-Id: Iafc813902a3646be56e8f1d3a2fdbf8fd32ac542
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'tests/auto/gui')
-rw-r--r-- | tests/auto/gui/image/qicon/qicon.pro | 2 | ||||
-rw-r--r-- | tests/auto/gui/image/qicon/second_icons/testtheme/32x32/actions/appointment-new.png (renamed from tests/auto/gui/image/qicon/icons/testtheme/32x32/actions/appointment-new.png) | bin | 2399 -> 2399 bytes | |||
-rw-r--r-- | tests/auto/gui/image/qicon/tst_qicon.cpp | 18 | ||||
-rw-r--r-- | tests/auto/gui/image/qicon/tst_qicon.qrc | 2 |
4 files changed, 16 insertions, 6 deletions
diff --git a/tests/auto/gui/image/qicon/qicon.pro b/tests/auto/gui/image/qicon/qicon.pro index f48fe90dd8..6ff20ec8fa 100644 --- a/tests/auto/gui/image/qicon/qicon.pro +++ b/tests/auto/gui/image/qicon/qicon.pro @@ -7,4 +7,4 @@ qtHaveModule(widgets): QT += widgets SOURCES += tst_qicon.cpp RESOURCES = tst_qicon.qrc -TESTDATA += icons/* *.png *.svg *.svgz +TESTDATA += icons/* second_icons/* *.png *.svg *.svgz diff --git a/tests/auto/gui/image/qicon/icons/testtheme/32x32/actions/appointment-new.png b/tests/auto/gui/image/qicon/second_icons/testtheme/32x32/actions/appointment-new.png Binary files differindex 85daef3b0b..85daef3b0b 100644 --- a/tests/auto/gui/image/qicon/icons/testtheme/32x32/actions/appointment-new.png +++ b/tests/auto/gui/image/qicon/second_icons/testtheme/32x32/actions/appointment-new.png diff --git a/tests/auto/gui/image/qicon/tst_qicon.cpp b/tests/auto/gui/image/qicon/tst_qicon.cpp index 550dd5bc33..add6da9efb 100644 --- a/tests/auto/gui/image/qicon/tst_qicon.cpp +++ b/tests/auto/gui/image/qicon/tst_qicon.cpp @@ -559,10 +559,12 @@ void tst_QIcon::task184901_badCache() void tst_QIcon::fromTheme() { - QString searchPath = QLatin1String(":/icons"); - QIcon::setThemeSearchPaths(QStringList() << searchPath); - QVERIFY(QIcon::themeSearchPaths().size() == 1); - QCOMPARE(searchPath, QIcon::themeSearchPaths()[0]); + QString firstSearchPath = QLatin1String(":/icons"); + QString secondSearchPath = QLatin1String(":/second_icons"); + QIcon::setThemeSearchPaths(QStringList() << firstSearchPath << secondSearchPath); + QVERIFY(QIcon::themeSearchPaths().size() == 2); + QCOMPARE(firstSearchPath, QIcon::themeSearchPaths()[0]); + QCOMPARE(secondSearchPath, QIcon::themeSearchPaths()[1]); QString themeName("testtheme"); QIcon::setThemeName(themeName); @@ -576,6 +578,14 @@ void tst_QIcon::fromTheme() QVERIFY(appointmentIcon.availableSizes().contains(QSize(32, 32))); QVERIFY(appointmentIcon.availableSizes().contains(QSize(22, 22))); + // Test fallback to less specific icon + QIcon specificAppointmentIcon = QIcon::fromTheme("appointment-new-specific"); + QVERIFY(!QIcon::hasThemeIcon("appointment-new-specific")); + QVERIFY(QIcon::hasThemeIcon("appointment-new")); + QCOMPARE(specificAppointmentIcon.name(), QString::fromLatin1("appointment-new")); + QCOMPARE(specificAppointmentIcon.availableSizes(), appointmentIcon.availableSizes()); + QCOMPARE(specificAppointmentIcon.pixmap(32).cacheKey(), appointmentIcon.pixmap(32).cacheKey()); + // Test icon from parent theme QIcon abIcon = QIcon::fromTheme("address-book-new"); QVERIFY(!abIcon.isNull()); diff --git a/tests/auto/gui/image/qicon/tst_qicon.qrc b/tests/auto/gui/image/qicon/tst_qicon.qrc index dc11a87ddd..1505ca925b 100644 --- a/tests/auto/gui/image/qicon/tst_qicon.qrc +++ b/tests/auto/gui/image/qicon/tst_qicon.qrc @@ -5,7 +5,7 @@ <file>rect.png</file> <file>./icons/testtheme/16x16/actions/appointment-new.png</file> <file>./icons/testtheme/22x22/actions/appointment-new.png</file> -<file>./icons/testtheme/32x32/actions/appointment-new.png</file> +<file>./second_icons/testtheme/32x32/actions/appointment-new.png</file> <file>./icons/testtheme/index.theme</file> <file>./icons/testtheme/scalable/actions/svg-only.svg</file> <file>./icons/themeparent/16x16/actions/address-book-new.png</file> |