diff --git a/src/plugins/coreplugin/welcomepagehelper.cpp b/src/plugins/coreplugin/welcomepagehelper.cpp index 4fb0cd08079..37874a9e46f 100644 --- a/src/plugins/coreplugin/welcomepagehelper.cpp +++ b/src/plugins/coreplugin/welcomepagehelper.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -57,6 +58,25 @@ QWidget *panelBar(QWidget *parent) return frame; } +void drawCardBackground(QPainter *painter, const QRectF &rect, + const QBrush &fill, const QPen &pen, qreal rounding) +{ + const qreal strokeWidth = pen.style() == Qt::NoPen ? 0 : pen.widthF(); + const qreal strokeShrink = strokeWidth / 2; + const QRectF itemRectAdjusted = rect.adjusted(strokeShrink, strokeShrink, + -strokeShrink, -strokeShrink); + const qreal roundingAdjusted = rounding - strokeShrink; + QPainterPath itemOutlinePath; + itemOutlinePath.addRoundedRect(itemRectAdjusted, roundingAdjusted, roundingAdjusted); + + painter->save(); + painter->setRenderHint(QPainter::Antialiasing); + painter->setBrush(fill); + painter->setPen(pen); + painter->drawPath(itemOutlinePath); + painter->restore(); +} + } // namespace WelcomePageHelpers SearchBox::SearchBox(QWidget *parent) diff --git a/src/plugins/coreplugin/welcomepagehelper.h b/src/plugins/coreplugin/welcomepagehelper.h index 191e1768d1d..c1792c08722 100644 --- a/src/plugins/coreplugin/welcomepagehelper.h +++ b/src/plugins/coreplugin/welcomepagehelper.h @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -36,6 +37,9 @@ constexpr QSize GridItemImageSize(GridItemWidth - GridItemGap - 67); // Bottom margin (for title + tags) CORE_EXPORT QWidget *panelBar(QWidget *parent = nullptr); +CORE_EXPORT void drawCardBackground(QPainter *painter, const QRectF &rect, + const QBrush &fill, const QPen &pen = QPen(Qt::NoPen), + qreal rounding = 5.0); } // namespace WelcomePageHelpers diff --git a/src/plugins/extensionmanager/extensionsbrowser.cpp b/src/plugins/extensionmanager/extensionsbrowser.cpp index 0e4b6ce9865..1758694ab97 100644 --- a/src/plugins/extensionmanager/extensionsbrowser.cpp +++ b/src/plugins/extensionmanager/extensionsbrowser.cpp @@ -339,19 +339,11 @@ public: { const bool selected = option.state & QStyle::State_Selected; const bool hovered = option.state & QStyle::State_MouseOver; - constexpr qreal strokeWidth = 1; - constexpr qreal shrink = strokeWidth / 2; - const QRectF itemRectAdjusted = itemRect.adjusted(shrink, shrink, -shrink, -shrink); - constexpr qreal rounding = 4.5; - QPainterPath itemOutlinePath; - itemOutlinePath.addRoundedRect(itemRectAdjusted, rounding, rounding); const QColor fillColor = creatorTheme()->color(hovered ? Theme::Token_Foreground_Muted : Theme::Token_Background_Muted); const QColor strokeColor = creatorTheme()->color(selected ? Theme::Token_Stroke_Strong : Theme::Token_Stroke_Subtle); - painter->setBrush(fillColor); - painter->setPen(strokeColor); - painter->drawPath(itemOutlinePath); + WelcomePageHelpers::drawCardBackground(painter, itemRect, fillColor, strokeColor); } { constexpr QRectF bigCircle(16, 16, 48, 48);