Back to index

kdeartwork  4.3.2
Classes | Public Types | Public Slots | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
KBlobSaver Class Reference

#include <blob.h>

Collaboration diagram for KBlobSaver:
Collaboration graph
[legend]

List of all members.

Classes

struct  KBSAlg

Public Types

typedef void(KBlobSaver::* AlgFunc )()

Public Slots

void setAlgorithm (int pos)

Public Member Functions

 KBlobSaver (WId id)
virtual ~KBlobSaver ()
void setDimension (int d)
void setShowlen (time_t s)
void setColorInc (int c)

Protected Member Functions

void paintEvent (QPaintEvent *event)

Private Member Functions

void lnSetup ()
void hsSetup ()
void cbSetup ()
void pcSetup ()
void lnNextFrame ()
void hsNextFrame ()
void cbNextFrame ()
void pcNextFrame ()
void box (int, int)
void readSettings ()

Private Attributes

QTimer timer
uint colors [RAMP]
uint lookup [256]
int colorInc
int tx
int ty
int dim
int xhalf
int yhalf
int alg
int newalg
int newalgp
time_t showlen
time_t start
KBSAlg Algs [ALG_LAST]
int ln_xinc
int ln_yinc
float hs_radians
float hs_rinc
float hs_flip
float hs_per
float cb_radians
float cb_rinc
float cb_sradians
float cb_radius
float cb_devradinc
float cb_deviate
float pc_angle
float pc_radius
float pc_inc
float pc_crot
float pc_div

Detailed Description

Definition at line 29 of file blob.h.


Class Documentation

struct KBlobSaver::KBSAlg

Definition at line 49 of file blob.h.

Class Members
AlgFunc Init
QString Name
AlgFunc NextFrame

Member Typedef Documentation

typedef void(KBlobSaver::* KBlobSaver::AlgFunc)()

Definition at line 48 of file blob.h.


Constructor & Destructor Documentation

Definition at line 91 of file blob.cpp.

    : KScreenSaver( id )
{
    setAttribute( Qt::WA_OpaquePaintEvent, true );

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

    rnd = new KRandomSequence();
    initAlg();
    QColor color;
    float ramp = (256.0-64.0)/(float)RAMP;

    // if 8-bit, create lookup table for color ramping further down
    if (QPixmap::defaultDepth() == 8)
    {
        QColormap cmap = QColormap::instance();
        memset(lookup, 0, 256*sizeof(uint));
        int i;
        for (i = 0; i < RAMP; i++)
        {
            color.setRgb(64+(int)(ramp*(float)i), 0, 0);
            colors[i] = cmap.pixel(color);
        }
        memset(lookup, cmap.pixel(Qt::black), sizeof(uint)*256);
        for (i = 0; i < RAMP-1; i++)
            lookup[colors[i]] = colors[i+1];
        lookup[cmap.pixel(Qt::black)] = lookup[colors[RAMP-1]] = colors[0];
    }
    else
    {
        // make special provision for preview mode
        if (height() < 400)
        {
            if (QPixmap::defaultDepth() > 8 )
                setColorInc(7);
            else
                setColorInc(4);
        }
        else
        {
            if (QPixmap::defaultDepth() > 8 )
                setColorInc(3);
            else
                setColorInc(2);
        }
    }

    // the dimensions of the blob painter
    dim = height()/70+1;

    // record starting time to know when to change frames
    start = time(NULL);

    // init some parameters used by all algorithms
    xhalf = width()/2;
    yhalf = height()/2;

    // means a new algorithm should be set at entrance of timer
    newalg = newalgp = 1;

    // init algorithm space
    Algs[0].Name = alg_str[0];
    Algs[0].Init = &KBlobSaver::lnSetup;
    Algs[0].NextFrame = &KBlobSaver::lnNextFrame;

    Algs[1].Name = alg_str[1];
    Algs[1].Init = &KBlobSaver::hsSetup;
    Algs[1].NextFrame = &KBlobSaver::hsNextFrame;

    Algs[2].Name = alg_str[2];
    Algs[2].Init = &KBlobSaver::cbSetup;
    Algs[2].NextFrame = &KBlobSaver::cbNextFrame;

    Algs[3].Name = alg_str[3];
    Algs[3].Init = &KBlobSaver::pcSetup;
    Algs[3].NextFrame = &KBlobSaver::pcNextFrame;

    // get setup from kde registry
    readSettings();

    // start timer which will update blob painter
    timer.start(SPEED);
    connect(&timer, SIGNAL(timeout()), SLOT(update()));
    show();
}

