forked from qt-creator/qt-creator
Core: Introduce WelcomePageHelpers::drawCardBackground
Pulled out of the ExtensionManager. It will also be used by the Welcomescreen pages. Change-Id: Ic5c67759e7f3af6a3b51968b7ae072c7058109b3 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QPainterPath>
|
||||||
#include <QPixmapCache>
|
#include <QPixmapCache>
|
||||||
#include <QScrollArea>
|
#include <QScrollArea>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
@@ -57,6 +58,25 @@ QWidget *panelBar(QWidget *parent)
|
|||||||
return frame;
|
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
|
} // namespace WelcomePageHelpers
|
||||||
|
|
||||||
SearchBox::SearchBox(QWidget *parent)
|
SearchBox::SearchBox(QWidget *parent)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include <QElapsedTimer>
|
#include <QElapsedTimer>
|
||||||
#include <QListView>
|
#include <QListView>
|
||||||
|
#include <QPen>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
#include <QStackedWidget>
|
#include <QStackedWidget>
|
||||||
@@ -36,6 +37,9 @@ constexpr QSize GridItemImageSize(GridItemWidth - GridItemGap
|
|||||||
- 67); // Bottom margin (for title + tags)
|
- 67); // Bottom margin (for title + tags)
|
||||||
|
|
||||||
CORE_EXPORT QWidget *panelBar(QWidget *parent = nullptr);
|
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
|
} // namespace WelcomePageHelpers
|
||||||
|
|
||||||
|
|||||||
@@ -339,19 +339,11 @@ public:
|
|||||||
{
|
{
|
||||||
const bool selected = option.state & QStyle::State_Selected;
|
const bool selected = option.state & QStyle::State_Selected;
|
||||||
const bool hovered = option.state & QStyle::State_MouseOver;
|
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
|
const QColor fillColor = creatorTheme()->color(hovered ? Theme::Token_Foreground_Muted
|
||||||
: Theme::Token_Background_Muted);
|
: Theme::Token_Background_Muted);
|
||||||
const QColor strokeColor = creatorTheme()->color(selected ? Theme::Token_Stroke_Strong
|
const QColor strokeColor = creatorTheme()->color(selected ? Theme::Token_Stroke_Strong
|
||||||
: Theme::Token_Stroke_Subtle);
|
: Theme::Token_Stroke_Subtle);
|
||||||
painter->setBrush(fillColor);
|
WelcomePageHelpers::drawCardBackground(painter, itemRect, fillColor, strokeColor);
|
||||||
painter->setPen(strokeColor);
|
|
||||||
painter->drawPath(itemOutlinePath);
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
constexpr QRectF bigCircle(16, 16, 48, 48);
|
constexpr QRectF bigCircle(16, 16, 48, 48);
|
||||||
|
|||||||
Reference in New Issue
Block a user