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

Fix warnings about scaling pixmaps

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