2010-11-06 23:04:47 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// LameXP - Audio Encoder Front-End
|
2011-01-01 17:04:25 +01:00
|
|
|
// Copyright (C) 2004-2011 LoRd_MuldeR <MuldeR2@GMX.de>
|
2010-11-06 23:04:47 +01:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
//
|
|
|
|
// http://www.gnu.org/licenses/gpl-2.0.txt
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "Dialog_WorkingBanner.h"
|
|
|
|
|
|
|
|
#include "Global.h"
|
2010-12-05 23:11:03 +01:00
|
|
|
#include "WinSevenTaskbar.h"
|
2010-11-06 23:04:47 +01:00
|
|
|
|
|
|
|
#include <QThread>
|
|
|
|
#include <QMovie>
|
|
|
|
#include <QKeyEvent>
|
|
|
|
#include <QFontMetrics>
|
|
|
|
|
|
|
|
#define EPS (1.0E-5)
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// Constructor
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
WorkingBanner::WorkingBanner(QWidget *parent)
|
2010-12-05 23:11:03 +01:00
|
|
|
:
|
|
|
|
QDialog(parent, Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint)
|
2010-11-06 23:04:47 +01:00
|
|
|
{
|
|
|
|
//Init the dialog, from the .ui file
|
|
|
|
setupUi(this);
|
|
|
|
setModal(true);
|
|
|
|
|
|
|
|
//Start animation
|
|
|
|
m_working = new QMovie(":/images/Busy.gif");
|
|
|
|
labelWorking->setMovie(m_working);
|
|
|
|
m_working->start();
|
|
|
|
|
|
|
|
//Set wait cursor
|
|
|
|
setCursor(Qt::WaitCursor);
|
2010-12-05 23:11:03 +01:00
|
|
|
|
|
|
|
//Init taskbar
|
|
|
|
WinSevenTaskbar::initTaskbar();
|
2010-11-06 23:04:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// Destructor
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
WorkingBanner::~WorkingBanner(void)
|
|
|
|
{
|
|
|
|
if(m_working)
|
|
|
|
{
|
|
|
|
m_working->stop();
|
|
|
|
delete m_working;
|
|
|
|
m_working = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// PUBLIC FUNCTIONS
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void WorkingBanner::show(const QString &text)
|
|
|
|
{
|
|
|
|
m_canClose = false;
|
|
|
|
QDialog::show();
|
|
|
|
setText(text);
|
|
|
|
QApplication::processEvents();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WorkingBanner::close(void)
|
|
|
|
{
|
|
|
|
m_canClose = true;
|
|
|
|
QDialog::close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WorkingBanner::show(const QString &text, QThread *thread)
|
|
|
|
{
|
|
|
|
//Show splash
|
|
|
|
this->show(text);
|
|
|
|
|
|
|
|
//Start the thread
|
|
|
|
thread->start();
|
|
|
|
|
2010-12-05 23:11:03 +01:00
|
|
|
//Set taskbar state
|
|
|
|
WinSevenTaskbar::setOverlayIcon(dynamic_cast<QWidget*>(this->parent()), &QIcon(":/icons/hourglass.png"));
|
|
|
|
WinSevenTaskbar::setTaskbarState(dynamic_cast<QWidget*>(this->parent()), WinSevenTaskbar::WinSevenTaskbarIndeterminateState);
|
|
|
|
|
2010-11-06 23:04:47 +01:00
|
|
|
//Loop while thread is running
|
|
|
|
while(thread->isRunning())
|
|
|
|
{
|
|
|
|
QApplication::processEvents(QEventLoop::AllEvents | QEventLoop::WaitForMoreEvents);
|
|
|
|
}
|
|
|
|
|
2010-12-05 23:11:03 +01:00
|
|
|
//Set taskbar state
|
|
|
|
WinSevenTaskbar::setTaskbarState(dynamic_cast<QWidget*>(this->parent()), WinSevenTaskbar::WinSevenTaskbarNoState);
|
|
|
|
WinSevenTaskbar::setOverlayIcon(dynamic_cast<QWidget*>(this->parent()), NULL);
|
|
|
|
|
2010-11-06 23:04:47 +01:00
|
|
|
//Hide splash
|
|
|
|
this->close();
|
|
|
|
}
|
|
|
|
|
2010-12-12 01:49:07 +01:00
|
|
|
void WorkingBanner::show(const QString &text, QEventLoop *loop)
|
|
|
|
{
|
|
|
|
//Show splash
|
|
|
|
this->show(text);
|
|
|
|
|
|
|
|
//Set taskbar state
|
|
|
|
WinSevenTaskbar::setOverlayIcon(dynamic_cast<QWidget*>(this->parent()), &QIcon(":/icons/hourglass.png"));
|
|
|
|
WinSevenTaskbar::setTaskbarState(dynamic_cast<QWidget*>(this->parent()), WinSevenTaskbar::WinSevenTaskbarIndeterminateState);
|
|
|
|
|
|
|
|
//Loop while thread is running
|
|
|
|
loop->exec(QEventLoop::ExcludeUserInputEvents);
|
|
|
|
|
|
|
|
//Set taskbar state
|
|
|
|
WinSevenTaskbar::setTaskbarState(dynamic_cast<QWidget*>(this->parent()), WinSevenTaskbar::WinSevenTaskbarNoState);
|
|
|
|
WinSevenTaskbar::setOverlayIcon(dynamic_cast<QWidget*>(this->parent()), NULL);
|
|
|
|
|
|
|
|
//Hide splash
|
|
|
|
this->close();
|
|
|
|
}
|
|
|
|
|
2010-11-06 23:04:47 +01:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// EVENTS
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void WorkingBanner::keyPressEvent(QKeyEvent *event)
|
|
|
|
{
|
|
|
|
event->ignore();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WorkingBanner::keyReleaseEvent(QKeyEvent *event)
|
|
|
|
{
|
|
|
|
event->ignore();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WorkingBanner::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
|
|
|
if(!m_canClose) event->ignore();
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// SLOTS
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void WorkingBanner::setText(const QString &text)
|
|
|
|
{
|
|
|
|
QFontMetrics metrics(labelStatus->font());
|
|
|
|
if(metrics.width(text) <= labelStatus->width())
|
|
|
|
{
|
|
|
|
labelStatus->setText(text);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QString choppedText = text.simplified().append("...");
|
|
|
|
while(metrics.width(choppedText) > labelStatus->width() && choppedText.length() > 8)
|
|
|
|
{
|
|
|
|
choppedText.chop(4);
|
|
|
|
choppedText = choppedText.trimmed();
|
|
|
|
choppedText.append("...");
|
|
|
|
}
|
|
|
|
labelStatus->setText(choppedText);
|
|
|
|
}
|
2010-11-17 00:49:38 +01:00
|
|
|
if(this->isVisible())
|
|
|
|
{
|
|
|
|
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
|
|
|
|
}
|
2010-11-06 23:04:47 +01:00
|
|
|
}
|