chore: 格式化ElaWidgetTools代码
This commit is contained in:
@@ -8,14 +8,12 @@
|
||||
#include <QPropertyAnimation>
|
||||
#include <QTimer>
|
||||
#include <cmath>
|
||||
ElaCentralStackedWidget::ElaCentralStackedWidget(QWidget* parent)
|
||||
: QStackedWidget(parent)
|
||||
{
|
||||
_pPopupAnimationYOffset = 0;
|
||||
_pScaleAnimationRatio = 1;
|
||||
ElaCentralStackedWidget::ElaCentralStackedWidget(QWidget *parent) : QStackedWidget(parent) {
|
||||
_pPopupAnimationYOffset = 0;
|
||||
_pScaleAnimationRatio = 1;
|
||||
_pScaleAnimationPixOpacity = 1;
|
||||
_pFlipAnimationRatio = 1;
|
||||
_pBlurAnimationRadius = 0;
|
||||
_pFlipAnimationRatio = 1;
|
||||
_pBlurAnimationRadius = 0;
|
||||
|
||||
_blurEffect = new QGraphicsBlurEffect(this);
|
||||
_blurEffect->setBlurHints(QGraphicsBlurEffect::BlurHint::QualityHint);
|
||||
@@ -29,53 +27,37 @@ ElaCentralStackedWidget::ElaCentralStackedWidget(QWidget* parent)
|
||||
connect(eTheme, &ElaTheme::themeModeChanged, this, &ElaCentralStackedWidget::onThemeModeChanged);
|
||||
}
|
||||
|
||||
ElaCentralStackedWidget::~ElaCentralStackedWidget()
|
||||
{
|
||||
}
|
||||
ElaCentralStackedWidget::~ElaCentralStackedWidget() {}
|
||||
|
||||
void ElaCentralStackedWidget::onThemeModeChanged(ElaThemeType::ThemeMode themeMode)
|
||||
{
|
||||
_themeMode = themeMode;
|
||||
}
|
||||
void ElaCentralStackedWidget::onThemeModeChanged(ElaThemeType::ThemeMode themeMode) { _themeMode = themeMode; }
|
||||
|
||||
void ElaCentralStackedWidget::setIsTransparent(bool isTransparent)
|
||||
{
|
||||
void ElaCentralStackedWidget::setIsTransparent(bool isTransparent) {
|
||||
this->_isTransparent = isTransparent;
|
||||
update();
|
||||
}
|
||||
|
||||
bool ElaCentralStackedWidget::getIsTransparent() const
|
||||
{
|
||||
return _isTransparent;
|
||||
}
|
||||
bool ElaCentralStackedWidget::getIsTransparent() const { return _isTransparent; }
|
||||
|
||||
void ElaCentralStackedWidget::setIsHasRadius(bool isHasRadius)
|
||||
{
|
||||
void ElaCentralStackedWidget::setIsHasRadius(bool isHasRadius) {
|
||||
this->_isHasRadius = isHasRadius;
|
||||
update();
|
||||
}
|
||||
|
||||
void ElaCentralStackedWidget::doWindowStackSwitch(ElaWindowType::StackSwitchMode stackSwitchMode, int nodeIndex, bool isRouteBack)
|
||||
{
|
||||
void ElaCentralStackedWidget::doWindowStackSwitch(ElaWindowType::StackSwitchMode stackSwitchMode, int nodeIndex, bool isRouteBack) {
|
||||
_stackSwitchMode = stackSwitchMode;
|
||||
switch (stackSwitchMode)
|
||||
{
|
||||
case ElaWindowType::None:
|
||||
{
|
||||
switch (stackSwitchMode) {
|
||||
case ElaWindowType::None: {
|
||||
this->setCurrentIndex(nodeIndex);
|
||||
break;
|
||||
}
|
||||
case ElaWindowType::Popup:
|
||||
{
|
||||
case ElaWindowType::Popup: {
|
||||
QTimer::singleShot(180, this, [=]() {
|
||||
QWidget* targetWidget = this->widget(nodeIndex);
|
||||
QWidget *targetWidget = this->widget(nodeIndex);
|
||||
this->setCurrentIndex(nodeIndex);
|
||||
_getTargetStackPix();
|
||||
targetWidget->setVisible(false);
|
||||
QPropertyAnimation* popupAnimation = new QPropertyAnimation(this, "pPopupAnimationYOffset");
|
||||
connect(popupAnimation, &QPropertyAnimation::valueChanged, this, [=]() {
|
||||
update();
|
||||
});
|
||||
QPropertyAnimation *popupAnimation = new QPropertyAnimation(this, "pPopupAnimationYOffset");
|
||||
connect(popupAnimation, &QPropertyAnimation::valueChanged, this, [=]() { update(); });
|
||||
connect(popupAnimation, &QPropertyAnimation::finished, this, [=]() {
|
||||
_targetStackPix = QPixmap();
|
||||
targetWidget->setVisible(true);
|
||||
@@ -90,36 +72,28 @@ void ElaCentralStackedWidget::doWindowStackSwitch(ElaWindowType::StackSwitchMode
|
||||
});
|
||||
break;
|
||||
}
|
||||
case ElaWindowType::Scale:
|
||||
{
|
||||
QWidget* targetWidget = this->widget(nodeIndex);
|
||||
case ElaWindowType::Scale: {
|
||||
QWidget *targetWidget = this->widget(nodeIndex);
|
||||
_getCurrentStackPix();
|
||||
this->setCurrentIndex(nodeIndex);
|
||||
_getTargetStackPix();
|
||||
targetWidget->setVisible(false);
|
||||
_isDrawNewPix = false;
|
||||
QPropertyAnimation* currentPixZoomAnimation = new QPropertyAnimation(this, "pScaleAnimationRatio");
|
||||
connect(currentPixZoomAnimation, &QPropertyAnimation::valueChanged, this, [=]() {
|
||||
update();
|
||||
});
|
||||
_isDrawNewPix = false;
|
||||
QPropertyAnimation *currentPixZoomAnimation = new QPropertyAnimation(this, "pScaleAnimationRatio");
|
||||
connect(currentPixZoomAnimation, &QPropertyAnimation::valueChanged, this, [=]() { update(); });
|
||||
connect(currentPixZoomAnimation, &QPropertyAnimation::finished, this, [=]() {
|
||||
_isDrawNewPix = true;
|
||||
QPropertyAnimation* targetPixZoomAnimation = new QPropertyAnimation(this, "pScaleAnimationRatio");
|
||||
connect(targetPixZoomAnimation, &QPropertyAnimation::valueChanged, this, [=]() {
|
||||
update();
|
||||
});
|
||||
_isDrawNewPix = true;
|
||||
QPropertyAnimation *targetPixZoomAnimation = new QPropertyAnimation(this, "pScaleAnimationRatio");
|
||||
connect(targetPixZoomAnimation, &QPropertyAnimation::valueChanged, this, [=]() { update(); });
|
||||
connect(targetPixZoomAnimation, &QPropertyAnimation::finished, this, [=]() {
|
||||
_targetStackPix = QPixmap();
|
||||
_targetStackPix = QPixmap();
|
||||
_currentStackPix = QPixmap();
|
||||
targetWidget->setVisible(true);
|
||||
});
|
||||
if (isRouteBack)
|
||||
{
|
||||
if (isRouteBack) {
|
||||
targetPixZoomAnimation->setStartValue(1.5);
|
||||
targetPixZoomAnimation->setEndValue(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// 放大
|
||||
targetPixZoomAnimation->setStartValue(0.85);
|
||||
targetPixZoomAnimation->setEndValue(1);
|
||||
@@ -128,14 +102,11 @@ void ElaCentralStackedWidget::doWindowStackSwitch(ElaWindowType::StackSwitchMode
|
||||
targetPixZoomAnimation->setEasingCurve(QEasingCurve::OutCubic);
|
||||
targetPixZoomAnimation->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
});
|
||||
if (isRouteBack)
|
||||
{
|
||||
if (isRouteBack) {
|
||||
// 缩小
|
||||
currentPixZoomAnimation->setStartValue(1);
|
||||
currentPixZoomAnimation->setEndValue(0.85);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// 放大
|
||||
currentPixZoomAnimation->setStartValue(1);
|
||||
currentPixZoomAnimation->setEndValue(1.15);
|
||||
@@ -143,9 +114,9 @@ void ElaCentralStackedWidget::doWindowStackSwitch(ElaWindowType::StackSwitchMode
|
||||
currentPixZoomAnimation->setDuration(150);
|
||||
currentPixZoomAnimation->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
|
||||
QPropertyAnimation* currentPixOpacityAnimation = new QPropertyAnimation(this, "pScaleAnimationPixOpacity");
|
||||
QPropertyAnimation *currentPixOpacityAnimation = new QPropertyAnimation(this, "pScaleAnimationPixOpacity");
|
||||
connect(currentPixZoomAnimation, &QPropertyAnimation::finished, this, [=]() {
|
||||
QPropertyAnimation* targetPixOpacityAnimation = new QPropertyAnimation(this, "pScaleAnimationPixOpacity");
|
||||
QPropertyAnimation *targetPixOpacityAnimation = new QPropertyAnimation(this, "pScaleAnimationPixOpacity");
|
||||
targetPixOpacityAnimation->setStartValue(0);
|
||||
targetPixOpacityAnimation->setEndValue(1);
|
||||
targetPixOpacityAnimation->setDuration(300);
|
||||
@@ -157,19 +128,16 @@ void ElaCentralStackedWidget::doWindowStackSwitch(ElaWindowType::StackSwitchMode
|
||||
currentPixOpacityAnimation->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
break;
|
||||
}
|
||||
case ElaWindowType::Flip:
|
||||
{
|
||||
QWidget* targetWidget = this->widget(nodeIndex);
|
||||
case ElaWindowType::Flip: {
|
||||
QWidget *targetWidget = this->widget(nodeIndex);
|
||||
_getCurrentStackPix();
|
||||
this->setCurrentIndex(nodeIndex);
|
||||
_getTargetStackPix();
|
||||
targetWidget->setVisible(false);
|
||||
QPropertyAnimation* flipAnimation = new QPropertyAnimation(this, "pFlipAnimationRatio");
|
||||
connect(flipAnimation, &QPropertyAnimation::valueChanged, this, [=]() {
|
||||
update();
|
||||
});
|
||||
QPropertyAnimation *flipAnimation = new QPropertyAnimation(this, "pFlipAnimationRatio");
|
||||
connect(flipAnimation, &QPropertyAnimation::valueChanged, this, [=]() { update(); });
|
||||
connect(flipAnimation, &QPropertyAnimation::finished, this, [=]() {
|
||||
_targetStackPix = QPixmap();
|
||||
_targetStackPix = QPixmap();
|
||||
_currentStackPix = QPixmap();
|
||||
targetWidget->setVisible(true);
|
||||
});
|
||||
@@ -180,17 +148,12 @@ void ElaCentralStackedWidget::doWindowStackSwitch(ElaWindowType::StackSwitchMode
|
||||
flipAnimation->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
break;
|
||||
}
|
||||
case ElaWindowType::Blur:
|
||||
{
|
||||
case ElaWindowType::Blur: {
|
||||
_targetStackPix = QPixmap();
|
||||
_blurEffect->setEnabled(true);
|
||||
QPropertyAnimation* blurAnimation = new QPropertyAnimation(this, "pBlurAnimationRadius");
|
||||
connect(blurAnimation, &QPropertyAnimation::valueChanged, this, [=]() {
|
||||
_blurEffect->setBlurRadius(_pBlurAnimationRadius);
|
||||
});
|
||||
connect(blurAnimation, &QPropertyAnimation::finished, this, [=]() {
|
||||
_blurEffect->setEnabled(false);
|
||||
});
|
||||
QPropertyAnimation *blurAnimation = new QPropertyAnimation(this, "pBlurAnimationRadius");
|
||||
connect(blurAnimation, &QPropertyAnimation::valueChanged, this, [=]() { _blurEffect->setBlurRadius(_pBlurAnimationRadius); });
|
||||
connect(blurAnimation, &QPropertyAnimation::finished, this, [=]() { _blurEffect->setEnabled(false); });
|
||||
blurAnimation->setEasingCurve(QEasingCurve::InOutSine);
|
||||
blurAnimation->setDuration(350);
|
||||
blurAnimation->setStartValue(40);
|
||||
@@ -203,45 +166,35 @@ void ElaCentralStackedWidget::doWindowStackSwitch(ElaWindowType::StackSwitchMode
|
||||
}
|
||||
}
|
||||
|
||||
void ElaCentralStackedWidget::paintEvent(QPaintEvent* event)
|
||||
{
|
||||
void ElaCentralStackedWidget::paintEvent(QPaintEvent *event) {
|
||||
QRect targetRect = this->rect();
|
||||
targetRect.adjust(1, 1, 10, 10);
|
||||
QPainter painter(this);
|
||||
painter.save();
|
||||
painter.setRenderHints(QPainter::Antialiasing);
|
||||
if (!_isTransparent)
|
||||
{
|
||||
if (!_isTransparent) {
|
||||
painter.setPen(QPen(ElaThemeColor(_themeMode, BasicBaseLine), 1.5));
|
||||
painter.setBrush(ElaThemeColor(_themeMode, WindowCentralStackBase));
|
||||
if (_isHasRadius)
|
||||
{
|
||||
if (_isHasRadius) {
|
||||
painter.drawRoundedRect(targetRect, 10, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
painter.drawRect(targetRect);
|
||||
}
|
||||
}
|
||||
// 切换动画
|
||||
if (!_targetStackPix.isNull())
|
||||
{
|
||||
if (!_targetStackPix.isNull()) {
|
||||
QPainterPath clipPath;
|
||||
clipPath.addRoundedRect(targetRect, 10, 10);
|
||||
painter.setClipPath(clipPath);
|
||||
switch (_stackSwitchMode)
|
||||
{
|
||||
case ElaWindowType::None:
|
||||
{
|
||||
switch (_stackSwitchMode) {
|
||||
case ElaWindowType::None: {
|
||||
break;
|
||||
}
|
||||
case ElaWindowType::Popup:
|
||||
{
|
||||
case ElaWindowType::Popup: {
|
||||
painter.drawPixmap(QRect(0, _pPopupAnimationYOffset, width(), height()), _targetStackPix);
|
||||
break;
|
||||
}
|
||||
case ElaWindowType::Scale:
|
||||
{
|
||||
case ElaWindowType::Scale: {
|
||||
painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
|
||||
painter.setOpacity(_pScaleAnimationPixOpacity);
|
||||
painter.translate(rect().center());
|
||||
@@ -250,33 +203,25 @@ void ElaCentralStackedWidget::paintEvent(QPaintEvent* event)
|
||||
painter.drawPixmap(rect(), _isDrawNewPix ? _targetStackPix : _currentStackPix);
|
||||
break;
|
||||
}
|
||||
case ElaWindowType::Flip:
|
||||
{
|
||||
case ElaWindowType::Flip: {
|
||||
painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
|
||||
QTransform transform;
|
||||
transform.translate(rect().center().x(), 0);
|
||||
if (abs(_pFlipAnimationRatio) >= 90)
|
||||
{
|
||||
if (abs(_pFlipAnimationRatio) >= 90) {
|
||||
transform.rotate(-180 + _pFlipAnimationRatio, Qt::YAxis);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
transform.rotate(_pFlipAnimationRatio, Qt::YAxis);
|
||||
}
|
||||
transform.translate(-rect().center().x(), 0);
|
||||
painter.setTransform(transform);
|
||||
if (abs(_pFlipAnimationRatio) >= 90)
|
||||
{
|
||||
if (abs(_pFlipAnimationRatio) >= 90) {
|
||||
painter.drawPixmap(rect(), _targetStackPix);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
painter.drawPixmap(rect(), _currentStackPix);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ElaWindowType::Blur:
|
||||
{
|
||||
case ElaWindowType::Blur: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -284,22 +229,20 @@ void ElaCentralStackedWidget::paintEvent(QPaintEvent* event)
|
||||
painter.restore();
|
||||
}
|
||||
|
||||
void ElaCentralStackedWidget::_getCurrentStackPix()
|
||||
{
|
||||
_targetStackPix = QPixmap();
|
||||
void ElaCentralStackedWidget::_getCurrentStackPix() {
|
||||
_targetStackPix = QPixmap();
|
||||
bool isTransparent = _isTransparent;
|
||||
_isTransparent = true;
|
||||
_isTransparent = true;
|
||||
currentWidget()->setVisible(true);
|
||||
_currentStackPix = this->grab(rect());
|
||||
currentWidget()->setVisible(false);
|
||||
_isTransparent = isTransparent;
|
||||
}
|
||||
|
||||
void ElaCentralStackedWidget::_getTargetStackPix()
|
||||
{
|
||||
_targetStackPix = QPixmap();
|
||||
void ElaCentralStackedWidget::_getTargetStackPix() {
|
||||
_targetStackPix = QPixmap();
|
||||
bool isTransparent = _isTransparent;
|
||||
_isTransparent = true;
|
||||
_targetStackPix = this->grab(rect());
|
||||
_isTransparent = isTransparent;
|
||||
_isTransparent = true;
|
||||
_targetStackPix = this->grab(rect());
|
||||
_isTransparent = isTransparent;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user