You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
232 lines
5.3 KiB
232 lines
5.3 KiB
15 years ago
|
/* This file is part of the KDE libraries
|
||
|
|
||
|
Copyright (c) 2001 Martin R. Jones <mjones@kde.org>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
15 years ago
|
#include <tqpainter.h>
|
||
|
#include <tqtimer.h>
|
||
15 years ago
|
#include <kapplication.h>
|
||
12 years ago
|
#include "tdescreensaver.h"
|
||
15 years ago
|
#ifdef Q_WS_X11
|
||
|
#include <X11/Xlib.h>
|
||
|
#else
|
||
|
typedef WId Window;
|
||
|
#endif
|
||
|
|
||
|
#undef KeyPress
|
||
|
#undef KeyRelease
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
|
||
|
class KScreenSaverPrivate
|
||
|
{
|
||
|
public:
|
||
15 years ago
|
TQWidget *owner;
|
||
15 years ago
|
};
|
||
|
|
||
15 years ago
|
KScreenSaver::KScreenSaver( WId id ) : TQWidget()
|
||
15 years ago
|
{
|
||
|
Window root;
|
||
|
int ai;
|
||
|
unsigned int au;
|
||
|
unsigned int w = 0;
|
||
|
unsigned int h = 0;
|
||
|
|
||
12 years ago
|
XSync(tqt_xdisplay(), false);
|
||
|
|
||
15 years ago
|
d = new KScreenSaverPrivate;
|
||
14 years ago
|
d->owner = TQT_TQWIDGET(find( id ));
|
||
15 years ago
|
if ( d->owner )
|
||
|
installEventFilter( this );
|
||
|
|
||
|
if ( id )
|
||
|
{
|
||
|
#ifdef Q_WS_X11 //FIXME
|
||
13 years ago
|
XGetGeometry(tqt_xdisplay(), (Drawable)id, &root, &ai, &ai,
|
||
15 years ago
|
&w, &h, &au, &au);
|
||
|
#endif
|
||
|
|
||
|
create( id, false, true );
|
||
|
}
|
||
|
|
||
|
if ( w == 0 ) w = 600;
|
||
|
if ( h == 0 ) h = 420;
|
||
|
resize( w, h );
|
||
12 years ago
|
TDEApplication::sendPostedEvents();
|
||
15 years ago
|
show();
|
||
|
}
|
||
|
|
||
|
KScreenSaver::~KScreenSaver()
|
||
|
{
|
||
|
destroy( false, false );
|
||
|
delete d;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KScreenSaver::embed( TQWidget *w )
|
||
15 years ago
|
{
|
||
12 years ago
|
TDEApplication::sendPostedEvents();
|
||
15 years ago
|
#ifdef Q_WS_X11 //FIXME
|
||
13 years ago
|
XReparentWindow(tqt_xdisplay(), w->winId(), winId(), 0, 0);
|
||
15 years ago
|
#endif
|
||
|
w->setGeometry( 0, 0, width(), height() );
|
||
12 years ago
|
TDEApplication::sendPostedEvents();
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
bool KScreenSaver::eventFilter( TQObject *o, TQEvent *e )
|
||
15 years ago
|
{
|
||
|
// make sure events get to the original window owner
|
||
14 years ago
|
if ( d->owner && TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(this) ) {
|
||
15 years ago
|
TQApplication::sendEvent( d->owner, e );
|
||
15 years ago
|
return false;
|
||
|
}
|
||
|
|
||
15 years ago
|
return TQWidget::eventFilter( o, e );
|
||
15 years ago
|
}
|
||
|
|
||
|
//============================================================================
|
||
|
|
||
|
class KBlankEffectPrivate
|
||
|
{
|
||
|
public:
|
||
|
KBlankEffect::BlankEffect currentEffect;
|
||
|
int effectProgress;
|
||
15 years ago
|
TQTimer *timer;
|
||
|
TQWidget *widget;
|
||
15 years ago
|
};
|
||
|
|
||
|
KBlankEffect::BlankEffect KBlankEffect::effects[] = {
|
||
|
&KBlankEffect::blankNormal,
|
||
|
&KBlankEffect::blankSweepRight,
|
||
|
&KBlankEffect::blankSweepDown,
|
||
|
&KBlankEffect::blankBlocks
|
||
|
};
|
||
|
|
||
15 years ago
|
KBlankEffect::KBlankEffect( TQObject *parent ) : TQObject( parent )
|
||
15 years ago
|
{
|
||
|
d = new KBlankEffectPrivate;
|
||
|
d->currentEffect = &KBlankEffect::blankNormal;
|
||
|
d->effectProgress = 0;
|
||
15 years ago
|
d->timer = new TQTimer( this );
|
||
|
connect( d->timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(timeout()) );
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
|
KBlankEffect::~KBlankEffect()
|
||
|
{
|
||
|
delete d;
|
||
|
}
|
||
|
|
||
|
void KBlankEffect::finished()
|
||
|
{
|
||
|
d->timer->stop();
|
||
|
d->effectProgress = 0;
|
||
|
emit doneBlank();
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
void KBlankEffect::blank( TQWidget *w, Effect effect )
|
||
15 years ago
|
{
|
||
|
if ( !w ) {
|
||
|
emit doneBlank();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if ( effect == Random )
|
||
|
effect = (Effect)(kapp->random() % MaximumEffects);
|
||
|
|
||
|
d->effectProgress = 0;
|
||
|
d->widget = w;
|
||
|
d->currentEffect = effects[ (int)effect ];
|
||
|
d->timer->start( 10 );
|
||
|
}
|
||
|
|
||
|
void KBlankEffect::timeout()
|
||
|
{
|
||
|
(this->*d->currentEffect)();
|
||
|
}
|
||
|
|
||
|
void KBlankEffect::blankNormal()
|
||
|
{
|
||
15 years ago
|
TQPainter p( d->widget );
|
||
15 years ago
|
p.fillRect( 0, 0, d->widget->width(), d->widget->height(), black );
|
||
|
finished();
|
||
|
}
|
||
|
|
||
|
|
||
|
void KBlankEffect::blankSweepRight()
|
||
|
{
|
||
15 years ago
|
TQPainter p( d->widget );
|
||
15 years ago
|
p.fillRect( d->effectProgress, 0, 50, d->widget->height(), black );
|
||
|
kapp->flushX();
|
||
|
d->effectProgress += 50;
|
||
|
if ( d->effectProgress >= d->widget->width() )
|
||
|
finished();
|
||
|
}
|
||
|
|
||
|
|
||
|
void KBlankEffect::blankSweepDown()
|
||
|
{
|
||
15 years ago
|
TQPainter p( d->widget );
|
||
15 years ago
|
p.fillRect( 0, d->effectProgress, d->widget->width(), 50, black );
|
||
|
kapp->flushX();
|
||
|
d->effectProgress += 50;
|
||
|
if ( d->effectProgress >= d->widget->height() )
|
||
|
finished();
|
||
|
}
|
||
|
|
||
|
|
||
|
void KBlankEffect::blankBlocks()
|
||
|
{
|
||
|
static int *block = 0;
|
||
|
|
||
|
int bx = (d->widget->width()+63)/64;
|
||
|
int by = (d->widget->height()+63)/64;
|
||
|
|
||
|
if ( !d->effectProgress ) {
|
||
|
block = new int [ bx*by ];
|
||
|
|
||
|
for ( int i = 0; i < bx*by; i++ )
|
||
|
block[i] = i;
|
||
|
for ( int i = 0; i < bx*by; i++ ) {
|
||
|
int swap = kapp->random()%(bx*by);
|
||
|
int tmp = block[i];
|
||
|
block[i] = block[swap];
|
||
|
block[swap] = tmp;
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
TQPainter p( d->widget );
|
||
15 years ago
|
|
||
|
// erase a couple of blocks at a time, otherwise it looks too slow
|
||
|
for ( int i = 0; i < 2 && d->effectProgress < bx*by; i++ ) {
|
||
|
int x = block[d->effectProgress]%bx;
|
||
|
int y = block[d->effectProgress]/bx;
|
||
|
p.fillRect( x*64, y*64, 64, 64, black );
|
||
|
d->effectProgress++;
|
||
|
}
|
||
|
|
||
|
kapp->flushX();
|
||
|
|
||
|
if ( d->effectProgress >= bx*by ) {
|
||
|
delete[] block;
|
||
|
finished();
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
#include "tdescreensaver.moc"
|