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

@@ -9,27 +9,20 @@
#include "ElaCalendarDelegate.h"
#include "ElaCalendarModel.h"
#include "ElaToolButton.h"
ElaCalendarPrivate::ElaCalendarPrivate(QObject* parent)
: QObject{parent}
{
_pZoomRatio = 1;
ElaCalendarPrivate::ElaCalendarPrivate(QObject *parent) : QObject{parent} {
_pZoomRatio = 1;
_pPixOpacity = 1;
}
ElaCalendarPrivate::~ElaCalendarPrivate()
{
}
ElaCalendarPrivate::~ElaCalendarPrivate() {}
void ElaCalendarPrivate::onSwitchButtonClicked()
{
if (!_isSwitchAnimationFinished)
{
void ElaCalendarPrivate::onSwitchButtonClicked() {
if (!_isSwitchAnimationFinished) {
return;
}
Q_Q(ElaCalendar);
ElaCalendarType displayMode = _calendarModel->getDisplayMode();
if (displayMode == ElaCalendarType::DayMode)
{
if (displayMode == ElaCalendarType::DayMode) {
_oldCalendarViewPix = q->grab(QRect(_borderWidth, _borderWidth + 45, q->width() - 2 * _borderWidth, q->height() - 2 * _borderWidth - 45));
_calendarModel->setDisplayMode(ElaCalendarType::MonthMode);
_calendarTitleView->setVisible(false);
@@ -38,9 +31,7 @@ void ElaCalendarPrivate::onSwitchButtonClicked()
_scrollToDate(_pSelectedDate.isValid() ? _pSelectedDate : QDate::currentDate());
_newCalendarViewPix = q->grab(QRect(_borderWidth, _borderWidth + 45, q->width() - 2 * _borderWidth, q->height() - 2 * _borderWidth - 45));
_doSwitchAnimation(false);
}
else if (displayMode == ElaCalendarType::MonthMode)
{
} else if (displayMode == ElaCalendarType::MonthMode) {
_oldCalendarViewPix = q->grab(QRect(_borderWidth, _borderWidth + 45, q->width() - 2 * _borderWidth, q->height() - 2 * _borderWidth - 45));
_calendarModel->setDisplayMode(ElaCalendarType::YearMode);
_scrollToDate(_pSelectedDate.isValid() ? _pSelectedDate : QDate::currentDate());
@@ -49,29 +40,24 @@ void ElaCalendarPrivate::onSwitchButtonClicked()
}
}
void ElaCalendarPrivate::onCalendarViewClicked(const QModelIndex& index)
{
void ElaCalendarPrivate::onCalendarViewClicked(const QModelIndex &index) {
Q_Q(ElaCalendar);
if (!_isSwitchAnimationFinished)
{
if (!_isSwitchAnimationFinished) {
return;
}
switch (_calendarModel->getDisplayMode())
{
case YearMode:
{
switch (_calendarModel->getDisplayMode()) {
case YearMode: {
_oldCalendarViewPix = q->grab(QRect(_borderWidth, _borderWidth + 45, q->width() - 2 * _borderWidth, q->height() - 2 * _borderWidth - 45));
_lastSelectedYear = _calendarModel->getMinimumDate().year() + index.row();
_lastSelectedYear = _calendarModel->getMinimumDate().year() + index.row();
_calendarModel->setDisplayMode(ElaCalendarType::MonthMode);
_scrollToDate(QDate(_lastSelectedYear, _lastSelectedMonth, 15));
_newCalendarViewPix = q->grab(QRect(_borderWidth, _borderWidth + 45, q->width() - 2 * _borderWidth, q->height() - 2 * _borderWidth - 45));
_doSwitchAnimation(true);
break;
}
case MonthMode:
{
case MonthMode: {
_oldCalendarViewPix = q->grab(QRect(_borderWidth, _borderWidth + 45, q->width() - 2 * _borderWidth, q->height() - 2 * _borderWidth - 45));
_lastSelectedMonth = index.row() % 12 + 1;
_lastSelectedMonth = index.row() % 12 + 1;
_calendarModel->setDisplayMode(ElaCalendarType::DayMode);
_calendarTitleView->setVisible(true);
_calendarView->setSpacing(0);
@@ -82,11 +68,9 @@ void ElaCalendarPrivate::onCalendarViewClicked(const QModelIndex& index)
_doSwitchAnimation(true);
break;
}
case DayMode:
{
case DayMode: {
QDate date = _calendarModel->getDateFromIndex(index);
if (date.isValid())
{
if (date.isValid()) {
_calendarView->clearSelection();
q->setSelectedDate(date);
}
@@ -96,10 +80,9 @@ void ElaCalendarPrivate::onCalendarViewClicked(const QModelIndex& index)
}
}
void ElaCalendarPrivate::onUpButtonClicked()
{
QScrollBar* vscrollBar = _calendarView->verticalScrollBar();
QPropertyAnimation* scrollAnimation = new QPropertyAnimation(vscrollBar, "value");
void ElaCalendarPrivate::onUpButtonClicked() {
QScrollBar *vscrollBar = _calendarView->verticalScrollBar();
QPropertyAnimation *scrollAnimation = new QPropertyAnimation(vscrollBar, "value");
scrollAnimation->setEasingCurve(QEasingCurve::OutSine);
scrollAnimation->setDuration(300);
scrollAnimation->setStartValue(vscrollBar->value());
@@ -107,10 +90,9 @@ void ElaCalendarPrivate::onUpButtonClicked()
scrollAnimation->start(QAbstractAnimation::DeleteWhenStopped);
}
void ElaCalendarPrivate::onDownButtonClicked()
{
QScrollBar* vscrollBar = _calendarView->verticalScrollBar();
QPropertyAnimation* scrollAnimation = new QPropertyAnimation(vscrollBar, "value");
void ElaCalendarPrivate::onDownButtonClicked() {
QScrollBar *vscrollBar = _calendarView->verticalScrollBar();
QPropertyAnimation *scrollAnimation = new QPropertyAnimation(vscrollBar, "value");
scrollAnimation->setEasingCurve(QEasingCurve::OutSine);
scrollAnimation->setDuration(300);
scrollAnimation->setStartValue(vscrollBar->value());
@@ -118,61 +100,47 @@ void ElaCalendarPrivate::onDownButtonClicked()
scrollAnimation->start(QAbstractAnimation::DeleteWhenStopped);
}
void ElaCalendarPrivate::_scrollToDate(QDate date)
{
void ElaCalendarPrivate::_scrollToDate(QDate date) {
int index = _calendarModel->getIndexFromDate(date).row();
switch (_calendarModel->getDisplayMode())
{
switch (_calendarModel->getDisplayMode()) {
case YearMode:
case MonthMode:
{
case MonthMode: {
_calendarView->scrollTo(_calendarModel->index(index - 4), QAbstractItemView::PositionAtTop);
break;
}
case DayMode:
{
case DayMode: {
_calendarView->scrollTo(_calendarModel->index(index - 14), QAbstractItemView::PositionAtTop);
break;
}
}
}
void ElaCalendarPrivate::_doSwitchAnimation(bool isZoomIn)
{
void ElaCalendarPrivate::_doSwitchAnimation(bool isZoomIn) {
Q_Q(ElaCalendar);
if (!_isSwitchAnimationFinished)
{
if (!_isSwitchAnimationFinished) {
return;
}
_isDrawNewPix = false;
_isDrawNewPix = false;
_isSwitchAnimationFinished = false;
_calendarDelegate->setIsTransparent(true);
QPropertyAnimation* oldPixZoomAnimation = new QPropertyAnimation(this, "pZoomRatio");
connect(oldPixZoomAnimation, &QPropertyAnimation::valueChanged, this, [=]() {
q->update();
});
QPropertyAnimation *oldPixZoomAnimation = new QPropertyAnimation(this, "pZoomRatio");
connect(oldPixZoomAnimation, &QPropertyAnimation::valueChanged, this, [=]() { q->update(); });
connect(oldPixZoomAnimation, &QPropertyAnimation::finished, this, [=]() {
_isDrawNewPix = true;
QPropertyAnimation* newPixZoomAnimation = new QPropertyAnimation(this, "pZoomRatio");
connect(newPixZoomAnimation, &QPropertyAnimation::valueChanged, this, [=]() {
q->update();
});
_isDrawNewPix = true;
QPropertyAnimation *newPixZoomAnimation = new QPropertyAnimation(this, "pZoomRatio");
connect(newPixZoomAnimation, &QPropertyAnimation::valueChanged, this, [=]() { q->update(); });
connect(newPixZoomAnimation, &QPropertyAnimation::finished, this, [=]() {
if (_calendarModel->getDisplayMode() == ElaCalendarType::DayMode)
{
if (_calendarModel->getDisplayMode() == ElaCalendarType::DayMode) {
_calendarTitleView->setVisible(true);
}
_isSwitchAnimationFinished = true;
_calendarDelegate->setIsTransparent(false);
});
if (isZoomIn)
{
if (isZoomIn) {
// 放大 年-月-日
newPixZoomAnimation->setStartValue(0.85);
newPixZoomAnimation->setEndValue(1);
}
else
{
} else {
newPixZoomAnimation->setStartValue(1.5);
newPixZoomAnimation->setEndValue(1);
}
@@ -180,14 +148,11 @@ void ElaCalendarPrivate::_doSwitchAnimation(bool isZoomIn)
newPixZoomAnimation->setEasingCurve(QEasingCurve::OutCubic);
newPixZoomAnimation->start(QAbstractAnimation::DeleteWhenStopped);
});
if (isZoomIn)
{
if (isZoomIn) {
// 放大 年-月-日
oldPixZoomAnimation->setStartValue(1);
oldPixZoomAnimation->setEndValue(1.15);
}
else
{
} else {
// 缩小 日-月-年
oldPixZoomAnimation->setStartValue(1);
oldPixZoomAnimation->setEndValue(0.85);
@@ -195,9 +160,9 @@ void ElaCalendarPrivate::_doSwitchAnimation(bool isZoomIn)
oldPixZoomAnimation->setDuration(150);
oldPixZoomAnimation->start(QAbstractAnimation::DeleteWhenStopped);
QPropertyAnimation* oldPixOpacityAnimation = new QPropertyAnimation(this, "pPixOpacity");
QPropertyAnimation *oldPixOpacityAnimation = new QPropertyAnimation(this, "pPixOpacity");
connect(oldPixZoomAnimation, &QPropertyAnimation::finished, this, [=]() {
QPropertyAnimation* newPixOpacityAnimation = new QPropertyAnimation(this, "pPixOpacity");
QPropertyAnimation *newPixOpacityAnimation = new QPropertyAnimation(this, "pPixOpacity");
newPixOpacityAnimation->setStartValue(0);
newPixOpacityAnimation->setEndValue(1);
newPixOpacityAnimation->setDuration(300);
@@ -209,28 +174,22 @@ void ElaCalendarPrivate::_doSwitchAnimation(bool isZoomIn)
oldPixOpacityAnimation->start(QAbstractAnimation::DeleteWhenStopped);
}
void ElaCalendarPrivate::_updateSwitchButtonText()
{
void ElaCalendarPrivate::_updateSwitchButtonText() {
QModelIndex modelIndex = _calendarView->indexAt(QPoint(_calendarView->rect().center().x() - 20, _calendarView->rect().center().y()));
if (!modelIndex.isValid())
{
if (!modelIndex.isValid()) {
return;
}
ElaCalendarData data = _calendarModel->data(modelIndex, Qt::UserRole).value<ElaCalendarData>();
switch (_calendarModel->getDisplayMode())
{
case YearMode:
{
switch (_calendarModel->getDisplayMode()) {
case YearMode: {
_modeSwitchButton->setText(QString("%1-%2").arg(data.year - 5).arg(data.year + 10));
break;
}
case MonthMode:
{
case MonthMode: {
_modeSwitchButton->setText(QString("%1年").arg(data.year));
break;
}
case DayMode:
{
case DayMode: {
_modeSwitchButton->setText(QString("%1年%2月").arg(data.year).arg(data.month));
break;
}