MCPcopy Create free account
hub / github.com/Liniyous/ElaWidgetTools / paintEvent

Method paintEvent

ElaWidgetTools/ElaAcrylicUrlCard.cpp:59–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

57 Q_D(ElaAcrylicUrlCard);
58 d->_pCardPixmapSize = QSize(width, height);
59 Q_EMIT pCardPixmapSizeChanged();
60}
61
62void ElaAcrylicUrlCard::paintEvent(QPaintEvent* event)
63{
64 Q_D(ElaAcrylicUrlCard);
65 QPainter painter(this);
66 painter.setRenderHints(QPainter::SmoothPixmapTransform | QPainter::Antialiasing | QPainter::TextAntialiasing);
67 // 亚克力绘制
68 painter.save();
69 painter.setPen(QPen(ElaThemeColor(d->_themeMode, BasicBorder), d->_borderWidth));
70 // 材质底色与透明控件填充分开 BrushAlpha 决定卡片的透光程度
71 QColor brushColor = ElaThemeColor(d->_themeMode, PopupBase);
72 const QColor hoverColor = ElaThemeColor(d->_themeMode, BasicHoverAlpha);
73 const qreal hoverAlpha = isEnabled() && underMouse() ? hoverColor.alphaF() : 0;
74 brushColor.setRgbF(brushColor.redF() * (1 - hoverAlpha) + hoverColor.redF() * hoverAlpha,
75 brushColor.greenF() * (1 - hoverAlpha) + hoverColor.greenF() * hoverAlpha,
76 brushColor.blueF() * (1 - hoverAlpha) + hoverColor.blueF() * hoverAlpha,
77 qBound(0, d->_pBrushAlpha, 255) / 255.0);
78 painter.setBrush(ElaColorAnimation::getColor(this, brushColor, "Background"));
79 QRect foregroundRect = rect();
80 foregroundRect.adjust(d->_borderWidth, d->_borderWidth, -d->_borderWidth, -d->_borderWidth);
81 int width = foregroundRect.width();
82 painter.setOpacity(d->_pNoiseOpacity);
83 painter.drawPixmap(foregroundRect, d->_noisePix);
84 painter.setOpacity(d->_pMainOpacity);
85 painter.drawRoundedRect(foregroundRect, d->_pBorderRadius, d->_pBorderRadius);
86 painter.restore();
87
88 // 图片绘制
89 QRectF pixRect(width / 8.5, height() / 4 - d->_pCardPixmapSize.height() / 2, d->_pCardPixmapSize.width(), d->_pCardPixmapSize.height());
90 if (!d->_pCardPixmap.isNull())
91 {
92 painter.save();
93 QPainterPath path;
94 if (d->_pCardPixMode == ElaCardPixType::PixMode::Ellipse)
95 {
96 path.addEllipse(pixRect.center(), d->_pCardPixmapSize.width() / 2, d->_pCardPixmapSize.height() / 2);
97 painter.setClipPath(path);
98 painter.drawPixmap(pixRect, d->_pCardPixmap, d->_pCardPixmap.rect());
99 }
100 else if (d->_pCardPixMode == ElaCardPixType::PixMode::Default)
101 {
102 painter.drawPixmap(pixRect, d->_pCardPixmap, d->_pCardPixmap.rect());
103 }
104 else if (d->_pCardPixMode == ElaCardPixType::PixMode::RoundedRect)
105 {
106 path.addRoundedRect(pixRect, d->_pCardPixmapBorderRadius, d->_pCardPixmapBorderRadius);
107 painter.setClipPath(path);
108 painter.drawPixmap(pixRect, d->_pCardPixmap, d->_pCardPixmap.rect());
109 }
110 painter.restore();
111 }
112
113 // 文字绘制
114 painter.save();
115 QFont font = this->font();
116 font.setWeight(QFont::Bold);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected