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

@@ -8,11 +8,9 @@
#include "ElaPivotPrivate.h"
#include "ElaPivotStyle.h"
#include "ElaPivotView.h"
ElaPivot::ElaPivot(QWidget* parent)
: QWidget{parent}, d_ptr(new ElaPivotPrivate())
{
ElaPivot::ElaPivot(QWidget *parent) : QWidget{parent}, d_ptr(new ElaPivotPrivate()) {
Q_D(ElaPivot);
d->q_ptr = this;
d->q_ptr = this;
d->_pTextPixelSize = 20;
setFixedHeight(40);
setObjectName("ElaPivot");
@@ -36,7 +34,7 @@ ElaPivot::ElaPivot(QWidget* parent)
d->_listView->setFont(textFont);
QScroller::grabGesture(d->_listView->viewport(), QScroller::LeftMouseButtonGesture);
QScroller* scroller = QScroller::scroller(d->_listView->viewport());
QScroller *scroller = QScroller::scroller(d->_listView->viewport());
QScrollerProperties properties = scroller->scrollerProperties();
properties.setScrollMetric(QScrollerProperties::MousePressEventDelay, 0);
properties.setScrollMetric(QScrollerProperties::HorizontalOvershootPolicy, QScrollerProperties::OvershootAlwaysOn);
@@ -46,61 +44,50 @@ ElaPivot::ElaPivot(QWidget* parent)
scroller->setScrollerProperties(properties);
connect(scroller, &QScroller::stateChanged, this, [=](QScroller::State newstate) {
if (newstate == QScroller::Pressed)
{
if (newstate == QScroller::Pressed) {
d->_listStyle->setPressIndex(d->_listView->indexAt(d->_listView->mapFromGlobal(QCursor::pos())));
d->_listView->viewport()->update();
}
else if (newstate == QScroller::Scrolling || newstate == QScroller::Inactive)
{
} else if (newstate == QScroller::Scrolling || newstate == QScroller::Inactive) {
d->_listStyle->setPressIndex(QModelIndex());
d->_listView->viewport()->update();
}
});
connect(d->_listView, &ElaPivotView::clicked, this, [=](const QModelIndex& index) {
if (index.row() != d->_listStyle->getCurrentIndex())
{
connect(d->_listView, &ElaPivotView::clicked, this, [=](const QModelIndex &index) {
if (index.row() != d->_listStyle->getCurrentIndex()) {
Q_EMIT pCurrentIndexChanged();
}
d->_listView->doCurrentIndexChangedAnimation(index);
d->_listStyle->setCurrentIndex(index.row());
Q_EMIT pivotClicked(index.row());
});
connect(d->_listView, &ElaPivotView::doubleClicked, this, [=](const QModelIndex& index) {
Q_EMIT pivotDoubleClicked(index.row());
});
QVBoxLayout* mainLayout = new QVBoxLayout(this);
connect(d->_listView, &ElaPivotView::doubleClicked, this, [=](const QModelIndex &index) { Q_EMIT pivotDoubleClicked(index.row()); });
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->setContentsMargins(0, 0, 0, 0);
mainLayout->addWidget(d->_listView);
}
ElaPivot::~ElaPivot()
{
ElaPivot::~ElaPivot() {
Q_D(ElaPivot);
delete d->_listStyle;
}
void ElaPivot::appendPivot(QString pivotTitle)
{
void ElaPivot::appendPivot(QString pivotTitle) {
Q_D(ElaPivot);
d->_listModel->appendPivot(pivotTitle);
d->_checkCurrentIndex();
}
void ElaPivot::removePivot(QString pivotTitle)
{
void ElaPivot::removePivot(QString pivotTitle) {
Q_D(ElaPivot);
d->_listModel->removePivot(pivotTitle);
d->_checkCurrentIndex();
}
void ElaPivot::setTextPixelSize(int textPixelSize)
{
void ElaPivot::setTextPixelSize(int textPixelSize) {
Q_D(ElaPivot);
if (textPixelSize > 0)
{
if (textPixelSize > 0) {
d->_pTextPixelSize = textPixelSize;
QFont textFont = this->font();
QFont textFont = this->font();
textFont.setLetterSpacing(QFont::AbsoluteSpacing, 0.5);
textFont.setPixelSize(d->_pTextPixelSize);
d->_listView->setFont(textFont);
@@ -108,63 +95,52 @@ void ElaPivot::setTextPixelSize(int textPixelSize)
}
}
int ElaPivot::getTextPixelSize() const
{
int ElaPivot::getTextPixelSize() const {
Q_D(const ElaPivot);
return d->_pTextPixelSize;
}
void ElaPivot::setCurrentIndex(int currentIndex)
{
void ElaPivot::setCurrentIndex(int currentIndex) {
Q_D(ElaPivot);
if (currentIndex < d->_listModel->getPivotListCount())
{
if (currentIndex < d->_listModel->getPivotListCount()) {
QModelIndex index = d->_listModel->index(currentIndex, 0);
d->_listView->doCurrentIndexChangedAnimation(index);
if (index.row() != d->_listStyle->getCurrentIndex())
{
if (index.row() != d->_listStyle->getCurrentIndex()) {
Q_EMIT pCurrentIndexChanged();
}
d->_listStyle->setCurrentIndex(currentIndex);
}
}
int ElaPivot::getCurrentIndex() const
{
int ElaPivot::getCurrentIndex() const {
Q_D(const ElaPivot);
return d->_listView->currentIndex().row();
}
void ElaPivot::setPivotSpacing(int pivotSpacing)
{
void ElaPivot::setPivotSpacing(int pivotSpacing) {
Q_D(ElaPivot);
if (pivotSpacing >= 0)
{
if (pivotSpacing >= 0) {
d->_listStyle->setPivotSpacing(pivotSpacing);
d->_listView->doItemsLayout();
Q_EMIT pPivotSpacingChanged();
}
}
int ElaPivot::getPivotSpacing() const
{
int ElaPivot::getPivotSpacing() const {
Q_D(const ElaPivot);
return d->_listStyle->getPivotSpacing();
}
void ElaPivot::setMarkWidth(int markWidth)
{
void ElaPivot::setMarkWidth(int markWidth) {
Q_D(ElaPivot);
if (markWidth >= 0)
{
if (markWidth >= 0) {
d->_listView->setMarkWidth(markWidth);
d->_listView->viewport()->update();
Q_EMIT pMarkWidthChanged();
}
}
int ElaPivot::getMarkWidth() const
{
int ElaPivot::getMarkWidth() const {
Q_D(const ElaPivot);
return d->_listView->getMarkWidth();
}