void WorkingBanner::show(const QString &text, QThread *thread) { //Show splash this->show(text); //Create event loop QEventLoop *loop = new QEventLoop(this); connect(thread, SIGNAL(finished()), loop, SLOT(quit())); connect(thread, SIGNAL(terminated()), loop, SLOT(quit())); //Set taskbar state m_taskbar->setOverlayIcon(&QIcon(":/icons/hourglass.png")); m_taskbar->setTaskbarState(MUtils::Taskbar7::TASKBAR_STATE_INTERMEDIATE); //Start the thread thread->start(); //Update cursor QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); //Loop while thread is still running while(THREAD_RUNNING(thread)) { loop->exec(); } //Restore cursor QApplication::restoreOverrideCursor(); //Set taskbar state m_taskbar->setTaskbarState(MUtils::Taskbar7::TASKBAR_STATE_NONE); m_taskbar->setOverlayIcon(NULL); //Free memory MUTILS_DELETE(loop); //Hide splash this->close(); }
void SplashScreen::showSplash(QThread *thread) { double opacity = OPACITY_DELTA; const int opacitySteps = qRound(1.0 / OPACITY_DELTA); SplashScreen *splashScreen = new SplashScreen(); bool bTaskBar = false; //Show splash splashScreen->m_canClose = false; splashScreen->setWindowOpacity(opacity); splashScreen->setFixedSize(splashScreen->size()); splashScreen->show(); //Wait for window to show QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); splashScreen->repaint(); QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); //Setup the event loop QEventLoop *loop = new QEventLoop(splashScreen); connect(thread, SIGNAL(terminated()), loop, SLOT(quit()), Qt::QueuedConnection); connect(thread, SIGNAL(finished()), loop, SLOT(quit()), Qt::QueuedConnection); //Create timer QTimer *timer = new QTimer(); connect(timer, SIGNAL(timeout()), loop, SLOT(quit())); //Start thread QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); thread->start(); QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); //Init taskbar SET_TASKBAR_STATE(true); //Fade in for(int i = 1; i <= opacitySteps; i++) { opacity = (i < opacitySteps) ? (OPACITY_DELTA * static_cast<double>(i)) : 1.0; splashScreen->setWindowOpacity(opacity); splashScreen->update(); QApplication::processEvents(QEventLoop::ExcludeUserInputEvents, FADE_DELAY); SET_TASKBAR_STATE(true); Sleep(FADE_DELAY); } //Start the timer timer->start(30720); //Loop while thread is still running if(bool bIsRunning = THREAD_RUNNING(thread)) { int deadlockCounter = 0; while(bIsRunning) { loop->exec(); if(bIsRunning = THREAD_RUNNING(thread)) { qWarning("Potential deadlock in initialization thread!"); if(++deadlockCounter >= 10) qFatal("Deadlock in initialization thread!"); } } } //Stop the timer timer->stop(); //Fade out for(int i = opacitySteps; i >= 0; i--) { opacity = OPACITY_DELTA * static_cast<double>(i); splashScreen->setWindowOpacity(opacity); splashScreen->update(); QApplication::processEvents(QEventLoop::ExcludeUserInputEvents, FADE_DELAY); Sleep(FADE_DELAY); } //Restore taskbar SET_TASKBAR_STATE(false); //Hide splash splashScreen->m_canClose = true; splashScreen->close(); //Free LAMEXP_DELETE(loop); LAMEXP_DELETE(timer); LAMEXP_DELETE(splashScreen); }