| 45 | d->_pCardPixmapSize = QSize(width, height); |
| 46 | Q_EMIT pCardPixmapSizeChanged(); |
| 47 | } |
| 48 | |
| 49 | void ElaInteractiveCard::paintEvent(QPaintEvent* event) |
| 50 | { |
| 51 | Q_D(ElaInteractiveCard); |
| 52 | QPainter painter(this); |
| 53 | painter.save(); |
| 54 | painter.setRenderHints(QPainter::SmoothPixmapTransform | QPainter::Antialiasing | QPainter::TextAntialiasing); |
| 55 | painter.setPen(Qt::NoPen); |
| 56 | painter.setBrush(ElaColorAnimation::getColor(this, underMouse() ? ElaThemeColor(d->_themeMode, BasicHoverAlpha) : Qt::transparent, "Background")); |
| 57 | painter.drawRoundedRect(rect(), d->_pBorderRadius, d->_pBorderRadius); |
| 58 | // 图片绘制 |
| 59 | if (!d->_pCardPixmap.isNull()) |
| 60 | { |
| 61 | painter.save(); |
| 62 | QPainterPath path; |
| 63 | if (d->_pCardPixMode == ElaCardPixType::PixMode::Ellipse) |
| 64 | { |
| 65 | path.addEllipse(QPointF(d->_pCardPixmapSize.width() / 2 + 10, height() / 2), d->_pCardPixmapSize.width() / 2, d->_pCardPixmapSize.height() / 2); |
| 66 | painter.setClipPath(path); |
| 67 | painter.drawPixmap(QRect(10, (height() - d->_pCardPixmapSize.height()) / 2, d->_pCardPixmapSize.width(), d->_pCardPixmapSize.height()), d->_pCardPixmap); // rect为绘制区域,image为要绘制的图片 |
| 68 | } |
| 69 | else if (d->_pCardPixMode == ElaCardPixType::PixMode::Default) |
| 70 | { |
| 71 | painter.drawPixmap(10, (height() - d->_pCardPixmapSize.height()) / 2, d->_pCardPixmapSize.width(), d->_pCardPixmapSize.height(), d->_pCardPixmap); |
| 72 | } |
| 73 | else if (d->_pCardPixMode == ElaCardPixType::PixMode::RoundedRect) |
| 74 | { |
| 75 | path.addRoundedRect(QRectF(10, (height() - d->_pCardPixmapSize.height()) / 2, d->_pCardPixmapSize.width(), d->_pCardPixmapSize.height()), d->_pCardPixmapBorderRadius, d->_pCardPixmapBorderRadius); |
| 76 | painter.setClipPath(path); |
| 77 | painter.drawPixmap(10, (height() - d->_pCardPixmapSize.height()) / 2, d->_pCardPixmapSize.width(), d->_pCardPixmapSize.height(), d->_pCardPixmap); |
| 78 | } |
| 79 | painter.restore(); |
| 80 | } |
| 81 | // 文字绘制 |
| 82 | painter.setPen(ElaThemeColor(d->_themeMode, BasicText)); |
| 83 | QFont font = this->font(); |
| 84 | font.setWeight(QFont::Bold); |
| 85 | font.setPixelSize(d->_pTitlePixelSize); |
| 86 | painter.setFont(font); |
| 87 | int textStartX = d->_pCardPixmapSize.width() + 26; |
| 88 | int textWidth = width() - textStartX; |
| 89 | painter.drawText(QRect(textStartX, rect().y(), textWidth, height() / 2 - d->_pTitleSpacing), Qt::TextWordWrap | Qt::AlignBottom | Qt::AlignLeft, d->_pTitle); |
| 90 | font.setWeight(QFont::Normal); |
| 91 | font.setPixelSize(d->_pSubTitlePixelSize); |
| 92 | painter.setFont(font); |
| 93 | painter.drawText(QRect(textStartX, height() / 2 + d->_pTitleSpacing, textWidth, height() / 2 - d->_pTitleSpacing), Qt::TextWordWrap | Qt::AlignTop | Qt::AlignLeft, d->_pSubTitle); |
| 94 | painter.restore(); |
| 95 | } |
nothing calls this directly
no outgoing calls
no test coverage detected