1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2013 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"
32 #include "WinSevenTaskbar.h"
35 #define OPACITY_DELTA 0.04
37 //Setup taskbar indicator
38 #define SET_TASKBAR_STATE(WIDGET,VAR,FLAG) do \
42 if(!(VAR)) (VAR) = WinSevenTaskbar::setTaskbarState((WIDGET), WinSevenTaskbar::WinSevenTaskbarIndeterminateState); \
46 if((VAR)) (VAR) = (!WinSevenTaskbar::setTaskbarState((WIDGET), WinSevenTaskbar::WinSevenTaskbarNoState)); \
51 ////////////////////////////////////////////////////////////
53 ////////////////////////////////////////////////////////////
55 SplashScreen::SplashScreen(QWidget *parent)
57 m_opacitySteps(qRound(1.0 / OPACITY_DELTA)),
58 QFrame(parent, Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint)
60 //Init the dialog, from the .ui file
64 setFixedSize(this->maximumSize());
67 m_loop = new QEventLoop(this);
70 m_timer = new QTimer(this);
71 m_timer->setInterval(FADE_DELAY);
72 m_timer->setSingleShot(false);
74 //Connect timer to slot
75 connect(m_timer, SIGNAL(timeout()), this, SLOT(updateHandler()));
77 //Enable "sheet of glass" effect on splash screen
78 lamexp_sheet_of_glass(this);
81 m_working = new QMovie(":/images/Loading4.gif");
82 m_working->setCacheMode(QMovie::CacheAll);
83 labelLoading->setMovie(m_working);
87 setCursor(Qt::WaitCursor);
91 m_status = STATUS_FADE_IN;
93 m_taskBarInit = false;
96 ////////////////////////////////////////////////////////////
98 ////////////////////////////////////////////////////////////
100 SplashScreen::~SplashScreen(void)
107 LAMEXP_DELETE(m_working);
108 LAMEXP_DELETE(m_loop);
109 LAMEXP_DELETE(m_timer);
112 ////////////////////////////////////////////////////////////
114 ////////////////////////////////////////////////////////////
116 void SplashScreen::showSplash(QThread *thread)
118 SplashScreen *splashScreen = new SplashScreen();
121 splashScreen->setWindowOpacity(OPACITY_DELTA);
122 splashScreen->show();
124 //Wait for window to show
125 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
126 splashScreen->repaint();
127 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
129 //Connect thread signals
130 connect(thread, SIGNAL(terminated()), splashScreen, SLOT(threadComplete()), Qt::QueuedConnection);
131 connect(thread, SIGNAL(finished()), splashScreen, SLOT(threadComplete()), Qt::QueuedConnection);
134 SET_TASKBAR_STATE(splashScreen, splashScreen->m_taskBarInit, true);
137 splashScreen->m_timer->start(FADE_DELAY);
138 QTimer::singleShot(8*60*1000, splashScreen->m_loop, SLOT(quit()));
139 QTimer::singleShot(0, thread, SLOT(start()));
141 //Start event handling!
142 const int ret = splashScreen->m_loop->exec(QEventLoop::ExcludeUserInputEvents);
148 qFatal("Deadlock in initialization thread encountered!");
152 SET_TASKBAR_STATE(splashScreen, splashScreen->m_taskBarInit, false);
155 splashScreen->m_canClose = true;
156 splashScreen->close();
159 LAMEXP_DELETE(splashScreen);
162 ////////////////////////////////////////////////////////////
164 ////////////////////////////////////////////////////////////
166 void SplashScreen::updateHandler(void)
168 if(m_status == STATUS_FADE_IN)
170 if(m_fadeValue < m_opacitySteps)
172 setWindowOpacity(OPACITY_DELTA * static_cast<double>(++m_fadeValue));
173 SET_TASKBAR_STATE(this, m_taskBarInit, true);
177 setWindowOpacity(1.0);
179 m_status = STATUS_WAIT;
182 else if(m_status == STATUS_FADE_OUT)
186 setWindowOpacity(OPACITY_DELTA * static_cast<double>(--m_fadeValue));
187 SET_TASKBAR_STATE(this, m_taskBarInit, true);
191 setWindowOpacity(0.0);
193 m_status = STATUS_DONE;
199 void SplashScreen::threadComplete(void)
201 m_status = STATUS_FADE_OUT;
202 if(!m_timer->isActive())
204 m_timer->start(FADE_DELAY);
208 ////////////////////////////////////////////////////////////
210 ////////////////////////////////////////////////////////////
212 void SplashScreen::keyPressEvent(QKeyEvent *event)
217 void SplashScreen::keyReleaseEvent(QKeyEvent *event)
222 void SplashScreen::closeEvent(QCloseEvent *event)
224 if(!m_canClose) event->ignore();
227 bool SplashScreen::winEvent(MSG *message, long *result)
229 return WinSevenTaskbar::handleWinEvent(message, result);