mirror of
https://github.com/tnodir/fort
synced 2024-11-15 06:35:23 +00:00
UI: Splash: Fade in/out
This commit is contained in:
parent
dc5555ebd6
commit
365bf30eda
@ -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()
|
||||
|
@ -16,7 +16,9 @@ public:
|
||||
static QLayout *createLogoTextLayout();
|
||||
|
||||
public slots:
|
||||
void showTemporary();
|
||||
void showFading();
|
||||
void closeDelayed();
|
||||
void closeFading();
|
||||
|
||||
private:
|
||||
void setupUi();
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user