OSDN Git Service

Clean up #include directives: Don't include 'Windows.h' directly, as it's included...
[lamexp/LameXP.git] / src / Dialog_SplashScreen.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2011 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
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.
9 //
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.
14 //
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.
18 //
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
21
22 #include "Dialog_SplashScreen.h"
23
24 #include "Global.h"
25
26 #include <QThread>
27 #include <QMovie>
28 #include <QKeyEvent>
29
30 #define EPS (1.0E-5)
31
32 ////////////////////////////////////////////////////////////
33 // Constructor
34 ////////////////////////////////////////////////////////////
35
36 SplashScreen::SplashScreen(QWidget *parent)
37         : QFrame(parent, Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint)
38 {
39         //Init the dialog, from the .ui file
40         setupUi(this);
41
42         //Start animation
43         m_working = new QMovie(":/images/Loading.gif");
44         labelLoading->setMovie(m_working);
45         m_working->start();
46
47         //Set wait cursor
48         setCursor(Qt::WaitCursor);
49
50         //Prevent close
51         m_canClose = false;
52 }
53
54 ////////////////////////////////////////////////////////////
55 // Destructor
56 ////////////////////////////////////////////////////////////
57
58 SplashScreen::~SplashScreen(void)
59 {
60         if(m_working)
61         {
62                 m_working->stop();
63                 delete m_working;
64                 m_working = NULL;
65         }
66 }
67
68 ////////////////////////////////////////////////////////////
69 // PUBLIC FUNCTIONS
70 ////////////////////////////////////////////////////////////
71
72 void SplashScreen::showSplash(QThread *thread)
73 {
74         SplashScreen *splashScreen = new SplashScreen();
75         
76         //Show splash
77         splashScreen->m_canClose = false;
78         splashScreen->setWindowOpacity(0.0);
79         splashScreen->show();
80         QApplication::processEvents();
81
82         //Start the thread
83         thread->start();
84         
85         //Fade in
86         for(double d = 0.0; d <= 1.0 + EPS; d = d + 0.01)
87         {
88                 splashScreen->setWindowOpacity(d);
89                 QApplication::processEvents();
90                 Sleep(6);
91         }
92
93         //Loop while thread is running
94         while(thread->isRunning())
95         {
96                 QApplication::processEvents(QEventLoop::AllEvents | QEventLoop::WaitForMoreEvents);
97         }
98         
99         //Fade out
100         for(double d = 1.0; d >= 0.0; d = d - 0.01)
101         {
102                 splashScreen->setWindowOpacity(d);
103                 QApplication::processEvents();
104                 Sleep(6);
105         }
106
107         //Hide splash
108         splashScreen->m_canClose = true;
109         splashScreen->close();
110
111         LAMEXP_DELETE(splashScreen);
112 }
113
114 ////////////////////////////////////////////////////////////
115 // EVENTS
116 ////////////////////////////////////////////////////////////
117
118 void SplashScreen::keyPressEvent(QKeyEvent *event)
119 {
120         event->ignore();
121 }
122
123 void SplashScreen::keyReleaseEvent(QKeyEvent *event)
124 {
125         event->ignore();
126 }
127
128 void SplashScreen::closeEvent(QCloseEvent *event)
129 {
130         if(!m_canClose) event->ignore();
131 }