1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2012 LoRd_MuldeR <MuldeR2@GMX.de>
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.
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"
25 #include "WinSevenTaskbar.h"
30 #include <QFontMetrics>
34 ////////////////////////////////////////////////////////////
36 ////////////////////////////////////////////////////////////
38 WorkingBanner::WorkingBanner(QWidget *parent)
40 QDialog(parent, Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint)
42 //Init the dialog, from the .ui file
47 m_working = new QMovie(":/images/Busy.gif");
48 labelWorking->setMovie(m_working);
52 setCursor(Qt::WaitCursor);
55 ////////////////////////////////////////////////////////////
57 ////////////////////////////////////////////////////////////
59 WorkingBanner::~WorkingBanner(void)
69 ////////////////////////////////////////////////////////////
71 ////////////////////////////////////////////////////////////
73 void WorkingBanner::show(const QString &text)
78 QApplication::processEvents();
81 bool WorkingBanner::close(void)
85 return QDialog::close();
88 void WorkingBanner::show(const QString &text, QThread *thread)
97 WinSevenTaskbar::setOverlayIcon(dynamic_cast<QWidget*>(this->parent()), &QIcon(":/icons/hourglass.png"));
98 WinSevenTaskbar::setTaskbarState(dynamic_cast<QWidget*>(this->parent()), WinSevenTaskbar::WinSevenTaskbarIndeterminateState);
100 //Loop while thread is running
101 while(thread->isRunning())
103 QApplication::processEvents(QEventLoop::AllEvents | QEventLoop::WaitForMoreEvents);
107 WinSevenTaskbar::setTaskbarState(dynamic_cast<QWidget*>(this->parent()), WinSevenTaskbar::WinSevenTaskbarNoState);
108 WinSevenTaskbar::setOverlayIcon(dynamic_cast<QWidget*>(this->parent()), NULL);
114 void WorkingBanner::show(const QString &text, QEventLoop *loop)
120 WinSevenTaskbar::setOverlayIcon(dynamic_cast<QWidget*>(this->parent()), &QIcon(":/icons/hourglass.png"));
121 WinSevenTaskbar::setTaskbarState(dynamic_cast<QWidget*>(this->parent()), WinSevenTaskbar::WinSevenTaskbarIndeterminateState);
123 //Loop while thread is running
124 loop->exec(QEventLoop::ExcludeUserInputEvents);
127 WinSevenTaskbar::setTaskbarState(dynamic_cast<QWidget*>(this->parent()), WinSevenTaskbar::WinSevenTaskbarNoState);
128 WinSevenTaskbar::setOverlayIcon(dynamic_cast<QWidget*>(this->parent()), NULL);
134 ////////////////////////////////////////////////////////////
136 ////////////////////////////////////////////////////////////
138 void WorkingBanner::keyPressEvent(QKeyEvent *event)
140 if(event->key() == Qt::Key_Escape)
142 qDebug("QT::KEY_ESCAPE pressed!");
149 void WorkingBanner::keyReleaseEvent(QKeyEvent *event)
154 void WorkingBanner::closeEvent(QCloseEvent *event)
156 if(!m_canClose) event->ignore();
159 bool WorkingBanner::winEvent(MSG *message, long *result)
161 return WinSevenTaskbar::handleWinEvent(message, result);
164 ////////////////////////////////////////////////////////////
166 ////////////////////////////////////////////////////////////
168 void WorkingBanner::setText(const QString &text)
170 QFontMetrics metrics(labelStatus->font());
171 if(metrics.width(text) <= labelStatus->width())
173 labelStatus->setText(text);
177 QString choppedText = text.simplified().append("...");
178 while(metrics.width(choppedText) > labelStatus->width() && choppedText.length() > 8)
181 choppedText = choppedText.trimmed();
182 choppedText.append("...");
184 labelStatus->setText(choppedText);
186 if(this->isVisible())
188 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);