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

Method paintEvent

ElaWidgetTools/ElaReminderCard.cpp:49–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47}
48
49void ElaReminderCard::paintEvent(QPaintEvent* event)
50{
51 Q_D(ElaReminderCard);
52 QPainter painter(this);
53 painter.setRenderHints(QPainter::SmoothPixmapTransform | QPainter::Antialiasing | QPainter::TextAntialiasing);
54 // 高性能阴影
55 eTheme->drawEffectShadow(&painter, rect(), d->_shadowBorderWidth, d->_pBorderRadius);
56
57 // 背景绘制
58 painter.save();
59 painter.setRenderHints(QPainter::SmoothPixmapTransform | QPainter::Antialiasing | QPainter::TextAntialiasing);
60 painter.setPen(ElaThemeColor(d->_themeMode, BasicBorder));
61 painter.setBrush(underMouse() ? ElaThemeColor(d->_themeMode, BasicHoverAlpha) : ElaThemeColor(d->_themeMode, BasicBaseAlpha));
62 QRect foregroundRect(d->_shadowBorderWidth, d->_shadowBorderWidth, width() - 2 * d->_shadowBorderWidth, height() - 2 * d->_shadowBorderWidth);
63 int width = foregroundRect.width();
64 painter.drawRoundedRect(foregroundRect, d->_pBorderRadius, d->_pBorderRadius);
65
66 // 图片绘制
67 int pixLeftMargin = width / 28;
68 if (!d->_pCardPixmap.isNull())
69 {
70 painter.save();
71 QPainterPath path;
72 if (d->_pCardPixMode == ElaCardPixType::PixMode::Ellipse)
73 {
74 path.addEllipse(QPointF(d->_pCardPixmapSize.width() / 2 + pixLeftMargin, height() / 2), d->_pCardPixmapSize.width() / 2, d->_pCardPixmapSize.height() / 2);
75 painter.setClipPath(path);
76 painter.drawPixmap(QRect(pixLeftMargin + d->_shadowBorderWidth, (height() - d->_pCardPixmapSize.height()) / 2, d->_pCardPixmapSize.width(), d->_pCardPixmapSize.height()), d->_pCardPixmap); // rect为绘制区域,image为要绘制的图片
77 }
78 else if (d->_pCardPixMode == ElaCardPixType::PixMode::Default)
79 {
80 painter.drawPixmap(pixLeftMargin + d->_shadowBorderWidth, (height() - d->_pCardPixmapSize.height()) / 2, d->_pCardPixmapSize.width(), d->_pCardPixmapSize.height(), d->_pCardPixmap);
81 }
82 else if (d->_pCardPixMode == ElaCardPixType::PixMode::RoundedRect)
83 {
84 path.addRoundedRect(QRectF(pixLeftMargin, (height() - d->_pCardPixmapSize.height()) / 2, d->_pCardPixmapSize.width(), d->_pCardPixmapSize.height()), d->_pCardPixmapBorderRadius, d->_pCardPixmapBorderRadius);
85 painter.setClipPath(path);
86 painter.drawPixmap(pixLeftMargin + d->_shadowBorderWidth, (height() - d->_pCardPixmapSize.height()) / 2, d->_pCardPixmapSize.width(), d->_pCardPixmapSize.height(), d->_pCardPixmap);
87 }
88 painter.restore();
89 }
90
91 // 焦点圆型绘制
92 painter.save();
93 painter.setBrush(ElaThemeColor(d->_themeMode, PrimaryNormal));
94 painter.drawEllipse(QPointF(width * 0.95 + d->_shadowBorderWidth, height() * 0.25), height() / 17, height() / 17);
95 painter.restore();
96
97 // 文字绘制
98 QFont font = this->font();
99 font.setWeight(QFont::Bold);
100 font.setPixelSize(d->_pTitlePixelSize);
101 painter.setPen(ElaThemeColor(d->_themeMode, BasicText));
102 painter.setFont(font);
103 // 主标题
104 int textLeftMargin = width / 11;
105 int textStartX = d->_pCardPixmapSize.width() + textLeftMargin + d->_shadowBorderWidth;
106 int textWidth = foregroundRect.width() - textStartX - d->_shadowBorderWidth - 5;

Callers

nothing calls this directly

Calls 1

drawEffectShadowMethod · 0.80

Tested by

no test coverage detected