1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2011 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 void WorkingBanner::close(void)
87 void WorkingBanner::show(const QString &text, QThread *thread)
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);
106 WinSevenTaskbar::setTaskbarState(dynamic_cast<QWidget*>(this->parent()), WinSevenTaskbar::WinSevenTaskbarNoState);
107 WinSevenTaskbar::setOverlayIcon(dynamic_cast<QWidget*>(this->parent()), NULL);
113 void WorkingBanner::show(const QString &text, QEventLoop *loop)
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);
126 WinSevenTaskbar::setTaskbarState(dynamic_cast<QWidget*>(this->parent()), WinSevenTaskbar::WinSevenTaskbarNoState);
127 WinSevenTaskbar::setOverlayIcon(dynamic_cast<QWidget*>(this->parent()), NULL);
133 ////////////////////////////////////////////////////////////
135 ////////////////////////////////////////////////////////////
137 void WorkingBanner::keyPressEvent(QKeyEvent *event)
139 if(event->key() == Qt::Key_Escape)
141 qDebug("QT::KEY_ESCAPE pressed!");
148 void WorkingBanner::keyReleaseEvent(QKeyEvent *event)
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 ////////////////////////////////////////////////////////////
165 ////////////////////////////////////////////////////////////
167 void WorkingBanner::setText(const QString &text)
169 QFontMetrics metrics(labelStatus->font());
170 if(metrics.width(text) <= labelStatus->width())
172 labelStatus->setText(text);
176 QString choppedText = text.simplified().append("...");
177 while(metrics.width(choppedText) > labelStatus->width() && choppedText.length() > 8)
180 choppedText = choppedText.trimmed();
181 choppedText.append("...");
183 labelStatus->setText(choppedText);
185 if(this->isVisible())
187 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);