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);
90 //Wait for window to show
91 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
92 splashScreen->repaint();
93 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
95 //Setup the event loop
96 QEventLoop *loop = new QEventLoop(splashScreen);
97 connect(thread, SIGNAL(terminated()), loop, SLOT(quit()), Qt::QueuedConnection);
98 connect(thread, SIGNAL(finished()), loop, SLOT(quit()), Qt::QueuedConnection);
101 QTimer *timer = new QTimer();
102 connect(timer, SIGNAL(timeout()), loop, SLOT(quit()));
105 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
107 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
110 WinSevenTaskbar::setTaskbarState(splashScreen, WinSevenTaskbar::WinSevenTaskbarIndeterminateState);
113 for(int i = 1; i <= opacitySteps; i++)
115 opacity = OPACITY_DELTA * static_cast<double>(i);
116 splashScreen->setWindowOpacity(opacity);
117 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents, FADE_DELAY);
124 //Loop while thread is still running
125 if(bool bIsRunning = THREAD_RUNNING(thread))
130 if(bIsRunning = THREAD_RUNNING(thread))
132 qWarning("Potential deadlock in initialization thread!");
141 for(int i = opacitySteps; i >= 0; i--)
143 opacity = OPACITY_DELTA * static_cast<double>(i);
144 splashScreen->setWindowOpacity(opacity);
145 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents, FADE_DELAY);
150 WinSevenTaskbar::setTaskbarState(splashScreen, WinSevenTaskbar::WinSevenTaskbarNoState);
153 splashScreen->m_canClose = true;
154 splashScreen->close();
158 LAMEXP_DELETE(timer);
159 LAMEXP_DELETE(splashScreen);
162 ////////////////////////////////////////////////////////////
164 ////////////////////////////////////////////////////////////
166 void SplashScreen::keyPressEvent(QKeyEvent *event)
171 void SplashScreen::keyReleaseEvent(QKeyEvent *event)
176 void SplashScreen::closeEvent(QCloseEvent *event)
178 if(!m_canClose) event->ignore();
181 bool SplashScreen::winEvent(MSG *message, long *result)
183 return WinSevenTaskbar::handleWinEvent(message, result);