2010-11-06 23:04:47 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// LameXP - Audio Encoder Front-End
|
2019-01-11 23:28:57 +01:00
|
|
|
// Copyright (C) 2004-2019 LoRd_MuldeR <MuldeR2@GMX.de>
|
2010-11-06 23:04:47 +01:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
2013-10-23 20:56:57 +02:00
|
|
|
// (at your option) any later version, but always including the *additional*
|
|
|
|
// restrictions defined in the "License.txt" file.
|
2010-11-06 23:04:47 +01:00
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
//
|
|
|
|
// http://www.gnu.org/licenses/gpl-2.0.txt
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "Dialog_SplashScreen.h"
|
|
|
|
|
2014-12-18 22:49:37 +01:00
|
|
|
//UIC includes
|
|
|
|
#include "UIC_SplashScreen.h"
|
|
|
|
|
2014-11-25 02:14:42 +01:00
|
|
|
//Internal
|
2010-11-06 23:04:47 +01:00
|
|
|
#include "Global.h"
|
2014-11-25 02:14:42 +01:00
|
|
|
|
|
|
|
//MUtils
|
|
|
|
#include <MUtils/Global.h>
|
2014-12-08 22:06:01 +01:00
|
|
|
#include <MUtils/GUI.h>
|
2014-12-18 22:49:37 +01:00
|
|
|
#include <MUtils/Taskbar7.h>
|
2010-11-06 23:04:47 +01:00
|
|
|
|
2014-11-25 02:14:42 +01:00
|
|
|
//Qt
|
2010-11-06 23:04:47 +01:00
|
|
|
#include <QThread>
|
|
|
|
#include <QMovie>
|
|
|
|
#include <QKeyEvent>
|
2012-02-23 17:00:22 +01:00
|
|
|
#include <QTimer>
|
2010-11-06 23:04:47 +01:00
|
|
|
|
2012-04-10 01:25:34 +02:00
|
|
|
#define FADE_DELAY 16
|
2013-10-28 00:27:29 +01:00
|
|
|
#define OPACITY_DELTA 0.04
|
2012-04-10 01:25:34 +02:00
|
|
|
|
2013-10-27 16:13:14 +01:00
|
|
|
//Setup taskbar indicator
|
2014-12-18 22:49:37 +01:00
|
|
|
#define SET_TASKBAR_STATE(WIDGET,FLAG) do \
|
2013-03-29 03:07:15 +01:00
|
|
|
{ \
|
2017-04-19 23:54:00 +02:00
|
|
|
const int _oldFlag = (WIDGET)->m_taskBarFlag.fetchAndStoreOrdered((FLAG) ? 1 : 0); \
|
|
|
|
if(_oldFlag != ((FLAG) ? 1 : 0)) \
|
2013-03-29 03:07:15 +01:00
|
|
|
{ \
|
2017-04-19 23:54:00 +02:00
|
|
|
(WIDGET)->m_taskbar->setTaskbarState((FLAG) ? MUtils::Taskbar7::TASKBAR_STATE_INTERMEDIATE : MUtils::Taskbar7::TASKBAR_STATE_NONE); \
|
2013-03-29 03:07:15 +01:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
while(0)
|
2012-04-26 13:43:40 +02:00
|
|
|
|
2010-11-06 23:04:47 +01:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// Constructor
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
SplashScreen::SplashScreen(QWidget *parent)
|
2012-03-23 01:29:50 +01:00
|
|
|
:
|
2014-12-18 22:49:37 +01:00
|
|
|
QFrame(parent, Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint),
|
|
|
|
ui(new Ui::SplashScreen),
|
2013-10-27 16:13:14 +01:00
|
|
|
m_opacitySteps(qRound(1.0 / OPACITY_DELTA)),
|
2014-12-18 22:49:37 +01:00
|
|
|
m_taskbar(new MUtils::Taskbar7(this))
|
2010-11-06 23:04:47 +01:00
|
|
|
{
|
|
|
|
//Init the dialog, from the .ui file
|
2014-12-18 22:49:37 +01:00
|
|
|
ui->setupUi(this);
|
2010-11-06 23:04:47 +01:00
|
|
|
|
2013-10-27 16:13:14 +01:00
|
|
|
//Make size fixed
|
2013-11-24 00:02:32 +01:00
|
|
|
setFixedSize(this->size());
|
|
|
|
|
2013-10-27 16:13:14 +01:00
|
|
|
//Create event loop
|
2014-12-18 22:49:37 +01:00
|
|
|
m_loop.reset(new QEventLoop(this));
|
2013-10-27 16:13:14 +01:00
|
|
|
|
|
|
|
//Create timer
|
2014-12-18 22:49:37 +01:00
|
|
|
m_timer.reset(new QTimer(this));
|
2013-10-27 16:13:14 +01:00
|
|
|
m_timer->setInterval(FADE_DELAY);
|
|
|
|
m_timer->setSingleShot(false);
|
|
|
|
|
|
|
|
//Connect timer to slot
|
2014-12-18 22:49:37 +01:00
|
|
|
connect(m_timer.data(), SIGNAL(timeout()), this, SLOT(updateHandler()));
|
2013-10-27 16:13:14 +01:00
|
|
|
|
2013-11-23 20:57:38 +01:00
|
|
|
//Enable "sheet of glass" effect on splash screen
|
2014-12-08 22:06:01 +01:00
|
|
|
if(!MUtils::GUI::sheet_of_glass(this))
|
2013-11-24 00:02:32 +01:00
|
|
|
{
|
|
|
|
setStyleSheet("background-image: url(:/images/Background.jpg)");
|
|
|
|
}
|
2013-11-23 20:57:38 +01:00
|
|
|
|
2010-11-06 23:04:47 +01:00
|
|
|
//Start animation
|
2014-12-18 22:49:37 +01:00
|
|
|
m_working.reset(new QMovie(":/images/Loading4.gif"));
|
2013-11-23 20:57:38 +01:00
|
|
|
m_working->setCacheMode(QMovie::CacheAll);
|
2014-12-18 22:49:37 +01:00
|
|
|
ui->labelLoading->setMovie(m_working.data());
|
2010-11-06 23:04:47 +01:00
|
|
|
m_working->start();
|
|
|
|
|
2013-10-27 16:13:14 +01:00
|
|
|
//Init status
|
|
|
|
m_status = STATUS_FADE_IN;
|
|
|
|
m_fadeValue = 0;
|
2010-11-06 23:04:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// Destructor
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
SplashScreen::~SplashScreen(void)
|
|
|
|
{
|
|
|
|
if(m_working)
|
|
|
|
{
|
|
|
|
m_working->stop();
|
|
|
|
}
|
2013-10-27 16:13:14 +01:00
|
|
|
|
2014-12-18 22:49:37 +01:00
|
|
|
delete ui;
|
2010-11-06 23:04:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// PUBLIC FUNCTIONS
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void SplashScreen::showSplash(QThread *thread)
|
|
|
|
{
|
2014-12-18 22:49:37 +01:00
|
|
|
QScopedPointer<SplashScreen> splashScreen(new SplashScreen());
|
2013-11-24 00:02:32 +01:00
|
|
|
|
2010-11-06 23:04:47 +01:00
|
|
|
//Show splash
|
2013-10-20 23:36:53 +02:00
|
|
|
splashScreen->setWindowOpacity(OPACITY_DELTA);
|
2010-11-06 23:04:47 +01:00
|
|
|
splashScreen->show();
|
2011-11-11 18:08:22 +01:00
|
|
|
|
2013-11-24 00:02:32 +01:00
|
|
|
//Set wait cursor
|
|
|
|
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
|
|
|
|
2011-11-11 18:08:22 +01:00
|
|
|
//Wait for window to show
|
2012-04-10 01:25:34 +02:00
|
|
|
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
|
2014-12-18 22:49:37 +01:00
|
|
|
splashScreen->repaint(); MUtils::GUI::bring_to_front(splashScreen.data());
|
2012-04-10 01:25:34 +02:00
|
|
|
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
|
2010-11-06 23:04:47 +01:00
|
|
|
|
2013-10-27 16:13:14 +01:00
|
|
|
//Connect thread signals
|
2014-12-18 22:49:37 +01:00
|
|
|
connect(thread, SIGNAL(terminated()), splashScreen.data(), SLOT(threadComplete()), Qt::QueuedConnection);
|
|
|
|
connect(thread, SIGNAL(finished()), splashScreen.data(), SLOT(threadComplete()), Qt::QueuedConnection);
|
2011-11-11 18:08:22 +01:00
|
|
|
|
|
|
|
//Init taskbar
|
2014-12-18 22:49:37 +01:00
|
|
|
SET_TASKBAR_STATE(splashScreen, true);
|
2010-11-06 23:04:47 +01:00
|
|
|
|
2013-10-27 16:13:14 +01:00
|
|
|
//Start the thread
|
|
|
|
splashScreen->m_timer->start(FADE_DELAY);
|
2014-12-18 22:49:37 +01:00
|
|
|
QTimer::singleShot(8*60*1000, splashScreen->m_loop.data(), SLOT(quit()));
|
2013-11-24 00:02:32 +01:00
|
|
|
QTimer::singleShot(333, thread, SLOT(start()));
|
2012-03-22 22:26:54 +01:00
|
|
|
|
2013-10-27 16:13:14 +01:00
|
|
|
//Start event handling!
|
|
|
|
const int ret = splashScreen->m_loop->exec(QEventLoop::ExcludeUserInputEvents);
|
2012-02-23 21:21:02 +01:00
|
|
|
|
2013-10-27 16:13:14 +01:00
|
|
|
//Check for timeout
|
|
|
|
if(ret != 42)
|
2010-11-06 23:04:47 +01:00
|
|
|
{
|
2013-10-27 16:13:14 +01:00
|
|
|
thread->terminate();
|
|
|
|
qFatal("Deadlock in initialization thread encountered!");
|
2010-11-06 23:04:47 +01:00
|
|
|
}
|
|
|
|
|
2011-11-07 17:13:41 +01:00
|
|
|
//Restore taskbar
|
2014-12-18 22:49:37 +01:00
|
|
|
SET_TASKBAR_STATE(splashScreen, false);
|
2011-11-07 17:13:41 +01:00
|
|
|
|
2013-11-24 00:02:32 +01:00
|
|
|
//Restore cursor
|
|
|
|
QApplication::restoreOverrideCursor();
|
|
|
|
|
2010-11-06 23:04:47 +01:00
|
|
|
//Hide splash
|
2017-04-19 23:54:00 +02:00
|
|
|
splashScreen->m_canClose.ref();
|
2010-11-06 23:04:47 +01:00
|
|
|
splashScreen->close();
|
|
|
|
}
|
|
|
|
|
2013-10-27 16:13:14 +01:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// SLOTS
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void SplashScreen::updateHandler(void)
|
|
|
|
{
|
|
|
|
if(m_status == STATUS_FADE_IN)
|
|
|
|
{
|
|
|
|
if(m_fadeValue < m_opacitySteps)
|
|
|
|
{
|
|
|
|
setWindowOpacity(OPACITY_DELTA * static_cast<double>(++m_fadeValue));
|
2014-12-18 22:49:37 +01:00
|
|
|
SET_TASKBAR_STATE(this, true);
|
2013-10-27 16:13:14 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setWindowOpacity(1.0);
|
2014-12-08 22:06:01 +01:00
|
|
|
MUtils::GUI::bring_to_front(this);
|
2013-10-27 16:13:14 +01:00
|
|
|
m_timer->stop();
|
|
|
|
m_status = STATUS_WAIT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(m_status == STATUS_FADE_OUT)
|
|
|
|
{
|
|
|
|
if(m_fadeValue > 0)
|
|
|
|
{
|
|
|
|
setWindowOpacity(OPACITY_DELTA * static_cast<double>(--m_fadeValue));
|
2014-12-18 22:49:37 +01:00
|
|
|
SET_TASKBAR_STATE(this, true);
|
2013-10-27 16:13:14 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setWindowOpacity(0.0);
|
|
|
|
m_timer->stop();
|
|
|
|
m_status = STATUS_DONE;
|
|
|
|
m_loop->exit(42);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SplashScreen::threadComplete(void)
|
|
|
|
{
|
|
|
|
m_status = STATUS_FADE_OUT;
|
|
|
|
if(!m_timer->isActive())
|
|
|
|
{
|
|
|
|
m_timer->start(FADE_DELAY);
|
|
|
|
}
|
2014-12-08 22:06:01 +01:00
|
|
|
MUtils::GUI::bring_to_front(this);
|
2013-10-27 16:13:14 +01:00
|
|
|
}
|
|
|
|
|
2010-11-06 23:04:47 +01:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// EVENTS
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void SplashScreen::keyPressEvent(QKeyEvent *event)
|
|
|
|
{
|
|
|
|
event->ignore();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SplashScreen::keyReleaseEvent(QKeyEvent *event)
|
|
|
|
{
|
|
|
|
event->ignore();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SplashScreen::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
2011-12-29 14:42:20 +01:00
|
|
|
if(!m_canClose) event->ignore();
|
2010-11-06 23:04:47 +01:00
|
|
|
}
|