kstars
starpixmap.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "starpixmap.h"
00020
00021 #include <kimageeffect.h>
00022 #include <qbitmap.h>
00023 #include <qimage.h>
00024 #include <qpainter.h>
00025
00026 #define STARSIZE 24
00027
00028 StarPixmap::StarPixmap (int starColorMode, int starColorIntensity)
00029 : colorMode (starColorMode), colorIntensity (starColorIntensity)
00030 {
00031 loadPixmaps (starColorMode, starColorIntensity);
00032 }
00033
00034 QPixmap* StarPixmap::getPixmap (QChar *color, int size) {
00035 int c;
00036
00037
00038 switch (*color) {
00039 case 'O' : c = 1; break;
00040 case 'B' : c = 2; break;
00041 case 'A' : c = 3; break;
00042 case 'F' : c = 4; break;
00043 case 'G' : c = 5; break;
00044 case 'K' : c = 6; break;
00045 case 'M' : c = 7; break;
00046 case 'N' : c = 8; break;
00047 case 'P' : c = 9; break;
00048 default : c = 0;
00049 }
00050
00051 if (size > 25) size = 25;
00052 return &starPixmaps[c][size];
00053 }
00054
00055 void StarPixmap::setColorMode( int newMode ) {
00056 colorMode = newMode;
00057 loadPixmaps ( colorMode, colorIntensity );
00058 }
00059
00060 void StarPixmap::setIntensity ( int newIntensity ) {
00061 colorIntensity = newIntensity;
00062 loadPixmaps ( colorMode, colorIntensity );
00063 }
00064
00065 void StarPixmap::loadPixmaps (int newColorMode, int newColorIntensity) {
00066 colorMode = newColorMode;
00067 colorIntensity = newColorIntensity;
00068
00069 if (colorIntensity < 0) colorIntensity = 0;
00070
00071 QPixmap pix (STARSIZE, STARSIZE);
00072 QBitmap mask (STARSIZE, STARSIZE);
00073 QImage image;
00074 QPainter p;
00075 QMemArray<QColor> starColor;
00076 starColor.resize( 8 );
00077 image.setAlphaBuffer(true);
00078
00079 starColor[0] = QColor( 255, 255, 255 );
00080 starColor[1] = QColor( 0, 0, 255 );
00081 starColor[2] = QColor( 0, 200, 255 );
00082 starColor[3] = QColor( 0, 255, 255 );
00083 starColor[4] = QColor( 200, 255, 100 );
00084 starColor[5] = QColor( 255, 255, 0 );
00085 starColor[6] = QColor( 255, 100, 0 );
00086 starColor[7] = QColor( 255, 0, 0 );
00087
00088
00089 if ( colorMode==1 )
00090 pix.fill (Qt::red);
00091 else if ( colorMode==2 )
00092 pix.fill (Qt::black);
00093 else
00094 pix.fill (Qt::white);
00095
00096 for (int color = 0; color < 10; color ++) {
00097 int ic = color;
00098 if ( color > 7 ) ic = 7;
00099
00100 if (colorMode==0) {
00101 p.begin (&pix);
00102 p.setPen (QPen (starColor[ic], colorIntensity));
00103 p.drawEllipse (0, 0, STARSIZE, STARSIZE);
00104 p.end();
00105 }
00106
00107 mask.fill (Qt::color0);
00108
00109 p.begin (&mask);
00110 p.setPen (QPen ( Qt::color1, 1));
00111 p.setBrush( QBrush( Qt::color1 ) );
00112 p.drawEllipse(0, 0, STARSIZE, STARSIZE);
00113 p.end();
00114
00115
00116
00117 QImage tmp = pix.convertToImage();
00118 pix.convertFromImage( KImageEffect::blur( tmp, 100.0 ) );
00119
00120 pix.setMask (mask);
00121 image = pix.convertToImage();
00122
00123 for (int i = 0; i < 26; i++)
00124 {
00125 tmp = image.smoothScale( STARSIZE*(i+1)/26, STARSIZE*(i+1)/26 );
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 starPixmaps[color][i].convertFromImage( tmp );
00136 }
00137 }
00138 }