Added support for custom encoder parameters.
[LameXP.git] / src / Dialog_WorkingBanner.cpp
blob03e38fd4b449169583e1933f12a87ae3e836d85b
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>
31 #include <Windows.h>
33 #define EPS (1.0E-5)
35 ////////////////////////////////////////////////////////////
36 // Constructor
37 ////////////////////////////////////////////////////////////
39 WorkingBanner::WorkingBanner(QWidget *parent)
41 QDialog(parent, Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint)
43 //Init the dialog, from the .ui file
44 setupUi(this);
45 setModal(true);
47 //Start animation
48 m_working = new QMovie(":/images/Busy.gif");
49 labelWorking->setMovie(m_working);
50 m_working->start();
52 //Set wait cursor
53 setCursor(Qt::WaitCursor);
55 //Init taskbar
56 WinSevenTaskbar::initTaskbar();
59 ////////////////////////////////////////////////////////////
60 // Destructor
61 ////////////////////////////////////////////////////////////
63 WorkingBanner::~WorkingBanner(void)
65 if(m_working)
67 m_working->stop();
68 delete m_working;
69 m_working = NULL;
73 ////////////////////////////////////////////////////////////
74 // PUBLIC FUNCTIONS
75 ////////////////////////////////////////////////////////////
77 void WorkingBanner::show(const QString &text)
79 m_canClose = false;
80 QDialog::show();
81 setText(text);
82 QApplication::processEvents();
85 void WorkingBanner::close(void)
87 m_canClose = true;
88 QDialog::close();
91 void WorkingBanner::show(const QString &text, QThread *thread)
93 //Show splash
94 this->show(text);
96 //Start the thread
97 thread->start();
99 //Set taskbar state
100 WinSevenTaskbar::setOverlayIcon(dynamic_cast<QWidget*>(this->parent()), &QIcon(":/icons/hourglass.png"));
101 WinSevenTaskbar::setTaskbarState(dynamic_cast<QWidget*>(this->parent()), WinSevenTaskbar::WinSevenTaskbarIndeterminateState);
103 //Loop while thread is running
104 while(thread->isRunning())
106 QApplication::processEvents(QEventLoop::AllEvents | QEventLoop::WaitForMoreEvents);
109 //Set taskbar state
110 WinSevenTaskbar::setTaskbarState(dynamic_cast<QWidget*>(this->parent()), WinSevenTaskbar::WinSevenTaskbarNoState);
111 WinSevenTaskbar::setOverlayIcon(dynamic_cast<QWidget*>(this->parent()), NULL);
113 //Hide splash
114 this->close();
117 void WorkingBanner::show(const QString &text, QEventLoop *loop)
119 //Show splash
120 this->show(text);
122 //Set taskbar state
123 WinSevenTaskbar::setOverlayIcon(dynamic_cast<QWidget*>(this->parent()), &QIcon(":/icons/hourglass.png"));
124 WinSevenTaskbar::setTaskbarState(dynamic_cast<QWidget*>(this->parent()), WinSevenTaskbar::WinSevenTaskbarIndeterminateState);
126 //Loop while thread is running
127 loop->exec(QEventLoop::ExcludeUserInputEvents);
129 //Set taskbar state
130 WinSevenTaskbar::setTaskbarState(dynamic_cast<QWidget*>(this->parent()), WinSevenTaskbar::WinSevenTaskbarNoState);
131 WinSevenTaskbar::setOverlayIcon(dynamic_cast<QWidget*>(this->parent()), NULL);
133 //Hide splash
134 this->close();
137 ////////////////////////////////////////////////////////////
138 // EVENTS
139 ////////////////////////////////////////////////////////////
141 void WorkingBanner::keyPressEvent(QKeyEvent *event)
143 event->ignore();
146 void WorkingBanner::keyReleaseEvent(QKeyEvent *event)
148 event->ignore();
151 void WorkingBanner::closeEvent(QCloseEvent *event)
153 if(!m_canClose) event->ignore();
156 ////////////////////////////////////////////////////////////
157 // SLOTS
158 ////////////////////////////////////////////////////////////
160 void WorkingBanner::setText(const QString &text)
162 QFontMetrics metrics(labelStatus->font());
163 if(metrics.width(text) <= labelStatus->width())
165 labelStatus->setText(text);
167 else
169 QString choppedText = text.simplified().append("...");
170 while(metrics.width(choppedText) > labelStatus->width() && choppedText.length() > 8)
172 choppedText.chop(4);
173 choppedText = choppedText.trimmed();
174 choppedText.append("...");
176 labelStatus->setText(choppedText);
178 if(this->isVisible())
180 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);