Here is the call graph for this function:

KBlobSaver::~KBlobSaver ( ) [virtual]

Definition at line 182 of file blob.cpp.

{
    timer.stop();

    delete rnd; rnd = 0;
}

Member Function Documentation

void KBlobSaver::box ( int  x,
int  y 
) [private]

Definition at line 364 of file blob.cpp.

{
    // for bad behaving algorithms that wants to cause an X trap
    // confine to the valid region before using potentially fatal XGetImage
    if ((x+dim) >= width())
        x = width()-dim-1;
    else if (x < 0)
        x = 0;
    if ((y+dim) > height())
        y = height()-dim-1;
    else if (y < 0)
        y = 0;

    // get the box region from the display to upgrade
    QImage img = QPixmap::grabWindow(winId(), x, y, dim, dim).toImage();

    // depending on the depth of the display, use either lookup table for
    // next rgb val ( 8-bit ) or ramp the color directly for other displays
    if ( img.depth() == 8)
    {
        // manipulate image by upgrading each pixel with 1 using a lookup
        // table as the color allocation could have resulted in a spread out
        // configuration of the color ramp
        for (int j = 0; j < img.height(); j++)
        {
            for (int i = 0; i < img.width(); i++)
            {
                img.scanLine(j)[i] = lookup[img.scanLine(j)[i]];
            }
        }
    }
    else
    {
        for (int j = 0; j < img.height(); j++)
        {
            for (int i = 0; i < img.width(); i++)
            {
                QRgb p = img.pixel( i, j );
                p += (colorInc<<18);
                img.setPixel( i, j, p );
            }
        }
    }

    // put the image back onto the screen
    QPainter p(this);
    p.drawImage( x, y, img );
}

Here is the caller graph for this function:

void KBlobSaver::cbNextFrame ( ) [private]

Definition at line 316 of file blob.cpp.

