///////////////////////////////////////////////////////////////////////////////
// LameXP - Audio Encoder Front-End
-// Copyright (C) 2004-2013 LoRd_MuldeR <MuldeR2@GMX.de>
+// Copyright (C) 2004-2020 LoRd_MuldeR <MuldeR2@GMX.de>
//
// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
+// it under the terms of the GNU GENERAL PUBLIC LICENSE as published by
// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version, but always including the *additional*
-// restrictions defined in the "License.txt" file.
+// (at your option) any later version; always including the non-optional
+// LAMEXP GNU GENERAL PUBLIC LICENSE ADDENDUM. See "License.txt" file!
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
#include "Dialog_SplashScreen.h"
+//UIC includes
+#include "UIC_SplashScreen.h"
+
+//Internal
#include "Global.h"
+//MUtils
+#include <MUtils/Global.h>
+#include <MUtils/GUI.h>
+#include <MUtils/Taskbar7.h>
+
+//Qt
#include <QThread>
#include <QMovie>
#include <QKeyEvent>
#include <QTimer>
-#include "WinSevenTaskbar.h"
-
#define FADE_DELAY 16
-#define OPACITY_DELTA 0.02
-
-/* It can happen that the QThread has just terminated and already emitted the 'terminated' signal, but did NOT change the 'isRunning' flag to FALSE yet. */
-/* For this reason the macro will first check the 'isRunning' flag. If (and only if) the flag still returns TRUE, we will call the wait() on the thread. */
-#define THREAD_RUNNING(THRD) (((THRD)->isRunning()) ? (!((THRD)->wait(1))) : false)
+#define OPACITY_DELTA 0.04
-#define SET_TASKBAR_STATE(FLAG) do \
+//Setup taskbar indicator
+#define SET_TASKBAR_STATE(WIDGET,FLAG) do \
{ \
- if(FLAG) \
+ const int _oldFlag = (WIDGET)->m_taskBarFlag.fetchAndStoreOrdered((FLAG) ? 1 : 0); \
+ if(_oldFlag != ((FLAG) ? 1 : 0)) \
{ \
- if(!bTaskBar) bTaskBar = WinSevenTaskbar::setTaskbarState(splashScreen, WinSevenTaskbar::WinSevenTaskbarIndeterminateState); \
- } \
- else \
- { \
- if(bTaskBar) bTaskBar = (!WinSevenTaskbar::setTaskbarState(splashScreen, WinSevenTaskbar::WinSevenTaskbarNoState)); \
+ (WIDGET)->m_taskbar->setTaskbarState((FLAG) ? MUtils::Taskbar7::TASKBAR_STATE_INTERMEDIATE : MUtils::Taskbar7::TASKBAR_STATE_NONE); \
} \
} \
while(0)
-#define ASYNC_WAIT(LOOP, DELAY) do \
-{ \
- QTimer::singleShot((DELAY), (LOOP), SLOT(quit())); \
- (LOOP)->exec(QEventLoop::ExcludeUserInputEvents); \
-} \
-while(0)
-
////////////////////////////////////////////////////////////
// Constructor
////////////////////////////////////////////////////////////
SplashScreen::SplashScreen(QWidget *parent)
:
- QFrame(parent, Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint)
+ QFrame(parent, Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint),
+ ui(new Ui::SplashScreen),
+ m_opacitySteps(qRound(1.0 / OPACITY_DELTA)),
+ m_taskbar(new MUtils::Taskbar7(this))
{
//Init the dialog, from the .ui file
- setupUi(this);
+ ui->setupUi(this);
+
+ //Make size fixed
+ setFixedSize(this->size());
+
+ //Create event loop
+ m_loop.reset(new QEventLoop(this));
+
+ //Create timer
+ m_timer.reset(new QTimer(this));
+ m_timer->setInterval(FADE_DELAY);
+ m_timer->setSingleShot(false);
+
+ //Connect timer to slot
+ connect(m_timer.data(), SIGNAL(timeout()), this, SLOT(updateHandler()));
+
+ //Enable "sheet of glass" effect on splash screen
+ if(!MUtils::GUI::sheet_of_glass(this))
+ {
+ setStyleSheet("background-image: url(:/images/Background.jpg)");
+ }
//Start animation
- m_working = new QMovie(":/images/Loading.gif");
- labelLoading->setMovie(m_working);
+ m_working.reset(new QMovie(":/images/Loading4.gif"));
+ m_working->setCacheMode(QMovie::CacheAll);
+ ui->labelLoading->setMovie(m_working.data());
m_working->start();
- //Set wait cursor
- setCursor(Qt::WaitCursor);
-
- //Prevent close
- m_canClose = false;
+ //Init status
+ m_status = STATUS_FADE_IN;
+ m_fadeValue = 0;
}
////////////////////////////////////////////////////////////
if(m_working)
{
m_working->stop();
- delete m_working;
- m_working = NULL;
}
+
+ delete ui;
}
////////////////////////////////////////////////////////////
void SplashScreen::showSplash(QThread *thread)
{
- const int opacitySteps = qRound(1.0 / OPACITY_DELTA);
- bool bTaskBar = false;
- unsigned int deadlockCounter = 0;
- SplashScreen *splashScreen = new SplashScreen();
-
+ QScopedPointer<SplashScreen> splashScreen(new SplashScreen());
+
//Show splash
- splashScreen->m_canClose = false;
splashScreen->setWindowOpacity(OPACITY_DELTA);
- splashScreen->setFixedSize(splashScreen->size());
splashScreen->show();
+ //Set wait cursor
+ QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
+
//Wait for window to show
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
- splashScreen->repaint();
+ splashScreen->repaint(); MUtils::GUI::bring_to_front(splashScreen.data());
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
- //Setup the event loop
- QEventLoop *loop = new QEventLoop(splashScreen);
- connect(thread, SIGNAL(terminated()), loop, SLOT(quit()), Qt::QueuedConnection);
- connect(thread, SIGNAL(finished()), loop, SLOT(quit()), Qt::QueuedConnection);
+ //Connect thread signals
+ connect(thread, SIGNAL(terminated()), splashScreen.data(), SLOT(threadComplete()), Qt::QueuedConnection);
+ connect(thread, SIGNAL(finished()), splashScreen.data(), SLOT(threadComplete()), Qt::QueuedConnection);
- //Create timer
- QTimer *timer = new QTimer();
- connect(timer, SIGNAL(timeout()), loop, SLOT(quit()));
+ //Init taskbar
+ SET_TASKBAR_STATE(splashScreen, true);
//Start the thread
- thread->start();
+ splashScreen->m_timer->start(FADE_DELAY);
+ QTimer::singleShot(8*60*1000, splashScreen->m_loop.data(), SLOT(quit()));
+ QTimer::singleShot(333, thread, SLOT(start()));
- //Init taskbar
- SET_TASKBAR_STATE(true);
+ //Start event handling!
+ const int ret = splashScreen->m_loop->exec(QEventLoop::ExcludeUserInputEvents);
- //Fade in
- for(int i = 1; i <= opacitySteps; i++)
+ //Check for timeout
+ if(ret != 42)
{
- const double opacity = (i < opacitySteps) ? (OPACITY_DELTA * static_cast<double>(i)) : 1.0;
- splashScreen->setWindowOpacity(opacity); //splashScreen->update();
- ASYNC_WAIT(loop, FADE_DELAY);
- SET_TASKBAR_STATE(true);
+ thread->terminate();
+ qFatal("Deadlock in initialization thread encountered!");
}
- //Start the timer
- timer->start(30720);
+ //Restore taskbar
+ SET_TASKBAR_STATE(splashScreen, false);
+
+ //Restore cursor
+ QApplication::restoreOverrideCursor();
+
+ //Hide splash
+ splashScreen->m_canClose.ref();
+ splashScreen->close();
+}
+
+////////////////////////////////////////////////////////////
+// SLOTS
+////////////////////////////////////////////////////////////
- //Loop while thread is still running
- while(THREAD_RUNNING(thread))
+void SplashScreen::updateHandler(void)
+{
+ if(m_status == STATUS_FADE_IN)
{
- if((++deadlockCounter) > 60)
+ if(m_fadeValue < m_opacitySteps)
+ {
+ setWindowOpacity(OPACITY_DELTA * static_cast<double>(++m_fadeValue));
+ SET_TASKBAR_STATE(this, true);
+ }
+ else
{
- qFatal("Deadlock in initialization thread detected!");
+ setWindowOpacity(1.0);
+ MUtils::GUI::bring_to_front(this);
+ m_timer->stop();
+ m_status = STATUS_WAIT;
}
- ASYNC_WAIT(loop, 5000);
}
-
- //Stop the timer
- timer->stop();
-
- //Fade out
- for(int i = opacitySteps; i >= 0; i--)
+ else if(m_status == STATUS_FADE_OUT)
{
- const double opacity = OPACITY_DELTA * static_cast<double>(i);
- splashScreen->setWindowOpacity(opacity); //splashScreen->update();
- ASYNC_WAIT(loop, FADE_DELAY);
+ if(m_fadeValue > 0)
+ {
+ setWindowOpacity(OPACITY_DELTA * static_cast<double>(--m_fadeValue));
+ SET_TASKBAR_STATE(this, true);
+ }
+ else
+ {
+ setWindowOpacity(0.0);
+ m_timer->stop();
+ m_status = STATUS_DONE;
+ m_loop->exit(42);
+ }
}
+}
- //Restore taskbar
- SET_TASKBAR_STATE(false);
-
- //Hide splash
- splashScreen->m_canClose = true;
- splashScreen->close();
-
- //Free
- LAMEXP_DELETE(loop);
- LAMEXP_DELETE(timer);
- LAMEXP_DELETE(splashScreen);
+void SplashScreen::threadComplete(void)
+{
+ m_status = STATUS_FADE_OUT;
+ if(!m_timer->isActive())
+ {
+ m_timer->start(FADE_DELAY);
+ }
+ MUtils::GUI::bring_to_front(this);
}
////////////////////////////////////////////////////////////
{
if(!m_canClose) event->ignore();
}
-
-bool SplashScreen::winEvent(MSG *message, long *result)
-{
- return WinSevenTaskbar::handleWinEvent(message, result);
-}