From c9374b4d74f3e687747df418590db7a9933042c4 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Thu, 20 Jan 2022 22:27:58 +0100 Subject: [PATCH] Core: Fix drawing of items without images For items without images (e.g. Marketplace items during the loading phase), the description text is drawn as fallback. This change fixes the layout of the fallback text. Also, The drawing of the hover effect is fixed by drawing a solid rectancgle instead of the "blurred" image. Fixes: QTCREATORBUG-26916 Change-Id: Icd1151d3b9412752a482abf869a2ec9ff5c3465e Reviewed-by: Christian Stenger --- src/plugins/coreplugin/welcomepagehelper.cpp | 57 +++++++++++--------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/src/plugins/coreplugin/welcomepagehelper.cpp b/src/plugins/coreplugin/welcomepagehelper.cpp index 42d23773b3c..e5c69d32797 100644 --- a/src/plugins/coreplugin/welcomepagehelper.cpp +++ b/src/plugins/coreplugin/welcomepagehelper.cpp @@ -391,6 +391,7 @@ void ListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti constexpr int nameY = TagsSeparatorY - 20; const QRect textRect = textArea.translated(0, nameY); + const QFont descriptionFont = sizedFont(11, option.widget); painter->save(); painter->translate(rc.topLeft()); @@ -436,36 +437,40 @@ void ListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti } else { // The description text as fallback. painter->setPen(textColor); - painter->setFont(sizedFont(11, option.widget)); - painter->drawText(thumbnailBgRect.adjusted(6, 10, -6, -10), item->description, wrapped); + painter->setFont(descriptionFont); + painter->drawText(textArea, item->description, wrapped); } // The description background - if (offset && !pm.isNull()) { - if (m_blurredThumbnail.isNull()) { - constexpr int blurRadius = 50; - QImage thumbnail(tileRect.size() + QSize(blurRadius, blurRadius) * 2, - QImage::Format_ARGB32_Premultiplied); - thumbnail.fill(hoverColor); - QPainter thumbnailPainter(&thumbnail); - thumbnailPainter.translate(blurRadius, blurRadius); - thumbnailPainter.fillRect(thumbnailBgRect, backgroundSecondaryColor); - thumbnailPainter.drawPixmap(thumbnailPos, pm); - thumbnailPainter.setPen(foregroundPrimaryColor); - drawPixmapOverlay(item, &thumbnailPainter, option, thumbnailBgRect); - thumbnailPainter.end(); + if (offset) { + QRect backgroundPortionRect = tileRect; + backgroundPortionRect.setTop(shiftY - offset); + if (!pm.isNull()) { + if (m_blurredThumbnail.isNull()) { + constexpr int blurRadius = 50; + QImage thumbnail(tileRect.size() + QSize(blurRadius, blurRadius) * 2, + QImage::Format_ARGB32_Premultiplied); + thumbnail.fill(hoverColor); + QPainter thumbnailPainter(&thumbnail); + thumbnailPainter.translate(blurRadius, blurRadius); + thumbnailPainter.fillRect(thumbnailBgRect, backgroundSecondaryColor); + thumbnailPainter.drawPixmap(thumbnailPos, pm); + thumbnailPainter.setPen(foregroundPrimaryColor); + drawPixmapOverlay(item, &thumbnailPainter, option, thumbnailBgRect); + thumbnailPainter.end(); - m_blurredThumbnail = QPixmap(tileRect.size()); - QPainter blurredThumbnailPainter(&m_blurredThumbnail); - blurredThumbnailPainter.translate(-blurRadius, -blurRadius); - qt_blurImage(&blurredThumbnailPainter, thumbnail, blurRadius, false, false); - blurredThumbnailPainter.setOpacity(0.825); - blurredThumbnailPainter.fillRect(tileRect, hoverColor); + m_blurredThumbnail = QPixmap(tileRect.size()); + QPainter blurredThumbnailPainter(&m_blurredThumbnail); + blurredThumbnailPainter.translate(-blurRadius, -blurRadius); + qt_blurImage(&blurredThumbnailPainter, thumbnail, blurRadius, false, false); + blurredThumbnailPainter.setOpacity(0.825); + blurredThumbnailPainter.fillRect(tileRect, hoverColor); + } + const QPixmap thumbnailPortionPM = m_blurredThumbnail.copy(backgroundPortionRect); + painter->drawPixmap(backgroundPortionRect.topLeft(), thumbnailPortionPM); + } else { + painter->fillRect(backgroundPortionRect, hoverColor); } - QRect thumbnailPortionRect = tileRect; - thumbnailPortionRect.setTop(shiftY - offset); - const QPixmap thumbnailPortionPM = m_blurredThumbnail.copy(thumbnailPortionRect); - painter->drawPixmap(thumbnailPortionRect.topLeft(), thumbnailPortionPM); } // The description Text (unhovered or hovered) @@ -487,7 +492,7 @@ void ListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti const int dd = ll + 5; const QRect descRect = shiftedTextRect.adjusted(0, dd, 0, dd); painter->setPen(textColor); - painter->setFont(sizedFont(11, option.widget)); + painter->setFont(descriptionFont); painter->drawText(descRect, item->description, wrapped); painter->setOpacity(1); } else {