mirror of
https://invent.kde.org/system/dolphin
synced 2024-08-22 01:40:02 +00:00
Fix warnings about scaling pixmaps
This commit is contained in:
parent
adfca90730
commit
891ebf5758
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue