Back to index

kdeartwork  4.3.2
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions
kPolygonSaver Class Reference

#include <polygon.h>

List of all members.

Public Member Functions

 kPolygonSaver (WId id)
virtual ~kPolygonSaver ()
void setPolygon (int len, int ver)
void setSpeed (int spd)

Protected Member Functions

void paintEvent (QPaintEvent *event)

Protected Attributes

QTimer timer
int numLines
int numVertices
int speed
QColor colors [64]
int currentColor
QList< QPolygon > polygons
QVector< QPoint > directions
KRandomSequence rnd

Private Member Functions

void readSettings ()
void initialisePolygons ()
void moveVertices ()
void initialiseColor ()
void nextColor ()

Detailed Description

Definition at line 21 of file polygon.h.


Constructor & Destructor Documentation

Definition at line 226 of file polygon.cpp.

                                     : KScreenSaver( id )
{
       readSettings();

       directions.resize( numVertices );

        {
            QPalette palette;
            palette.setColor( backgroundRole(), Qt::black );
            setPalette( palette );
           setAutoFillBackground(true);
        }

       initialiseColor();
       initialisePolygons();

       timer.start( speed );
       connect( &timer, SIGNAL( timeout() ), SLOT( update() ) );
        show();
}

Here is the call graph for this function:

Definition at line 247 of file polygon.cpp.

{
       timer.stop();
}

Member Function Documentation

void kPolygonSaver::initialiseColor ( ) [private]

Definition at line 375 of file polygon.cpp.

{
       for ( int i = 0; i < 64; i++ )
       {
              colors[i].setHsv( i * 360 / 64, 255, 255 );
       }

    currentColor = 0;
}

Here is the caller graph for this function:

Definition at line 317 of file polygon.cpp.

{
       int i;

       polygons.append( QPolygon( numVertices + 1 ) );

       QPolygon &poly = polygons.last();

       for ( i = 0; i < numVertices; i++ )
       {
              poly.setPoint( i, rnd.getLong(width()), rnd.getLong(height()) );
              directions[i].setX( 16 - rnd.getLong(8) * 4 );
              if ( directions[i].x() == 0 )
                     directions[i].setX( 1 );
              directions[i].setY( 16 - rnd.getLong(8) * 4 );
              if ( directions[i].y() == 0 )
                     directions[i].setY( 1 );
       }

       poly.setPoint( i, poly.point(0) );
}

Here is the caller graph for this function:

void kPolygonSaver::moveVertices ( ) [private]

Definition at line 340 of file polygon.cpp.

{
       int i;
       QPolygon &poly = polygons.last();

       for ( i = 0; i < numVertices; i++ )
       {
              poly.setPoint( i, poly.point(i) + directions[i] );
              if ( poly[i].x() >= (int)width() )
              {
                     directions[i].setX( -(rnd.getLong(4) + 1) * 4 );
                     poly[i].setX( (int)width() );
              }
              else if ( poly[i].x() < 0 )
              {
                     directions[i].setX( (rnd.getLong(4) + 1) * 4 );
                     poly[i].setX( 0 );
              }

              if ( poly[i].y() >= (int)height() )
              {
                     directions[i].setY( -(rnd.getLong(4) + 1) * 4 );
                     poly[i].setY( height() );
              }
              else if ( poly[i].y() < 0 )
              {
                     directions[i].setY( (rnd.getLong(4) + 1) * 4 );
                     poly[i].setY( 0 );
              }
       }

       poly.setPoint( i, poly.point(0) );
}

Here is the caller graph for this function:

void kPolygonSaver::nextColor ( ) [private]

Definition at line 386 of file polygon.cpp.

{
       currentColor++;

       if ( currentColor > 63 )
              currentColor = 0;
}

Here is the caller graph for this function:

void kPolygonSaver::paintEvent ( QPaintEvent *  event) [protected]

Definition at line 295 of file polygon.cpp.

{
    setAttribute( Qt::WA_NoSystemBackground ); // Only after initial clear
    QPainter p( this );
       if ( polygons.count() > numLines )
       {
              p.setPen( Qt::black );
                p.drawPolyline( polygons.first() );
       }

       nextColor();
    p.setPen( colors[currentColor] );
    p.drawPolyline( polygons.last() );

       if ( polygons.count() > numLines )
              polygons.removeFirst();

       polygons.append( QPolygon( polygons.last() ) );
       moveVertices();
}

Here is the call graph for this function:

void kPolygonSaver::readSettings ( ) [private]

Definition at line 275 of file polygon.cpp.

{
    KConfigGroup config(KGlobal::config(), "Settings");

    numLines = config.readEntry( "Length", 10 );
    if ( numLines > 50 )
           numLines = 50;
    else if ( numLines < 1 )
           numLines = 1;

    numVertices = config.readEntry( "Vertices", 3 );
    if ( numVertices > 20 )
           numVertices = 20;
    else if ( numVertices < 3 )
           numVertices = 3;

    speed = 100 - config.readEntry( "Speed", 50 );
}

Here is the caller graph for this function:

void kPolygonSaver::setPolygon ( int  len,
int  ver 
)

Definition at line 253 of file polygon.cpp.

{
       timer.stop();
       numLines = len;
       numVertices = ver;

       directions.resize( numVertices );
       polygons.clear();
       initialisePolygons();

       timer.start( speed );
}

Here is the call graph for this function:

Here is the caller graph for this function:

void kPolygonSaver::setSpeed ( int  spd)

Definition at line 267 of file polygon.cpp.

{
       timer.stop();
       speed = 100-spd;
       timer.start( speed );
}

Here is the caller graph for this function:


Member Data Documentation

QColor kPolygonSaver::colors[64] [protected]

Definition at line 46 of file polygon.h.

int kPolygonSaver::currentColor [protected]

Definition at line 47 of file polygon.h.

QVector<QPoint> kPolygonSaver::directions [protected]

Definition at line 49 of file polygon.h.

int kPolygonSaver::numLines [protected]

Definition at line 43 of file polygon.h.

int kPolygonSaver::numVertices [protected]

Definition at line 44 of file polygon.h.

QList<QPolygon> kPolygonSaver::polygons [protected]

Definition at line 48 of file polygon.h.

KRandomSequence kPolygonSaver::rnd [protected]

Definition at line 50 of file polygon.h.

int kPolygonSaver::speed [protected]

Definition at line 45 of file polygon.h.

QTimer kPolygonSaver::timer [protected]

Definition at line 42 of file polygon.h.


The documentation for this class was generated from the following files: