~ubuntu-branches/ubuntu/feisty/digikam/feisty

« back to all changes in this revision

Viewing changes to digikam/utilities/splashscreen/splashscreen.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Achim Bohnet
  • Date: 2005-03-10 02:39:02 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 hoary)
  • Revision ID: james.westby@ubuntu.com-20050310023902-023nymfst5mg696c
Tags: 0.7.2-2
* debian/TODO: clean
* digikam manpage: better --detect-camera description

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ============================================================
 
2
 * Author: Renchi Raju <renchi@pooh.tam.uiuc.edu>
 
3
 * Date  : 2003-02-10
 
4
 * Description :
 
5
 *
 
6
 * Copyright 2003 by Renchi Raju
 
7
 
 
8
 * This program is free software; you can redistribute it
 
9
 * and/or modify it under the terms of the GNU General
 
10
 * Public License as published by the Free Software Foundation;
 
11
 * either version 2, or (at your option)
 
12
 * any later version.
 
13
 *
 
14
 * This program is distributed in the hope that it will be useful,
 
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 * GNU General Public License for more details.
 
18
 *
 
19
 * ============================================================ */
 
20
 
 
21
#include <qpixmap.h>
 
22
#include <qstring.h>
 
23
#include <qapplication.h>
 
24
#include <qtimer.h>
 
25
#include <qpainter.h>
 
26
 
 
27
#include <klocale.h>
 
28
#include <kstandarddirs.h>
 
29
#include <kglobalsettings.h>
 
30
 
 
31
#include "splashscreen.h"
 
32
 
 
33
 
 
34
SplashScreen::SplashScreen()
 
35
    : QWidget(0, 0, WStyle_Customize|WStyle_Splash)
 
36
{
 
37
    currState_ = 0;
 
38
    progressBarSize_ = 3;
 
39
    
 
40
    QString file = locate( "appdata", "digikam-splash.png" );
 
41
 
 
42
    pix_ = new QPixmap(file);
 
43
 
 
44
    setErasePixmap( *pix_ );
 
45
    resize( pix_->size() );
 
46
    QRect scr = QApplication::desktop()->screenGeometry();
 
47
    move( scr.center() - rect().center() );
 
48
    show();
 
49
    animate();
 
50
 
 
51
    close_ = false;
 
52
    
 
53
    timer_ = new QTimer;
 
54
    connect(timer_, SIGNAL(timeout()),
 
55
            this,   SLOT(slotClose()));
 
56
    timer_->start(1000, true);
 
57
}
 
58
 
 
59
SplashScreen::~SplashScreen()
 
60
{
 
61
    delete pix_;
 
62
    delete timer_;
 
63
}
 
64
 
 
65
#if defined(Q_WS_X11)
 
66
void qt_wait_for_window_manager( QWidget *widget );
 
67
#endif
 
68
 
 
69
void SplashScreen::finish( QWidget *mainWin )
 
70
{
 
71
#if defined(Q_WS_X11)
 
72
    qt_wait_for_window_manager( mainWin );
 
73
#endif
 
74
    close_ = true;
 
75
    slotClose();
 
76
}
 
77
 
 
78
void SplashScreen::repaint()
 
79
{
 
80
    drawContents();
 
81
    QWidget::repaint();
 
82
    QApplication::flush();
 
83
}
 
84
 
 
85
void SplashScreen::mousePressEvent( QMouseEvent * )
 
86
{
 
87
    hide();
 
88
}
 
89
 
 
90
void SplashScreen::slotClose()
 
91
{
 
92
    if (!close_) {
 
93
        timer_->start(500, true);
 
94
        return;
 
95
    }
 
96
    
 
97
    if (timer_->isActive()) return;
 
98
    delete this;
 
99
}
 
100
 
 
101
void SplashScreen::message(const QString &message, int alignment,
 
102
                           const QColor &color )
 
103
{
 
104
    currStatus_ = message;
 
105
    currAlign_ = alignment;
 
106
    currColor_ = color;
 
107
    animate();
 
108
}
 
109
 
 
110
 
 
111
void SplashScreen::animate()
 
112
{
 
113
    currState_ = ((currState_ + 1) % (2*progressBarSize_-1));
 
114
    repaint();
 
115
}
 
116
 
 
117
void SplashScreen::drawContents()
 
118
{
 
119
    QPixmap textPix = *pix_;
 
120
    QPainter painter(&textPix, this);
 
121
    drawContents(&painter);
 
122
    setErasePixmap(textPix);
 
123
}
 
124
 
 
125
void SplashScreen::drawContents( QPainter *painter )
 
126
{
 
127
    int position;
 
128
    QColor basecolor (155, 192, 231);
 
129
 
 
130
    // Draw background circles
 
131
    painter->setPen(NoPen);
 
132
    painter->setBrush(QColor(225,234,231));
 
133
    painter->drawEllipse(21,7,9,9);
 
134
    painter->drawEllipse(32,7,9,9);
 
135
    painter->drawEllipse(43,7,9,9);
 
136
    
 
137
    // Draw animated circles, increments are chosen
 
138
    // to get close to background's color
 
139
    // (didn't work well with QColor::light function)
 
140
    for (int i=0; i < progressBarSize_; i++)
 
141
    {
 
142
        position = (currState_+i)%(2*progressBarSize_-1);
 
143
        if (position < 3)
 
144
        {
 
145
            painter->setBrush(QColor(basecolor.red()-18*i,
 
146
                              basecolor.green()-28*i,
 
147
                              basecolor.blue()-10*i));
 
148
            painter->drawEllipse(21+position*11,7,9,9);
 
149
        }
 
150
    }
 
151
    
 
152
    
 
153
    painter->setPen(currColor_);
 
154
    
 
155
    QFont fnt(KGlobalSettings::generalFont());
 
156
    int fntSize = fnt.pointSize();
 
157
    if (fntSize > 0)
 
158
    {
 
159
        fnt.setPointSize(fntSize-2);
 
160
    }
 
161
    else
 
162
    {
 
163
        fntSize = fnt.pixelSize();
 
164
        fnt.setPixelSize(fntSize-2);
 
165
    }
 
166
    painter->setFont(fnt);
 
167
   
 
168
    QRect r = rect();
 
169
    r.setRect( r.x() + 59, r.y() + 5, r.width() - 10, r.height() - 10 );
 
170
    painter->drawText(r, currAlign_, currStatus_);
 
171
}
 
172
 
 
173
#include "splashscreen.moc"