RCC for icons - update: Re: Icons installed by apps

Jaroslaw Staniek staniek at kde.org
Mon Mar 7 11:41:52 UTC 2016


On 7 March 2016 at 10:46, Jaroslaw Staniek <staniek at kde.org> wrote:

>
>
> On 18 February 2016 at 18:25, Kåre Särs <kare.sars at iki.fi> wrote:
>
>> On Thursday, February 18, 2016 02:51:58 PM René J.V. Bertin wrote:
>> > On Thursday February 18 2016 13:55:18 Jaroslaw Staniek wrote:
>> > >>> > since QIcon::fromTheme() apaprently isn't able to find app icons.
>> >
>> > Care to explain? QIcon::fromTheme() doesn't find anything "out of the
>> box"
>> > on OS X (and I presume on MS Windows), but that is only because no theme
>> > search path is set on those platforms. When you add the standard XDG
>> icon
>> > repository to the icon search path on OS X, even "pure" Qt5 application
>> > will start showing icons all over if you have an icon theme installed --
>> > including in widgets that should not have icons according to the HIG.
>> Also
>> > on OS X, fromTheme() will only return the application icon (as in the
>> icon
>> > shown in the Finder) if the current theme defines that same icon for the
>> > calling application, and the theme search path is set of course. In all
>> > other cases it will not, because the application icon is not defined
>> > through a theme on OS X (nor is it on MS Windows, I presume).
>> > >> I think the solution with a packaged breeze icons resource working
>> > >> out-of-the box could be a good (lightweight) addition for non-Plasma
>> > >> (non-Linux?) users of KF5, to popularize KF5. They grab the icons
>> package
>> >
>> > Popularise, with Breeze "art"work? O:-)
>> > Anyway,  I don't think "grabbing an icon package" will work on OS X,
>> not if
>> > you want to create standalone app bundles which by definition contain
>> > everything they need.
>> > >> and icons just work without thousands of files, caching, etc. 'One
>> in a
>> > >> million' would of these users would be interested in theming.
>> >
>> > I'd up that estimate if we're still talking about Breeze icons here O:-)
>> >
>> > >> PS2: I have been beaten by situations such as KToolBar setting 0-size
>> > >> icons by default.
>> >
>> > Partly this is because almost no KF5 code uses the fallback argument of
>> > QIcon::fromTheme() explicitly, which means that the function returns an
>> > empty icon if the search fails. In particular, statements like
>> >
>> > app->setWindowIcon(QIcon::fromTheme(programName))
>> >
>> > should read
>> >
>> > app->setWindowIcon(QIcon::fromTheme(programName, app->windowIcon()))
>> >
>> > >> This is in a Windows env where no themes are (properly) installed.
>> If the
>> > >> rcc-based solution is in use I would imagine that ideally all the KF5
>> > >> code
>> > >> detects this somehow and would not look for xdg standard themes
>> through
>> > >> the
>> > >> classic KIconLoader but silently adapt so the rcc resource works
>> great.
>> > >> Just a dream.
>> >
>> > If your rcc resource corresponds to the resource mentioned in the
>> > QIcon::fromTheme() documentation (I think that talks about "qrc") and
>> if I
>> > interpret that documentation correctly then yes, code using that
>> function
>> > will find icons from the rcc/qrc "builtin" resource over those in xdg
>> > themes (if the XDG icon repository is even in the icon theme search
>> path).
>> > >>> What I don't know however is whether artists consider that these
>> icons
>> > >>> should be themeable...
>> >
>> > I think icon artists will consider that you should touch their icons
>> (for
>> > theming or anything else). They will probably also consider that their
>> > icons are the "best" but they really should also consider it a right for
>> > anyone to use other icons ;)
>> >
>>
>> The breeze.rcc file way is actually how Christoph solved it in Kate for
>> Windows and OSX. We create an .rcc file from the breeze icons and at
>> start-up
>> we search for the file in QStandardPaths::DataLocation and if the file is
>> found we load it with  registerResource() and add ":/icons" to the
>> themeSearchPaths. (kate.git/icons.h)
>>
>> Christoph also added ":/icons" to the search path in kicontheme so that
>> xmlgui
>> toolbars and friends also get the icons from the .rcc file.
>>
>> We get all the same icons as on Linux neatly in one file :)
>>
>
> ​Thanks, it works on Windows (no platform theme).
> ​​How to make it work on Linux too (KF5 5.19.0, Qt 5.5.1), i.e. I'd like
> to have only used icons from the .rcc regardless of availability of
> FrameworkIntegrationPlugin.so KDEPlatformTheme.so?
>> We're talking about this code:​
>
>https://quickgit.kde.org/?p=kate.git&a=blob&f=icons.h​​​
>
> As soon as QResource::registerResource("breeze.rcc") is called, ":/icons"
> is
> ​appended to the theme search path (checked using
> QIcon::themeSearchPaths()).
>
> There's a line QIcon::setThemeSearchPaths(QStringList() <<
> QStringLiteral(":/icons")).
>
> - When I have this line enabled and I have no
> FrameworkIntegrationPlugin.so & KDEPlatformTheme.so installed, no icons are
> available at all
>
> - When I have this line disabled, breeze XDG theme is used but kexi icons
> (from the .rcc file are missing), regardless of availability of
> FrameworkIntegrationPlugin.so & KDEPlatformTheme.so.
>
>
> ​For the record, Qt 5.5's code is:​
>
> ​QIcon QIcon::fromTheme(const QString &name, const QIcon &fallback)
> {
>     QIcon icon;
>
>     if (qtIconCache()->contains(name)) {
>         icon = *qtIconCache()->object(name);
>     } else {
>         QPlatformTheme * const platformTheme =
> QGuiApplicationPrivate::platformTheme();
>         bool hasUserTheme = QIconLoader::instance()->hasUserTheme();
>         QIconEngine * const engine = (platformTheme && !hasUserTheme) ?
> platformTheme->createIconEngine(name)
>                                                    : new
> QIconLoaderEngine(name);
>         QIcon *cachedIcon  = new QIcon(engine);
>         icon = *cachedIcon;
>         qtIconCache()->insert(name, cachedIcon);
>     }
>
>     // Note the qapp check is to allow lazy loading of static icons
>     // Supporting fallbacks will not work for this case.
>     if (qApp && icon.availableSizes().isEmpty())
>         return fallback;
>
>     return icon;
> }
>>

BTW: The only difference between Kexi and Kate here is that Kate has no
"own" icons at all that are installed by themes.
Commit 0a31a2d7630ccfed5cf19 by Christoph in kate.git makes changes such as:

     if (pk.contains(fieldName))
-      item->setIcon(0, QIcon::fromTheme(QLatin1String("sql-field-pk")));
+      item->setIcon(0,
QIcon(QLatin1String(":/katesql/pics/16-actions-sql-field-pk.png")));
     else

- it works because it omits the themes API while I am trying to use
app-defined icons through QIcon::fromTheme() in Kexi. Without that I'd have
to duplicate logic of icon themes just to make QIcon::fromTheme() work
cross-platform.

Any ideas what is missing?


-- 
regards, Jaroslaw Staniek

KDE:
: A world-wide network of software engineers, artists, writers, translators
: and facilitators committed to Free Software development - http://kde.org
Calligra Suite:
: A graphic art and office suite - http://calligra.org
Kexi:
: A visual database apps builder - http://calligra.org/kexi
Qt Certified Specialist:
: http://www.linkedin.com/in/jstaniek
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-frameworks-devel/attachments/20160307/98d6e51d/attachment-0001.html>


More information about the Kde-frameworks-devel mailing list