• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kstars

starpixmap.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           starpixmap.cpp  -  K Desktop Planetarium
00003                              -------------------
00004     begin                : Wed Sep 19 2001
00005     copyright            : (C) 2001 by Thomas Kabelmann
00006     email                : tk78@gmx.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
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 //  the colors from blue to red +, O, B, A, F, G, K, M, N, P
00037 // if *color is '+' use white star
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     // don't overflow the array
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; // min
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 );   //default to white
00080     starColor[1] = QColor(   0,   0, 255 );   //type O
00081     starColor[2] = QColor(   0, 200, 255 );   //type B
00082     starColor[3] = QColor(   0, 255, 255 );   //type A
00083     starColor[4] = QColor( 200, 255, 100 );   //type F
00084     starColor[5] = QColor( 255, 255,   0 );   //type G
00085     starColor[6] = QColor( 255, 100,   0 );   //type K
00086     starColor[7] = QColor( 255,   0,   0 );   //type M
00087 
00088 // background of the star
00089     if ( colorMode==1 ) // night colors (fill red, no temperature colors)
00090         pix.fill (Qt::red);
00091     else if ( colorMode==2 ) //star chart colors (fill black, no temperature colors)
00092         pix.fill (Qt::black);
00093     else
00094         pix.fill (Qt::white);   // default (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));    // the intensity of color determines the width of the pen
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         //BLUR!! ugliness-- requires temporary conversion to pixmap, then back again.
00116         //       if we defer the blur until the end, we lose the transparency.  Bleh.
00117         QImage tmp = pix.convertToImage();
00118         pix.convertFromImage( KImageEffect::blur( tmp, 100.0 ) );
00119 
00120         pix.setMask (mask); // set the mask
00121         image = pix.convertToImage();   // create the image for smoothScale()
00122 
00123         for (int i = 0; i < 26; i++)
00124         {
00125             tmp = image.smoothScale( STARSIZE*(i+1)/26, STARSIZE*(i+1)/26 );
00126 /*          if (i < 6)
00127                 tmp = image.smoothScale (1+ i, 1+ i);   // size: 1x1 .. 6x6
00128             else    if (i < 12)
00129                 tmp = image.smoothScale (int((1+ i)*1.25), int((1+ i)*1.25));   // size: 8x8 ... 16x16
00130             else    if (i < 18)
00131                 tmp = image.smoothScale (int((1+ i)*1.5), int((1+ i)*1.5)); // size: 19x19 .. 27x27
00132             else
00133                 tmp = image.smoothScale ((1+ i)*2, (1+ i)*2);   // size: 38 .. 52x52
00134 */
00135             starPixmaps[color][i].convertFromImage( tmp );  // fill the array of pixmaps
00136         }
00137     }
00138 }

kstars

Skip menu "kstars"
  • Main Page
  • Modules
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • keduca
  • kstars
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal