mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-12-14 04:42:03 +08:00
repo: 添加 BaseWidgetOpacity 基础类来实现继承者的淡出动画来代替主窗口的实现
BaseWidgetOpacity 是一个提供了淡出/淡入动画的基础类
1. closeEvent 窗口关闭时进行淡出动画
此前在 MainWindow 中实现的淡出动画将由 BaseWidgetOpacity 来实现。
此前 MainWindow 原有的 DBlurEffectWidget 父类将移交至 BaseWidgetOpacity 继承。
注意:
如果 MainWindow 在未来重写 closeEvent 事件时将可能丢失 BaseWidgetOpacity 中的淡出效果
This commit is contained in:
37
src/widgets/base/basewidgetopacity.cpp
Normal file
37
src/widgets/base/basewidgetopacity.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "basewidgetopacity.h"
|
||||
|
||||
#include <QCloseEvent>
|
||||
#include <QPropertyAnimation>
|
||||
|
||||
BaseWidgetOpacity::BaseWidgetOpacity(QWidget *parent) : DBlurEffectWidget(parent)
|
||||
{
|
||||
// WidgetAnimation::widgetOpacity(this,true);
|
||||
}
|
||||
|
||||
/// @brief 窗口关闭事件
|
||||
/// @param event
|
||||
void BaseWidgetOpacity::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
if (!closeWindowAnimation) {
|
||||
QPropertyAnimation *animation = new QPropertyAnimation(this, "windowOpacity");
|
||||
animation->setEasingCurve(QEasingCurve::OutQuart);
|
||||
animation->setDuration(500);
|
||||
animation->setStartValue(1.0);
|
||||
animation->setEndValue(0.0);
|
||||
|
||||
QObject::connect(animation, &QPropertyAnimation::valueChanged, this, [=](const QVariant &value){
|
||||
this->update();
|
||||
// setWindowTitle(QString("ヾ(⌒∇⌒*)See You♪ - %1%").arg(int(value.toFloat() * 100)));
|
||||
});
|
||||
|
||||
QObject::connect(animation, &QPropertyAnimation::finished, this, [=](){
|
||||
closeWindowAnimation = true;
|
||||
this->close();
|
||||
});
|
||||
|
||||
animation->start();
|
||||
event->ignore();
|
||||
} else {
|
||||
event->accept();
|
||||
}
|
||||
}
|
||||
24
src/widgets/base/basewidgetopacity.h
Normal file
24
src/widgets/base/basewidgetopacity.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef BASEWIDGETOPACITY_H
|
||||
#define BASEWIDGETOPACITY_H
|
||||
|
||||
#include <DBlurEffectWidget>
|
||||
|
||||
DWIDGET_USE_NAMESPACE
|
||||
|
||||
class BaseWidgetOpacity : public DBlurEffectWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit BaseWidgetOpacity(QWidget *parent = nullptr);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
// QWidget interface
|
||||
protected:
|
||||
bool closeWindowAnimation = false;
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
};
|
||||
|
||||
#endif // BASEWIDGETOPACITY_H
|
||||
Reference in New Issue
Block a user