Relicense all GPLv2 only code to GPLv2+.
[kdenetwork.git] / kget / ui / splash.cpp
blob6efd652dd1e2d925dfdb5294f3bab4ce51806ade
1 /* This file is part of the KDE project
3 Copyright (C) 2004 - 2005 KGet Developers <kget@kde.org>
4 Splash.cpp/.h taken from Amarok. Thanks to Amarok's authors, cool piece
5 of code.. and our favourite player!
6 Copyright (C) 2003 by Christian Muehlhaeuser <muesli@chareit.net>
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public
10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version.
14 #include "splash.h"
16 #include <QApplication>
17 #include <QBitmap>
18 #include <QImage>
19 #include <QPainter>
20 #include <QTimer>
21 #include <QMouseEvent>
22 #include <QPaintEvent>
23 #include <QDesktopWidget>
25 Splash::Splash(const QString& imagePath)
26 : QWidget(0, Qt::SplashScreen | Qt::X11BypassWindowManagerHint)
28 cachedPixmap = QPixmap(imagePath);
29 if (!cachedPixmap.mask().isNull())
31 QBitmap mask(cachedPixmap.size());
32 mask.fill(Qt::color0);
33 QBitmap pixMask = cachedPixmap.mask();
34 QPainter p(&mask);
35 p.drawPixmap((mask.width() - pixMask.width())/2, (mask.height() - pixMask.height())/2,
36 pixMask);
37 setMask(mask);
39 else
40 setMask(QBitmap());
42 QWidget *d = QApplication::desktop()->screen();
43 move( (d->width() - cachedPixmap.width ()) / 2,
44 (d->height() - cachedPixmap.height()) / 2 );
45 resize( cachedPixmap.size() );
46 setFocusPolicy( Qt::NoFocus );
48 show();
49 update();
51 QTimer::singleShot( SPLASH_DURATION, this, SLOT(hide()) );
54 void Splash::removeSplash( int timeout )
56 QTimer::singleShot( timeout, this, SLOT(hide()) );
59 void Splash::paintEvent( QPaintEvent * )
61 QPainter p(this);
62 const QRect r = rect();
63 p.drawPixmap(r.x() + (r.width() - cachedPixmap.width())/2,
64 r.y() + (r.height() - cachedPixmap.height())/2,
65 cachedPixmap);
68 void Splash::mousePressEvent( QMouseEvent* )
70 removeSplash(100);
73 #include "splash.moc"