moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kstars / kstars / starpixmap.cpp
blob1c1e92694da94e02f98cc55bd69729df47162e32
1 /***************************************************************************
2 starpixmap.cpp - K Desktop Planetarium
3 -------------------
4 begin : Wed Sep 19 2001
5 copyright : (C) 2001 by Thomas Kabelmann
6 email : tk78@gmx.de
7 ***************************************************************************/
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
19 #include "starpixmap.h"
21 #include <kimageeffect.h>
22 #include <qbitmap.h>
23 #include <qimage.h>
24 #include <qpainter.h>
26 #define STARSIZE 24
28 StarPixmap::StarPixmap (int starColorMode, int starColorIntensity)
29 : colorMode (starColorMode), colorIntensity (starColorIntensity)
31 loadPixmaps (starColorMode, starColorIntensity);
34 QPixmap* StarPixmap::getPixmap (QChar *color, int size) {
35 int c;
36 // the colors from blue to red +, O, B, A, F, G, K, M, N, P
37 // if *color is '+' use white star
38 switch (*color) {
39 case 'O' : c = 1; break;
40 case 'B' : c = 2; break;
41 case 'A' : c = 3; break;
42 case 'F' : c = 4; break;
43 case 'G' : c = 5; break;
44 case 'K' : c = 6; break;
45 case 'M' : c = 7; break;
46 case 'N' : c = 8; break;
47 case 'P' : c = 9; break;
48 default : c = 0;
50 // don't overflow the array
51 if (size > 25) size = 25;
52 return &starPixmaps[c][size];
55 void StarPixmap::setColorMode( int newMode ) {
56 colorMode = newMode;
57 loadPixmaps ( colorMode, colorIntensity );
60 void StarPixmap::setIntensity ( int newIntensity ) {
61 colorIntensity = newIntensity;
62 loadPixmaps ( colorMode, colorIntensity );
65 void StarPixmap::loadPixmaps (int newColorMode, int newColorIntensity) {
66 colorMode = newColorMode;
67 colorIntensity = newColorIntensity;
69 if (colorIntensity < 0) colorIntensity = 0; // min
71 QPixmap pix (STARSIZE, STARSIZE);
72 QBitmap mask (STARSIZE, STARSIZE);
73 QImage image;
74 QPainter p;
75 QMemArray<QColor> starColor;
76 starColor.resize( 8 );
77 image.setAlphaBuffer(true);
79 starColor[0] = QColor( 255, 255, 255 ); //default to white
80 starColor[1] = QColor( 0, 0, 255 ); //type O
81 starColor[2] = QColor( 0, 200, 255 ); //type B
82 starColor[3] = QColor( 0, 255, 255 ); //type A
83 starColor[4] = QColor( 200, 255, 100 ); //type F
84 starColor[5] = QColor( 255, 255, 0 ); //type G
85 starColor[6] = QColor( 255, 100, 0 ); //type K
86 starColor[7] = QColor( 255, 0, 0 ); //type M
88 // background of the star
89 if ( colorMode==1 ) // night colors (fill red, no temperature colors)
90 pix.fill (Qt::red);
91 else if ( colorMode==2 ) //star chart colors (fill black, no temperature colors)
92 pix.fill (Qt::black);
93 else
94 pix.fill (Qt::white); // default (white)
96 for (int color = 0; color < 10; color ++) {
97 int ic = color;
98 if ( color > 7 ) ic = 7;
100 if (colorMode==0) {
101 p.begin (&pix);
102 p.setPen (QPen (starColor[ic], colorIntensity)); // the intensity of color determines the width of the pen
103 p.drawEllipse (0, 0, STARSIZE, STARSIZE);
104 p.end();
107 mask.fill (Qt::color0);
109 p.begin (&mask);
110 p.setPen (QPen ( Qt::color1, 1));
111 p.setBrush( QBrush( Qt::color1 ) );
112 p.drawEllipse(0, 0, STARSIZE, STARSIZE);
113 p.end();
115 //BLUR!! ugliness-- requires temporary conversion to pixmap, then back again.
116 // if we defer the blur until the end, we lose the transparency. Bleh.
117 QImage tmp = pix.convertToImage();
118 pix.convertFromImage( KImageEffect::blur( tmp, 100.0 ) );
120 pix.setMask (mask); // set the mask
121 image = pix.convertToImage(); // create the image for smoothScale()
123 for (int i = 0; i < 26; i++)
125 tmp = image.smoothScale( STARSIZE*(i+1)/26, STARSIZE*(i+1)/26 );
126 /* if (i < 6)
127 tmp = image.smoothScale (1+ i, 1+ i); // size: 1x1 .. 6x6
128 else if (i < 12)
129 tmp = image.smoothScale (int((1+ i)*1.25), int((1+ i)*1.25)); // size: 8x8 ... 16x16
130 else if (i < 18)
131 tmp = image.smoothScale (int((1+ i)*1.5), int((1+ i)*1.5)); // size: 19x19 .. 27x27
132 else
133 tmp = image.smoothScale ((1+ i)*2, (1+ i)*2); // size: 38 .. 52x52
135 starPixmaps[color][i].convertFromImage( tmp ); // fill the array of pixmaps