| 176 | } |
| 177 | |
| 178 | void ElaPromotionCard::paintEvent(QPaintEvent* event) |
| 179 | { |
| 180 | Q_D(ElaPromotionCard); |
| 181 | QPainter painter(this); |
| 182 | painter.save(); |
| 183 | painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform); |
| 184 | painter.setPen(Qt::NoPen); |
| 185 | //阴影绘制 |
| 186 | eTheme->drawEffectShadow(&painter, rect(), d->_shadowBorderWidth, d->_pBorderRadius); |
| 187 | QRect foregroundRect(d->_shadowBorderWidth, d->_shadowBorderWidth, width() - 2 * d->_shadowBorderWidth, height() - 2 * d->_shadowBorderWidth); |
| 188 | QPainterPath path; |
| 189 | path.addRoundedRect(foregroundRect, d->_pBorderRadius, d->_pBorderRadius); |
| 190 | painter.setClipPath(path); |
| 191 | //背景图片绘制 |
| 192 | if (!d->_pCardPixmap.isNull()) |
| 193 | { |
| 194 | //源区域计算 |
| 195 | QRect pixSourceRect = d->_pCardPixmap.rect(); |
| 196 | qreal horizontalOffset = d->_pCardPixmap.width() * (1 - d->_pHorizontalCardPixmapRatio) / 2; |
| 197 | qreal verticalOffset = d->_pCardPixmap.height() * (1 - d->_pVerticalCardPixmapRatio) / 2; |
| 198 | pixSourceRect.adjust(horizontalOffset, verticalOffset, -horizontalOffset, -verticalOffset); |
| 199 | painter.drawPixmap(foregroundRect, d->_pCardPixmap, pixSourceRect); |
| 200 | } |
| 201 | //文字绘制 |
| 202 | painter.save(); |
| 203 | QFont font = painter.font(); |
| 204 | //卡片标题 |
| 205 | font.setWeight(QFont::Bold); |
| 206 | font.setPixelSize(d->_pCardTitlePixelSize); |
| 207 | painter.setFont(font); |
| 208 | painter.setPen(d->_pCardTitleColor); |
| 209 | painter.drawText(QRect(25, 25, foregroundRect.width() - 25, foregroundRect.height()), Qt::AlignLeft | Qt::AlignTop | Qt::TextSingleLine, d->_pCardTitle); |
| 210 | //标题 |
| 211 | font.setWeight(QFont::Bold); |
| 212 | font.setPixelSize(d->_pTitlePixelSize); |
| 213 | painter.setFont(font); |
| 214 | painter.setPen(d->_pTitleColor); |
| 215 | int titleTextHeight = painter.fontMetrics().height(); |
| 216 | QRect titleRect(25, (height() - titleTextHeight) / 2, foregroundRect.width() - 25, titleTextHeight); |
| 217 | painter.drawText(titleRect, Qt::AlignLeft | Qt::AlignBottom | Qt::TextSingleLine, d->_pTitle); |
| 218 | //推广标题 |
| 219 | if (!d->_pPromotionTitle.isEmpty()) |
| 220 | { |
| 221 | font.setWeight(QFont::Normal); |
| 222 | font.setPixelSize(d->_pPromotionTitlePixelSize); |
| 223 | painter.setFont(font); |
| 224 | int promotionTitleTextWidth = painter.fontMetrics().horizontalAdvance(d->_pPromotionTitle); |
| 225 | int promotionTitleTextHeight = painter.fontMetrics().height(); |
| 226 | QRect promotionTitleTextRect(32, titleRect.top() - promotionTitleTextHeight - 5, foregroundRect.width() / 2 - 25, promotionTitleTextHeight); |
| 227 | //背景绘制 |
| 228 | painter.setPen(Qt::NoPen); |
| 229 | painter.setBrush(d->_pPromotionTitleBaseColor); |
| 230 | painter.drawRoundedRect(QRect(25, promotionTitleTextRect.top() - 2, promotionTitleTextWidth + 14, promotionTitleTextHeight + 4), 8, 8); |
| 231 | //文字绘制 |
| 232 | painter.setPen(d->_pPromotionTitleColor); |
| 233 | painter.drawText(promotionTitleTextRect, Qt::AlignLeft | Qt::AlignBottom | Qt::TextSingleLine, d->_pPromotionTitle); |
| 234 | } |
| 235 | //副标题 |
nothing calls this directly
no test coverage detected