blendColor that doesn't need additional setup code

Aaron J. Seigo aseigo at kde.org
Tue May 29 01:28:09 BST 2007


On Monday 28 May 2007, Andreas Pakulat wrote:
> Hi,
>
> as I said to Aaron already here's a patch that adds
>
> blendColor(QColor,QColor, qreal, CompositionMode)
>
> (simplified API). This needed a rename of the existing blendColor to
> overlayColor (which fits its implementation much better). I'm not 100%
> if the api dox of the overlayColor is proper, but it tells you what the
> function does.
>
> blendColor helps to reduce usages from:
> QBrush fg = ret->foreground();
> QColor bg = QApplication::palette().window().color();
> if( background.alphaF() < 1 )
>    
> fg.setColor(KGraphicsUtils::blendColor(QApplication::palette().highlight().
>color(), bg)); else
> {
>     background.setAlpha(128);
>    
> foreground.setColor(KGraphicsUtils::blendColor(QApplication::palette().high
>light().color(), bg)); }
> ret->setForeground(fg);
> //ret == QStandardItem pointer
>
> to this:
> QBrush fg = ret->foreground();
> fg.setColor( KGraphicsUtils::blendColor(
>    QApplication::palette().highlight().color(),
>    QApplication::palette().window().color()
> ) );
> ret->setForeground(fg);
>
> Comments? Rants? Improvements? (I saw Ingo's mail about improving
> overlayColor to include the alpha value of both colors but as I'm not a
> graphics guy and didn't really understand that, I left it out).
>
> Andreas

this:

+        second.setAlphaF(amount);

should be:

+        second.setAlphaF(255*amount);

with amount being a value between 0 and 1, no?

amount = qmax(0, qmin(amount, 1));

also... if the first colour has an alpha, then i'd expect that to be taken 
into consideration, so something like (if i get the math right, which i may 
well not be; would have to test it):

second.setAlpha(255 * ((second.alpha()/255.0) * amount)))

iow if the second colour already has a 50% alpha (128) on it and the request 
is for a .5 amount blend then the result would be a 1/4 intensity blend with 
second having an alpha of 64. in the case of an opaque colour, it would just 
be 255*amount. that would match my expectations of the method better, at 
least.

does that make sense? =)

-- 
Aaron J. Seigo
humru othro a kohnu se
GPG Fingerprint: 8B8B 2209 0C6F 7C47 B1EA  EE75 D6B7 2EB1 A7F1 DB43

Full time KDE developer sponsored by Trolltech (http://www.trolltech.com)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20070528/76860f06/attachment.sig>


More information about the kde-core-devel mailing list