use KDE standard for toolbar icon's text
[kdenetwork.git] / kget / ui / splash.cpp
blob0171f835ee3fca769ddf2326770ff91c822149b1
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 <QPainter>
19 #include <QTimer>
20 #include <QMouseEvent>
21 #include <QPaintEvent>
22 #include <QDesktopWidget>
24 Splash::Splash(const QString& imagePath)
25 : QWidget(0, Qt::SplashScreen | Qt::X11BypassWindowManagerHint)
27 cachedPixmap = QPixmap(imagePath);
28 if (!cachedPixmap.mask().isNull())
30 QBitmap mask(cachedPixmap.size());
31 mask.fill(Qt::color0);
32 QBitmap pixMask = cachedPixmap.mask();
33 QPainter p(&mask);
34 p.drawPixmap((mask.width() - pixMask.width())/2, (mask.height() - pixMask.height())/2,
35 pixMask);
36 setMask(mask);
38 else
39 setMask(QBitmap());
41 QWidget *d = QApplication::desktop()->screen();
42 move( (d->width() - cachedPixmap.width ()) / 2,
43 (d->height() - cachedPixmap.height()) / 2 );
44 resize( cachedPixmap.size() );
45 setFocusPolicy( Qt::NoFocus );
47 show();
48 update();
50 QTimer::singleShot( SPLASH_DURATION, this, SLOT(hide()) );
53 void Splash::removeSplash( int timeout )
55 QTimer::singleShot( timeout, this, SLOT(hide()) );
58 void Splash::paintEvent( QPaintEvent * )
60 QPainter p(this);
61 const QRect r = rect();
62 p.drawPixmap(r.x() + (r.width() - cachedPixmap.width())/2,
63 r.y() + (r.height() - cachedPixmap.height())/2,
64 cachedPixmap);
67 void Splash::mousePressEvent( QMouseEvent* )
69 removeSplash(100);
72 #include "splash.moc"