Updated FAQ document + small installer fix.
[LameXP.git] / src / Dialog_WorkingBanner.cpp
blob417e6649e5bddd75200af845073773a7cef9d445
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.
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.
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
22 #include "Dialog_WorkingBanner.h"
24 #include "Global.h"
25 #include "WinSevenTaskbar.h"
27 #include <QThread>
28 #include <QMovie>
29 #include <QKeyEvent>
30 #include <QFontMetrics>
32 #define EPS (1.0E-5)
34 ////////////////////////////////////////////////////////////
35 // Constructor
36 ////////////////////////////////////////////////////////////
38 WorkingBanner::WorkingBanner(QWidget *parent)
40 QDialog(parent, Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint)
42 //Init the dialog, from the .ui file
43 setupUi(this);
44 setModal(true);
46 //Start animation
47 m_working = new QMovie(":/images/Busy.gif");
48 labelWorking->setMovie(m_working);
49 m_working->start();
51 //Set wait cursor
52 setCursor(Qt::WaitCursor);
55 ////////////////////////////////////////////////////////////
56 // Destructor
57 ////////////////////////////////////////////////////////////
59 WorkingBanner::~WorkingBanner(void)
61 if(m_working)
63 m_working->stop();
64 delete m_working;
65 m_working = NULL;
69 ////////////////////////////////////////////////////////////
70 // PUBLIC FUNCTIONS
71 ////////////////////////////////////////////////////////////
73 void WorkingBanner::show(const QString &text)
75 m_canClose = false;
76 QDialog::show();
77 setText(text);
78 QApplication::processEvents();
81 void WorkingBanner::close(void)
83 m_canClose = true;
84 QDialog::close();
87 void WorkingBanner::show(const QString &text, QThread *thread)
89 //Show splash
90 this->show(text);
92 //Start the thread
93 thread->start();
95 //Set taskbar state
96 WinSevenTaskbar::setOverlayIcon(dynamic_cast<QWidget*>(this->parent()), &QIcon(":/icons/hourglass.png"));
97 WinSevenTaskbar::setTaskbarState(dynamic_cast<QWidget*>(this->parent()), WinSevenTaskbar::WinSevenTaskbarIndeterminateState);
99 //Loop while thread is running
100 while(thread->isRunning())
102 QApplication::processEvents(QEventLoop::AllEvents | QEventLoop::WaitForMoreEvents);
105 //Set taskbar state
106 WinSevenTaskbar::setTaskbarState(dynamic_cast<QWidget*>(this->parent()), WinSevenTaskbar::WinSevenTaskbarNoState);
107 WinSevenTaskbar::setOverlayIcon(dynamic_cast<QWidget*>(this->parent()), NULL);
109 //Hide splash
110 this->close();
113 void WorkingBanner::show(const QString &text, QEventLoop *loop)
115 //Show splash
116 this->show(text);
118 //Set taskbar state
119 WinSevenTaskbar::setOverlayIcon(dynamic_cast<QWidget*>(this->parent()), &QIcon(":/icons/hourglass.png"));
120 WinSevenTaskbar::setTaskbarState(dynamic_cast<QWidget*>(this->parent()), WinSevenTaskbar::WinSevenTaskbarIndeterminateState);
122 //Loop while thread is running
123 loop->exec(QEventLoop::ExcludeUserInputEvents);
125 //Set taskbar state
126 WinSevenTaskbar::setTaskbarState(dynamic_cast<QWidget*>(this->parent()), WinSevenTaskbar::WinSevenTaskbarNoState);
127 WinSevenTaskbar::setOverlayIcon(dynamic_cast<QWidget*>(this->parent()), NULL);
129 //Hide splash
130 this->close();
133 ////////////////////////////////////////////////////////////
134 // EVENTS
135 ////////////////////////////////////////////////////////////
137 void WorkingBanner::keyPressEvent(QKeyEvent *event)
139 if(event->key() == Qt::Key_Escape)
141 qDebug("QT::KEY_ESCAPE pressed!");
142 emit userAbort();
145 event->ignore();
148 void WorkingBanner::keyReleaseEvent(QKeyEvent *event)
150 event->ignore();
153 void WorkingBanner::closeEvent(QCloseEvent *event)
155 if(!m_canClose) event->ignore();
158 bool WorkingBanner::winEvent(MSG *message, long *result)
160 return WinSevenTaskbar::handleWinEvent(message, result);
163 ////////////////////////////////////////////////////////////
164 // SLOTS
165 ////////////////////////////////////////////////////////////
167 void WorkingBanner::setText(const QString &text)
169 QFontMetrics metrics(labelStatus->font());
170 if(metrics.width(text) <= labelStatus->width())
172 labelStatus->setText(text);
174 else
176 QString choppedText = text.simplified().append("...");
177 while(metrics.width(choppedText) > labelStatus->width() && choppedText.length() > 8)
179 choppedText.chop(4);
180 choppedText = choppedText.trimmed();
181 choppedText.append("...");
183 labelStatus->setText(choppedText);
185 if(this->isVisible())
187 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);