Back to index

kdeartwork  4.3.2
Public Member Functions | Private Attributes
Glow::GlowButtonFactory Class Reference

#include <glowbutton.h>

List of all members.

Public Member Functions

 GlowButtonFactory ()
int getSteps ()
void setSteps (int steps)
 Sets the number of pixmaps used to create the glow effect of the glow buttons.
QPixmap * createGlowButtonPixmap (const QImage &bg_image, const QImage &fg_image, const QImage &glow_image, const QColor &color, const QColor &glow_color)
 Creates a background pixmap for a glow button.
GlowButtoncreateGlowButton (QWidget *parent, const char *name, const QString &tip, const int realizeBtns=Qt::LeftButton)

Private Attributes

int _steps

Detailed Description

Definition at line 96 of file glowbutton.h.


Constructor & Destructor Documentation

Definition at line 233 of file glowbutton.cpp.

{
       _steps = 20;
}

Member Function Documentation

GlowButton * Glow::GlowButtonFactory::createGlowButton ( QWidget *  parent,
const char *  name,
const QString &  tip,
const int  realizeBtns = Qt::LeftButton 
)

Definition at line 333 of file glowbutton.cpp.

{
       GlowButton *glowButton = new GlowButton(parent, name, tip, realizeBtns);
       return glowButton;
}

Here is the caller graph for this function:

QPixmap * Glow::GlowButtonFactory::createGlowButtonPixmap ( const QImage &  bg_image,
const QImage &  fg_image,
const QImage &  glow_image,
const QColor &  color,
const QColor &  glow_color 
)

Creates a background pixmap for a glow button.

The pixmap will consist of sub pixmaps of the size of the button which are placed one below the other. Each sub pixmap is copied on the button in succession to create the glow effect. The last sub pixmap is used when the button is pressed.

Definition at line 248 of file glowbutton.cpp.

{
              if (bg_image.size() != fg_image.size()
                     || fg_image.size() != glow_image.size()) {
                            std::cerr << "Image size error" << std::endl;
                            return new QPixmap();
              }

              QImage colorized_bg_image = bg_image.copy();
              KIconEffect::colorize (colorized_bg_image, color, 1.0);

              int w = colorized_bg_image.width();
              int h = colorized_bg_image.height();

              QImage image (w, (_steps+1)*h, 32);
              image.setAlphaBuffer (true);
              for (int i=0; i<_steps+1; ++i) {
                     for (int y=0; y<h; ++y) {
                            uint * src1_line = (uint*) colorized_bg_image.scanLine (y);
                            uint * src2_line = (uint*) fg_image.scanLine (y);
                            uint * dst_line = (uint*) image.scanLine (i*h+y);
                            for (int x=0; x<w; ++x) {
                                   int r = qRed (*(src1_line+x));
                                   int g = qGreen (*(src1_line+x));
                                   int b = qBlue (*(src1_line+x));
                                   int a = qMax (qAlpha(*(src1_line+x)),qGray(*(src2_line+x)));
                                   *(dst_line+x) = qRgba (r, g, b, a);
                            }
                     }
              }
              QPixmap * pixmap = new QPixmap (image);
              QPainter painter (pixmap);

              bool dark = (qGray(color.rgb()) <= 127);
              QImage fg_img (w, h, 32);
              fg_img.setAlphaBuffer (true);
              for (int y=0; y<h; ++y) {
                     uint * src_line = (uint*) fg_image.scanLine (y);
                     uint * dst_line = (uint*) fg_img.scanLine (y);
                     for (int x=0; x<w; ++x) {
                            int alpha = qGray (*(src_line+x));
                            if (dark)
                                          *(dst_line+x) = qRgba (255, 255, 255, alpha);
                            else
                                          *(dst_line+x) = qRgba (0, 0, 0, alpha);
                     }
              }

              int r = glow_color.red();
              int g = glow_color.green();
              int b = glow_color.blue();
              QImage glow_img (w, h, 32);
              glow_img.setAlphaBuffer (true);
              for (int i=0; i<_steps; ++i) {
                     painter.drawImage (0, i*h, fg_img);
                     for (int y=0; y<h; ++y) {
                            uint * src_line = (uint*) glow_image.scanLine(y);
                            uint * dst_line = (uint*) glow_img.scanLine(y);
                            for (int x=0; x<w; ++x) {
                                   int alpha =
                                                 (int) (qGray (*(src_line+x)) * ((double) i/_steps));
                                   *(dst_line+x) = qRgba (r, g, b, alpha);
                            }
                     }
                     painter.drawImage (0, i*h, glow_img);
              }
              painter.drawImage (0, _steps*h, fg_img);
              for (int y=0; y<h; ++y) {
                            uint * src_line = (uint*) glow_image.scanLine (y);
                            uint * dst_line = (uint*) glow_img.scanLine (y);
                            for (int x=0; x<w; ++x) {
                                   int alpha = qGray (*(src_line+x));
                                   *(dst_line+x) = qRgba (r, g, b, alpha);
                            }
              }
              painter.drawImage (0, _steps*h, glow_img);

              return pixmap;
}

Here is the caller graph for this function:

Definition at line 238 of file glowbutton.cpp.

{
       return _steps;
}
void Glow::GlowButtonFactory::setSteps ( int  steps)

Sets the number of pixmaps used to create the glow effect of the glow buttons.

Definition at line 243 of file glowbutton.cpp.

{
       _steps = steps;
}

Member Data Documentation

Definition at line 128 of file glowbutton.h.


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