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 /* 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. */
37 /* For this reason the macro will first check the 'isRunning' flag. If (and only if) the flag still returns TRUE, then we will wait() for at most 50 ms. */
38 /* If, after 50 ms, the wait() function returns with FALSE, then the thread probably is still running and we return TRUE. Otherwise we can return FALSE. */
39 #define THREAD_RUNNING(THRD) (((THRD)->isRunning()) ? (!((THRD)->wait(50))) : false)
42 ////////////////////////////////////////////////////////////
44 ////////////////////////////////////////////////////////////
46 SplashScreen::SplashScreen(QWidget
*parent
)
48 QFrame(parent
, Qt::CustomizeWindowHint
| Qt::WindowStaysOnTopHint
)
50 //Init the dialog, from the .ui file
54 m_working
= new QMovie(":/images/Loading.gif");
55 labelLoading
->setMovie(m_working
);
59 setCursor(Qt::WaitCursor
);
65 ////////////////////////////////////////////////////////////
67 ////////////////////////////////////////////////////////////
69 SplashScreen::~SplashScreen(void)
79 ////////////////////////////////////////////////////////////
81 ////////////////////////////////////////////////////////////
83 void SplashScreen::showSplash(QThread
*thread
)
85 double opacity
= OPACITY_DELTA
;
86 const int opacitySteps
= qRound(1.0 / OPACITY_DELTA
);
87 SplashScreen
*splashScreen
= new SplashScreen();
90 splashScreen
->m_canClose
= false;
91 splashScreen
->setWindowOpacity(opacity
);
92 splashScreen
->setFixedSize(splashScreen
->size());
95 //Wait for window to show
96 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents
);
97 splashScreen
->repaint();
98 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents
);
100 //Setup the event loop
101 QEventLoop
*loop
= new QEventLoop(splashScreen
);
102 connect(thread
, SIGNAL(terminated()), loop
, SLOT(quit()), Qt::QueuedConnection
);
103 connect(thread
, SIGNAL(finished()), loop
, SLOT(quit()), Qt::QueuedConnection
);
106 QTimer
*timer
= new QTimer();
107 connect(timer
, SIGNAL(timeout()), loop
, SLOT(quit()));
110 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents
);
112 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents
);
115 WinSevenTaskbar::setTaskbarState(splashScreen
, WinSevenTaskbar::WinSevenTaskbarIndeterminateState
);
118 for(int i
= 1; i
<= opacitySteps
; i
++)
120 opacity
= OPACITY_DELTA
* static_cast<double>(i
);
121 splashScreen
->setWindowOpacity(opacity
);
122 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents
, FADE_DELAY
);
129 //Loop while thread is still running
130 if(bool bIsRunning
= THREAD_RUNNING(thread
))
135 if(bIsRunning
= THREAD_RUNNING(thread
))
137 qWarning("Potential deadlock in initialization thread!");
146 for(int i
= opacitySteps
; i
>= 0; i
--)
148 opacity
= OPACITY_DELTA
* static_cast<double>(i
);
149 splashScreen
->setWindowOpacity(opacity
);
150 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents
, FADE_DELAY
);
155 WinSevenTaskbar::setTaskbarState(splashScreen
, WinSevenTaskbar::WinSevenTaskbarNoState
);
158 splashScreen
->m_canClose
= true;
159 splashScreen
->close();
163 LAMEXP_DELETE(timer
);
164 LAMEXP_DELETE(splashScreen
);
167 ////////////////////////////////////////////////////////////
169 ////////////////////////////////////////////////////////////
171 void SplashScreen::keyPressEvent(QKeyEvent
*event
)
176 void SplashScreen::keyReleaseEvent(QKeyEvent
*event
)
181 void SplashScreen::closeEvent(QCloseEvent
*event
)
183 if(!m_canClose
) event
->ignore();
186 bool SplashScreen::winEvent(MSG
*message
, long *result
)
188 return WinSevenTaskbar::handleWinEvent(message
, result
);