QPixmap MIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) { QPixmap pm; QString pmckey(d->pmcKey(size, mode, state)); if (QPixmapCache::find(pmckey, pm)) return pm; if (d->addedPixmaps) { pm = d->addedPixmaps->value(d->hashKey(mode, state)); if (!pm.isNull() && pm.size() == size) return pm; } QSvgRenderer renderer; d->loadDataForModeAndState(&renderer, mode, state); if (!renderer.isValid()) return pm; QSize actualSize = renderer.defaultSize(); if (!actualSize.isNull()) actualSize.scale(size, Qt::KeepAspectRatio); QImage img(actualSize, QImage::Format_ARGB32); img.fill(0x00000000); QPainter p(&img); renderer.render(&p); p.end(); pm = QPixmap::fromImage(img); if (!pm.isNull()) QPixmapCache::insert(pmckey, pm); return pm; }
QPixmap QSvgIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) { QPixmap pm; QString pmckey(d->pmcKey(size, mode, state)); if (QPixmapCache::find(pmckey, pm)) return pm; if (d->addedPixmaps) { pm = d->addedPixmaps->value(d->hashKey(mode, state)); if (!pm.isNull() && pm.size() == size) return pm; } QSvgRenderer renderer; d->loadDataForModeAndState(&renderer, mode, state); if (!renderer.isValid()) return pm; QSize actualSize = renderer.defaultSize(); if (!actualSize.isNull()) actualSize.scale(size, Qt::KeepAspectRatio); if (actualSize.isEmpty()) return QPixmap(); QImage img(actualSize, QImage::Format_ARGB32_Premultiplied); img.fill(0x00000000); QPainter p(&img); renderer.render(&p); p.end(); pm = QPixmap::fromImage(img); if (qobject_cast<QGuiApplication *>(QCoreApplication::instance())) { const QPixmap generated = QGuiApplicationPrivate::instance()->applyQIconStyleHelper(mode, pm); if (!generated.isNull()) pm = generated; } if (!pm.isNull()) QPixmapCache::insert(pmckey, pm); return pm; }
QPixmap QSvgIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) { QPixmap pm; QString pmckey(d->pmcKey(size, mode, state)); if (QPixmapCache::find(pmckey, pm)) return pm; if (d->addedPixmaps) { pm = d->addedPixmaps->value(d->hashKey(mode, state)); if (!pm.isNull() && pm.size() == size) return pm; } QSvgRenderer renderer; d->loadDataForModeAndState(&renderer, mode, state); if (!renderer.isValid()) return pm; QSize actualSize = renderer.defaultSize(); if (!actualSize.isNull()) actualSize.scale(size, Qt::KeepAspectRatio); QImage img(actualSize, QImage::Format_ARGB32_Premultiplied); img.fill(0x00000000); QPainter p(&img); renderer.render(&p); p.end(); pm = QPixmap::fromImage(img); QStyleOption opt(0); opt.palette = QApplication::palette(); QPixmap generated = QApplication::style()->generatedIconPixmap(mode, pm, &opt); if (!generated.isNull()) pm = generated; if (!pm.isNull()) QPixmapCache::insert(pmckey, pm); return pm; }
QPixmap MIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) { QPixmap pm; QString pmckey(d->pmcKey(size, mode, state)); pmckey.prepend("Ms"); if (QPixmapCache::find(pmckey, pm)) return pm; if (d->addedPixmaps) { pm = d->addedPixmaps->value(d->hashKey(mode, state)); if (!pm.isNull() && pm.size() == size) return pm; } QSvgRenderer renderer; d->loadDataForModeAndState(&renderer, mode, state); if (!renderer.isValid()) return pm; QSize actualSize = renderer.defaultSize(); if (!actualSize.isNull()) actualSize.scale(size, Qt::KeepAspectRatio); // Generate an image of the requested size, but render the // the SVG with the correct aspect ratio centered in the image // to prevent scaling issues when setting non square icon size. QImage img(size, QImage::Format_ARGB32); img.fill(0x00000000); QPainter p(&img); renderer.render(&p, getBounds(size, actualSize)); p.end(); pm = QPixmap::fromImage(img); if (!pm.isNull()) QPixmapCache::insert(pmckey, pm); return pm; }
QPixmap MIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) { QPixmap pm; QString pmckey(d->pmcKey(size, mode, state)); if (QPixmapCache::find(pmckey, pm)) return pm; if (d->addedPixmaps) { pm = d->addedPixmaps->value(d->hashKey(mode, state)); if (!pm.isNull() && pm.size() == size) return pm; } QSvgRenderer renderer; d->loadDataForModeAndState(&renderer, mode, state); if (!renderer.isValid()) return pm; QSize actualSize = renderer.defaultSize(); if (!actualSize.isNull()) actualSize.scale(size, Qt::KeepAspectRatio); QImage img(actualSize, QImage::Format_ARGB32); img.fill(0x00000000); QPainter p(&img); renderer.render(&p); p.end(); bool light = Ms::preferences.globalStyle == Ms::STYLE_LIGHT; int ww = img.width(); if (state == QIcon::On) { if (light) { for (int y = 0; y < img.height(); ++y) { QRgb *scanLine = (QRgb*)img.scanLine(y); for (int x = 0; x < img.width(); ++x) { QRgb pixel = *scanLine; int alpha = qAlpha(pixel); if (alpha < 0) alpha = 0; *scanLine = qRgba(qRed(255-pixel), qGreen(255-pixel), qBlue(255-pixel), alpha); ++scanLine; } } } else { for (int y = 0; y < img.height(); ++y) { quint32* p = (quint32*)img.scanLine(y); for (int x = 0; x < ww; ++x) { if (*p & 0xff000000) { int d = 0xff - (*p & 0xff); int dd = 50; QColor color(QColor::fromRgba(*p)); int r = 70 - d + dd; if (r < 0) r = 0; int g = 130 - d + dd; if (g < 0) g = 0; int b = 180 - d + dd; if (b < 0) b = 0; QColor nc = QColor(r, g, b, color.alpha()); *p = nc.rgba(); } ++p; } } } } else { // change alpha channel int delta = 51; if (mode == QIcon::Disabled) delta = 178; else if (state == QIcon::On) delta = 0; if (light) { for (int y = 0; y < img.height(); ++y) { QRgb *scanLine = (QRgb*)img.scanLine(y); for (int x = 0; x < img.width(); ++x) { QRgb pixel = *scanLine; int alpha = qAlpha(pixel) - delta; if (alpha < 0) alpha = 0; *scanLine = qRgba(qRed(255-pixel), qGreen(255-pixel), qBlue(255-pixel), alpha); ++scanLine; } } } else { for (int y = 0; y < img.height(); ++y) { QRgb *scanLine = (QRgb*)img.scanLine(y); for (int x = 0; x < img.width(); ++x) { QRgb pixel = *scanLine; int alpha = qAlpha(pixel) - delta; if (alpha < 0) alpha = 0; *scanLine = qRgba(qRed(pixel), qGreen(pixel), qBlue(pixel), alpha); ++scanLine; } } } } pm = QPixmap::fromImage(img); if (!pm.isNull()) QPixmapCache::insert(pmckey, pm); return pm; }