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

@@ -9,11 +9,9 @@
#include <QLineEdit>
#include <QPainter>
#include <QPropertyAnimation>
ElaDoubleSpinBox::ElaDoubleSpinBox(QWidget* parent)
: QDoubleSpinBox(parent), d_ptr(new ElaDoubleSpinBoxPrivate())
{
ElaDoubleSpinBox::ElaDoubleSpinBox(QWidget *parent) : QDoubleSpinBox(parent), d_ptr(new ElaDoubleSpinBoxPrivate()) {
Q_D(ElaDoubleSpinBox);
d->q_ptr = this;
d->q_ptr = this;
d->_pExpandMarkWidth = 0;
setFixedSize(115, 35);
d->_style = new ElaSpinBoxStyle(style());
@@ -24,32 +22,26 @@ ElaDoubleSpinBox::ElaDoubleSpinBox(QWidget* parent)
connect(eTheme, &ElaTheme::themeModeChanged, d, &ElaDoubleSpinBoxPrivate::onThemeChanged);
}
ElaDoubleSpinBox::~ElaDoubleSpinBox()
{
ElaDoubleSpinBox::~ElaDoubleSpinBox() {
Q_D(ElaDoubleSpinBox);
delete d->_style;
}
void ElaDoubleSpinBox::setButtonMode(ElaSpinBoxType::ButtonMode buttonMode)
{
void ElaDoubleSpinBox::setButtonMode(ElaSpinBoxType::ButtonMode buttonMode) {
Q_D(ElaDoubleSpinBox);
if (minimumWidth() < 90)
{
if (minimumWidth() < 90) {
setMinimumWidth(90);
}
d->_style->setButtonMode(buttonMode);
switch (buttonMode)
{
case ElaSpinBoxType::Inline:
{
switch (buttonMode) {
case ElaSpinBoxType::Inline: {
lineEdit()->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
lineEdit()->setStyleSheet("background-color:transparent;padding-left:10px;padding-bottom:3px;");
break;
}
case ElaSpinBoxType::Compact:
case ElaSpinBoxType::Side:
case ElaSpinBoxType::PMSide:
{
case ElaSpinBoxType::PMSide: {
lineEdit()->setAlignment(Qt::AlignCenter);
lineEdit()->setStyleSheet("background-color:transparent;padding-bottom:3px;");
break;
@@ -60,21 +52,16 @@ void ElaDoubleSpinBox::setButtonMode(ElaSpinBoxType::ButtonMode buttonMode)
Q_EMIT pButtonModeChanged();
}
ElaSpinBoxType::ButtonMode ElaDoubleSpinBox::getButtonMode() const
{
ElaSpinBoxType::ButtonMode ElaDoubleSpinBox::getButtonMode() const {
Q_D(const ElaDoubleSpinBox);
return d->_style->getButtonMode();
}
void ElaDoubleSpinBox::focusInEvent(QFocusEvent* event)
{
void ElaDoubleSpinBox::focusInEvent(QFocusEvent *event) {
Q_D(ElaDoubleSpinBox);
if (event->reason() == Qt::MouseFocusReason)
{
QPropertyAnimation* markAnimation = new QPropertyAnimation(d, "pExpandMarkWidth");
connect(markAnimation, &QPropertyAnimation::valueChanged, this, [=](const QVariant& value) {
update();
});
if (event->reason() == Qt::MouseFocusReason) {
QPropertyAnimation *markAnimation = new QPropertyAnimation(d, "pExpandMarkWidth");
connect(markAnimation, &QPropertyAnimation::valueChanged, this, [=](const QVariant &value) { update(); });
markAnimation->setDuration(300);
markAnimation->setEasingCurve(QEasingCurve::InOutSine);
markAnimation->setStartValue(d->_pExpandMarkWidth);
@@ -84,15 +71,11 @@ void ElaDoubleSpinBox::focusInEvent(QFocusEvent* event)
QDoubleSpinBox::focusInEvent(event);
}
void ElaDoubleSpinBox::focusOutEvent(QFocusEvent* event)
{
void ElaDoubleSpinBox::focusOutEvent(QFocusEvent *event) {
Q_D(ElaDoubleSpinBox);
if (event->reason() != Qt::PopupFocusReason)
{
QPropertyAnimation* markAnimation = new QPropertyAnimation(d, "pExpandMarkWidth");
connect(markAnimation, &QPropertyAnimation::valueChanged, this, [=](const QVariant& value) {
update();
});
if (event->reason() != Qt::PopupFocusReason) {
QPropertyAnimation *markAnimation = new QPropertyAnimation(d, "pExpandMarkWidth");
connect(markAnimation, &QPropertyAnimation::valueChanged, this, [=](const QVariant &value) { update(); });
markAnimation->setDuration(300);
markAnimation->setEasingCurve(QEasingCurve::InOutSine);
markAnimation->setStartValue(d->_pExpandMarkWidth);
@@ -102,8 +85,7 @@ void ElaDoubleSpinBox::focusOutEvent(QFocusEvent* event)
QDoubleSpinBox::focusOutEvent(event);
}
void ElaDoubleSpinBox::paintEvent(QPaintEvent* event)
{
void ElaDoubleSpinBox::paintEvent(QPaintEvent *event) {
Q_D(ElaDoubleSpinBox);
QDoubleSpinBox::paintEvent(event);
QPainter painter(this);
@@ -115,36 +97,29 @@ void ElaDoubleSpinBox::paintEvent(QPaintEvent* event)
painter.restore();
}
void ElaDoubleSpinBox::contextMenuEvent(QContextMenuEvent* event)
{
void ElaDoubleSpinBox::contextMenuEvent(QContextMenuEvent *event) {
Q_D(ElaDoubleSpinBox);
ElaMenu* menu = d->_createStandardContextMenu();
if (!menu)
{
ElaMenu *menu = d->_createStandardContextMenu();
if (!menu) {
return;
}
menu->addSeparator();
const uint se = stepEnabled();
QAction* up = menu->addElaIconAction(ElaIconType::Plus, tr("增加"));
QAction *up = menu->addElaIconAction(ElaIconType::Plus, tr("增加"));
up->setEnabled(se & StepUpEnabled);
QAction* down = menu->addElaIconAction(ElaIconType::Minus, tr("减少"));
QAction *down = menu->addElaIconAction(ElaIconType::Minus, tr("减少"));
down->setEnabled(se & StepDownEnabled);
menu->addSeparator();
const QAbstractSpinBox* that = this;
const QPoint pos = (event->reason() == QContextMenuEvent::Mouse)
? event->globalPos()
: mapToGlobal(QPoint(event->pos().x(), 0)) + QPoint(width() / 2, height() / 2);
const QAction* action = menu->exec(pos);
const QAbstractSpinBox *that = this;
const QPoint pos = (event->reason() == QContextMenuEvent::Mouse) ? event->globalPos()
: mapToGlobal(QPoint(event->pos().x(), 0)) + QPoint(width() / 2, height() / 2);
const QAction *action = menu->exec(pos);
delete menu;
if (that && action)
{
if (action == up)
{
if (that && action) {
if (action == up) {
stepBy(1);
}
else if (action == down)
{
} else if (action == down) {
stepBy(-1);
}
}