1 /*
2  * %kadu copyright begin%
3  * Copyright 2013, 2014 Bartosz Brachaczek (b.brachaczek@gmail.com)
4  * Copyright 2012, 2013, 2014 Rafał Przemysław Malinowski (rafal.przemyslaw.malinowski@gmail.com)
5  * %kadu copyright end%
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of
10  * the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include "wait-overlay.h"
22 
23 #include "icons/icons-manager.h"
24 #include "icons/kadu-icon.h"
25 
26 #include <QtCore/QTimer>
27 #include <QtGui/QMovie>
28 #include <QtGui/QResizeEvent>
29 #include <QtWidgets/QLabel>
30 
WaitOverlay(QWidget * parent)31 WaitOverlay::WaitOverlay(QWidget *parent) :
32 		QLabel(parent)
33 {
34 }
35 
~WaitOverlay()36 WaitOverlay::~WaitOverlay()
37 {
38 }
39 
setIconsManager(IconsManager * iconsManager)40 void WaitOverlay::setIconsManager(IconsManager *iconsManager)
41 {
42 	m_iconsManager = iconsManager;
43 }
44 
init()45 void WaitOverlay::init()
46 {
47 	setAlignment(Qt::AlignCenter);
48 	setMovie(new QMovie(m_iconsManager->iconPath(KaduIcon("kadu_icons/please-wait", "64x64")), QByteArray(), this));
49 	setStyleSheet("background-color: rgba(127, 127, 127, 127)");
50 
51 	hide();
52 
53 	if (parent())
54 		QTimer::singleShot(500, this, SLOT(timeoutPassed()));
55 }
56 
timeoutPassed()57 void WaitOverlay::timeoutPassed()
58 {
59 	if (!parentWidget()) // in case of reparenting
60 		return;
61 
62 	movie()->start();
63 
64 	move(0, 0);
65 	resize(parentWidget()->size());
66 	parentWidget()->installEventFilter(this);
67 
68 	show();
69 	raise();
70 }
71 
eventFilter(QObject * object,QEvent * event)72 bool WaitOverlay::eventFilter(QObject *object, QEvent *event)
73 {
74 	if (QEvent::Resize != event->type())
75 		return QWidget::eventFilter(object, event);
76 
77 	QResizeEvent *resizeEvent = static_cast<QResizeEvent *>(event);
78 	resize(resizeEvent->size());
79 
80 	return QWidget::eventFilter(object, event);
81 }
82 
83 #include "moc_wait-overlay.cpp"
84