OSDN Git Service

Bump version.
[lamexp/LameXP.git] / src / Dialog_SplashScreen.cpp
index e9c4427..7905cea 100644 (file)
@@ -1,12 +1,12 @@
 ///////////////////////////////////////////////////////////////////////////////
 // LameXP - Audio Encoder Front-End
-// Copyright (C) 2004-2013 LoRd_MuldeR <MuldeR2@GMX.de>
+// Copyright (C) 2004-2020 LoRd_MuldeR <MuldeR2@GMX.de>
 //
 // This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
+// it under the terms of the GNU GENERAL PUBLIC LICENSE as published by
 // the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version, but always including the *additional*
-// restrictions defined in the "License.txt" file.
+// (at your option) any later version; always including the non-optional
+// LAMEXP GNU GENERAL PUBLIC LICENSE ADDENDUM. See "License.txt" file!
 //
 // This program is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 #include "Dialog_SplashScreen.h"
 
+//UIC includes
+#include "UIC_SplashScreen.h"
+
+//Internal
 #include "Global.h"
 
+//MUtils
+#include <MUtils/Global.h>
+#include <MUtils/GUI.h>
+#include <MUtils/Taskbar7.h>
+
+//Qt
 #include <QThread>
 #include <QMovie>
 #include <QKeyEvent>
 #include <QTimer>
 
-#include "WinSevenTaskbar.h"
-
 #define FADE_DELAY 16
 #define OPACITY_DELTA 0.04
 
 //Setup taskbar indicator
-#define SET_TASKBAR_STATE(WIDGET,VAR,FLAG) do \
+#define SET_TASKBAR_STATE(WIDGET,FLAG) do \
 { \
-       if(FLAG) \
-       { \
-               if(!(VAR)) (VAR) = WinSevenTaskbar::setTaskbarState((WIDGET), WinSevenTaskbar::WinSevenTaskbarIndeterminateState); \
-       } \
-       else \
+       const int _oldFlag = (WIDGET)->m_taskBarFlag.fetchAndStoreOrdered((FLAG) ? 1 : 0); \
+       if(_oldFlag != ((FLAG) ? 1 : 0)) \
        { \
-               if((VAR)) (VAR) = (!WinSevenTaskbar::setTaskbarState((WIDGET), WinSevenTaskbar::WinSevenTaskbarNoState)); \
+               (WIDGET)->m_taskbar->setTaskbarState((FLAG) ? MUtils::Taskbar7::TASKBAR_STATE_INTERMEDIATE : MUtils::Taskbar7::TASKBAR_STATE_NONE); \
        } \
 } \
 while(0)
@@ -54,43 +59,43 @@ while(0)
 
 SplashScreen::SplashScreen(QWidget *parent)
 :
+       QFrame(parent, Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint),
+       ui(new Ui::SplashScreen),
        m_opacitySteps(qRound(1.0 / OPACITY_DELTA)),
-       QFrame(parent, Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint)
+       m_taskbar(new MUtils::Taskbar7(this))
 {
        //Init the dialog, from the .ui file
-       setupUi(this);
+       ui->setupUi(this);
 
        //Make size fixed
        setFixedSize(this->size());
        
        //Create event loop
-       m_loop = new QEventLoop(this);
+       m_loop.reset(new QEventLoop(this));
 
        //Create timer
-       m_timer = new QTimer(this);
+       m_timer.reset(new QTimer(this));
        m_timer->setInterval(FADE_DELAY);
        m_timer->setSingleShot(false);
 
        //Connect timer to slot
-       connect(m_timer, SIGNAL(timeout()), this, SLOT(updateHandler()));
+       connect(m_timer.data(), SIGNAL(timeout()), this, SLOT(updateHandler()));
 
        //Enable "sheet of glass" effect on splash screen
-       if(!lamexp_sheet_of_glass(this))
+       if(!MUtils::GUI::sheet_of_glass(this))
        {
                setStyleSheet("background-image: url(:/images/Background.jpg)");
        }
 
        //Start animation
-       m_working = new QMovie(":/images/Loading4.gif");
+       m_working.reset(new QMovie(":/images/Loading4.gif"));
        m_working->setCacheMode(QMovie::CacheAll);
-       labelLoading->setMovie(m_working);
+       ui->labelLoading->setMovie(m_working.data());
        m_working->start();
 
        //Init status
-       m_canClose = false;
        m_status = STATUS_FADE_IN;
        m_fadeValue = 0;
-       m_taskBarInit = false;
 }
 
 ////////////////////////////////////////////////////////////
