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->size());
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()));
78 m_working = new QMovie(":/images/Loading.gif");
79 labelLoading->setMovie(m_working);
83 setCursor(Qt::WaitCursor);
87 m_status = STATUS_FADE_IN;
89 m_taskBarInit = false;
92 ////////////////////////////////////////////////////////////
94 ////////////////////////////////////////////////////////////
96 SplashScreen::~SplashScreen(void)
103 LAMEXP_DELETE(m_working);
104 LAMEXP_DELETE(m_loop);
105 LAMEXP_DELETE(m_timer);
108 ////////////////////////////////////////////////////////////
110 ////////////////////////////////////////////////////////////
112 void SplashScreen::showSplash(QThread *thread)
114 SplashScreen *splashScreen = new SplashScreen();
117 splashScreen->setWindowOpacity(OPACITY_DELTA);
118 splashScreen->show();
120 //Wait for window to show
121 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
122 splashScreen->repaint();
123 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
125 //Connect thread signals
126 connect(thread, SIGNAL(terminated()), splashScreen, SLOT(threadComplete()), Qt::QueuedConnection);
127 connect(thread, SIGNAL(finished()), splashScreen, SLOT(threadComplete()), Qt::QueuedConnection);
130 SET_TASKBAR_STATE(splashScreen, splashScreen->m_taskBarInit, true);
133 splashScreen->m_timer->start(FADE_DELAY);
134 QTimer::singleShot(8*60*1000, splashScreen->m_loop, SLOT(quit()));
135 QTimer::singleShot(0, thread, SLOT(start()));
137 //Start event handling!
138 const int ret = splashScreen->m_loop->exec(QEventLoop::ExcludeUserInputEvents);
144 qFatal("Deadlock in initialization thread encountered!");
148 SET_TASKBAR_STATE(splashScreen, splashScreen->m_taskBarInit, false);
151 splashScreen->m_canClose = true;
152 splashScreen->close();
155 LAMEXP_DELETE(splashScreen);
158 ////////////////////////////////////////////////////////////
160 ////////////////////////////////////////////////////////////
162 void SplashScreen::updateHandler(void)
164 if(m_status == STATUS_FADE_IN)
166 if(m_fadeValue < m_opacitySteps)
168 setWindowOpacity(OPACITY_DELTA * static_cast<double>(++m_fadeValue));
169 SET_TASKBAR_STATE(this, m_taskBarInit, true);
173 setWindowOpacity(1.0);
175 m_status = STATUS_WAIT;
178 else if(m_status == STATUS_FADE_OUT)
182 setWindowOpacity(OPACITY_DELTA * static_cast<double>(--m_fadeValue));
183 SET_TASKBAR_STATE(this, m_taskBarInit, true);
187 setWindowOpacity(0.0);
189 m_status = STATUS_DONE;
195 void SplashScreen::threadComplete(void)
197 m_status = STATUS_FADE_OUT;
198 if(!m_timer->isActive())
200 m_timer->start(FADE_DELAY);
204 ////////////////////////////////////////////////////////////
206 ////////////////////////////////////////////////////////////
208 void SplashScreen::keyPressEvent(QKeyEvent *event)
213 void SplashScreen::keyReleaseEvent(QKeyEvent *event)
218 void SplashScreen::closeEvent(QCloseEvent *event)
220 if(!m_canClose) event->ignore();
223 bool SplashScreen::winEvent(MSG *message, long *result)
225 return WinSevenTaskbar::handleWinEvent(message, result);