mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-16 17:29:55 +00:00
Use grayscale images for disabled icons
This commit is contained in:
parent
070327a259
commit
98abfcfe00
1 changed files with 19 additions and 15 deletions
|
@ -77,25 +77,29 @@ namespace Misc
|
||||||
|
|
||||||
QPixmap ScalableIcon::pixmap(const QSize& size, QIcon::Mode mode, QIcon::State state)
|
QPixmap ScalableIcon::pixmap(const QSize& size, QIcon::Mode mode, QIcon::State state)
|
||||||
{
|
{
|
||||||
QImage img(size, QImage::Format_ARGB32);
|
QPixmap pix = QPixmap(size);
|
||||||
img.fill(qRgba(0, 0, 0, 0));
|
pix.fill(Qt::transparent);
|
||||||
QPixmap pix = QPixmap::fromImage(img, Qt::NoFormatConversion);
|
|
||||||
{
|
|
||||||
QPainter painter(&pix);
|
QPainter painter(&pix);
|
||||||
QRect r(QPoint(0.0, 0.0), size);
|
QRect r(QPoint(0.0, 0.0), size);
|
||||||
this->paint(&painter, r, mode, state);
|
this->paint(&painter, r, mode, state);
|
||||||
}
|
|
||||||
|
|
||||||
if (mode != QIcon::Disabled)
|
if (mode != QIcon::Disabled)
|
||||||
return pix;
|
return pix;
|
||||||
|
|
||||||
QPixmap output(pix.size());
|
// For disabled icons use grayscale icons with 50% transparency
|
||||||
output.fill(Qt::transparent);
|
QImage img = pix.toImage();
|
||||||
QPainter p(&output);
|
|
||||||
p.setOpacity(0.5);
|
|
||||||
p.drawPixmap(0, 0, pix);
|
|
||||||
p.end();
|
|
||||||
|
|
||||||
return output;
|
for (int x = 0; x < img.width(); x++)
|
||||||
|
{
|
||||||
|
for (int y = 0; y < img.height(); y++)
|
||||||
|
{
|
||||||
|
QColor n = img.pixelColor(x, y);
|
||||||
|
int gray = qGray(n.red(), n.green(), n.blue());
|
||||||
|
img.setPixelColor(x, y, QColor(gray, gray, gray, n.alpha() / 2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return QPixmap::fromImage(img, Qt::NoFormatConversion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue