From d82ab0709286f6b6816064affee4705d821830ec Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig Date: Wed, 5 Aug 2009 18:19:11 +0200 Subject: Make QIconloader use resource directory as fallback Instead of using different paths on Mac and Windows we now simply use ":\icons" on all platforms. It is a little more effort to create resources but it is certainly the Qt way to do it. :) Reviewed-by: ogoffart --- src/gui/image/qicon.cpp | 13 ++++--------- src/gui/image/qiconloader.cpp | 7 +++++-- tests/auto/qicon/tst_qicon.cpp | 3 +-- tests/auto/qicon/tst_qicon.qrc | 14 ++++++++++++++ 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp index a4ea6af..e23677f 100644 --- a/src/gui/image/qicon.cpp +++ b/src/gui/image/qicon.cpp @@ -888,10 +888,9 @@ void QIcon::setThemeSearchPaths(const QStringList &paths) On X11, the search path will use the XDG_DATA_DIRS environment variable if available. - On Windows the search path defaults to [Application Directory]/icons - - On Mac the default search path will search in the - [Contents/Resources/icons] part of the application bundle. + By default all platforms will have the resource directory + ":\icons" as their fallback. You can use "rcc -project" + to generate a resource file from your icon theme. \sa setThemeSearchPaths(), fromTheme(), setThemeName() */ @@ -906,7 +905,7 @@ QStringList QIcon::themeSearchPaths() Sets the current icon theme to \a name. The \a name should correspond to a directory name in the - current themeSearchPath() containing an index.theme + themeSearchPath() containing an index.theme file describing it's contents. \sa themeSearchPaths(), themeName() @@ -939,10 +938,6 @@ QString QIcon::themeName() icon theme. If no such icon is found in the current theme \a fallback is return instead. - To use an icon theme on Windows or Mac, you will need to - bundle a compliant theme with your application and make sure - it is located in your themeSarchPaths. - The lastest version of the freedesktop icon specification and naming spesification can be obtained here: http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html diff --git a/src/gui/image/qiconloader.cpp b/src/gui/image/qiconloader.cpp index 279703c..cb1cc61 100644 --- a/src/gui/image/qiconloader.cpp +++ b/src/gui/image/qiconloader.cpp @@ -187,14 +187,17 @@ QStringList QIconLoader::themeSearchPaths() const QDir homeDir(QDir::homePath() + QLatin1String("/.icons")); if (homeDir.exists()) m_iconDirs.prepend(homeDir.path()); - -#elif defined(Q_WS_WIN) +#endif + +#if defined(Q_WS_WIN) m_iconDirs.append(qApp->applicationDirPath() + QLatin1String("/icons")); #elif defined(Q_WS_MAC) m_iconDirs.append(qApp->applicationDirPath() + QLatin1String("/../Resources/icons")); #endif + // Allways add resource directory as search path + m_iconDirs.append(QLatin1String(":/icons")); } return m_iconDirs; } diff --git a/tests/auto/qicon/tst_qicon.cpp b/tests/auto/qicon/tst_qicon.cpp index b614ab9..bacf7a5 100644 --- a/tests/auto/qicon/tst_qicon.cpp +++ b/tests/auto/qicon/tst_qicon.cpp @@ -609,8 +609,7 @@ void tst_QIcon::task184901_badCache() void tst_QIcon::fromTheme() { - const QString prefix = QLatin1String(SRCDIR) + QLatin1String("/"); - QString searchPath = prefix + QLatin1String("/icons"); + QString searchPath = QLatin1String(":/icons"); QIcon::setThemeSearchPaths(QStringList() << searchPath); QVERIFY(QIcon::themeSearchPaths().size() == 1); QCOMPARE(searchPath, QIcon::themeSearchPaths()[0]); diff --git a/tests/auto/qicon/tst_qicon.qrc b/tests/auto/qicon/tst_qicon.qrc index 1e1a030..7925a33 100644 --- a/tests/auto/qicon/tst_qicon.qrc +++ b/tests/auto/qicon/tst_qicon.qrc @@ -2,5 +2,19 @@ image.png rect.png +./icons/testtheme/16x16/actions/appointment-new.png +./icons/testtheme/22x22/actions/appointment-new.png +./icons/testtheme/32x32/actions/appointment-new.png +./icons/testtheme/index.theme +./icons/testtheme/scalable/actions/svg-only.svg +./icons/themeparent/16x16/actions/address-book-new.png +./icons/themeparent/16x16/actions/appointment-new.png +./icons/themeparent/22x22/actions/address-book-new.png +./icons/themeparent/22x22/actions/appointment-new.png +./icons/themeparent/32x32/actions/address-book-new.png +./icons/themeparent/32x32/actions/appointment-new.png +./icons/themeparent/index.theme +./icons/themeparent/scalable/actions/address-book-new.svg +./icons/themeparent/scalable/actions/appointment-new.svg -- cgit v0.12