[PATCH] Using KIcon for icons with overlay

Gustavo Pichorim Boiko gustavo.boiko at kdemail.net
Mon Aug 27 13:22:50 BST 2007


A Saturday 25 August 2007 08:23:56, Andreas Hartmetz escreveu:
> On Thursday 23 August 2007 13:58:51 Gustavo Pichorim Boiko wrote:
> > A Wednesday 22 August 2007 14:25:59, Aaron J. Seigo escreveu:
> > > On Wednesday 22 August 2007, Gustavo Pichorim Boiko wrote:
> > > > Is there a way to apply a custom effect to an icon (in this case
> > > > applying a color) before it gets the overlays drawn?
> > >
> > > so you want the overlay to not have the same effect as the overlay,
> > > correct? so the overlay would be done using the regular presentation
> > > while the icon might be greyed out, colourized, etc ... essentially
> > > anything in KIconEffect?
> > >
> > > > If not, would it be possible to change KIcon to support this before
> > > > 4.0?
> > >
> > > probably. do you have any specific API suggestions?
> >
> > I've tried to do it in a not-much intrusive way.
> > This patch adds a setEffect() method to KIconLoader. If you want a custom
> > effect to be applied to a set of icons, just create a KIconLoader and set
> > its effect, and use this loader when loading icons.
> > Every time you change the effect, the cache of the iconloader is
> > discarded, making sure the new effect is going to be applied to all
> > requested icons.
> >
> > Please review it and make suggestions/critics to this approach.
>
> Just as a general principle it's always better to carry as few state around
> as possible. The less there is to know about something you are using (a
> KIconLoader instance in that case) the easier it is to figure out what is
> actually happening in a piece of code.
> There are other factors, of course. I just wanted to point out that if you
> can make effects "stateless" without major disadvantages you should
> definitely do so. AFAIK (not really sure) KIconLoader is also not exactly
> lightweight, which would be another reason to not have more of them around
> in an application than you absolutely need.

Indeed it is not lightweight, but it allows caching the icons with effects 
applied (which for Kopete as an example is an advantage, as every contact 
from the account that has been custom coloured will have such icons), and 
that was the point of adding this to KIconLoader.

Most applications won't be penalized by adding this patch, the only ones that 
will have custom icon loaders are the ones that really need such effects. 
And also in the case of Kopete, it kind of has parts of an icon loader just to 
be able to do this, so it would be basically swapping between a private 
implementation to a public one (which IMHO is better).

Cheers
-- 
Gustavo Pichorim Boiko
-----------------------------------
KDE Developer      www.kde.org
Mandriva Labs      www.mandriva.com




More information about the kde-core-devel mailing list