Commit 891ebf57 authored by Martin Tobias Holmedahl Sandsmark's avatar Martin Tobias Holmedahl Sandsmark Committed by Elvis Angelaccio

Fix warnings about scaling pixmaps

parent adfca907
...@@ -168,7 +168,12 @@ QPixmap KFileItemListView::createDragPixmap(const KItemSet& indexes) const ...@@ -168,7 +168,12 @@ QPixmap KFileItemListView::createDragPixmap(const KItemSet& indexes) const
QPixmap pixmap = model()->data(index).value("iconPixmap").value<QPixmap>(); QPixmap pixmap = model()->data(index).value("iconPixmap").value<QPixmap>();
if (pixmap.isNull()) { if (pixmap.isNull()) {
QIcon icon = QIcon::fromTheme(model()->data(index).value("iconName").toString()); QIcon icon = QIcon::fromTheme(model()->data(index).value("iconName").toString());
pixmap = icon.pixmap(size, size); if (!icon.isNull()) {
pixmap = icon.pixmap(size, size);
} else {
pixmap = QPixmap(size, size);
pixmap.fill(Qt::transparent);
}
} else { } else {
KPixmapModifier::scale(pixmap, QSize(size, size) * dpr); KPixmapModifier::scale(pixmap, QSize(size, size) * dpr);
} }
......
...@@ -494,7 +494,7 @@ void KFileItemModelRolesUpdater::slotGotPreview(const KFileItem& item, const QPi ...@@ -494,7 +494,7 @@ void KFileItemModelRolesUpdater::slotGotPreview(const KFileItem& item, const QPi
QPixmap scaledPixmap = pixmap; QPixmap scaledPixmap = pixmap;
if (!pixmap.hasAlpha() if (!pixmap.hasAlpha() && !pixmap.isNull()
&& m_iconSize.width() > KIconLoader::SizeSmallMedium && m_iconSize.width() > KIconLoader::SizeSmallMedium
&& m_iconSize.height() > KIconLoader::SizeSmallMedium) { && m_iconSize.height() > KIconLoader::SizeSmallMedium) {
if (m_enlargeSmallPreviews) { if (m_enlargeSmallPreviews) {
...@@ -525,7 +525,7 @@ void KFileItemModelRolesUpdater::slotGotPreview(const KFileItem& item, const QPi ...@@ -525,7 +525,7 @@ void KFileItemModelRolesUpdater::slotGotPreview(const KFileItem& item, const QPi
KPixmapModifier::applyFrame(scaledPixmap, m_iconSize); KPixmapModifier::applyFrame(scaledPixmap, m_iconSize);
} }
} }
} else { } else if (!pixmap.isNull()) {
KPixmapModifier::scale(scaledPixmap, m_iconSize * qApp->devicePixelRatio()); KPixmapModifier::scale(scaledPixmap, m_iconSize * qApp->devicePixelRatio());
scaledPixmap.setDevicePixelRatio(qApp->devicePixelRatio()); scaledPixmap.setDevicePixelRatio(qApp->devicePixelRatio());
} }
...@@ -538,12 +538,14 @@ void KFileItemModelRolesUpdater::slotGotPreview(const KFileItem& item, const QPi ...@@ -538,12 +538,14 @@ void KFileItemModelRolesUpdater::slotGotPreview(const KFileItem& item, const QPi
// It is more efficient to do it here, as KIconLoader::drawOverlays() // It is more efficient to do it here, as KIconLoader::drawOverlays()
// assumes that an overlay will be drawn and has some additional // assumes that an overlay will be drawn and has some additional
// setup time. // setup time.
for (const QString& overlay : overlays) { if (!scaledPixmap.isNull()) {
if (!overlay.isEmpty()) { for (const QString& overlay : overlays) {
// There is at least one overlay, draw all overlays above m_pixmap if (!overlay.isEmpty()) {
// and cancel the check // There is at least one overlay, draw all overlays above m_pixmap
KIconLoader::global()->drawOverlays(overlays, scaledPixmap, KIconLoader::Desktop); // and cancel the check
break; KIconLoader::global()->drawOverlays(overlays, scaledPixmap, KIconLoader::Desktop);
break;
}
} }
} }
......
...@@ -314,7 +314,7 @@ void KStandardItemListWidget::paint(QPainter* painter, const QStyleOptionGraphic ...@@ -314,7 +314,7 @@ void KStandardItemListWidget::paint(QPainter* painter, const QStyleOptionGraphic
} }
const KItemListStyleOption& itemListStyleOption = styleOption(); const KItemListStyleOption& itemListStyleOption = styleOption();
if (isHovered()) { if (isHovered() && !m_pixmap.isNull()) {
if (hoverOpacity() < 1.0) { if (hoverOpacity() < 1.0) {
/* /*
* Linear interpolation between m_pixmap and m_hoverPixmap. * Linear interpolation between m_pixmap and m_hoverPixmap.
...@@ -357,7 +357,7 @@ void KStandardItemListWidget::paint(QPainter* painter, const QStyleOptionGraphic ...@@ -357,7 +357,7 @@ void KStandardItemListWidget::paint(QPainter* painter, const QStyleOptionGraphic
} else { } else {
drawPixmap(painter, m_hoverPixmap); drawPixmap(painter, m_hoverPixmap);
} }
} else { } else if (!m_pixmap.isNull()) {
drawPixmap(painter, m_pixmap); drawPixmap(painter, m_pixmap);
} }
...@@ -962,6 +962,11 @@ void KStandardItemListWidget::updatePixmapCache() ...@@ -962,6 +962,11 @@ void KStandardItemListWidget::updatePixmapCache()
KPixmapModifier::scale(m_pixmap, QSize(maxIconWidth, maxIconHeight) * qApp->devicePixelRatio()); KPixmapModifier::scale(m_pixmap, QSize(maxIconWidth, maxIconHeight) * qApp->devicePixelRatio());
} }
if (m_pixmap.isNull()) {
m_hoverPixmap = QPixmap();
return;
}
if (m_isCut) { if (m_isCut) {
KIconEffect* effect = KIconLoader::global()->iconEffect(); KIconEffect* effect = KIconLoader::global()->iconEffect();
m_pixmap = effect->apply(m_pixmap, KIconLoader::Desktop, KIconLoader::DisabledState); m_pixmap = effect->apply(m_pixmap, KIconLoader::Desktop, KIconLoader::DisabledState);
...@@ -974,6 +979,10 @@ void KStandardItemListWidget::updatePixmapCache() ...@@ -974,6 +979,10 @@ void KStandardItemListWidget::updatePixmapCache()
if (m_layout == IconsLayout && isSelected()) { if (m_layout == IconsLayout && isSelected()) {
const QColor color = palette().brush(QPalette::Normal, QPalette::Highlight).color(); const QColor color = palette().brush(QPalette::Normal, QPalette::Highlight).color();
QImage image = m_pixmap.toImage(); QImage image = m_pixmap.toImage();
if (image.isNull()) {
m_hoverPixmap = QPixmap();
return;
}
KIconEffect::colorize(image, color, 0.8f); KIconEffect::colorize(image, color, 0.8f);
m_pixmap = QPixmap::fromImage(image); m_pixmap = QPixmap::fromImage(image);
} }
......
...@@ -298,7 +298,7 @@ namespace { ...@@ -298,7 +298,7 @@ namespace {
void KPixmapModifier::scale(QPixmap& pixmap, const QSize& scaledSize) void KPixmapModifier::scale(QPixmap& pixmap, const QSize& scaledSize)
{ {
if (scaledSize.isEmpty()) { if (scaledSize.isEmpty() || pixmap.isNull()) {
pixmap = QPixmap(); pixmap = QPixmap();
return; return;
} }
...@@ -309,6 +309,12 @@ void KPixmapModifier::scale(QPixmap& pixmap, const QSize& scaledSize) ...@@ -309,6 +309,12 @@ void KPixmapModifier::scale(QPixmap& pixmap, const QSize& scaledSize)
void KPixmapModifier::applyFrame(QPixmap& icon, const QSize& scaledSize) void KPixmapModifier::applyFrame(QPixmap& icon, const QSize& scaledSize)
{ {
if (icon.isNull()) {
icon = QPixmap(scaledSize);
icon.fill(Qt::transparent);
return;
}
static TileSet tileSet; static TileSet tileSet;
qreal dpr = qApp->devicePixelRatio(); qreal dpr = qApp->devicePixelRatio();
......
...@@ -136,7 +136,7 @@ void PixmapViewer::paintEvent(QPaintEvent* event) ...@@ -136,7 +136,7 @@ void PixmapViewer::paintEvent(QPaintEvent* event)
style()->drawItemPixmap(&painter, rect(), Qt::AlignCenter, scaledPixmap); style()->drawItemPixmap(&painter, rect(), Qt::AlignCenter, scaledPixmap);
} }
} else { } else if (!m_pixmap.isNull()) {
style()->drawItemPixmap(&painter, rect(), Qt::AlignCenter, m_pixmap); style()->drawItemPixmap(&painter, rect(), Qt::AlignCenter, m_pixmap);
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment