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

@@ -6,14 +6,12 @@
#include "ElaPivotStyle.h"
#include "ElaScrollBar.h"
ElaPivotView::ElaPivotView(QWidget* parent)
: QListView(parent)
{
_pMarkX = 0;
_pMarkWidth = 40;
_pMarkAnimationWidth = 0;
_pCurrentIndex = QModelIndex();
_pCurrentIndexRect = QRect();
ElaPivotView::ElaPivotView(QWidget *parent) : QListView(parent) {
_pMarkX = 0;
_pMarkWidth = 40;
_pMarkAnimationWidth = 0;
_pCurrentIndex = QModelIndex();
_pCurrentIndexRect = QRect();
_pIsAnimationFinished = true;
setObjectName("ElaPivotView");
setStyleSheet("#ElaPivotView{background-color:transparent;}");
@@ -24,37 +22,28 @@ ElaPivotView::ElaPivotView(QWidget* parent)
setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
}
ElaPivotView::~ElaPivotView()
{
}
ElaPivotView::~ElaPivotView() {}
void ElaPivotView::doCurrentIndexChangedAnimation(const QModelIndex& index)
{
void ElaPivotView::doCurrentIndexChangedAnimation(const QModelIndex &index) {
int xOffset = visualRect(_pCurrentIndex).x() - _pCurrentIndexRect.x();
if (index.row() >= 0)
{
_pCurrentIndexRect = visualRect(index);
QPropertyAnimation* markAnimation = new QPropertyAnimation(this, "pMarkX");
connect(markAnimation, &QPropertyAnimation::valueChanged, this, [=]() {
update();
});
if (index.row() >= 0) {
_pCurrentIndexRect = visualRect(index);
QPropertyAnimation *markAnimation = new QPropertyAnimation(this, "pMarkX");
connect(markAnimation, &QPropertyAnimation::valueChanged, this, [=]() { update(); });
connect(markAnimation, &QPropertyAnimation::finished, this, [=]() {
_pIsAnimationFinished = true;
update();
});
markAnimation->setDuration(300);
markAnimation->setEasingCurve(QEasingCurve::InOutSine);
if (_pPivotStyle->getCurrentIndex() >= 0)
{
if (_pPivotStyle->getCurrentIndex() >= 0) {
markAnimation->setStartValue(_pMarkX + xOffset);
markAnimation->setEndValue(_pCurrentIndexRect.center().x() - _pMarkWidth / 2);
}
else
{
} else {
markAnimation->setStartValue(_pCurrentIndexRect.center().x());
markAnimation->setEndValue(_pCurrentIndexRect.center().x() - _pMarkWidth / 2);
QPropertyAnimation* markWidthAnimation = new QPropertyAnimation(this, "pMarkAnimationWidth");
QPropertyAnimation *markWidthAnimation = new QPropertyAnimation(this, "pMarkAnimationWidth");
markWidthAnimation->setDuration(300);
markWidthAnimation->setEasingCurve(QEasingCurve::InOutSine);
markWidthAnimation->setStartValue(0);
@@ -62,14 +51,10 @@ void ElaPivotView::doCurrentIndexChangedAnimation(const QModelIndex& index)
markWidthAnimation->start(QAbstractAnimation::DeleteWhenStopped);
}
markAnimation->start(QAbstractAnimation::DeleteWhenStopped);
}
else
{
_pCurrentIndexRect = visualRect(model()->index(_pPivotStyle->getCurrentIndex(), 0));
QPropertyAnimation* markAnimation = new QPropertyAnimation(this, "pMarkX");
connect(markAnimation, &QPropertyAnimation::valueChanged, this, [=]() {
update();
});
} else {
_pCurrentIndexRect = visualRect(model()->index(_pPivotStyle->getCurrentIndex(), 0));
QPropertyAnimation *markAnimation = new QPropertyAnimation(this, "pMarkX");
connect(markAnimation, &QPropertyAnimation::valueChanged, this, [=]() { update(); });
connect(markAnimation, &QPropertyAnimation::finished, this, [=]() {
_pIsAnimationFinished = true;
update();
@@ -80,56 +65,48 @@ void ElaPivotView::doCurrentIndexChangedAnimation(const QModelIndex& index)
markAnimation->setEndValue(_pCurrentIndexRect.center().x());
markAnimation->start(QAbstractAnimation::DeleteWhenStopped);
QPropertyAnimation* markWidthAnimation = new QPropertyAnimation(this, "pMarkAnimationWidth");
QPropertyAnimation *markWidthAnimation = new QPropertyAnimation(this, "pMarkAnimationWidth");
markWidthAnimation->setDuration(300);
markWidthAnimation->setEasingCurve(QEasingCurve::InOutSine);
markWidthAnimation->setStartValue(_pMarkAnimationWidth);
markWidthAnimation->setEndValue(0);
markWidthAnimation->start(QAbstractAnimation::DeleteWhenStopped);
}
_pCurrentIndex = index;
_pCurrentIndex = index;
_pIsAnimationFinished = false;
setCurrentIndex(index);
}
void ElaPivotView::mouseDoubleClickEvent(QMouseEvent* event)
{
void ElaPivotView::mouseDoubleClickEvent(QMouseEvent *event) {
_pPivotStyle->setPressIndex(indexAt(event->pos()));
viewport()->update();
QListView::mouseDoubleClickEvent(event);
}
void ElaPivotView::mouseReleaseEvent(QMouseEvent* event)
{
if (event->button() == Qt::LeftButton)
{
void ElaPivotView::mouseReleaseEvent(QMouseEvent *event) {
if (event->button() == Qt::LeftButton) {
_pPivotStyle->setPressIndex(QModelIndex());
viewport()->update();
}
QListView::mouseReleaseEvent(event);
}
void ElaPivotView::wheelEvent(QWheelEvent* event)
{
void ElaPivotView::wheelEvent(QWheelEvent *event) {
QListView::wheelEvent(event);
event->accept();
}
void ElaPivotView::paintEvent(QPaintEvent* event)
{
void ElaPivotView::paintEvent(QPaintEvent *event) {
QPainter painter(viewport());
QRect viewPortRect = viewport()->rect();
QRect viewPortRect = viewport()->rect();
painter.save();
painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(Qt::NoPen);
painter.setBrush(_pPivotStyle->getMarkColor());
QRect currentIndexRect = visualRect(_pCurrentIndex);
if (_pIsAnimationFinished)
{
if (_pIsAnimationFinished) {
painter.drawRoundedRect(QRect(currentIndexRect.center().x() - _pMarkWidth / 2, viewPortRect.bottom() - 4, _pMarkAnimationWidth, 3), 3, 3);
}
else
{
} else {
int xOffset = currentIndexRect.x() - _pCurrentIndexRect.x();
painter.drawRoundedRect(QRect(_pMarkX + xOffset, viewPortRect.bottom() - 4, _pMarkAnimationWidth, 3), 3, 3);
}