blendColor that doesn't need additional setup code

Andreas Pakulat apaku at gmx.de
Tue May 29 09:24:59 BST 2007


On 28.05.07 18:28:09, Aaron J. Seigo wrote:
> 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?

Just a short comment here: No, setAlphaF takes a _f_loating point
number between 0.0 and 1.0. I just realise this isn't documented
properly in the api docs though.

> 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):

Yes, that would need some changes in overlayColor but I'd like to leave
the solution for that to some graphics expert because I have absolutely
no idea what is the "right" solution here...

Andreas

-- 
Be careful!  Is it classified?




More information about the kde-core-devel mailing list