{
    int deviate;

    // calculate deviation of circle main radius
    deviate = (int)(sin(cb_sradians)*cb_deviate);

    // calculate topleft of box as a circle with a sine perturbed radius
    tx = (int)(cos(cb_radians)*(cb_radius+deviate))+xhalf;
    ty = (int)(sin(cb_radians)*(cb_radius+deviate))+yhalf;

    // draw the box
    box(tx, ty);

    // increase greater circle render angle
    cb_radians += cb_rinc;
    if (cb_radians > 2.0*M_PI)
        cb_radians -= 2.0*M_PI;

    // increase radius deviation offset on sine wave
    cb_sradians += cb_devradinc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void KBlobSaver::cbSetup ( ) [private]

Definition at line 215 of file blob.cpp.

{
    cb_radians = 0.0;
    cb_rinc = (2.0*M_PI)/360.0;
    cb_sradians = 0.0;
    cb_deviate = SMALLRAND(height()/20)+(height()/15);
    cb_radius = height()/2-cb_deviate*2-2*dim;
    cb_devradinc = (rnd->getDouble()*10.0*2.0*M_PI)/360.0;
}

Here is the caller graph for this function:

void KBlobSaver::hsNextFrame ( ) [private]

Definition at line 291 of file blob.cpp.

{
    static int xlen = width()-(4*dim);
    static int ylen = height()-(4*dim);

    // calc x as offset on angle line and y as vertical offset
    // on interval -1..1 sine of angle
    tx = (int)((hs_radians/(hs_per*M_PI))*(float)xlen);
    ty = (int)((float)(ylen/4)*(hs_flip*sin(hs_radians)))+yhalf;

    // draw new box
    box(tx, ty);

    // set new radians
    hs_radians += hs_rinc;
    if (hs_radians > hs_per*M_PI)
    {
        hs_rinc *= -1.0;
        hs_radians += hs_rinc;
        hs_flip *= -1.0;
    }
    else if (hs_radians < 0.0)
        hsSetup();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void KBlobSaver::hsSetup ( ) [private]

Definition at line 207 of file blob.cpp.

{
    hs_per = SMALLRAND(7);
    hs_radians = 0.0;
    hs_rinc = (hs_per*M_PI)/(hs_per*90*4);
    hs_flip = 1.0;
}

Here is the caller graph for this function:

void KBlobSaver::lnNextFrame ( ) [private]

Definition at line 259 of file blob.cpp.

{
    int dir;

    // depending on the algorithm to use, move the blob painter to
    // a new location
    // check for wall hit to change direction
    if (tx+dim+ln_xinc > (int)width()-1 || tx+ln_xinc < 0)
    {
        if (ln_xinc > 0)
            dir = -1;
        else
            dir = 1;
        ln_xinc = SMALLRAND(3)*dir;
    }
    if (ty+dim+ln_yinc > (int)height()-1 || ty+ln_yinc < 0)
    {
        if (ln_yinc > 0)
            dir = -1;
        else
            dir = 1;
        ln_yinc = SMALLRAND(2)*dir;
    }

    // move box to new position
    tx += ln_xinc;
    ty += ln_yinc;

    // draw new box
    box(tx, ty);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void KBlobSaver::lnSetup ( ) [private]

Definition at line 195 of file blob.cpp.

{
    // initialize the blob movement dictators with random vals
    // incrementals on axis
    ln_xinc = SMALLRAND(3);
    ln_yinc = SMALLRAND(2);

    // start position
    tx = SMALLRAND(width()-dim-ln_xinc*2);
    ty = SMALLRAND(height()-dim-ln_yinc*2);
}

Here is the caller graph for this function:

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

Definition at line 235 of file blob.cpp.

{
    time_t now = time(NULL);

    // should algorithm be changed
    if (now-start > showlen)
        newalg = newalgp;

    // set new algorithm
    if (newalg)
    {
        QPainter p(this);
        p.fillRect(rect(), p.background());
        if (newalg == 1)
            alg = SMALLRAND(ALG_LAST)-1;
        (this->*Algs[alg].Init)();
        newalg = 0;
        start = time(NULL);
    }

    // gen next fram for current algorithm
    (this->*Algs[alg].NextFrame)();
}
void KBlobSaver::pcNextFrame ( ) [private]

Definition at line 339 of file blob.cpp.

{
    static float scale = (float)height()/3.0 - 4.0*dim;

    // simple polar coordinate equation
    if (pc_div < 1.0)
        pc_radius = cos(2.0*pc_angle);
    else
        pc_radius = 1.0/pc_div + cos(2.0*pc_angle);

    tx = (int)(scale*pc_radius*cos(pc_angle+pc_crot))+xhalf;
    ty = (int)(scale*pc_radius*sin(pc_angle+pc_crot))+yhalf;

    // advance blob painter
    box(tx, ty);

    // new movement parameters
    pc_angle += pc_inc;
    if (pc_angle > 2.0*M_PI)
    {
        pc_angle -= 2.0*M_PI;
        pc_crot += M_PI/45.0;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void KBlobSaver::pcSetup ( ) [private]

Definition at line 225 of file blob.cpp.

{
    pc_angle = 0.0;
    pc_radius = 0.0;
    pc_inc = (2.0*M_PI)/720.0;
    pc_crot = 0.0;
    pc_div = SMALLRAND(4)-1;
}

Here is the caller graph for this function:

void KBlobSaver::readSettings ( ) [private]

Definition at line 413 of file blob.cpp.

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

    // number of seconds to spend on a frame
    showlen = config.readEntry("Showtime", 3*60);

    // algorithm to use. if not set then use random
    alg = config.readEntry("Algorithm", int(ALG_RANDOM));
    if (alg == ALG_RANDOM)
       newalg = 1;
    else
       newalg = 2;
    newalgp = newalg;
}

Here is the caller graph for this function:

void KBlobSaver::setAlgorithm ( int  pos) [slot]

Definition at line 189 of file blob.cpp.

{
    newalg = newalgp = ((a == ALG_RANDOM) ? 1 : 2);
    alg = a;
}

Here is the caller graph for this function:

void KBlobSaver::setColorInc ( int  c) [inline]

Definition at line 41 of file blob.h.

       { colorInc = c; }

Here is the caller graph for this function:

void KBlobSaver::setDimension ( int  d) [inline]

Definition at line 37 of file blob.h.

       { dim = d; }

Here is the caller graph for this function:

void KBlobSaver::setShowlen ( time_t  s) [inline]

Definition at line 39 of file blob.h.

       { showlen = s; }

Member Data Documentation

int KBlobSaver::alg [private]

Definition at line 64 of file blob.h.

Definition at line 66 of file blob.h.

float KBlobSaver::cb_deviate [private]

Definition at line 70 of file blob.h.

float KBlobSaver::cb_devradinc [private]

Definition at line 69 of file blob.h.

float KBlobSaver::cb_radians [private]

Definition at line 69 of file blob.h.

float KBlobSaver::cb_radius [private]

Definition at line 69 of file blob.h.

float KBlobSaver::cb_rinc [private]

Definition at line 69 of file blob.h.

float KBlobSaver::cb_sradians [private]

Definition at line 69 of file blob.h.

int KBlobSaver::colorInc [private]

Definition at line 60 of file blob.h.

uint KBlobSaver::colors[RAMP] [private]

Definition at line 58 of file blob.h.

int KBlobSaver::dim [private]

Definition at line 62 of file blob.h.

float KBlobSaver::hs_flip [private]

Definition at line 68 of file blob.h.

float KBlobSaver::hs_per [private]

Definition at line 68 of file blob.h.

float KBlobSaver::hs_radians [private]

Definition at line 68 of file blob.h.

float KBlobSaver::hs_rinc [private]

Definition at line 68 of file blob.h.

int KBlobSaver::ln_xinc [private]

Definition at line 67 of file blob.h.

int KBlobSaver::ln_yinc [private]

Definition at line 67 of file blob.h.

uint KBlobSaver::lookup[256] [private]

Definition at line 59 of file blob.h.

int KBlobSaver::newalg [private]

Definition at line 64 of file blob.h.

int KBlobSaver::newalgp [private]

Definition at line 64 of file blob.h.

float KBlobSaver::pc_angle [private]

Definition at line 71 of file blob.h.

float KBlobSaver::pc_crot [private]

Definition at line 71 of file blob.h.

float KBlobSaver::pc_div [private]

Definition at line 71 of file blob.h.

float KBlobSaver::pc_inc [private]

Definition at line 71 of file blob.h.

float KBlobSaver::pc_radius [private]

Definition at line 71 of file blob.h.

time_t KBlobSaver::showlen [private]

Definition at line 65 of file blob.h.

time_t KBlobSaver::start [private]

Definition at line 65 of file blob.h.

QTimer KBlobSaver::timer [private]

Definition at line 57 of file blob.h.

int KBlobSaver::tx [private]

Definition at line 61 of file blob.h.

int KBlobSaver::ty [private]

Definition at line 61 of file blob.h.

int KBlobSaver::xhalf [private]

Definition at line 63 of file blob.h.

int KBlobSaver::yhalf [private]

Definition at line 63 of file blob.h.


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