1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2012 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.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
22 #include "Dialog_SplashScreen.h"
31 #include "WinSevenTaskbar.h"
34 #define OPACITY_DELTA 0.02
36 #define THREAD_RUNNING(THRD) (((THRD)->isRunning()) ? (!((THRD)->wait(50))) : false)
38 ////////////////////////////////////////////////////////////
40 ////////////////////////////////////////////////////////////
42 SplashScreen::SplashScreen(QWidget *parent)
44 QFrame(parent, Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint)
46 //Init the dialog, from the .ui file
50 m_working = new QMovie(":/images/Loading.gif");
51 labelLoading->setMovie(m_working);
55 setCursor(Qt::WaitCursor);
61 ////////////////////////////////////////////////////////////
63 ////////////////////////////////////////////////////////////
65 SplashScreen::~SplashScreen(void)
75 ////////////////////////////////////////////////////////////
77 ////////////////////////////////////////////////////////////
79 void SplashScreen::showSplash(QThread *thread)
81 double opacity = OPACITY_DELTA;
82 const int opacitySteps = qRound(1.0 / OPACITY_DELTA);
83 SplashScreen *splashScreen = new SplashScreen();
86 splashScreen->m_canClose = false;
87 splashScreen->setWindowOpacity(opacity);
88 splashScreen->setFixedSize(splashScreen->size());
91 //Wait for window to show
92 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
93 splashScreen->repaint();
94 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
96 //Setup the event loop
97 QEventLoop *loop = new QEventLoop(splashScreen);
98 connect(thread, SIGNAL(terminated()), loop, SLOT(quit()), Qt::QueuedConnection);
99 connect(thread, SIGNAL(finished()), loop, SLOT(quit()), Qt::QueuedConnection);
102 QTimer *timer = new QTimer();
103 connect(timer, SIGNAL(timeout()), loop, SLOT(quit()));
106 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
108 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
111 WinSevenTaskbar::setTaskbarState(splashScreen, WinSevenTaskbar::WinSevenTaskbarIndeterminateState);
114 for(int i = 1; i <= opacitySteps; i++)
116 opacity = OPACITY_DELTA * static_cast<double>(i);
117 splashScreen->setWindowOpacity(opacity);
118 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents, FADE_DELAY);
125 //Loop while thread is still running
126 if(bool bIsRunning = THREAD_RUNNING(thread))
131 if(bIsRunning = THREAD_RUNNING(thread))
133 qWarning("Potential deadlock in initialization thread!");
142 for(int i = opacitySteps; i >= 0; i--)
144 opacity = OPACITY_DELTA * static_cast<double>(i);
145 splashScreen->setWindowOpacity(opacity);
146 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents, FADE_DELAY);
151 WinSevenTaskbar::setTaskbarState(splashScreen, WinSevenTaskbar::WinSevenTaskbarNoState);
154 splashScreen->m_canClose = true;
155 splashScreen->close();
159 LAMEXP_DELETE(timer);
160 LAMEXP_DELETE(splashScreen);
163 ////////////////////////////////////////////////////////////
165 ////////////////////////////////////////////////////////////
167 void SplashScreen::keyPressEvent(QKeyEvent *event)
172 void SplashScreen::keyReleaseEvent(QKeyEvent *event)
177 void SplashScreen::closeEvent(QCloseEvent *event)
179 if(!m_canClose) event->ignore();
182 bool SplashScreen::winEvent(MSG *message, long *result)
184 return WinSevenTaskbar::handleWinEvent(message, result);