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

@@ -4,11 +4,9 @@
#include <QMouseEvent>
#include <QPainter>
#include <QPropertyAnimation>
ElaDrawerHeader::ElaDrawerHeader(QWidget* parent)
: QWidget(parent)
{
_pBorderRadius = 6;
_pIsExpand = false;
ElaDrawerHeader::ElaDrawerHeader(QWidget *parent) : QWidget(parent) {
_pBorderRadius = 6;
_pIsExpand = false;
_pExpandIconRotate = 0;
setFixedHeight(75);
setMouseTracking(true);
@@ -20,23 +18,16 @@ ElaDrawerHeader::ElaDrawerHeader(QWidget* parent)
setContentsMargins(0, 0, 30, 0);
_themeMode = eTheme->getThemeMode();
connect(eTheme, &ElaTheme::themeModeChanged, this, [=](ElaThemeType::ThemeMode themeMode) {
_themeMode = themeMode;
});
connect(eTheme, &ElaTheme::themeModeChanged, this, [=](ElaThemeType::ThemeMode themeMode) { _themeMode = themeMode; });
}
ElaDrawerHeader::~ElaDrawerHeader()
{
}
ElaDrawerHeader::~ElaDrawerHeader() {}
void ElaDrawerHeader::setHeaderWidget(QWidget* widget)
{
if (!widget)
{
void ElaDrawerHeader::setHeaderWidget(QWidget *widget) {
if (!widget) {
return;
}
if (_headerWidget)
{
if (_headerWidget) {
_mainLayout->removeWidget(_headerWidget);
_headerWidget->deleteLater();
}
@@ -44,12 +35,9 @@ void ElaDrawerHeader::setHeaderWidget(QWidget* widget)
_headerWidget = widget;
}
void ElaDrawerHeader::doExpandOrCollpaseAnimation()
{
QPropertyAnimation* rotateAnimation = new QPropertyAnimation(this, "pExpandIconRotate");
connect(rotateAnimation, &QPropertyAnimation::valueChanged, this, [=](const QVariant& value) {
update();
});
void ElaDrawerHeader::doExpandOrCollpaseAnimation() {
QPropertyAnimation *rotateAnimation = new QPropertyAnimation(this, "pExpandIconRotate");
connect(rotateAnimation, &QPropertyAnimation::valueChanged, this, [=](const QVariant &value) { update(); });
rotateAnimation->setDuration(300);
rotateAnimation->setEasingCurve(QEasingCurve::InOutSine);
rotateAnimation->setStartValue(_pExpandIconRotate);
@@ -57,80 +45,68 @@ void ElaDrawerHeader::doExpandOrCollpaseAnimation()
rotateAnimation->start(QAbstractAnimation::DeleteWhenStopped);
}
bool ElaDrawerHeader::event(QEvent* event)
{
switch (event->type())
{
bool ElaDrawerHeader::event(QEvent *event) {
switch (event->type()) {
case QEvent::Enter:
case QEvent::Leave:
{
case QEvent::Leave: {
update();
break;
}
default:
{
default: {
break;
}
}
return QWidget::event(event);
}
void ElaDrawerHeader::mousePressEvent(QMouseEvent* event)
{
QWidget* posWidget = childAt(event->pos());
if (!posWidget || (posWidget && posWidget->objectName().isEmpty()))
{
void ElaDrawerHeader::mousePressEvent(QMouseEvent *event) {
QWidget *posWidget = childAt(event->pos());
if (!posWidget || (posWidget && posWidget->objectName().isEmpty())) {
_isPressed = true;
update();
}
QWidget::mousePressEvent(event);
}
void ElaDrawerHeader::mouseReleaseEvent(QMouseEvent* event)
{
QWidget* posWidget = childAt(event->pos());
if (!posWidget || (posWidget && posWidget->objectName().isEmpty()))
{
void ElaDrawerHeader::mouseReleaseEvent(QMouseEvent *event) {
QWidget *posWidget = childAt(event->pos());
if (!posWidget || (posWidget && posWidget->objectName().isEmpty())) {
_isPressed = false;
_pIsExpand = !_pIsExpand;
//指示器动画
// 指示器动画
doExpandOrCollpaseAnimation();
Q_EMIT drawerHeaderClicked(_pIsExpand);
}
QWidget::mouseReleaseEvent(event);
}
void ElaDrawerHeader::mouseMoveEvent(QMouseEvent* event)
{
void ElaDrawerHeader::mouseMoveEvent(QMouseEvent *event) {
update();
QWidget::mouseMoveEvent(event);
}
void ElaDrawerHeader::paintEvent(QPaintEvent* event)
{
bool isUnderMouse = underMouse();
void ElaDrawerHeader::paintEvent(QPaintEvent *event) {
bool isUnderMouse = underMouse();
QPainter painter(this);
painter.save();
painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(ElaThemeColor(_themeMode, BasicBorder));
painter.setBrush(_isPressed ? ElaThemeColor(_themeMode, BasicSelectedAlpha) : isUnderMouse ? ElaThemeColor(_themeMode, BasicPressAlpha)
: ElaThemeColor(_themeMode, BasicBaseAlpha));
painter.setBrush(_isPressed ? ElaThemeColor(_themeMode, BasicSelectedAlpha)
: isUnderMouse ? ElaThemeColor(_themeMode, BasicPressAlpha)
: ElaThemeColor(_themeMode, BasicBaseAlpha));
QRect foregroundRect(1, 1, width() - 2, _pIsExpand ? height() + _pBorderRadius : height() - 2);
painter.drawRoundedRect(foregroundRect, _pBorderRadius, _pBorderRadius);
// 底边线绘制
if (isUnderMouse)
{
if (isUnderMouse) {
painter.setPen(ElaThemeColor(_themeMode, BasicBorderDeep));
}
if (_pIsExpand)
{
if (_pIsExpand) {
painter.drawLine(0, height() - 1, width(), height() - 1);
}
else
{
} else {
painter.drawLine(_pBorderRadius, height() - 1, width() - _pBorderRadius, height() - 1);
painter.drawArc(QRectF(1, height() - 1 - 2 * _pBorderRadius, 2 * _pBorderRadius, 2 * _pBorderRadius), 240 * 16, 30 * 16);
painter.drawArc(QRectF(width() - 2 * _pBorderRadius, height() - 1 - 2 * _pBorderRadius, 2 * _pBorderRadius, 2 * _pBorderRadius), -90 * 16, 30 * 16);
painter.drawArc(QRectF(width() - 2 * _pBorderRadius, height() - 1 - 2 * _pBorderRadius, 2 * _pBorderRadius, 2 * _pBorderRadius), -90 * 16,
30 * 16);
}
// 展开图标绘制