mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-07-05 05:05:59 +08:00
repo: 添加 BaseWidgetOpacity 基础类来实现继承者的淡出动画来代替主窗口的实现
BaseWidgetOpacity 是一个提供了淡出/淡入动画的基础类 1. closeEvent 窗口关闭时进行淡出动画 此前在 MainWindow 中实现的淡出动画将由 BaseWidgetOpacity 来实现。 此前 MainWindow 原有的 DBlurEffectWidget 父类将移交至 BaseWidgetOpacity 继承。 注意: 如果 MainWindow 在未来重写 closeEvent 事件时将可能丢失 BaseWidgetOpacity 中的淡出效果
This commit is contained in:
parent
adf9032897
commit
c9d0c8b751
@ -11,7 +11,7 @@
|
|||||||
#define AppPageSettings 3
|
#define AppPageSettings 3
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: DBlurEffectWidget(parent)
|
: BaseWidgetOpacity(parent)
|
||||||
, ui(new Ui::MainWindow)
|
, ui(new Ui::MainWindow)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
@ -299,32 +299,3 @@ void MainWindow::on_pushButton_14_clicked()
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// @brief 窗口关闭事件
|
|
||||||
/// @param event
|
|
||||||
void MainWindow::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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
#define MAINWINDOWDTK_H
|
#define MAINWINDOWDTK_H
|
||||||
|
|
||||||
#include <DMainWindow>
|
#include <DMainWindow>
|
||||||
#include <DBlurEffectWidget>
|
|
||||||
#include <DTitlebar>
|
#include <DTitlebar>
|
||||||
#include <DSearchEdit>
|
#include <DSearchEdit>
|
||||||
#include <QGraphicsDropShadowEffect>
|
#include <QGraphicsDropShadowEffect>
|
||||||
@ -12,6 +11,7 @@
|
|||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
|
|
||||||
|
#include "widgets/base/basewidgetopacity.h"
|
||||||
#include "widgets/downloadlistwidget.h"
|
#include "widgets/downloadlistwidget.h"
|
||||||
#include "widgets/common/progressbutton.h"
|
#include "widgets/common/progressbutton.h"
|
||||||
#include "utils/widgetanimation.h"
|
#include "utils/widgetanimation.h"
|
||||||
@ -23,7 +23,7 @@ namespace Ui {
|
|||||||
class MainWindow;
|
class MainWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
class MainWindow : public DBlurEffectWidget
|
class MainWindow : public BaseWidgetOpacity
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@ -53,10 +53,6 @@ private slots:
|
|||||||
void onGetUrl(const QString &url);
|
void onGetUrl(const QString &url);
|
||||||
void on_pushButton_14_clicked();
|
void on_pushButton_14_clicked();
|
||||||
|
|
||||||
// QWidget interface
|
|
||||||
protected:
|
|
||||||
bool closeWindowAnimation = false;
|
|
||||||
void closeEvent(QCloseEvent *event) override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOWDTK_H
|
#endif // MAINWINDOWDTK_H
|
||||||
|
@ -58,7 +58,8 @@ SOURCES += \
|
|||||||
backend/downloadworker.cpp \
|
backend/downloadworker.cpp \
|
||||||
pages/appintopage.cpp \
|
pages/appintopage.cpp \
|
||||||
widgets/big_image.cpp \
|
widgets/big_image.cpp \
|
||||||
backend/image_show.cpp
|
backend/image_show.cpp \
|
||||||
|
widgets/base/basewidgetopacity.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
dbus/dbussparkstoreservice.h \
|
dbus/dbussparkstoreservice.h \
|
||||||
@ -79,7 +80,8 @@ HEADERS += \
|
|||||||
backend/downloadworker.h \
|
backend/downloadworker.h \
|
||||||
pages/appintopage.h \
|
pages/appintopage.h \
|
||||||
widgets/big_image.h \
|
widgets/big_image.h \
|
||||||
backend/image_show.h
|
backend/image_show.h \
|
||||||
|
widgets/base/basewidgetopacity.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
mainwindow-dtk.ui \
|
mainwindow-dtk.ui \
|
||||||
|
@ -25,7 +25,7 @@ void WidgetAnimation::widgetShake(QWidget *pWidget, int nRange)
|
|||||||
pAnimation->start(QAbstractAnimation::DeleteWhenStopped);
|
pAnimation->start(QAbstractAnimation::DeleteWhenStopped);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WidgetAnimation::widgetOpacity(QWidget *pWidget, bool isAppear)
|
QPropertyAnimation* WidgetAnimation::createWidgetOpacity(QWidget *pWidget, bool isAppear)
|
||||||
{
|
{
|
||||||
QPropertyAnimation *animation = new QPropertyAnimation(pWidget, "windowOpacity", pWidget);
|
QPropertyAnimation *animation = new QPropertyAnimation(pWidget, "windowOpacity", pWidget);
|
||||||
//设置动画效果
|
//设置动画效果
|
||||||
@ -42,6 +42,11 @@ void WidgetAnimation::widgetOpacity(QWidget *pWidget, bool isAppear)
|
|||||||
animation->setKeyValueAt(0, 1);
|
animation->setKeyValueAt(0, 1);
|
||||||
animation->setKeyValueAt(1, 0);
|
animation->setKeyValueAt(1, 0);
|
||||||
}
|
}
|
||||||
// 开始动画
|
return animation;
|
||||||
animation->start();
|
}
|
||||||
|
|
||||||
|
void WidgetAnimation::widgetOpacity(QWidget *pWidget, bool isAppear)
|
||||||
|
{
|
||||||
|
// 开始动画
|
||||||
|
createWidgetOpacity(pWidget, isAppear)->start();
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,8 @@ class WidgetAnimation
|
|||||||
public:
|
public:
|
||||||
WidgetAnimation();
|
WidgetAnimation();
|
||||||
static void widgetShake(QWidget *pWidget, int nRange);
|
static void widgetShake(QWidget *pWidget, int nRange);
|
||||||
|
|
||||||
|
static QPropertyAnimation* createWidgetOpacity(QWidget *pWidget, bool isAppear);
|
||||||
static void widgetOpacity(QWidget *pWidget, bool isAppear);
|
static void widgetOpacity(QWidget *pWidget, bool isAppear);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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
|
Loading…
x
Reference in New Issue
Block a user