chore: 格式化ElaWidgetTools代码
This commit is contained in:
@@ -15,37 +15,31 @@ Q_PROPERTY_CREATE_Q_CPP(ElaInteractiveCard, QPixmap, CardPixmap);
|
||||
Q_PROPERTY_CREATE_Q_CPP(ElaInteractiveCard, QSize, CardPixmapSize);
|
||||
Q_PROPERTY_CREATE_Q_CPP(ElaInteractiveCard, int, CardPixmapBorderRadius)
|
||||
Q_PROPERTY_CREATE_Q_CPP(ElaInteractiveCard, ElaCardPixType::PixMode, CardPixMode);
|
||||
ElaInteractiveCard::ElaInteractiveCard(QWidget* parent)
|
||||
: QPushButton(parent), d_ptr(new ElaInteractiveCardPrivate())
|
||||
{
|
||||
ElaInteractiveCard::ElaInteractiveCard(QWidget *parent) : QPushButton(parent), d_ptr(new ElaInteractiveCardPrivate()) {
|
||||
Q_D(ElaInteractiveCard);
|
||||
d->q_ptr = this;
|
||||
d->_pBorderRadius = 6;
|
||||
d->_pTitlePixelSize = 15;
|
||||
d->q_ptr = this;
|
||||
d->_pBorderRadius = 6;
|
||||
d->_pTitlePixelSize = 15;
|
||||
d->_pSubTitlePixelSize = 12;
|
||||
setMinimumSize(270, 80);
|
||||
d->_pCardPixmapSize = QSize(64, 64);
|
||||
d->_pTitleSpacing = 2;
|
||||
d->_pCardPixmapSize = QSize(64, 64);
|
||||
d->_pTitleSpacing = 2;
|
||||
d->_pCardPixmapBorderRadius = 6;
|
||||
d->_pCardPixMode = ElaCardPixType::PixMode::Ellipse;
|
||||
d->_themeMode = eTheme->getThemeMode();
|
||||
d->_pCardPixMode = ElaCardPixType::PixMode::Ellipse;
|
||||
d->_themeMode = eTheme->getThemeMode();
|
||||
setMouseTracking(true);
|
||||
connect(eTheme, &ElaTheme::themeModeChanged, this, [=](ElaThemeType::ThemeMode themeMode) { d->_themeMode = themeMode; });
|
||||
}
|
||||
|
||||
ElaInteractiveCard::~ElaInteractiveCard()
|
||||
{
|
||||
}
|
||||
ElaInteractiveCard::~ElaInteractiveCard() {}
|
||||
|
||||
void ElaInteractiveCard::setCardPixmapSize(int width, int height)
|
||||
{
|
||||
void ElaInteractiveCard::setCardPixmapSize(int width, int height) {
|
||||
Q_D(ElaInteractiveCard);
|
||||
d->_pCardPixmapSize = QSize(width, height);
|
||||
Q_EMIT pCardPixmapSizeChanged();
|
||||
}
|
||||
|
||||
void ElaInteractiveCard::paintEvent(QPaintEvent* event)
|
||||
{
|
||||
void ElaInteractiveCard::paintEvent(QPaintEvent *event) {
|
||||
Q_D(ElaInteractiveCard);
|
||||
QPainter painter(this);
|
||||
painter.save();
|
||||
@@ -54,25 +48,24 @@ void ElaInteractiveCard::paintEvent(QPaintEvent* event)
|
||||
painter.setBrush(underMouse() ? ElaThemeColor(d->_themeMode, BasicHoverAlpha) : Qt::transparent);
|
||||
painter.drawRoundedRect(rect(), d->_pBorderRadius, d->_pBorderRadius);
|
||||
// 图片绘制
|
||||
if (!d->_pCardPixmap.isNull())
|
||||
{
|
||||
if (!d->_pCardPixmap.isNull()) {
|
||||
painter.save();
|
||||
QPainterPath path;
|
||||
if (d->_pCardPixMode == ElaCardPixType::PixMode::Ellipse)
|
||||
{
|
||||
path.addEllipse(QPointF(d->_pCardPixmapSize.width() / 2 + 10, height() / 2), d->_pCardPixmapSize.width() / 2, d->_pCardPixmapSize.height() / 2);
|
||||
if (d->_pCardPixMode == ElaCardPixType::PixMode::Ellipse) {
|
||||
path.addEllipse(QPointF(d->_pCardPixmapSize.width() / 2 + 10, height() / 2), d->_pCardPixmapSize.width() / 2,
|
||||
d->_pCardPixmapSize.height() / 2);
|
||||
painter.setClipPath(path);
|
||||
painter.drawPixmap(QRect(10, (height() - d->_pCardPixmapSize.height()) / 2, d->_pCardPixmapSize.width(), d->_pCardPixmapSize.height()), d->_pCardPixmap); // rect为绘制区域,image为要绘制的图片
|
||||
}
|
||||
else if (d->_pCardPixMode == ElaCardPixType::PixMode::Default)
|
||||
{
|
||||
painter.drawPixmap(10, (height() - d->_pCardPixmapSize.height()) / 2, d->_pCardPixmapSize.width(), d->_pCardPixmapSize.height(), d->_pCardPixmap);
|
||||
}
|
||||
else if (d->_pCardPixMode == ElaCardPixType::PixMode::RoundedRect)
|
||||
{
|
||||
path.addRoundedRect(QRectF(10, (height() - d->_pCardPixmapSize.height()) / 2, d->_pCardPixmapSize.width(), d->_pCardPixmapSize.height()), d->_pCardPixmapBorderRadius, d->_pCardPixmapBorderRadius);
|
||||
painter.drawPixmap(QRect(10, (height() - d->_pCardPixmapSize.height()) / 2, d->_pCardPixmapSize.width(), d->_pCardPixmapSize.height()),
|
||||
d->_pCardPixmap); // rect为绘制区域,image为要绘制的图片
|
||||
} else if (d->_pCardPixMode == ElaCardPixType::PixMode::Default) {
|
||||
painter.drawPixmap(10, (height() - d->_pCardPixmapSize.height()) / 2, d->_pCardPixmapSize.width(), d->_pCardPixmapSize.height(),
|
||||
d->_pCardPixmap);
|
||||
} else if (d->_pCardPixMode == ElaCardPixType::PixMode::RoundedRect) {
|
||||
path.addRoundedRect(QRectF(10, (height() - d->_pCardPixmapSize.height()) / 2, d->_pCardPixmapSize.width(), d->_pCardPixmapSize.height()),
|
||||
d->_pCardPixmapBorderRadius, d->_pCardPixmapBorderRadius);
|
||||
painter.setClipPath(path);
|
||||
painter.drawPixmap(10, (height() - d->_pCardPixmapSize.height()) / 2, d->_pCardPixmapSize.width(), d->_pCardPixmapSize.height(), d->_pCardPixmap);
|
||||
painter.drawPixmap(10, (height() - d->_pCardPixmapSize.height()) / 2, d->_pCardPixmapSize.width(), d->_pCardPixmapSize.height(),
|
||||
d->_pCardPixmap);
|
||||
}
|
||||
painter.restore();
|
||||
}
|
||||
@@ -83,11 +76,13 @@ void ElaInteractiveCard::paintEvent(QPaintEvent* event)
|
||||
font.setPixelSize(d->_pTitlePixelSize);
|
||||
painter.setFont(font);
|
||||
int textStartX = d->_pCardPixmapSize.width() + 26;
|
||||
int textWidth = width() - textStartX;
|
||||
painter.drawText(QRect(textStartX, rect().y(), textWidth, height() / 2 - d->_pTitleSpacing), Qt::TextWordWrap | Qt::AlignBottom | Qt::AlignLeft, d->_pTitle);
|
||||
int textWidth = width() - textStartX;
|
||||
painter.drawText(QRect(textStartX, rect().y(), textWidth, height() / 2 - d->_pTitleSpacing), Qt::TextWordWrap | Qt::AlignBottom | Qt::AlignLeft,
|
||||
d->_pTitle);
|
||||
font.setWeight(QFont::Normal);
|
||||
font.setPixelSize(d->_pSubTitlePixelSize);
|
||||
painter.setFont(font);
|
||||
painter.drawText(QRect(textStartX, height() / 2 + d->_pTitleSpacing, textWidth, height() / 2 - d->_pTitleSpacing), Qt::TextWordWrap | Qt::AlignTop | Qt::AlignLeft, d->_pSubTitle);
|
||||
painter.drawText(QRect(textStartX, height() / 2 + d->_pTitleSpacing, textWidth, height() / 2 - d->_pTitleSpacing),
|
||||
Qt::TextWordWrap | Qt::AlignTop | Qt::AlignLeft, d->_pSubTitle);
|
||||
painter.restore();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user