diff options
author | Alexander Volkov <a.volkov@rusbitech.ru> | 2017-12-20 16:03:42 +0300 |
---|---|---|
committer | Alexander Volkov <a.volkov@rusbitech.ru> | 2018-01-15 10:12:22 +0000 |
commit | 85aa0fd041fbaa258f089d86f227311e53f6206a (patch) | |
tree | bafaed0633d4034232af4a9d725d009e0c2a7155 /tests | |
parent | 537af273026eaf0a18d2151ad6928b7797d7955b (diff) |
Introduce QIcon::fallbackSearchPaths()
... that will be used if an icon can't be found in the
current theme.
The Icon Theme Specification
https://standards.freedesktop.org/icon-theme-spec/latest/ar01s05.html
states that unthemed icons must be searched in the base directories,
i.e. /usr/share/icons, ... But in practice unthemed icons are
installed into /usr/share/pixmaps and this dir is not used as
a base dir for icon themes. So it's better to explicitly specify
fallback dirs to avoid needless access to the filesystem.
Also some KDE application install their own unthemed icons
(into /usr/share/<appname>/pics), that can't be found by
QIconLoader. With this change it would be possible for them
to specify dirs with unthemed icons and thus be displayed
correctly in non-KDE environments.
[ChangeLog][QtGui][QIcon] Added fallbackSearchPaths() that
will be used to find icons missing in the current icon theme.
Change-Id: I0dc55ba958b29356a3b0a2123d6b8faa24d4c91e
Task-number: QTBUG-33123
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/gui/image/qicon/fallback_icons/red.png | bin | 0 -> 105 bytes | |||
-rw-r--r-- | tests/auto/gui/image/qicon/qicon.pro | 2 | ||||
-rw-r--r-- | tests/auto/gui/image/qicon/tst_qicon.cpp | 11 | ||||
-rw-r--r-- | tests/auto/gui/image/qicon/tst_qicon.qrc | 1 |
4 files changed, 13 insertions, 1 deletions
diff --git a/tests/auto/gui/image/qicon/fallback_icons/red.png b/tests/auto/gui/image/qicon/fallback_icons/red.png Binary files differnew file mode 100644 index 0000000000..4a843e744f --- /dev/null +++ b/tests/auto/gui/image/qicon/fallback_icons/red.png diff --git a/tests/auto/gui/image/qicon/qicon.pro b/tests/auto/gui/image/qicon/qicon.pro index b3c60bf32b..c96f0555ad 100644 --- a/tests/auto/gui/image/qicon/qicon.pro +++ b/tests/auto/gui/image/qicon/qicon.pro @@ -6,4 +6,4 @@ qtHaveModule(widgets): QT += widgets SOURCES += tst_qicon.cpp RESOURCES = tst_qicon.qrc tst_qicon.cpp -TESTDATA += icons/* second_icons/* *.png *.svg *.svgz +TESTDATA += icons/* second_icons/* fallback_icons/* *.png *.svg *.svgz diff --git a/tests/auto/gui/image/qicon/tst_qicon.cpp b/tests/auto/gui/image/qicon/tst_qicon.cpp index bf8f7ade9e..b1a4e4312f 100644 --- a/tests/auto/gui/image/qicon/tst_qicon.cpp +++ b/tests/auto/gui/image/qicon/tst_qicon.cpp @@ -554,6 +554,11 @@ void tst_QIcon::fromTheme() QCOMPARE(firstSearchPath, QIcon::themeSearchPaths()[0]); QCOMPARE(secondSearchPath, QIcon::themeSearchPaths()[1]); + QString fallbackSearchPath = QStringLiteral(":/fallback_icons"); + QIcon::setFallbackSearchPaths(QStringList() << fallbackSearchPath); + QCOMPARE(QIcon::fallbackSearchPaths().size(), 1); + QCOMPARE(fallbackSearchPath, QIcon::fallbackSearchPaths().at(0)); + QString themeName("testtheme"); QIcon::setThemeName(themeName); QCOMPARE(QIcon::themeName(), themeName); @@ -580,6 +585,12 @@ void tst_QIcon::fromTheme() QVERIFY(QIcon::hasThemeIcon("address-book-new")); QVERIFY(!abIcon.availableSizes().isEmpty()); + // Test icon from fallback path + QIcon fallbackIcon = QIcon::fromTheme("red"); + QVERIFY(!fallbackIcon.isNull()); + QVERIFY(QIcon::hasThemeIcon("red")); + QCOMPARE(fallbackIcon.availableSizes().size(), 1); + // Test non existing icon QIcon noIcon = QIcon::fromTheme("broken-icon"); QVERIFY(noIcon.isNull()); diff --git a/tests/auto/gui/image/qicon/tst_qicon.qrc b/tests/auto/gui/image/qicon/tst_qicon.qrc index 3c8fbba7c2..4b347ec88c 100644 --- a/tests/auto/gui/image/qicon/tst_qicon.qrc +++ b/tests/auto/gui/image/qicon/tst_qicon.qrc @@ -6,6 +6,7 @@ <file>./icons/testtheme/16x16/actions/appointment-new.png</file> <file>./icons/testtheme/22x22/actions/appointment-new.png</file> <file>./second_icons/testtheme/32x32/actions/appointment-new.png</file> +<file>./fallback_icons/red.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> |