1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2015 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"
26 #include "UIC_SplashScreen.h"
32 #include <MUtils/Global.h>
33 #include <MUtils/GUI.h>
34 #include <MUtils/Taskbar7.h>
43 #define OPACITY_DELTA 0.04
45 //Setup taskbar indicator
46 #define SET_TASKBAR_STATE(WIDGET,FLAG) do \
48 if((WIDGET)->m_taskBarFlag != (FLAG)) \
50 if((WIDGET)->m_taskbar->setTaskbarState((FLAG) ? MUtils::Taskbar7::TASKBAR_STATE_INTERMEDIATE : MUtils::Taskbar7::TASKBAR_STATE_NONE)) \
52 (WIDGET)->m_taskBarFlag = (FLAG); \
58 ////////////////////////////////////////////////////////////
60 ////////////////////////////////////////////////////////////
62 SplashScreen::SplashScreen(QWidget
*parent
)
64 QFrame(parent
, Qt::CustomizeWindowHint
| Qt::WindowStaysOnTopHint
),
65 ui(new Ui::SplashScreen
),
66 m_opacitySteps(qRound(1.0 / OPACITY_DELTA
)),
67 m_taskbar(new MUtils::Taskbar7(this))
69 //Init the dialog, from the .ui file
73 setFixedSize(this->size());
76 m_loop
.reset(new QEventLoop(this));
79 m_timer
.reset(new QTimer(this));
80 m_timer
->setInterval(FADE_DELAY
);
81 m_timer
->setSingleShot(false);
83 //Connect timer to slot
84 connect(m_timer
.data(), SIGNAL(timeout()), this, SLOT(updateHandler()));
86 //Enable "sheet of glass" effect on splash screen
87 if(!MUtils::GUI::sheet_of_glass(this))
89 setStyleSheet("background-image: url(:/images/Background.jpg)");
93 m_working
.reset(new QMovie(":/images/Loading4.gif"));
94 m_working
->setCacheMode(QMovie::CacheAll
);
95 ui
->labelLoading
->setMovie(m_working
.data());
100 m_status
= STATUS_FADE_IN
;
102 m_taskBarFlag
= false;
105 ////////////////////////////////////////////////////////////
107 ////////////////////////////////////////////////////////////
109 SplashScreen::~SplashScreen(void)
119 ////////////////////////////////////////////////////////////
121 ////////////////////////////////////////////////////////////
123 void SplashScreen::showSplash(QThread
*thread
)
125 QScopedPointer
<SplashScreen
> splashScreen(new SplashScreen());
128 splashScreen
->setWindowOpacity(OPACITY_DELTA
);
129 splashScreen
->show();
132 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor
));
134 //Wait for window to show
135 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents
);
136 splashScreen
->repaint(); MUtils::GUI::bring_to_front(splashScreen
.data());
137 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents
);
139 //Connect thread signals
140 connect(thread
, SIGNAL(terminated()), splashScreen
.data(), SLOT(threadComplete()), Qt::QueuedConnection
);
141 connect(thread
, SIGNAL(finished()), splashScreen
.data(), SLOT(threadComplete()), Qt::QueuedConnection
);
144 SET_TASKBAR_STATE(splashScreen
, true);
147 splashScreen
->m_timer
->start(FADE_DELAY
);
148 QTimer::singleShot(8*60*1000, splashScreen
->m_loop
.data(), SLOT(quit()));
149 QTimer::singleShot(333, thread
, SLOT(start()));
151 //Start event handling!
152 const int ret
= splashScreen
->m_loop
->exec(QEventLoop::ExcludeUserInputEvents
);
158 qFatal("Deadlock in initialization thread encountered!");
162 SET_TASKBAR_STATE(splashScreen
, false);
165 QApplication::restoreOverrideCursor();
168 splashScreen
->m_canClose
= true;
169 splashScreen
->close();
172 ////////////////////////////////////////////////////////////
174 ////////////////////////////////////////////////////////////
176 void SplashScreen::updateHandler(void)
178 if(m_status
== STATUS_FADE_IN
)
180 if(m_fadeValue
< m_opacitySteps
)
182 setWindowOpacity(OPACITY_DELTA
* static_cast<double>(++m_fadeValue
));
183 SET_TASKBAR_STATE(this, true);
187 setWindowOpacity(1.0);
188 MUtils::GUI::bring_to_front(this);
190 m_status
= STATUS_WAIT
;
193 else if(m_status
== STATUS_FADE_OUT
)
197 setWindowOpacity(OPACITY_DELTA
* static_cast<double>(--m_fadeValue
));
198 SET_TASKBAR_STATE(this, true);
202 setWindowOpacity(0.0);
204 m_status
= STATUS_DONE
;
210 void SplashScreen::threadComplete(void)
212 m_status
= STATUS_FADE_OUT
;
213 if(!m_timer
->isActive())
215 m_timer
->start(FADE_DELAY
);
217 MUtils::GUI::bring_to_front(this);
220 ////////////////////////////////////////////////////////////
222 ////////////////////////////////////////////////////////////
224 void SplashScreen::keyPressEvent(QKeyEvent
*event
)
229 void SplashScreen::keyReleaseEvent(QKeyEvent
*event
)
234 void SplashScreen::closeEvent(QCloseEvent
*event
)
236 if(!m_canClose
) event
->ignore();