| 136 | } |
| 137 | |
| 138 | void ElaPopularCard::paintEvent(QPaintEvent* event) |
| 139 | { |
| 140 | Q_D(ElaPopularCard); |
| 141 | if (d->_isFloating) |
| 142 | { |
| 143 | return; |
| 144 | } |
| 145 | QPainter painter(this); |
| 146 | painter.save(); |
| 147 | painter.setRenderHints(QPainter::SmoothPixmapTransform | QPainter::Antialiasing | QPainter::TextAntialiasing); |
| 148 | if (underMouse()) |
| 149 | { |
| 150 | // 阴影绘制 |
| 151 | painter.setOpacity(d->_pHoverOpacity); |
| 152 | QRect shadowRect = rect().adjusted(0, -d->_pHoverYOffset, 0, -d->_pHoverYOffset); |
| 153 | eTheme->drawEffectShadow(&painter, shadowRect, d->_shadowBorderWidth, d->_pBorderRadius); |
| 154 | } |
| 155 | QRectF foregroundRect(d->_shadowBorderWidth, d->_shadowBorderWidth - d->_pHoverYOffset + 1, width() - 2 * d->_shadowBorderWidth, height() - 2 * d->_shadowBorderWidth); |
| 156 | //背景绘制 |
| 157 | painter.setOpacity(1); |
| 158 | painter.setPen(underMouse() ? ElaThemeColor(d->_themeMode, PopupBorderHover) : ElaThemeColor(d->_themeMode, BasicBorder)); |
| 159 | painter.setBrush(ElaThemeColor(d->_themeMode, BasicBaseAlpha)); |
| 160 | painter.drawRoundedRect(foregroundRect, d->_pBorderRadius, d->_pBorderRadius); |
| 161 | //图片绘制 |
| 162 | painter.save(); |
| 163 | QRectF pixRect(foregroundRect.x() + foregroundRect.height() * 0.15, foregroundRect.y() + foregroundRect.height() * 0.15, foregroundRect.height() * 0.7, foregroundRect.height() * 0.7); |
| 164 | QPainterPath pixPath; |
| 165 | pixPath.addRoundedRect(pixRect, 4, 4); |
| 166 | painter.setClipPath(pixPath); |
| 167 | painter.drawPixmap(pixRect, d->_pCardPixmap, d->_pCardPixmap.rect()); |
| 168 | painter.restore(); |
| 169 | |
| 170 | //文字绘制 |
| 171 | //计算按钮最终矩形 |
| 172 | int buttonTargetWidth = d->_floater->_overButton->fontMetrics().horizontalAdvance(d->_floater->_overButton->text()) + 40; |
| 173 | if (buttonTargetWidth > width() * 0.25) |
| 174 | { |
| 175 | buttonTargetWidth = width() * 0.25; |
| 176 | } |
| 177 | //处理ElaPushButton的阴影偏移 |
| 178 | d->_buttonTargetRect = QRect(QPoint(width() + 2 * d->_floater->_floatGeometryOffset - d->_shadowBorderWidth + 3 - foregroundRect.height() * 0.15 - buttonTargetWidth, foregroundRect.height() * 0.15 - 3), QSize(buttonTargetWidth, 36)); |
| 179 | |
| 180 | // Title |
| 181 | painter.setPen(ElaThemeColor(d->_themeMode, BasicText)); |
| 182 | QFont font = painter.font(); |
| 183 | font.setWeight(QFont::Bold); |
| 184 | font.setPixelSize(15); |
| 185 | painter.setFont(font); |
| 186 | int titleHeight = painter.fontMetrics().height(); |
| 187 | QRectF titleRect(pixRect.right() + d->_textHSpacing, pixRect.y(), d->_floater->_floatGeometryOffset * 2 + foregroundRect.width() - pixRect.width() - d->_textHSpacing * 2 - foregroundRect.height() * 0.15 - buttonTargetWidth, titleHeight); |
| 188 | QString titleText = painter.fontMetrics().elidedText(d->_pTitle, Qt::ElideRight, titleRect.width()); |
| 189 | painter.drawText(titleRect, Qt::AlignLeft | Qt::AlignTop | Qt::TextSingleLine, titleText); |
| 190 | |
| 191 | // SubTitle |
| 192 | font.setWeight(QFont::DemiBold); |
| 193 | font.setPixelSize(13); |
| 194 | painter.setFont(font); |
| 195 | int subTitleHeight = painter.fontMetrics().height(); |
nothing calls this directly
no test coverage detected