@@ -104,9 +109,7 @@ SplashScreen::~SplashScreen(void)
                m_working->stop();
        }
 
-       LAMEXP_DELETE(m_working);
-       LAMEXP_DELETE(m_loop);
-       LAMEXP_DELETE(m_timer);
+       delete ui;
 }
 
 ////////////////////////////////////////////////////////////
@@ -115,7 +118,7 @@ SplashScreen::~SplashScreen(void)
 
 void SplashScreen::showSplash(QThread *thread)
 {
-       SplashScreen *splashScreen = new SplashScreen();
+       QScopedPointer<SplashScreen> splashScreen(new SplashScreen());
 
        //Show splash
        splashScreen->setWindowOpacity(OPACITY_DELTA);
@@ -126,19 +129,19 @@ void SplashScreen::showSplash(QThread *thread)
 
        //Wait for window to show
        QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
-       splashScreen->repaint(); lamexp_bring_to_front(splashScreen);
+       splashScreen->repaint(); MUtils::GUI::bring_to_front(splashScreen.data());
        QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
 
        //Connect thread signals
-       connect(thread, SIGNAL(terminated()), splashScreen, SLOT(threadComplete()), Qt::QueuedConnection);
-       connect(thread, SIGNAL(finished()),   splashScreen, SLOT(threadComplete()), Qt::QueuedConnection);
+       connect(thread, SIGNAL(terminated()), splashScreen.data(), SLOT(threadComplete()), Qt::QueuedConnection);
+       connect(thread, SIGNAL(finished()),   splashScreen.data(), SLOT(threadComplete()), Qt::QueuedConnection);
 
        //Init taskbar
-       SET_TASKBAR_STATE(splashScreen, splashScreen->m_taskBarInit, true);
+       SET_TASKBAR_STATE(splashScreen, true);
 
        //Start the thread
        splashScreen->m_timer->start(FADE_DELAY);
-       QTimer::singleShot(8*60*1000, splashScreen->m_loop, SLOT(quit()));
+       QTimer::singleShot(8*60*1000, splashScreen->m_loop.data(), SLOT(quit()));
        QTimer::singleShot(333, thread, SLOT(start()));
 
        //Start event handling!
@@ -152,17 +155,14 @@ void SplashScreen::showSplash(QThread *thread)
        }
 
        //Restore taskbar
-       SET_TASKBAR_STATE(splashScreen, splashScreen->m_taskBarInit, false);
+       SET_TASKBAR_STATE(splashScreen, false);
 
        //Restore cursor
        QApplication::restoreOverrideCursor();
 
        //Hide splash
-       splashScreen->m_canClose = true;
+       splashScreen->m_canClose.ref();
        splashScreen->close();
-
-       //Free
-       LAMEXP_DELETE(splashScreen);
 }
 
 ////////////////////////////////////////////////////////////
@@ -176,12 +176,12 @@ void SplashScreen::updateHandler(void)
                if(m_fadeValue < m_opacitySteps)
                {
                        setWindowOpacity(OPACITY_DELTA * static_cast<double>(++m_fadeValue));
-                       SET_TASKBAR_STATE(this, m_taskBarInit, true);
+                       SET_TASKBAR_STATE(this, true);
                }
                else
                {
                        setWindowOpacity(1.0);
-                       lamexp_bring_to_front(this);
+                       MUtils::GUI::bring_to_front(this);
                        m_timer->stop();
                        m_status = STATUS_WAIT;
                }
@@ -191,7 +191,7 @@ void SplashScreen::updateHandler(void)
                if(m_fadeValue > 0)
                {
                        setWindowOpacity(OPACITY_DELTA * static_cast<double>(--m_fadeValue));
-                       SET_TASKBAR_STATE(this, m_taskBarInit, true);
+                       SET_TASKBAR_STATE(this, true);
                }
                else
                {
@@ -210,7 +210,7 @@ void SplashScreen::threadComplete(void)
        {
                m_timer->start(FADE_DELAY);
        }
-       lamexp_bring_to_front(this);
+       MUtils::GUI::bring_to_front(this);
 }
 
 ////////////////////////////////////////////////////////////
@@ -231,8 +231,3 @@ void SplashScreen::closeEvent(QCloseEvent *event)
 {
        if(!m_canClose) event->ignore();
 }
-
-bool SplashScreen::winEvent(MSG *message, long *result)
-{
-       return WinSevenTaskbar::handleWinEvent(message, result);
-}