void SkyQPainter::drawPointSource(const QPointF& pos, float size, char sp) { int isize = qMin(static_cast<int>(size), 14); if( !m_vectorStars || starColorMode == 0 ) { // Draw stars as bitmaps, either because we were asked to, or because we're painting real colors QPixmap* im = imageCache[ harvardToIndex(sp) ][isize]; float offset = 0.5 * im->width(); drawPixmap( QPointF(pos.x()-offset, pos.y()-offset), *im ); } else { // Draw stars as vectors, for better printing / SVG export etc. if ( starColorMode != 4 ) { setPen( m_starColor ); setBrush( m_starColor ); } else { // Note: This is not efficient, but we use vector stars only when plotting SVG, not when drawing the skymap, so speed is not very important. QColor c = ColorMap.value( sp, Qt::white ); setPen( c ); setBrush( c ); } // Be consistent with old raster representation if( size > 14 ) size = 14; if( size >= 2 ) drawEllipse( pos.x() - 0.5 * size, pos.y() - 0.5 * size, int(size), int(size) ); else if( size >= 1 ) drawPoint( pos.x(), pos.y() ); } }
void SkyQPainter::drawPointSource(const QPointF& pos, float size, char sp) { int isize = qMin(static_cast<int>(size), 14); if( !m_vectorStars || ( starColorMode <=0 || starColorMode > 3 ) ) { // Draw stars as bitmaps, either because we were asked to, or because we're painting real colors QPixmap* im = imageCache[ harvardToIndex(sp) ][isize]; float offset = 0.5 * im->width(); drawPixmap( QPointF(pos.x()-offset, pos.y()-offset), *im ); } else { // Draw stars as vectors, for better printing / SVG export etc. static QColor color; // FIXME: This slows down things a bit, but we won't care because we're not painting the SkyMap this way anyway. switch( Options::starColorMode() ) { case 1: color = QColor::fromRgb(255, 0, 0); break; case 2: color = QColor::fromRgb(0, 0, 0); break; case 3: color = QColor::fromRgb(255, 255, 255); break; default: Q_ASSERT( false ); } setPen( color ); setBrush( color ); // Be consistent with old raster representation if( size > 14 ) size = 14; if( size >= 2 ) drawEllipse( pos.x() - 0.5 * size, pos.y() - 0.5 * size, int(size), int(size) ); else if( size >= 1 ) drawPoint( pos.x(), pos.y() ); } }
void SkyQPainter::initStarImages() { QMap<char, QColor> ColorMap; const int starColorIntensity = Options::starColorIntensity(); switch( Options::starColorMode() ) { case 1: // Red stars. ColorMap.insert( 'O', QColor::fromRgb( 255, 0, 0 ) ); ColorMap.insert( 'B', QColor::fromRgb( 255, 0, 0 ) ); ColorMap.insert( 'A', QColor::fromRgb( 255, 0, 0 ) ); ColorMap.insert( 'F', QColor::fromRgb( 255, 0, 0 ) ); ColorMap.insert( 'G', QColor::fromRgb( 255, 0, 0 ) ); ColorMap.insert( 'K', QColor::fromRgb( 255, 0, 0 ) ); ColorMap.insert( 'M', QColor::fromRgb( 255, 0, 0 ) ); break; case 2: // Black stars. ColorMap.insert( 'O', QColor::fromRgb( 0, 0, 0 ) ); ColorMap.insert( 'B', QColor::fromRgb( 0, 0, 0 ) ); ColorMap.insert( 'A', QColor::fromRgb( 0, 0, 0 ) ); ColorMap.insert( 'F', QColor::fromRgb( 0, 0, 0 ) ); ColorMap.insert( 'G', QColor::fromRgb( 0, 0, 0 ) ); ColorMap.insert( 'K', QColor::fromRgb( 0, 0, 0 ) ); ColorMap.insert( 'M', QColor::fromRgb( 0, 0, 0 ) ); break; case 3: // White stars ColorMap.insert( 'O', QColor::fromRgb( 255, 255, 255 ) ); ColorMap.insert( 'B', QColor::fromRgb( 255, 255, 255 ) ); ColorMap.insert( 'A', QColor::fromRgb( 255, 255, 255 ) ); ColorMap.insert( 'F', QColor::fromRgb( 255, 255, 255 ) ); ColorMap.insert( 'G', QColor::fromRgb( 255, 255, 255 ) ); ColorMap.insert( 'K', QColor::fromRgb( 255, 255, 255 ) ); ColorMap.insert( 'M', QColor::fromRgb( 255, 255, 255 ) ); case 0: // Real color default: // And use real color for everything else ColorMap.insert( 'O', QColor::fromRgb( 0, 0, 255 ) ); ColorMap.insert( 'B', QColor::fromRgb( 0, 200, 255 ) ); ColorMap.insert( 'A', QColor::fromRgb( 0, 255, 255 ) ); ColorMap.insert( 'F', QColor::fromRgb( 200, 255, 100 ) ); ColorMap.insert( 'G', QColor::fromRgb( 255, 255, 0 ) ); ColorMap.insert( 'K', QColor::fromRgb( 255, 100, 0 ) ); ColorMap.insert( 'M', QColor::fromRgb( 255, 0, 0 ) ); } foreach( char color, ColorMap.keys() ) { QPixmap BigImage( 15, 15 ); BigImage.fill( Qt::transparent ); QPainter p; p.begin( &BigImage ); if ( Options::starColorMode() == 0 ) { qreal h, s, v, a; p.setRenderHint( QPainter::Antialiasing, false ); QColor starColor = ColorMap[color]; starColor.getHsvF(&h, &s, &v, &a); for (int i = 0; i < 8; i++ ) { for (int j = 0; j < 8; j++ ) { qreal x = i - 7; qreal y = j - 7; qreal dist = sqrt( x*x + y*y ) / 7.0; starColor.setHsvF(h, qMin( qreal(1), dist < (10-starColorIntensity)/10.0 ? 0 : dist ), v, qMax( qreal(0), dist < (10-starColorIntensity)/20.0 ? 1 : 1-dist ) ); p.setPen( starColor ); p.drawPoint( i, j ); p.drawPoint( 14-i, j ); p.drawPoint( i, 14-j ); p.drawPoint (14-i, 14-j); } } } else { p.setRenderHint(QPainter::Antialiasing, true ); p.setPen( QPen(ColorMap[color], 2.0 ) ); p.setBrush( p.pen().color() ); p.drawEllipse( QRectF( 2, 2, 10, 10 ) ); } p.end(); // Cache array slice QPixmap** pmap = imageCache[ harvardToIndex(color) ]; for( int size = 1; size < nStarSizes; size++ ) { if( !pmap[size] ) pmap[size] = new QPixmap(); *pmap[size] = BigImage.scaled( size, size, Qt::KeepAspectRatio, Qt::SmoothTransformation ); } } starColorMode = Options::starColorMode(); }