OSDN Git Service

Implemented a more correct way to initialize the ITaskbarList3 interface. We now...
[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 #include "WinSevenTaskbar.h"
31
32 #define EPS (1.0E-5)
33
34 ////////////////////////////////////////////////////////////
35 // Constructor
36 ////////////////////////////////////////////////////////////
37
38 SplashScreen::SplashScreen(QWidget *parent)
39         : QFrame(parent, Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint)
40 {
41         //Init the dialog, from the .ui file
42         setupUi(this);
43
44         //Start animation
45         m_working = new QMovie(":/images/Loading.gif");
46         labelLoading->setMovie(m_working);
47         m_working->start();
48
49         //Set wait cursor
50         setCursor(Qt::WaitCursor);
51
52         //Prevent close
53         m_canClose = false;
54 }
55
56 ////////////////////////////////////////////////////////////
57 // Destructor
58 ////////////////////////////////////////////////////////////
59
60 SplashScreen::~SplashScreen(void)
61 {
62         if(m_working)
63         {
64                 m_working->stop();
65                 delete m_working;
66                 m_working = NULL;
67         }
68 }
69
70 ////////////////////////////////////////////////////////////
71 // PUBLIC FUNCTIONS
72 ////////////////////////////////////////////////////////////
73
74 void SplashScreen::showSplash(QThread *thread)
75 {
76         SplashScreen *splashScreen = new SplashScreen();
77         
78         //Show splash
79         splashScreen->m_canClose = false;
80         splashScreen->setWindowOpacity(0.0);
81         splashScreen->show();
82         QApplication::processEvents();
83
84         //Setup event loop
85         QEventLoop *loop = new QEventLoop(splashScreen);
86         connect(thread, SIGNAL(terminated()), loop, SLOT(quit()), Qt::QueuedConnection);
87         connect(thread, SIGNAL(finished()), loop, SLOT(quit()), Qt::QueuedConnection);
88
89         //Start the thread
90         thread->start();
91         bool flag = false;
92
93         //Fade in
94         for(double d = 0.0; d <= 1.0 + EPS; d = d + 0.01)
95         {
96                 splashScreen->setWindowOpacity(d);
97                 QApplication::processEvents();
98                 if(!flag) flag = WinSevenTaskbar::setTaskbarState(splashScreen, WinSevenTaskbar::WinSevenTaskbarIndeterminateState);
99                 Sleep(6);
100         }
101
102         //Loop while thread is running
103         loop->exec();
104         
105         //Fade out
106         for(double d = 1.0; d >= 0.0; d = d - 0.01)
107         {
108                 splashScreen->setWindowOpacity(d);
109                 QApplication::processEvents();
110                 Sleep(6);
111         }
112
113         //Restore taskbar
114         WinSevenTaskbar::setTaskbarState(splashScreen, WinSevenTaskbar::WinSevenTaskbarNoState);
115
116         //Hide splash
117         splashScreen->m_canClose = true;
118         splashScreen->close();
119
120         LAMEXP_DELETE(loop);
121         LAMEXP_DELETE(splashScreen);
122 }
123
124 ////////////////////////////////////////////////////////////
125 // EVENTS
126 ////////////////////////////////////////////////////////////
127
128 void SplashScreen::keyPressEvent(QKeyEvent *event)
129 {
130         event->ignore();
131 }
132
133 void SplashScreen::keyReleaseEvent(QKeyEvent *event)
134 {
135         event->ignore();
136 }
137
138 void SplashScreen::closeEvent(QCloseEvent *event)
139 {
140         if(!m_canClose) event->ignore();
141 }
142
143 bool SplashScreen::winEvent(MSG *message, long *result)
144 {
145         return WinSevenTaskbar::handleWinEvent(message, result);
146 }