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

@@ -14,16 +14,14 @@
#include "private/ElaLineEditPrivate.h"
Q_PROPERTY_CREATE_Q_CPP(ElaLineEdit, int, BorderRadius)
ElaLineEdit::ElaLineEdit(QWidget* parent)
: QLineEdit(parent), d_ptr(new ElaLineEditPrivate())
{
ElaLineEdit::ElaLineEdit(QWidget *parent) : QLineEdit(parent), d_ptr(new ElaLineEditPrivate()) {
Q_D(ElaLineEdit);
d->q_ptr = this;
setObjectName("ElaLineEdit");
setFixedHeight(35);
d->_themeMode = eTheme->getThemeMode();
d->_pBorderRadius = 6;
d->_pExpandMarkWidth = 0;
d->_themeMode = eTheme->getThemeMode();
d->_pBorderRadius = 6;
d->_pExpandMarkWidth = 0;
d->_pIsClearButtonEnable = true;
setFocusPolicy(Qt::StrongFocus);
// 事件总线
@@ -40,39 +38,29 @@ ElaLineEdit::ElaLineEdit(QWidget* parent)
setVisible(true);
}
ElaLineEdit::~ElaLineEdit()
{
delete this->style();
}
ElaLineEdit::~ElaLineEdit() { delete this->style(); }
void ElaLineEdit::setIsClearButtonEnable(bool isClearButtonEnable)
{
void ElaLineEdit::setIsClearButtonEnable(bool isClearButtonEnable) {
Q_D(ElaLineEdit);
d->_pIsClearButtonEnable = isClearButtonEnable;
setClearButtonEnabled(isClearButtonEnable);
Q_EMIT pIsClearButtonEnableChanged();
}
bool ElaLineEdit::getIsClearButtonEnable() const
{
bool ElaLineEdit::getIsClearButtonEnable() const {
Q_D(const ElaLineEdit);
return d->_pIsClearButtonEnable;
}
void ElaLineEdit::focusInEvent(QFocusEvent* event)
{
void ElaLineEdit::focusInEvent(QFocusEvent *event) {
Q_D(ElaLineEdit);
Q_EMIT focusIn(this->text());
if (event->reason() == Qt::MouseFocusReason)
{
if (d->_pIsClearButtonEnable)
{
if (event->reason() == Qt::MouseFocusReason) {
if (d->_pIsClearButtonEnable) {
setClearButtonEnabled(true);
}
QPropertyAnimation* markAnimation = new QPropertyAnimation(d, "pExpandMarkWidth");
connect(markAnimation, &QPropertyAnimation::valueChanged, this, [=](const QVariant& value) {
update();
});
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);
@@ -82,20 +70,15 @@ void ElaLineEdit::focusInEvent(QFocusEvent* event)
QLineEdit::focusInEvent(event);
}
void ElaLineEdit::focusOutEvent(QFocusEvent* event)
{
void ElaLineEdit::focusOutEvent(QFocusEvent *event) {
Q_D(ElaLineEdit);
Q_EMIT focusOut(this->text());
if (event->reason() != Qt::PopupFocusReason)
{
if (d->_pIsClearButtonEnable)
{
if (event->reason() != Qt::PopupFocusReason) {
if (d->_pIsClearButtonEnable) {
setClearButtonEnabled(false);
}
QPropertyAnimation* markAnimation = new QPropertyAnimation(d, "pExpandMarkWidth");
connect(markAnimation, &QPropertyAnimation::valueChanged, this, [=](const QVariant& value) {
update();
});
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);
@@ -106,11 +89,9 @@ void ElaLineEdit::focusOutEvent(QFocusEvent* event)
QLineEdit::focusOutEvent(event);
}
void ElaLineEdit::paintEvent(QPaintEvent* event)
{
void ElaLineEdit::paintEvent(QPaintEvent *event) {
Q_D(ElaLineEdit);
if (palette().color(QPalette::Text) != ElaThemeColor(d->_themeMode, BasicText))
{
if (palette().color(QPalette::Text) != ElaThemeColor(d->_themeMode, BasicText)) {
d->onThemeChanged(d->_themeMode);
}
QLineEdit::paintEvent(event);
@@ -123,14 +104,12 @@ void ElaLineEdit::paintEvent(QPaintEvent* event)
painter.restore();
}
void ElaLineEdit::contextMenuEvent(QContextMenuEvent* event)
{
ElaMenu* menu = new ElaMenu(this);
void ElaLineEdit::contextMenuEvent(QContextMenuEvent *event) {
ElaMenu *menu = new ElaMenu(this);
menu->setMenuItemHeight(27);
menu->setAttribute(Qt::WA_DeleteOnClose);
QAction* action = nullptr;
if (!isReadOnly())
{
QAction *action = nullptr;
if (!isReadOnly()) {
action = menu->addElaIconAction(ElaIconType::ArrowRotateLeft, tr("撤销"), QKeySequence::Undo);
action->setEnabled(isUndoAvailable());
connect(action, &QAction::triggered, this, &ElaLineEdit::undo);
@@ -141,8 +120,7 @@ void ElaLineEdit::contextMenuEvent(QContextMenuEvent* event)
menu->addSeparator();
}
#ifndef QT_NO_CLIPBOARD
if (!isReadOnly())
{
if (!isReadOnly()) {
action = menu->addElaIconAction(ElaIconType::KnifeKitchen, tr("剪切"), QKeySequence::Cut);
action->setEnabled(!isReadOnly() && hasSelectedText() && echoMode() == QLineEdit::Normal);
connect(action, &QAction::triggered, this, &ElaLineEdit::cut);
@@ -152,28 +130,24 @@ void ElaLineEdit::contextMenuEvent(QContextMenuEvent* event)
action->setEnabled(hasSelectedText() && echoMode() == QLineEdit::Normal);
connect(action, &QAction::triggered, this, &ElaLineEdit::copy);
if (!isReadOnly())
{
if (!isReadOnly()) {
action = menu->addElaIconAction(ElaIconType::Paste, tr("粘贴"), QKeySequence::Paste);
action->setEnabled(!isReadOnly() && !QGuiApplication::clipboard()->text().isEmpty());
connect(action, &QAction::triggered, this, &ElaLineEdit::paste);
}
#endif
if (!isReadOnly())
{
if (!isReadOnly()) {
action = menu->addElaIconAction(ElaIconType::DeleteLeft, tr("删除"));
action->setEnabled(!isReadOnly() && !text().isEmpty() && hasSelectedText());
connect(action, &QAction::triggered, this, [=](bool checked) {
if (hasSelectedText())
{
if (hasSelectedText()) {
int startIndex = selectionStart();
int endIndex = selectionEnd();
int endIndex = selectionEnd();
setText(text().remove(startIndex, endIndex - startIndex));
}
});
}
if (!menu->isEmpty())
{
if (!menu->isEmpty()) {
menu->addSeparator();
}
action = menu->addAction(tr("全选"));