Utils: Changed crumblepath to use qpainter instead of stylesheets

This commit is contained in:
Lasse Holmstedt
2010-08-02 17:02:53 +02:00
parent 118f253a38
commit ef57d20a67
11 changed files with 156 additions and 44 deletions

View File

@@ -479,4 +479,28 @@ void StyleHelper::drawCornerImage(const QImage &img, QPainter *painter, QRect re
}
}
// Tints an image with tintColor, while preserving alpha and lightness
void StyleHelper::tintImage(QImage &img, const QColor &tintColor)
{
QPainter p(&img);
p.setCompositionMode(QPainter::CompositionMode_Screen);
for (int x = 0; x < img.width(); ++x) {
for (int y = 0; y < img.height(); ++y) {
QRgb rgbColor = img.pixel(x, y);
int alpha = qAlpha(rgbColor);
QColor c = QColor(rgbColor);
if (alpha > 0) {
c.toHsl();
qreal l = c.lightnessF();
QColor newColor = QColor::fromHslF(tintColor.hslHueF(), tintColor.hslSaturationF(), l);
newColor.setAlpha(alpha);
img.setPixel(x, y, newColor.rgba());
}
}
}
}
} // namespace Utils