1 /***************************************************************************
2 starpixmap.cpp - K Desktop Planetarium
4 begin : Wed Sep 19 2001
5 copyright : (C) 2001 by Thomas Kabelmann
7 ***************************************************************************/
9 /***************************************************************************
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. *
16 ***************************************************************************/
19 #include "starpixmap.h"
21 #include <kimageeffect.h>
28 StarPixmap::StarPixmap (int starColorMode
, int starColorIntensity
)
29 : colorMode (starColorMode
), colorIntensity (starColorIntensity
)
31 loadPixmaps (starColorMode
, starColorIntensity
);
34 QPixmap
* StarPixmap::getPixmap (QChar
*color
, int size
) {
36 // the colors from blue to red +, O, B, A, F, G, K, M, N, P
37 // if *color is '+' use white star
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;
50 // don't overflow the array
51 if (size
> 25) size
= 25;
52 return &starPixmaps
[c
][size
];
55 void StarPixmap::setColorMode( int 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
);
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)
91 else if ( colorMode
==2 ) //star chart colors (fill black, no temperature colors)
94 pix
.fill (Qt::white
); // default (white)
96 for (int color
= 0; color
< 10; color
++) {
98 if ( color
> 7 ) ic
= 7;
102 p
.setPen (QPen (starColor
[ic
], colorIntensity
)); // the intensity of color determines the width of the pen
103 p
.drawEllipse (0, 0, STARSIZE
, STARSIZE
);
107 mask
.fill (Qt::color0
);
110 p
.setPen (QPen ( Qt::color1
, 1));
111 p
.setBrush( QBrush( Qt::color1
) );
112 p
.drawEllipse(0, 0, STARSIZE
, STARSIZE
);
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 );
127 tmp = image.smoothScale (1+ i, 1+ i); // size: 1x1 .. 6x6
129 tmp = image.smoothScale (int((1+ i)*1.25), int((1+ i)*1.25)); // size: 8x8 ... 16x16
131 tmp = image.smoothScale (int((1+ i)*1.5), int((1+ i)*1.5)); // size: 19x19 .. 27x27
133 tmp = image.smoothScale ((1+ i)*2, (1+ i)*2); // size: 38 .. 52x52
135 starPixmaps
[color
][i
].convertFromImage( tmp
); // fill the array of pixmaps