1
/* This file is part of the KDE libraries
3
Copyright (c) 2001 Martin R. Jones <mjones@kde.org>
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
License as published by the Free Software Foundation; either
8
version 2 of the License, or (at your option) any later version.
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Library General Public License for more details.
15
You should have received a copy of the GNU Library General Public License
16
along with this library; see the file COPYING.LIB. If not, write to
17
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
Boston, MA 02110-1301, USA.
21
#include "kscreensaver.h"
25
#include <QtGui/QX11Info>
26
#include <QApplication>
34
//-----------------------------------------------------------------------------
36
KScreenSaver::KScreenSaver( WId id ) : QWidget(), embeddedWidget(0)
40
create( id, false, true );
44
KScreenSaver::~KScreenSaver()
46
destroy( false, false );
49
bool KScreenSaver::event(QEvent* e)
51
bool r = QWidget::event(e);
52
if (e->type() == QEvent::Polish)
53
setAttribute(Qt::WA_StyledBackground, false);
54
if ((e->type() == QEvent::Resize) && embeddedWidget)
55
embeddedWidget->resize( size() );
59
void KScreenSaver::embed( QWidget *w )
62
QApplication::sendPostedEvents();
63
#ifdef Q_WS_X11 //FIXME
64
XReparentWindow(QX11Info::display(), w->winId(), winId(), 0, 0);
66
w->setGeometry( 0, 0, width(), height() );
68
QApplication::sendPostedEvents();
71
KScreenSaverInterface::~KScreenSaverInterface()
75
QDialog* KScreenSaverInterface::setup()
80
//============================================================================
82
class KBlankEffectPrivate
85
KBlankEffect::BlankEffect currentEffect;
91
KBlankEffect::BlankEffect KBlankEffect::effects[] = {
92
&KBlankEffect::blankNormal,
93
&KBlankEffect::blankSweepRight,
94
&KBlankEffect::blankSweepDown,
95
&KBlankEffect::blankBlocks
98
KBlankEffect::KBlankEffect( QObject *parent ) : QObject( parent )
100
d = new KBlankEffectPrivate;
101
d->currentEffect = &KBlankEffect::blankNormal;
102
d->effectProgress = 0;
103
d->timer = new QTimer( this );
104
connect( d->timer, SIGNAL(timeout()), this, SLOT(timeout()) );
108
KBlankEffect::~KBlankEffect()
113
void KBlankEffect::finished()
116
d->effectProgress = 0;
121
void KBlankEffect::blank( QWidget *w, Effect effect )
128
if ( effect == Random )
129
effect = (Effect)(KRandom::random() % MaximumEffects);
131
d->effectProgress = 0;
133
d->currentEffect = effects[ (int)effect ];
134
d->timer->start( 10 );
137
void KBlankEffect::timeout()
139
(this->*d->currentEffect)();
142
void KBlankEffect::blankNormal()
144
QPainter p( d->widget );
145
p.fillRect( 0, 0, d->widget->width(), d->widget->height(), Qt::black );
150
void KBlankEffect::blankSweepRight()
152
QPainter p( d->widget );
153
p.fillRect( d->effectProgress, 0, 50, d->widget->height(), Qt::black );
155
d->effectProgress += 50;
156
if ( d->effectProgress >= d->widget->width() )
161
void KBlankEffect::blankSweepDown()
163
QPainter p( d->widget );
164
p.fillRect( 0, d->effectProgress, d->widget->width(), 50, Qt::black );
166
d->effectProgress += 50;
167
if ( d->effectProgress >= d->widget->height() )
172
void KBlankEffect::blankBlocks()
174
static int *block = 0;
176
int bx = (d->widget->width()+63)/64;
177
int by = (d->widget->height()+63)/64;
179
if ( !d->effectProgress ) {
180
block = new int [ bx*by ];
182
for ( int i = 0; i < bx*by; i++ )
184
for ( int i = 0; i < bx*by; i++ ) {
185
int swap = KRandom::random()%(bx*by);
187
block[i] = block[swap];
192
QPainter p( d->widget );
194
// erase a couple of blocks at a time, otherwise it looks too slow
195
for ( int i = 0; i < 2 && d->effectProgress < bx*by; i++ ) {
196
int x = block[d->effectProgress]%bx;
197
int y = block[d->effectProgress]/bx;
198
p.fillRect( x*64, y*64, 64, 64, Qt::black );
204
if ( d->effectProgress >= bx*by ) {
210
#include "kscreensaver.moc"