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

@@ -20,9 +20,7 @@
#include "ElaTheme.h"
#include "ElaToolButton.h"
Q_TAKEOVER_NATIVEEVENT_CPP(ElaColorDialog, d_func()->_appBar);
ElaColorDialog::ElaColorDialog(QWidget* parent)
: QDialog{parent}, d_ptr(new ElaColorDialogPrivate())
{
ElaColorDialog::ElaColorDialog(QWidget *parent) : QDialog{parent}, d_ptr(new ElaColorDialogPrivate()) {
Q_D(ElaColorDialog);
d->q_ptr = this;
setFixedSize(600, 600); // 默认宽高
@@ -37,14 +35,12 @@ ElaColorDialog::ElaColorDialog(QWidget* parent)
d->_appBar->setIsStayTop(true);
d->_appBar->setWindowButtonFlags(ElaAppBarType::CloseButtonHint);
d->_appBar->setIsDefaultClosed(false);
connect(d->_appBar, &ElaAppBar::closeButtonClicked, this, [=]() {
close();
});
connect(d->_appBar, &ElaAppBar::closeButtonClicked, this, [=]() { close(); });
// 颜色选择器
ElaText* colorPickerText = new ElaText("编辑颜色", this);
ElaText *colorPickerText = new ElaText("编辑颜色", this);
colorPickerText->setTextPixelSize(17);
QHBoxLayout* colorPickerTextLayout = new QHBoxLayout();
QHBoxLayout *colorPickerTextLayout = new QHBoxLayout();
colorPickerTextLayout->setContentsMargins(0, 0, 0, 0);
colorPickerTextLayout->addSpacing(3);
colorPickerTextLayout->addWidget(colorPickerText);
@@ -52,14 +48,14 @@ ElaColorDialog::ElaColorDialog(QWidget* parent)
d->_colorPicker = new ElaColorPicker(this);
connect(d->_colorPicker, &ElaColorPicker::selectedColorChanged, d, &ElaColorDialogPrivate::onColorPickerColorChanged);
QVBoxLayout* colorPickerLayout = new QVBoxLayout();
QVBoxLayout *colorPickerLayout = new QVBoxLayout();
colorPickerLayout->setContentsMargins(0, 0, 0, 0);
colorPickerLayout->addWidget(d->_colorPicker);
colorPickerLayout->addStretch();
// 颜色预览
d->_colorPreview = new ElaColorPreview(this);
QVBoxLayout* colorPreviewLayout = new QVBoxLayout();
d->_colorPreview = new ElaColorPreview(this);
QVBoxLayout *colorPreviewLayout = new QVBoxLayout();
colorPreviewLayout->setContentsMargins(0, 0, 0, 0);
colorPreviewLayout->addWidget(d->_colorPreview);
colorPreviewLayout->addStretch();
@@ -73,7 +69,7 @@ ElaColorDialog::ElaColorDialog(QWidget* parent)
d->_colorValueSliderStyle = new ElaColorValueSliderStyle();
d->_colorValueSlider->setStyle(d->_colorValueSliderStyle);
connect(d->_colorValueSlider, &QSlider::valueChanged, d, &ElaColorDialogPrivate::onColorValueSliderChanged);
QVBoxLayout* colorValueSliderLayout = new QVBoxLayout();
QVBoxLayout *colorValueSliderLayout = new QVBoxLayout();
colorValueSliderLayout->setContentsMargins(0, 0, 0, 0);
colorValueSliderLayout->addWidget(d->_colorValueSlider);
colorValueSliderLayout->addStretch();
@@ -81,7 +77,7 @@ ElaColorDialog::ElaColorDialog(QWidget* parent)
// 颜色控制器
d->_htmlEdit = new ElaLineEdit(this);
d->_htmlEdit->setText("#000000");
ElaIntValidator* htmlValidator = new ElaIntValidator(0x000000, 0xFFFFFF, this);
ElaIntValidator *htmlValidator = new ElaIntValidator(0x000000, 0xFFFFFF, this);
htmlValidator->setIsHexMode(true);
d->_htmlEdit->setValidator(htmlValidator);
d->_htmlEdit->setFixedSize(120, 33);
@@ -89,7 +85,7 @@ ElaColorDialog::ElaColorDialog(QWidget* parent)
connect(d->_htmlEdit, &ElaLineEdit::textEdited, d, &ElaColorDialogPrivate::onHtmlEditChanged);
// 数值预览
QHBoxLayout* htmlEditLayout = new QHBoxLayout();
QHBoxLayout *htmlEditLayout = new QHBoxLayout();
htmlEditLayout->setContentsMargins(0, 0, 0, 0);
htmlEditLayout->addSpacing(6);
htmlEditLayout->addWidget(d->_htmlEdit);
@@ -110,7 +106,7 @@ ElaColorDialog::ElaColorDialog(QWidget* parent)
d->_firstText->setTextPixelSize(13);
connect(d->_firstEdit, &ElaLineEdit::textEdited, d, &ElaColorDialogPrivate::onColorEditChanged);
QHBoxLayout* firstEditLayout = new QHBoxLayout();
QHBoxLayout *firstEditLayout = new QHBoxLayout();
firstEditLayout->setContentsMargins(0, 0, 0, 0);
firstEditLayout->addSpacing(6);
firstEditLayout->addWidget(d->_firstEdit);
@@ -125,7 +121,7 @@ ElaColorDialog::ElaColorDialog(QWidget* parent)
d->_secondText = new ElaText("绿色", this);
d->_secondText->setTextPixelSize(13);
connect(d->_secondEdit, &ElaLineEdit::textEdited, d, &ElaColorDialogPrivate::onColorEditChanged);
QHBoxLayout* secondEditLayout = new QHBoxLayout();
QHBoxLayout *secondEditLayout = new QHBoxLayout();
secondEditLayout->setContentsMargins(0, 0, 0, 0);
secondEditLayout->addSpacing(6);
secondEditLayout->addWidget(d->_secondEdit);
@@ -140,14 +136,14 @@ ElaColorDialog::ElaColorDialog(QWidget* parent)
d->_thridText = new ElaText("蓝色", this);
d->_thridText->setTextPixelSize(13);
connect(d->_thridEdit, &ElaLineEdit::textEdited, d, &ElaColorDialogPrivate::onColorEditChanged);
QHBoxLayout* thridEditLayout = new QHBoxLayout();
QHBoxLayout *thridEditLayout = new QHBoxLayout();
thridEditLayout->setContentsMargins(0, 0, 0, 0);
thridEditLayout->addSpacing(6);
thridEditLayout->addWidget(d->_thridEdit);
thridEditLayout->addWidget(d->_thridText);
thridEditLayout->addStretch();
QVBoxLayout* paramControlLayout = new QVBoxLayout();
QVBoxLayout *paramControlLayout = new QVBoxLayout();
paramControlLayout->setContentsMargins(0, 0, 0, 0);
paramControlLayout->setSpacing(10);
paramControlLayout->addLayout(htmlEditLayout);
@@ -157,7 +153,7 @@ ElaColorDialog::ElaColorDialog(QWidget* parent)
paramControlLayout->addLayout(thridEditLayout);
paramControlLayout->addStretch();
QHBoxLayout* colorControlLayout = new QHBoxLayout();
QHBoxLayout *colorControlLayout = new QHBoxLayout();
colorControlLayout->setSpacing(0);
colorControlLayout->setContentsMargins(0, 0, 0, 0);
colorControlLayout->addLayout(colorPickerLayout);
@@ -183,9 +179,9 @@ ElaColorDialog::ElaColorDialog(QWidget* parent)
d->_initBasicColor();
connect(d->_basicColorView, &ElaBaseListView::clicked, d, &ElaColorDialogPrivate::onBasicColorViewClicked);
ElaText* basicColorViewText = new ElaText("基本颜色", this);
ElaText *basicColorViewText = new ElaText("基本颜色", this);
basicColorViewText->setTextPixelSize(14);
QVBoxLayout* basicColorLayout = new QVBoxLayout();
QVBoxLayout *basicColorLayout = new QVBoxLayout();
basicColorLayout->setContentsMargins(3, 0, 0, 0);
basicColorLayout->addWidget(basicColorViewText);
basicColorLayout->addSpacing(15);
@@ -217,9 +213,9 @@ ElaColorDialog::ElaColorDialog(QWidget* parent)
d->_removeCustomColorButton->setElaIcon(ElaIconType::Minus);
connect(d->_removeCustomColorButton, &ElaToolButton::clicked, d, &ElaColorDialogPrivate::onRemoveCustomColorButtonClicked);
ElaText* customColorViewText = new ElaText("自定义颜色", this);
ElaText *customColorViewText = new ElaText("自定义颜色", this);
customColorViewText->setTextPixelSize(14);
QHBoxLayout* customButtonLayout = new QHBoxLayout();
QHBoxLayout *customButtonLayout = new QHBoxLayout();
customButtonLayout->setContentsMargins(0, 0, 0, 0);
customButtonLayout->addWidget(customColorViewText);
customButtonLayout->addSpacing(35);
@@ -227,14 +223,14 @@ ElaColorDialog::ElaColorDialog(QWidget* parent)
customButtonLayout->addWidget(d->_removeCustomColorButton);
customButtonLayout->addStretch();
QVBoxLayout* customColorLayout = new QVBoxLayout();
QVBoxLayout *customColorLayout = new QVBoxLayout();
customColorLayout->setContentsMargins(3, 0, 0, 0);
customColorLayout->addLayout(customButtonLayout);
customColorLayout->addSpacing(5);
customColorLayout->addWidget(d->_customColorView);
customColorLayout->addStretch();
QHBoxLayout* colorDisplayLayout = new QHBoxLayout();
QHBoxLayout *colorDisplayLayout = new QHBoxLayout();
colorDisplayLayout->setContentsMargins(0, 0, 0, 0);
colorDisplayLayout->addLayout(basicColorLayout);
colorDisplayLayout->addLayout(customColorLayout);
@@ -257,15 +253,13 @@ ElaColorDialog::ElaColorDialog(QWidget* parent)
});
d->_cancelButton = new ElaPushButton("取消", this);
d->_cancelButton->setBorderRadius(6);
connect(d->_cancelButton, &ElaPushButton::clicked, this, [=]() {
close();
});
QHBoxLayout* buttonLayout = new QHBoxLayout();
connect(d->_cancelButton, &ElaPushButton::clicked, this, [=]() { close(); });
QHBoxLayout *buttonLayout = new QHBoxLayout();
buttonLayout->setContentsMargins(0, 0, 0, 0);
buttonLayout->addWidget(d->_overButton);
buttonLayout->addWidget(d->_cancelButton);
QVBoxLayout* mainLayout = new QVBoxLayout(this);
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->setContentsMargins(20, 10, 11, 20);
mainLayout->addLayout(colorPickerTextLayout);
mainLayout->addSpacing(3);
@@ -276,20 +270,16 @@ ElaColorDialog::ElaColorDialog(QWidget* parent)
mainLayout->addStretch();
d->_themeMode = eTheme->getThemeMode();
connect(eTheme, &ElaTheme::themeModeChanged, this, [=](ElaThemeType::ThemeMode themeMode) {
d->_themeMode = themeMode;
});
connect(eTheme, &ElaTheme::themeModeChanged, this, [=](ElaThemeType::ThemeMode themeMode) { d->_themeMode = themeMode; });
setCurrentColor(QColor(0x80, 0xFF, 0xEF));
}
ElaColorDialog::~ElaColorDialog()
{
ElaColorDialog::~ElaColorDialog() {
Q_D(ElaColorDialog);
delete d->_colorValueSlider->style();
}
void ElaColorDialog::setCurrentColor(QColor currentColor)
{
void ElaColorDialog::setCurrentColor(QColor currentColor) {
Q_D(ElaColorDialog);
d->_pCurrentColor = currentColor.toHsv();
d->_updateHtmlEditValue();
@@ -300,32 +290,27 @@ void ElaColorDialog::setCurrentColor(QColor currentColor)
Q_EMIT pCurrentColorChanged();
}
QColor ElaColorDialog::getCurrentColor() const
{
QColor ElaColorDialog::getCurrentColor() const {
Q_D(const ElaColorDialog);
return d->_pCurrentColor;
}
QList<QColor> ElaColorDialog::getCustomColorList() const
{
QList<QColor> ElaColorDialog::getCustomColorList() const {
Q_D(const ElaColorDialog);
return d->_customColorModel->getDisplayColorList();
}
QColor ElaColorDialog::getCustomColor(int index) const
{
QColor ElaColorDialog::getCustomColor(int index) const {
Q_D(const ElaColorDialog);
return d->_customColorModel->getDisplayColor(index);
}
QString ElaColorDialog::getCurrentColorRGB() const
{
QString ElaColorDialog::getCurrentColorRGB() const {
Q_D(const ElaColorDialog);
return d->_getHexRgbValue();
}
void ElaColorDialog::paintEvent(QPaintEvent* event)
{
void ElaColorDialog::paintEvent(QPaintEvent *event) {
Q_D(ElaColorDialog);
QPainter painter(this);
painter.save();