OSDN Git Service

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