splashscreen.cpp 3.38 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/***************************************************************************
                          splashscreen.cpp  -  description
                             -------------------
    begin                : Sun Dec 8 2002
    copyright            : (C) 2002 by Scott Wheeler
    email                : wheeler@kde.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include <kapplication.h>
#include <kiconloader.h>
#include <klocale.h>
21
#include <kdebug.h>
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

#include <qlabel.h>

#include "splashscreen.h"

SplashScreen *SplashScreen::splash = 0;
bool SplashScreen::done = false;
int SplashScreen::count = 0;

////////////////////////////////////////////////////////////////////////////////
// pubic members
////////////////////////////////////////////////////////////////////////////////

SplashScreen *SplashScreen::instance()
{
37
    if(!splash && !done)
38
        splash = new SplashScreen();
39
    return splash;
40 41 42 43 44
}

void SplashScreen::finishedLoading()
{
    done = true;
45
    delete splash;
46 47 48 49 50 51
    splash = 0;
}

void SplashScreen::increment()
{
    if(splash) {
52 53 54
        count++;
        if(( count & 63 ) == 0)
            splash->processEvents();
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
    }
}

////////////////////////////////////////////////////////////////////////////////
// protected members
////////////////////////////////////////////////////////////////////////////////

SplashScreen::SplashScreen() : QHBox(0 , "splashScreen", Qt::WStyle_Splash)
{
    setMargin(10);
    setSpacing(5);

    setLineWidth(5);
    setFrameShape(Box);
    setFrameShadow(Plain);
70

71 72 73
    QFont font = QWidget::font();

    if(font.pixelSize() > 0)
74
        font.setPixelSize(font.pixelSize() * 2);
75
    else
76
        font.setPointSize(font.pointSize() * 2);
77 78 79 80 81 82 83

    QLabel *iconLabel = new QLabel(this);
    iconLabel->setPixmap(DesktopIcon("juk"));

    QLabel *textLabel = new QLabel(i18n("Items loaded:"), this);
    textLabel->setFont(font);

84 85 86
    m_countLabel = new QLabel(this);
    m_countLabel->setText(QString::number(count));
    m_countLabel->setFont(font);
87
    m_countLabel->setMinimumWidth(m_countLabel->fontMetrics().width("00000"));
88

89
    setMaximumWidth(iconLabel->width() + textLabel->width() + m_countLabel->width() + 10);
90 91 92 93 94
    setMaximumHeight(QMAX(iconLabel->height(), textLabel->height()));

    QDesktopWidget *desktop = KApplication::desktop();
    QRect r = desktop->screenGeometry(desktop->primaryScreen());
    setGeometry((r.width() / 2) - (width() / 2), (r.height() / 2) - (height() / 2), width(), height());
95 96 97 98 99 100
}

SplashScreen::~SplashScreen()
{

}
101 102 103 104 105 106 107

////////////////////////////////////////////////////////////////////////////////
// private methods
////////////////////////////////////////////////////////////////////////////////

void SplashScreen::processEvents()
{
108
    m_countLabel->setText(QString::number(count));
109
    kapp->processEvents();
110
}