UI: Splash: Fade in/out

This commit is contained in:
Nodir Temirkhodjaev 2024-02-13 19:55:18 +03:00
parent dc5555ebd6
commit 365bf30eda
3 changed files with 37 additions and 4 deletions

View File

@ -4,12 +4,31 @@
#include <QHBoxLayout>
#include <QIcon>
#include <QLabel>
#include <QPropertyAnimation>
#include <QTimer>
#include <form/controls/controlutil.h>
#include <manager/windowmanager.h>
#include <util/iconcache.h>
namespace {
void startOpacityAnimation(
QWidget *w, const std::function<void()> &onFinished, bool backward = false)
{
auto anim = new QPropertyAnimation(w, "windowOpacity", w);
anim->setDirection(backward ? QPropertyAnimation::Backward : QPropertyAnimation::Forward);
anim->setDuration(900);
anim->setStartValue(0.0f);
anim->setEndValue(1.0f);
QObject::connect(anim, &QPropertyAnimation::finished, onFinished);
anim->start(QPropertyAnimation::DeleteWhenStopped);
}
}
SplashScreen::SplashScreen() : QSplashScreen()
{
this->setAttribute(Qt::WA_DeleteOnClose);
@ -17,11 +36,23 @@ SplashScreen::SplashScreen() : QSplashScreen()
setupUi();
}
void SplashScreen::showTemporary()
void SplashScreen::showFading()
{
setWindowOpacity(0.0f);
show();
QTimer::singleShot(2000, this, &QWidget::close);
startOpacityAnimation(this, [&] { closeDelayed(); });
}
void SplashScreen::closeDelayed()
{
QTimer::singleShot(1600, this, &SplashScreen::closeFading);
}
void SplashScreen::closeFading()
{
startOpacityAnimation(
this, [&] { close(); }, /*backward=*/true);
}
void SplashScreen::setupUi()

View File

@ -16,7 +16,9 @@ public:
static QLayout *createLogoTextLayout();
public slots:
void showTemporary();
void showFading();
void closeDelayed();
void closeFading();
private:
void setupUi();

View File

@ -302,7 +302,7 @@ void WindowManager::showTrayMessage(const QString &message, WindowManager::TrayM
void WindowManager::showSplashScreen()
{
auto splash = new SplashScreen();
splash->showTemporary();
splash->showFading();
}
void WindowManager::showHomeWindow()