blend function urgently needed in kdelibs
Peter Penz
peter.penz at gmx.at
Tue May 22 19:56:34 BST 2007
Hi Matthew!
On Tuesday 22 May 2007 16:37:29 Matthew Woehlke wrote:
> Peter Penz wrote:
> > On Monday 21 May 2007 22:35:49 David Faure wrote:
> > <snip>
> >
> >> But the reason for kdefx to exist is probably disappearing (well it was
> >> about dlopen/dlclose iirc, needs to be retested one day) as Aaron said,
> >> and I also agree with him about asking: why "urgently"?
> >
> > Might not be "the" reason for "urgently", but we have already code for
> > mixing colors in kdelibs/kfile/kurlbutton_p.h (protected method:
> > KUrlButton::mixColors(...)) and Dolphin also requires it on other places
> > (e. g. for having a slightly darker background on the inactive view, for
> > creating mixed colors in the disk usage progress indication). I thought
> > already about making a helper class inside Dolphin, but I would be glad
> > if we would have a central place in kdelibs for such kind of things to
> > prevent code duplication.
>
> Ah, see, /more/ examples! :-)
>
> I'll make a note to look at kurlbutton_p.h, meanwhile if you could give
> me specifics on what your requirements are that would be helpful. The
> current design should be extensible to practically anything, but the
> initial algorithms should of course cover existing needs :-).
<snip>
Great, thanks! I'm really happy that you brought in the suggestion that this
kind of functionality is needed.
My requirements for Dolphin are straight forward I think. Here they are:
- Mixing of 2 colors by 50 %: I use this for the inactive URL navigator and
the inactive views to get a shaded look. I e. g. mix the text color with the
background color. This could be done by alpha blending too, but this would be
more expensive... Although it's only an old KDE3 screenshot, you can see the
idea at http://enzosworld.gmxhome.de/view_modes_06.html (the right view is
shaded).
- Darkening colors: in the status bar of Dolphin the disk usage is shown. I
did not use a default progress bar for this, as it is visually too
distracting. So I render a very simple progress bar like you can see at
http://enzosworld.gmxhome.de/images/dolphin4_oxygen.png. But darkening with
QColor::darker() is very problematic, as it does not give enough contrast in
some cases (or too much) and also does not work if the color is already
black.
I implemented a custom method for calculating a darker color, with a fallback
of having a lighter color if there is not enough contrast (see [1] at the end
of the mail, the code is in kdebase/apps/dolphin/statusbarspaceinfo.cpp). I'm
not sure whether it's worth to make those kind of method accessable in a
generic way, but maybe you get input from other application developers too. I
could imagine that this use case (getting a darker color, with a fallback to
a lighter color if not enough contrast is given) might be helpful for
applications which should also work with themes having e. g. very dark
backgrounds and a light text.
Thanks again, I'll have a look at the SVN commits and will adapt Dolphin if
your code is committed :-)
Best regards,
Peter
[1]
/**
* Returns a color for the progress bar by respecting
* the given background color \a bgColor. It is assured
* that enough contrast is given to have a visual indication.
*/
QColor StatusBarSpaceInfo::progressColor(const QColor& bgColor) const
{
QColor color = KGlobalSettings::buttonBackground();
// assure that enough contrast is given between the background color
// and the progressbar color
int bgRed = bgColor.red();
int bgGreen = bgColor.green();
int bgBlue = bgColor.blue();
const int backgrBrightness = qGray(bgRed, bgGreen, bgBlue);
const int progressBrightness = qGray(color.red(), color.green(),
color.blue());
const int limit = 32;
const int diff = backgrBrightness - progressBrightness;
bool adjustColor = ((diff >= 0) && (diff < limit)) ||
((diff < 0) && (diff > -limit));
if (adjustColor) {
const int inc = (backgrBrightness < 2 * limit) ? (2 * limit) : -limit;
color = QColor(bgRed + inc, bgGreen + inc, bgBlue + inc);
}
return color;
}
More information about the kde-core-devel
mailing list