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

@@ -12,9 +12,7 @@
#include "ElaPlainTextEditStyle.h"
#include "ElaScrollBar.h"
#include "ElaTheme.h"
ElaPlainTextEdit::ElaPlainTextEdit(QWidget* parent)
: QPlainTextEdit(parent), d_ptr(new ElaPlainTextEditPrivate())
{
ElaPlainTextEdit::ElaPlainTextEdit(QWidget *parent) : QPlainTextEdit(parent), d_ptr(new ElaPlainTextEditPrivate()) {
Q_D(ElaPlainTextEdit);
d->q_ptr = this;
setObjectName("ElaPlainTextEdit");
@@ -32,27 +30,18 @@ ElaPlainTextEdit::ElaPlainTextEdit(QWidget* parent)
connect(eTheme, &ElaTheme::themeModeChanged, d, &ElaPlainTextEditPrivate::onThemeChanged);
}
ElaPlainTextEdit::ElaPlainTextEdit(const QString& text, QWidget* parent)
: ElaPlainTextEdit(parent)
{
setPlainText(text);
}
ElaPlainTextEdit::ElaPlainTextEdit(const QString &text, QWidget *parent) : ElaPlainTextEdit(parent) { setPlainText(text); }
ElaPlainTextEdit::~ElaPlainTextEdit()
{
ElaPlainTextEdit::~ElaPlainTextEdit() {
Q_D(ElaPlainTextEdit);
delete d->_style;
}
void ElaPlainTextEdit::focusInEvent(QFocusEvent* event)
{
void ElaPlainTextEdit::focusInEvent(QFocusEvent *event) {
Q_D(ElaPlainTextEdit);
if (event->reason() == Qt::MouseFocusReason)
{
QPropertyAnimation* markAnimation = new QPropertyAnimation(d->_style, "pExpandMarkWidth");
connect(markAnimation, &QPropertyAnimation::valueChanged, this, [=](const QVariant& value) {
update();
});
if (event->reason() == Qt::MouseFocusReason) {
QPropertyAnimation *markAnimation = new QPropertyAnimation(d->_style, "pExpandMarkWidth");
connect(markAnimation, &QPropertyAnimation::valueChanged, this, [=](const QVariant &value) { update(); });
markAnimation->setDuration(300);
markAnimation->setEasingCurve(QEasingCurve::InOutSine);
markAnimation->setStartValue(d->_style->getExpandMarkWidth());
@@ -62,15 +51,11 @@ void ElaPlainTextEdit::focusInEvent(QFocusEvent* event)
QPlainTextEdit::focusInEvent(event);
}
void ElaPlainTextEdit::focusOutEvent(QFocusEvent* event)
{
void ElaPlainTextEdit::focusOutEvent(QFocusEvent *event) {
Q_D(ElaPlainTextEdit);
if (event->reason() != Qt::PopupFocusReason)
{
QPropertyAnimation* markAnimation = new QPropertyAnimation(d->_style, "pExpandMarkWidth");
connect(markAnimation, &QPropertyAnimation::valueChanged, this, [=](const QVariant& value) {
update();
});
if (event->reason() != Qt::PopupFocusReason) {
QPropertyAnimation *markAnimation = new QPropertyAnimation(d->_style, "pExpandMarkWidth");
connect(markAnimation, &QPropertyAnimation::valueChanged, this, [=](const QVariant &value) { update(); });
markAnimation->setDuration(300);
markAnimation->setEasingCurve(QEasingCurve::InOutSine);
markAnimation->setStartValue(d->_style->getExpandMarkWidth());
@@ -80,14 +65,12 @@ void ElaPlainTextEdit::focusOutEvent(QFocusEvent* event)
QPlainTextEdit::focusOutEvent(event);
}
void ElaPlainTextEdit::contextMenuEvent(QContextMenuEvent* event)
{
ElaMenu* menu = new ElaMenu(this);
void ElaPlainTextEdit::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, "撤销", QKeySequence::Undo);
action->setEnabled(isUndoRedoEnabled() ? document()->isUndoAvailable() : false);
connect(action, &QAction::triggered, this, &ElaPlainTextEdit::undo);
@@ -98,8 +81,7 @@ void ElaPlainTextEdit::contextMenuEvent(QContextMenuEvent* event)
menu->addSeparator();
}
#ifndef QT_NO_CLIPBOARD
if (!isReadOnly())
{
if (!isReadOnly()) {
action = menu->addElaIconAction(ElaIconType::KnifeKitchen, "剪切", QKeySequence::Cut);
action->setEnabled(!isReadOnly() && !textCursor().selectedText().isEmpty());
connect(action, &QAction::triggered, this, &ElaPlainTextEdit::cut);
@@ -109,26 +91,22 @@ void ElaPlainTextEdit::contextMenuEvent(QContextMenuEvent* event)
action->setEnabled(!textCursor().selectedText().isEmpty());
connect(action, &QAction::triggered, this, &ElaPlainTextEdit::copy);
if (!isReadOnly())
{
if (!isReadOnly()) {
action = menu->addElaIconAction(ElaIconType::Paste, "粘贴", QKeySequence::Paste);
action->setEnabled(!isReadOnly() && !QGuiApplication::clipboard()->text().isEmpty());
connect(action, &QAction::triggered, this, &ElaPlainTextEdit::paste);
}
#endif
if (!isReadOnly())
{
if (!isReadOnly()) {
action = menu->addElaIconAction(ElaIconType::DeleteLeft, "删除");
action->setEnabled(!isReadOnly() && !toPlainText().isEmpty() && !textCursor().selectedText().isEmpty());
connect(action, &QAction::triggered, this, [=](bool checked) {
if (!textCursor().selectedText().isEmpty())
{
if (!textCursor().selectedText().isEmpty()) {
textCursor().deleteChar();
}
});
}
if (!menu->isEmpty())
{
if (!menu->isEmpty()) {
menu->addSeparator();
}
action = menu->addAction("全选");
@@ -139,11 +117,9 @@ void ElaPlainTextEdit::contextMenuEvent(QContextMenuEvent* event)
this->setFocus();
}
void ElaPlainTextEdit::paintEvent(QPaintEvent* event)
{
void ElaPlainTextEdit::paintEvent(QPaintEvent *event) {
Q_D(ElaPlainTextEdit);
if (palette().color(QPalette::Text) != ElaThemeColor(d->_themeMode, BasicText))
{
if (palette().color(QPalette::Text) != ElaThemeColor(d->_themeMode, BasicText)) {
d->onThemeChanged(d->_themeMode);
}
QPlainTextEdit::paintEvent(event);