dde-dock/frame/util/imagefactory.cpp
石博文 8b479bbf14 add hover effects
Change-Id: I4bcdceb7c3a8b41e6c8b64c0e72ade11a1e4fd81
2016-08-02 09:28:06 +08:00

33 lines
795 B
C++

#include "imagefactory.h"
#include <QDebug>
ImageFactory::ImageFactory(QObject *parent)
: QObject(parent)
{
}
QPixmap ImageFactory::lighter(const QPixmap pixmap, const int delta)
{
QImage image = pixmap.toImage();
const int width = image.width();
const int height = image.height();
const int bytesPerPixel = image.bytesPerLine() / image.width();
for (int i(0); i != height; ++i)
{
uchar *scanLine = image.scanLine(i);
for (int j(0); j != width; ++j)
{
QRgb &rgba = *(QRgb*)scanLine;
if (qAlpha(rgba) && (qRed(rgba) || qGreen(rgba) || qBlue(rgba)))
rgba = QColor::fromRgba(rgba).lighter(delta).rgba();
scanLine += bytesPerPixel;
}
}
return QPixmap::fromImage(image);
}