chore: 格式化ElaWidgetTools代码

This commit is contained in:
sleepwithoutbz
2025-09-20 01:39:00 +08:00
parent d2fded145d
commit 4ab391f8a1
394 changed files with 10913 additions and 15860 deletions

View File

@@ -22,42 +22,36 @@ Q_PROPERTY_CREATE_Q_CPP(ElaAcrylicUrlCard, QSize, CardPixmapSize);
Q_PROPERTY_CREATE_Q_CPP(ElaAcrylicUrlCard, int, CardPixmapBorderRadius)
Q_PROPERTY_CREATE_Q_CPP(ElaAcrylicUrlCard, ElaCardPixType::PixMode, CardPixMode);
Q_PROPERTY_CREATE_Q_CPP(ElaAcrylicUrlCard, QString, Url);
ElaAcrylicUrlCard::ElaAcrylicUrlCard(QWidget* parent)
: QPushButton(parent), d_ptr(new ElaAcrylicUrlCardPrivate())
{
ElaAcrylicUrlCard::ElaAcrylicUrlCard(QWidget *parent) : QPushButton(parent), d_ptr(new ElaAcrylicUrlCardPrivate()) {
Q_D(ElaAcrylicUrlCard);
d->q_ptr = this;
d->_noisePix = QPixmap(":/include/Image/noise.png");
d->_pBorderRadius = 5;
d->_pMainOpacity = 0.95;
d->_pNoiseOpacity = 0.06;
d->_pBrushAlpha = 245;
d->_pTitlePixelSize = 15;
d->q_ptr = this;
d->_noisePix = QPixmap(":/include/Image/noise.png");
d->_pBorderRadius = 5;
d->_pMainOpacity = 0.95;
d->_pNoiseOpacity = 0.06;
d->_pBrushAlpha = 245;
d->_pTitlePixelSize = 15;
d->_pSubTitlePixelSize = 12;
setFixedSize(180, 200);
d->_pCardPixmapSize = QSize(54, 54);
d->_pTitleSpacing = 10;
d->_pSubTitleSpacing = 10;
d->_pCardPixmapSize = QSize(54, 54);
d->_pTitleSpacing = 10;
d->_pSubTitleSpacing = 10;
d->_pCardPixmapBorderRadius = 6;
d->_pCardPixMode = ElaCardPixType::PixMode::Ellipse;
d->_themeMode = eTheme->getThemeMode();
d->_pCardPixMode = ElaCardPixType::PixMode::Ellipse;
d->_themeMode = eTheme->getThemeMode();
connect(this, &ElaAcrylicUrlCard::clicked, this, [=]() { QDesktopServices::openUrl(QUrl(d->_pUrl)); });
connect(eTheme, &ElaTheme::themeModeChanged, this, [=](ElaThemeType::ThemeMode themeMode) { d->_themeMode = themeMode; });
}
ElaAcrylicUrlCard::~ElaAcrylicUrlCard()
{
}
ElaAcrylicUrlCard::~ElaAcrylicUrlCard() {}
void ElaAcrylicUrlCard::setCardPixmapSize(int width, int height)
{
void ElaAcrylicUrlCard::setCardPixmapSize(int width, int height) {
Q_D(ElaAcrylicUrlCard);
d->_pCardPixmapSize = QSize(width, height);
Q_EMIT pCardPixmapSizeChanged();
}
void ElaAcrylicUrlCard::paintEvent(QPaintEvent* event)
{
void ElaAcrylicUrlCard::paintEvent(QPaintEvent *event) {
Q_D(ElaAcrylicUrlCard);
QPainter painter(this);
painter.setRenderHints(QPainter::SmoothPixmapTransform | QPainter::Antialiasing | QPainter::TextAntialiasing);
@@ -79,22 +73,16 @@ void ElaAcrylicUrlCard::paintEvent(QPaintEvent* event)
// 图片绘制
QRectF pixRect(width / 8.5, height() / 4 - d->_pCardPixmapSize.height() / 2, d->_pCardPixmapSize.width(), d->_pCardPixmapSize.height());
if (!d->_pCardPixmap.isNull())
{
if (!d->_pCardPixmap.isNull()) {
painter.save();
QPainterPath path;
if (d->_pCardPixMode == ElaCardPixType::PixMode::Ellipse)
{
if (d->_pCardPixMode == ElaCardPixType::PixMode::Ellipse) {
path.addEllipse(pixRect.center(), d->_pCardPixmapSize.width() / 2, d->_pCardPixmapSize.height() / 2);
painter.setClipPath(path);
painter.drawPixmap(pixRect, d->_pCardPixmap, d->_pCardPixmap.rect());
}
else if (d->_pCardPixMode == ElaCardPixType::PixMode::Default)
{
} else if (d->_pCardPixMode == ElaCardPixType::PixMode::Default) {
painter.drawPixmap(pixRect, d->_pCardPixmap, d->_pCardPixmap.rect());
}
else if (d->_pCardPixMode == ElaCardPixType::PixMode::RoundedRect)
{
} else if (d->_pCardPixMode == ElaCardPixType::PixMode::RoundedRect) {
path.addRoundedRect(pixRect, d->_pCardPixmapBorderRadius, d->_pCardPixmapBorderRadius);
painter.setClipPath(path);
painter.drawPixmap(pixRect, d->_pCardPixmap, d->_pCardPixmap.rect());
@@ -109,13 +97,15 @@ void ElaAcrylicUrlCard::paintEvent(QPaintEvent* event)
font.setPixelSize(d->_pTitlePixelSize);
painter.setFont(font);
painter.setPen(ElaThemeColor(d->_themeMode, BasicText));
painter.drawText(QRect(pixRect.x(), pixRect.bottom() + d->_pTitleSpacing, width - width / 7, height() / 3), Qt::AlignLeft | Qt::AlignTop | Qt::TextSingleLine, d->_pTitle);
painter.drawText(QRect(pixRect.x(), pixRect.bottom() + d->_pTitleSpacing, width - width / 7, height() / 3),
Qt::AlignLeft | Qt::AlignTop | Qt::TextSingleLine, d->_pTitle);
font.setWeight(QFont::Normal);
font.setPixelSize(d->_pSubTitlePixelSize);
painter.setFont(font);
painter.setPen(ElaThemeColor(d->_themeMode, BasicDetailsText));
int titleHeight = painter.fontMetrics().boundingRect(d->_pTitle).height() * 1.1;
painter.drawText(QRect(pixRect.x(), d->_pSubTitleSpacing + titleHeight + pixRect.bottom() + d->_pTitleSpacing, width - width / 7, height() / 3), Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, d->_pSubTitle);
painter.drawText(QRect(pixRect.x(), d->_pSubTitleSpacing + titleHeight + pixRect.bottom() + d->_pTitleSpacing, width - width / 7, height() / 3),
Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, d->_pSubTitle);
painter.restore();
// 图标绘制