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>
33 //-----------------------------------------------------------------------------
35 KScreenSaver::KScreenSaver( WId id
) : QWidget()
39 create( id
, false, true );
43 KScreenSaver::~KScreenSaver()
45 destroy( false, false );
48 void KScreenSaver::embed( QWidget
*w
)
50 QApplication::sendPostedEvents();
51 #ifdef Q_WS_X11 //FIXME
52 XReparentWindow(QX11Info::display(), w
->winId(), winId(), 0, 0);
54 w
->setGeometry( 0, 0, width(), height() );
55 QApplication::sendPostedEvents();
58 KScreenSaverInterface::~KScreenSaverInterface()
62 QDialog
* KScreenSaverInterface::setup()
67 //============================================================================
69 class KBlankEffectPrivate
72 KBlankEffect::BlankEffect currentEffect
;
78 KBlankEffect::BlankEffect
KBlankEffect::effects
[] = {
79 &KBlankEffect::blankNormal
,
80 &KBlankEffect::blankSweepRight
,
81 &KBlankEffect::blankSweepDown
,
82 &KBlankEffect::blankBlocks
85 KBlankEffect::KBlankEffect( QObject
*parent
) : QObject( parent
)
87 d
= new KBlankEffectPrivate
;
88 d
->currentEffect
= &KBlankEffect::blankNormal
;
89 d
->effectProgress
= 0;
90 d
->timer
= new QTimer( this );
91 connect( d
->timer
, SIGNAL(timeout()), this, SLOT(timeout()) );
95 KBlankEffect::~KBlankEffect()
100 void KBlankEffect::finished()
103 d
->effectProgress
= 0;
108 void KBlankEffect::blank( QWidget
*w
, Effect effect
)
115 if ( effect
== Random
)
116 effect
= (Effect
)(KRandom::random() % MaximumEffects
);
118 d
->effectProgress
= 0;
120 d
->currentEffect
= effects
[ (int)effect
];
121 d
->timer
->start( 10 );
124 void KBlankEffect::timeout()
126 (this->*d
->currentEffect
)();
129 void KBlankEffect::blankNormal()
131 QPainter
p( d
->widget
);
132 p
.fillRect( 0, 0, d
->widget
->width(), d
->widget
->height(), Qt::black
);
137 void KBlankEffect::blankSweepRight()
139 QPainter
p( d
->widget
);
140 p
.fillRect( d
->effectProgress
, 0, 50, d
->widget
->height(), Qt::black
);
142 d
->effectProgress
+= 50;
143 if ( d
->effectProgress
>= d
->widget
->width() )
148 void KBlankEffect::blankSweepDown()
150 QPainter
p( d
->widget
);
151 p
.fillRect( 0, d
->effectProgress
, d
->widget
->width(), 50, Qt::black
);
153 d
->effectProgress
+= 50;
154 if ( d
->effectProgress
>= d
->widget
->height() )
159 void KBlankEffect::blankBlocks()
161 static int *block
= 0;
163 int bx
= (d
->widget
->width()+63)/64;
164 int by
= (d
->widget
->height()+63)/64;
166 if ( !d
->effectProgress
) {
167 block
= new int [ bx
*by
];
169 for ( int i
= 0; i
< bx
*by
; i
++ )
171 for ( int i
= 0; i
< bx
*by
; i
++ ) {
172 int swap
= KRandom::random()%(bx
*by
);
174 block
[i
] = block
[swap
];
179 QPainter
p( d
->widget
);
181 // erase a couple of blocks at a time, otherwise it looks too slow
182 for ( int i
= 0; i
< 2 && d
->effectProgress
< bx
*by
; i
++ ) {
183 int x
= block
[d
->effectProgress
]%bx
;
184 int y
= block
[d
->effectProgress
]/bx
;
185 p
.fillRect( x
*64, y
*64, 64, 64, Qt::black
);
191 if ( d
->effectProgress
>= bx
*by
) {
197 #include "kscreensaver.moc"