1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version, but always including the *additional*
9 // restrictions defined in the "License.txt" file.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this program; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // http://www.gnu.org/licenses/gpl-2.0.txt
21 ///////////////////////////////////////////////////////////////////////////////
23 #include "Dialog_SplashScreen.h"
27 #include "WinSevenTaskbar.h"
30 #include <MUtils/Global.h>
31 #include <MUtils/GUI.h>
40 #define OPACITY_DELTA 0.04
42 //Setup taskbar indicator
43 #define SET_TASKBAR_STATE(WIDGET,VAR,FLAG) do \
47 if(!(VAR)) (VAR) = WinSevenTaskbar::setTaskbarState((WIDGET), WinSevenTaskbar::WinSevenTaskbarIndeterminateState); \
51 if((VAR)) (VAR) = (!WinSevenTaskbar::setTaskbarState((WIDGET), WinSevenTaskbar::WinSevenTaskbarNoState)); \
56 ////////////////////////////////////////////////////////////
58 ////////////////////////////////////////////////////////////
60 SplashScreen::SplashScreen(QWidget *parent)
62 m_opacitySteps(qRound(1.0 / OPACITY_DELTA)),
63 QFrame(parent, Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint)
65 //Init the dialog, from the .ui file
69 setFixedSize(this->size());
72 m_loop = new QEventLoop(this);
75 m_timer = new QTimer(this);
76 m_timer->setInterval(FADE_DELAY);
77 m_timer->setSingleShot(false);
79 //Connect timer to slot
80 connect(m_timer, SIGNAL(timeout()), this, SLOT(updateHandler()));
82 //Enable "sheet of glass" effect on splash screen
83 if(!MUtils::GUI::sheet_of_glass(this))
85 setStyleSheet("background-image: url(:/images/Background.jpg)");
89 m_working = new QMovie(":/images/Loading4.gif");
90 m_working->setCacheMode(QMovie::CacheAll);
91 labelLoading->setMovie(m_working);
96 m_status = STATUS_FADE_IN;
98 m_taskBarInit = false;
101 ////////////////////////////////////////////////////////////
103 ////////////////////////////////////////////////////////////
105 SplashScreen::~SplashScreen(void)
112 MUTILS_DELETE(m_working);
113 MUTILS_DELETE(m_loop);
114 MUTILS_DELETE(m_timer);
117 ////////////////////////////////////////////////////////////
119 ////////////////////////////////////////////////////////////
121 void SplashScreen::showSplash(QThread *thread)
123 SplashScreen *splashScreen = new SplashScreen();
126 splashScreen->setWindowOpacity(OPACITY_DELTA);
127 splashScreen->show();
130 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
132 //Wait for window to show
133 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
134 splashScreen->repaint(); MUtils::GUI::bring_to_front(splashScreen);
135 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
137 //Connect thread signals
138 connect(thread, SIGNAL(terminated()), splashScreen, SLOT(threadComplete()), Qt::QueuedConnection);
139 connect(thread, SIGNAL(finished()), splashScreen, SLOT(threadComplete()), Qt::QueuedConnection);
142 SET_TASKBAR_STATE(splashScreen, splashScreen->m_taskBarInit, true);
145 splashScreen->m_timer->start(FADE_DELAY);
146 QTimer::singleShot(8*60*1000, splashScreen->m_loop, SLOT(quit()));
147 QTimer::singleShot(333, thread, SLOT(start()));
149 //Start event handling!
150 const int ret = splashScreen->m_loop->exec(QEventLoop::ExcludeUserInputEvents);
156 qFatal("Deadlock in initialization thread encountered!");
160 SET_TASKBAR_STATE(splashScreen, splashScreen->m_taskBarInit, false);
163 QApplication::restoreOverrideCursor();
166 splashScreen->m_canClose = true;
167 splashScreen->close();
170 MUTILS_DELETE(splashScreen);
173 ////////////////////////////////////////////////////////////
175 ////////////////////////////////////////////////////////////
177 void SplashScreen::updateHandler(void)
179 if(m_status == STATUS_FADE_IN)
181 if(m_fadeValue < m_opacitySteps)
183 setWindowOpacity(OPACITY_DELTA * static_cast<double>(++m_fadeValue));
184 SET_TASKBAR_STATE(this, m_taskBarInit, true);
188 setWindowOpacity(1.0);
189 MUtils::GUI::bring_to_front(this);
191 m_status = STATUS_WAIT;
194 else if(m_status == STATUS_FADE_OUT)
198 setWindowOpacity(OPACITY_DELTA * static_cast<double>(--m_fadeValue));
199 SET_TASKBAR_STATE(this, m_taskBarInit, true);
203 setWindowOpacity(0.0);
205 m_status = STATUS_DONE;
211 void SplashScreen::threadComplete(void)
213 m_status = STATUS_FADE_OUT;
214 if(!m_timer->isActive())
216 m_timer->start(FADE_DELAY);
218 MUtils::GUI::bring_to_front(this);
221 ////////////////////////////////////////////////////////////
223 ////////////////////////////////////////////////////////////
225 void SplashScreen::keyPressEvent(QKeyEvent *event)
230 void SplashScreen::keyReleaseEvent(QKeyEvent *event)
235 void SplashScreen::closeEvent(QCloseEvent *event)
237 if(!m_canClose) event->ignore();
240 bool SplashScreen::winEvent(MSG *message, long *result)
242 return WinSevenTaskbar::handleWinEvent(message, result);