chore: 格式化ElaWidgetTools代码
This commit is contained in:
@@ -17,37 +17,31 @@ Q_PROPERTY_CREATE_Q_CPP(ElaReminderCard, QSize, CardPixmapSize);
|
||||
Q_PROPERTY_CREATE_Q_CPP(ElaReminderCard, int, CardPixmapBorderRadius)
|
||||
Q_PROPERTY_CREATE_Q_CPP(ElaReminderCard, ElaCardPixType::PixMode, CardPixMode);
|
||||
|
||||
ElaReminderCard::ElaReminderCard(QWidget* parent)
|
||||
: QPushButton{parent}, d_ptr(new ElaReminderCardPrivate())
|
||||
{
|
||||
ElaReminderCard::ElaReminderCard(QWidget *parent) : QPushButton{parent}, d_ptr(new ElaReminderCardPrivate()) {
|
||||
Q_D(ElaReminderCard);
|
||||
d->q_ptr = this;
|
||||
d->_pBorderRadius = 6;
|
||||
d->_pTitlePixelSize = 15;
|
||||
d->q_ptr = this;
|
||||
d->_pBorderRadius = 6;
|
||||
d->_pTitlePixelSize = 15;
|
||||
d->_pSubTitlePixelSize = 12;
|
||||
setFixedSize(330, 105);
|
||||
d->_pCardPixmapSize = QSize(79, 79);
|
||||
d->_pTitleSpacing = 3;
|
||||
d->_pCardPixmapSize = QSize(79, 79);
|
||||
d->_pTitleSpacing = 3;
|
||||
d->_pCardPixmapBorderRadius = 6;
|
||||
d->_pCardPixMode = ElaCardPixType::PixMode::Default;
|
||||
d->_themeMode = eTheme->getThemeMode();
|
||||
d->_pCardPixMode = ElaCardPixType::PixMode::Default;
|
||||
d->_themeMode = eTheme->getThemeMode();
|
||||
setMouseTracking(true);
|
||||
connect(eTheme, &ElaTheme::themeModeChanged, this, [=](ElaThemeType::ThemeMode themeMode) { d->_themeMode = themeMode; });
|
||||
}
|
||||
|
||||
ElaReminderCard::~ElaReminderCard()
|
||||
{
|
||||
}
|
||||
ElaReminderCard::~ElaReminderCard() {}
|
||||
|
||||
void ElaReminderCard::setCardPixmapSize(int width, int height)
|
||||
{
|
||||
void ElaReminderCard::setCardPixmapSize(int width, int height) {
|
||||
Q_D(ElaReminderCard);
|
||||
d->_pCardPixmapSize = QSize(width, height);
|
||||
Q_EMIT pCardPixmapSizeChanged();
|
||||
}
|
||||
|
||||
void ElaReminderCard::paintEvent(QPaintEvent* event)
|
||||
{
|
||||
void ElaReminderCard::paintEvent(QPaintEvent *event) {
|
||||
Q_D(ElaReminderCard);
|
||||
QPainter painter(this);
|
||||
painter.setRenderHints(QPainter::SmoothPixmapTransform | QPainter::Antialiasing | QPainter::TextAntialiasing);
|
||||
@@ -60,30 +54,31 @@ void ElaReminderCard::paintEvent(QPaintEvent* event)
|
||||
painter.setPen(ElaThemeColor(d->_themeMode, BasicBorder));
|
||||
painter.setBrush(underMouse() ? ElaThemeColor(d->_themeMode, BasicHoverAlpha) : ElaThemeColor(d->_themeMode, BasicBaseAlpha));
|
||||
QRect foregroundRect(d->_shadowBorderWidth, d->_shadowBorderWidth, width() - 2 * d->_shadowBorderWidth, height() - 2 * d->_shadowBorderWidth);
|
||||
int width = foregroundRect.width();
|
||||
int width = foregroundRect.width();
|
||||
painter.drawRoundedRect(foregroundRect, d->_pBorderRadius, d->_pBorderRadius);
|
||||
|
||||
// 图片绘制
|
||||
int pixLeftMargin = width / 28;
|
||||
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 + pixLeftMargin, height() / 2), d->_pCardPixmapSize.width() / 2, d->_pCardPixmapSize.height() / 2);
|
||||
if (d->_pCardPixMode == ElaCardPixType::PixMode::Ellipse) {
|
||||
path.addEllipse(QPointF(d->_pCardPixmapSize.width() / 2 + pixLeftMargin, height() / 2), d->_pCardPixmapSize.width() / 2,
|
||||
d->_pCardPixmapSize.height() / 2);
|
||||
painter.setClipPath(path);
|
||||
painter.drawPixmap(QRect(pixLeftMargin + d->_shadowBorderWidth, (height() - d->_pCardPixmapSize.height()) / 2, d->_pCardPixmapSize.width(), d->_pCardPixmapSize.height()), d->_pCardPixmap); // rect为绘制区域,image为要绘制的图片
|
||||
}
|
||||
else if (d->_pCardPixMode == ElaCardPixType::PixMode::Default)
|
||||
{
|
||||
painter.drawPixmap(pixLeftMargin + d->_shadowBorderWidth, (height() - d->_pCardPixmapSize.height()) / 2, d->_pCardPixmapSize.width(), d->_pCardPixmapSize.height(), d->_pCardPixmap);
|
||||
}
|
||||
else if (d->_pCardPixMode == ElaCardPixType::PixMode::RoundedRect)
|
||||
{
|
||||
path.addRoundedRect(QRectF(pixLeftMargin, (height() - d->_pCardPixmapSize.height()) / 2, d->_pCardPixmapSize.width(), d->_pCardPixmapSize.height()), d->_pCardPixmapBorderRadius, d->_pCardPixmapBorderRadius);
|
||||
painter.drawPixmap(QRect(pixLeftMargin + d->_shadowBorderWidth, (height() - d->_pCardPixmapSize.height()) / 2,
|
||||
d->_pCardPixmapSize.width(), d->_pCardPixmapSize.height()),
|
||||
d->_pCardPixmap); // rect为绘制区域,image为要绘制的图片
|
||||
} else if (d->_pCardPixMode == ElaCardPixType::PixMode::Default) {
|
||||
painter.drawPixmap(pixLeftMargin + d->_shadowBorderWidth, (height() - d->_pCardPixmapSize.height()) / 2, d->_pCardPixmapSize.width(),
|
||||
d->_pCardPixmapSize.height(), d->_pCardPixmap);
|
||||
} else if (d->_pCardPixMode == ElaCardPixType::PixMode::RoundedRect) {
|
||||
path.addRoundedRect(
|
||||
QRectF(pixLeftMargin, (height() - d->_pCardPixmapSize.height()) / 2, d->_pCardPixmapSize.width(), d->_pCardPixmapSize.height()),
|
||||
d->_pCardPixmapBorderRadius, d->_pCardPixmapBorderRadius);
|
||||
painter.setClipPath(path);
|
||||
painter.drawPixmap(pixLeftMargin + d->_shadowBorderWidth, (height() - d->_pCardPixmapSize.height()) / 2, d->_pCardPixmapSize.width(), d->_pCardPixmapSize.height(), d->_pCardPixmap);
|
||||
painter.drawPixmap(pixLeftMargin + d->_shadowBorderWidth, (height() - d->_pCardPixmapSize.height()) / 2, d->_pCardPixmapSize.width(),
|
||||
d->_pCardPixmapSize.height(), d->_pCardPixmap);
|
||||
}
|
||||
painter.restore();
|
||||
}
|
||||
@@ -102,14 +97,16 @@ void ElaReminderCard::paintEvent(QPaintEvent* event)
|
||||
painter.setFont(font);
|
||||
// 主标题
|
||||
int textLeftMargin = width / 11;
|
||||
int textStartX = d->_pCardPixmapSize.width() + textLeftMargin + d->_shadowBorderWidth;
|
||||
int textWidth = foregroundRect.width() - textStartX - d->_shadowBorderWidth - 5;
|
||||
painter.drawText(QRect(textStartX, foregroundRect.y(), textWidth, this->height() / 2 - d->_pTitleSpacing), Qt::AlignLeft | Qt::AlignBottom | Qt::TextWordWrap | Qt::TextWrapAnywhere, d->_pTitle);
|
||||
int textStartX = d->_pCardPixmapSize.width() + textLeftMargin + d->_shadowBorderWidth;
|
||||
int textWidth = foregroundRect.width() - textStartX - d->_shadowBorderWidth - 5;
|
||||
painter.drawText(QRect(textStartX, foregroundRect.y(), textWidth, this->height() / 2 - d->_pTitleSpacing),
|
||||
Qt::AlignLeft | Qt::AlignBottom | Qt::TextWordWrap | Qt::TextWrapAnywhere, d->_pTitle);
|
||||
// 副标题
|
||||
font.setWeight(QFont::Normal);
|
||||
font.setPixelSize(d->_pSubTitlePixelSize);
|
||||
painter.setFont(font);
|
||||
painter.setPen(ElaThemeColor(d->_themeMode, BasicDetailsText));
|
||||
painter.drawText(QRect(textStartX, height() / 2 + d->_pTitleSpacing, textWidth, height() / 2 - d->_pTitleSpacing), Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap | Qt::TextWrapAnywhere, d->_pSubTitle);
|
||||
painter.drawText(QRect(textStartX, height() / 2 + d->_pTitleSpacing, textWidth, height() / 2 - d->_pTitleSpacing),
|
||||
Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap | Qt::TextWrapAnywhere, d->_pSubTitle);
|
||||
painter.restore();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user