• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
skyqpainter.cpp
Go to the documentation of this file.
1 /*
2  (C) 2010 Henry de Valence <hdevalence@gmail.com>
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License along
15  with this program; if not, write to the Free Software Foundation, Inc.,
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 
18 */
19 
20 #include "skyqpainter.h"
21 
22 #include <QMap>
23 #include <QWidget>
24 
25 #include "kstarsdata.h"
26 #include "Options.h"
27 #include "skymap.h"
28 
29 #include "skycomponents/linelist.h"
30 #include "skycomponents/skiplist.h"
31 #include "skycomponents/linelistlabel.h"
32 #include "skycomponents/skymapcomposite.h"
33 #include "skycomponents/flagcomponent.h"
34 #include "skycomponents/satellitescomponent.h"
35 
36 #include "skyobjects/deepskyobject.h"
37 #include "skyobjects/kscomet.h"
38 #include "skyobjects/ksasteroid.h"
39 #include "skyobjects/trailobject.h"
40 #include "skyobjects/satellite.h"
41 #include "skyobjects/supernova.h"
42 
43 #include "projections/projector.h"
44 #include "ksutils.h"
45 
46 namespace {
47 
48  // Convert spectral class to numerical index.
49  // If spectral class is invalid return index for white star (A class)
50  int harvardToIndex(char c) {
51  switch( c ) {
52  case 'o': case 'O': return 0;
53  case 'b': case 'B': return 1;
54  case 'a': case 'A': return 2;
55  case 'f': case 'F': return 3;
56  case 'g': case 'G': return 4;
57  case 'k': case 'K': return 5;
58  case 'm': case 'M': return 6;
59  // For unknown spectral class assume A class (white star)
60  default: return 2;
61  }
62  }
63 
64  // Total number of sizes of stars.
65  const int nStarSizes = 15;
66  // Total number of specatral classes
67  // N.B. Must be in sync with harvardToIndex
68  const int nSPclasses = 7;
69 
70  // Cache for star images.
71  //
72  // These pixmaps are never deallocated. Not really good...
73  QPixmap* imageCache[nSPclasses][nStarSizes] = {{0}};
74 }
75 
76 int SkyQPainter::starColorMode = 0;
77 
78 SkyQPainter::SkyQPainter( QPaintDevice *pd )
79  : SkyPainter(), QPainter()
80 {
81  Q_ASSERT( pd );
82  m_pd = pd;
83  m_size = QSize( pd->width(), pd->height() );
84  m_vectorStars = false;
85 }
86 
87 SkyQPainter::SkyQPainter( QPaintDevice *pd, const QSize &size )
88  : SkyPainter(), QPainter()
89 {
90  Q_ASSERT( pd );
91  m_pd = pd;
92  m_size = size;
93  m_vectorStars = false;
94 }
95 
96 SkyQPainter::SkyQPainter( QWidget *widget, QPaintDevice *pd )
97  : SkyPainter(), QPainter()
98 {
99  Q_ASSERT( widget );
100  // Set paint device pointer to pd or to the widget if pd = 0
101  m_pd = ( pd ? pd : widget );
102  m_size = widget->size();
103  m_vectorStars = false;
104 }
105 
106 SkyQPainter::~SkyQPainter()
107 {
108 }
109 
110 void SkyQPainter::begin()
111 {
112  QPainter::begin(m_pd);
113  bool aa = !m_sm->isSlewing() && Options::useAntialias();
114  setRenderHint(QPainter::Antialiasing, aa );
115  setRenderHint(QPainter::HighQualityAntialiasing, aa);
116  m_proj = m_sm->projector();
117 }
118 
119 void SkyQPainter::end()
120 {
121  QPainter::end();
122 }
123 
124 void SkyQPainter::drawSkyBackground()
125 {
126  //FIXME use projector
127  fillRect( 0, 0, m_size.width(), m_size.height(), KStarsData::Instance()->colorScheme()->colorNamed( "SkyColor" ) );
128 }
129 
130 void SkyQPainter::setPen(const QPen& pen)
131 {
132  QPainter::setPen(pen);
133 }
134 
135 void SkyQPainter::setBrush(const QBrush& brush)
136 {
137  QPainter::setBrush(brush);
138 }
139 
140 void SkyQPainter::initStarImages()
141 {
142 
143  QMap<char, QColor> ColorMap;
144  const int starColorIntensity = Options::starColorIntensity();
145 
146  switch( Options::starColorMode() ) {
147  case 1: // Red stars.
148  ColorMap.insert( 'O', QColor::fromRgb( 255, 0, 0 ) );
149  ColorMap.insert( 'B', QColor::fromRgb( 255, 0, 0 ) );
150  ColorMap.insert( 'A', QColor::fromRgb( 255, 0, 0 ) );
151  ColorMap.insert( 'F', QColor::fromRgb( 255, 0, 0 ) );
152  ColorMap.insert( 'G', QColor::fromRgb( 255, 0, 0 ) );
153  ColorMap.insert( 'K', QColor::fromRgb( 255, 0, 0 ) );
154  ColorMap.insert( 'M', QColor::fromRgb( 255, 0, 0 ) );
155  break;
156  case 2: // Black stars.
157  ColorMap.insert( 'O', QColor::fromRgb( 0, 0, 0 ) );
158  ColorMap.insert( 'B', QColor::fromRgb( 0, 0, 0 ) );
159  ColorMap.insert( 'A', QColor::fromRgb( 0, 0, 0 ) );
160  ColorMap.insert( 'F', QColor::fromRgb( 0, 0, 0 ) );
161  ColorMap.insert( 'G', QColor::fromRgb( 0, 0, 0 ) );
162  ColorMap.insert( 'K', QColor::fromRgb( 0, 0, 0 ) );
163  ColorMap.insert( 'M', QColor::fromRgb( 0, 0, 0 ) );
164  break;
165  case 3: // White stars
166  ColorMap.insert( 'O', QColor::fromRgb( 255, 255, 255 ) );
167  ColorMap.insert( 'B', QColor::fromRgb( 255, 255, 255 ) );
168  ColorMap.insert( 'A', QColor::fromRgb( 255, 255, 255 ) );
169  ColorMap.insert( 'F', QColor::fromRgb( 255, 255, 255 ) );
170  ColorMap.insert( 'G', QColor::fromRgb( 255, 255, 255 ) );
171  ColorMap.insert( 'K', QColor::fromRgb( 255, 255, 255 ) );
172  ColorMap.insert( 'M', QColor::fromRgb( 255, 255, 255 ) );
173  case 0: // Real color
174  default: // And use real color for everything else
175  ColorMap.insert( 'O', QColor::fromRgb( 0, 0, 255 ) );
176  ColorMap.insert( 'B', QColor::fromRgb( 0, 200, 255 ) );
177  ColorMap.insert( 'A', QColor::fromRgb( 0, 255, 255 ) );
178  ColorMap.insert( 'F', QColor::fromRgb( 200, 255, 100 ) );
179  ColorMap.insert( 'G', QColor::fromRgb( 255, 255, 0 ) );
180  ColorMap.insert( 'K', QColor::fromRgb( 255, 100, 0 ) );
181  ColorMap.insert( 'M', QColor::fromRgb( 255, 0, 0 ) );
182  }
183 
184  foreach( char color, ColorMap.keys() ) {
185  QPixmap BigImage( 15, 15 );
186  BigImage.fill( Qt::transparent );
187 
188  QPainter p;
189  p.begin( &BigImage );
190 
191  if ( Options::starColorMode() == 0 ) {
192  qreal h, s, v, a;
193  p.setRenderHint( QPainter::Antialiasing, false );
194  QColor starColor = ColorMap[color];
195  starColor.getHsvF(&h, &s, &v, &a);
196  for (int i = 0; i < 8; i++ ) {
197  for (int j = 0; j < 8; j++ ) {
198  qreal x = i - 7;
199  qreal y = j - 7;
200  qreal dist = sqrt( x*x + y*y ) / 7.0;
201  starColor.setHsvF(h,
202  qMin( qreal(1), dist < (10-starColorIntensity)/10.0 ? 0 : dist ),
203  v,
204  qMax( qreal(0), dist < (10-starColorIntensity)/20.0 ? 1 : 1-dist ) );
205  p.setPen( starColor );
206  p.drawPoint( i, j );
207  p.drawPoint( 14-i, j );
208  p.drawPoint( i, 14-j );
209  p.drawPoint (14-i, 14-j);
210  }
211  }
212  } else {
213  p.setRenderHint(QPainter::Antialiasing, true );
214  p.setPen( QPen(ColorMap[color], 2.0 ) );
215  p.setBrush( p.pen().color() );
216  p.drawEllipse( QRectF( 2, 2, 10, 10 ) );
217  }
218  p.end();
219 
220  // Cache array slice
221  QPixmap** pmap = imageCache[ harvardToIndex(color) ];
222  for( int size = 1; size < nStarSizes; size++ ) {
223  if( !pmap[size] )
224  pmap[size] = new QPixmap();
225  *pmap[size] = BigImage.scaled( size, size, Qt::KeepAspectRatio, Qt::SmoothTransformation );
226  }
227  }
228  starColorMode = Options::starColorMode();
229 }
230 
231 void SkyQPainter::drawSkyLine(SkyPoint* a, SkyPoint* b)
232 {
233  bool aVisible, bVisible;
234  QPointF aScreen = m_proj->toScreen(a,true,&aVisible);
235  QPointF bScreen = m_proj->toScreen(b,true,&bVisible);
236  //THREE CASES:
237  if( aVisible && bVisible ) {
238  //Both a,b visible, so paint the line normally:
239  drawLine(aScreen, bScreen);
240  } else if( aVisible ) {
241  //a is visible but b isn't:
242  drawLine(aScreen, m_proj->clipLine(a,b));
243  } else if( bVisible ) {
244  //b is visible but a isn't:
245  drawLine(bScreen, m_proj->clipLine(b,a));
246  } //FIXME: what if both are offscreen but the line isn't?
247 }
248 
249 void SkyQPainter::drawSkyPolyline(LineList* list, SkipList* skipList, LineListLabel* label)
250 {
251  SkyList *points = list->points();
252  bool isVisible, isVisibleLast;
253 
254  QPointF oLast = m_proj->toScreen( points->first(), true, &isVisibleLast );
255  // & with the result of checkVisibility to clip away things below horizon
256  isVisibleLast &= m_proj->checkVisibility( points->first() );
257  QPointF oThis, oThis2;
258 
259  for ( int j = 1 ; j < points->size() ; j++ ) {
260  SkyPoint* pThis = points->at( j );
261  oThis2 = oThis = m_proj->toScreen( pThis, true, &isVisible );
262  // & with the result of checkVisibility to clip away things below horizon
263  isVisible &= m_proj->checkVisibility(pThis);
264  bool doSkip = false;
265  if( skipList ) {
266  doSkip = skipList->skip(j);
267  }
268 
269  if ( !doSkip ) {
270  if ( isVisible && isVisibleLast ) {
271  drawLine( oLast, oThis );
272  if ( label )
273  label->updateLabelCandidates( oThis.x(), oThis.y(), list, j );
274  }
275  }
276 
277  oLast = oThis2;
278  isVisibleLast = isVisible;
279  }
280 }
281 
282 void SkyQPainter::drawSkyPolygon(LineList* list)
283 {
284  SkyList *points = list->points();
285  bool isVisible, isVisibleLast;
286  SkyPoint* pLast = points->last();
287  QPointF oLast = m_proj->toScreen( pLast, true, &isVisibleLast );
288  // & with the result of checkVisibility to clip away things below horizon
289  isVisibleLast &= m_proj->checkVisibility(pLast);
290 
291 
292  QPolygonF polygon;
293  for ( int i = 0; i < points->size(); ++i ) {
294  SkyPoint* pThis = points->at( i );
295  QPointF oThis = m_proj->toScreen( pThis, true, &isVisible );
296  // & with the result of checkVisibility to clip away things below horizon
297  isVisible &= m_proj->checkVisibility(pThis);
298 
299 
300  if ( isVisible && isVisibleLast ) {
301  polygon << oThis;
302  } else if ( isVisibleLast ) {
303  QPointF oMid = m_proj->clipLine( pLast, pThis );
304  polygon << oMid;
305  } else if ( isVisible ) {
306  QPointF oMid = m_proj->clipLine( pThis, pLast );
307  polygon << oMid;
308  polygon << oThis;
309  }
310 
311  pLast = pThis;
312  oLast = oThis;
313  isVisibleLast = isVisible;
314  }
315 
316  if ( polygon.size() )
317  drawPolygon(polygon);
318 }
319 
320 bool SkyQPainter::drawPlanet(KSPlanetBase* planet)
321 {
322  if( !m_proj->checkVisibility(planet) ) return false;
323 
324  bool visible = false;
325  QPointF pos = m_proj->toScreen(planet,true,&visible);
326  if( !visible || !m_proj->onScreen(pos) ) return false;
327 
328  float fakeStarSize = ( 10.0 + log10( Options::zoomFactor() ) - log10( MINZOOM ) ) * ( 10 - planet->mag() ) / 10;
329  if( fakeStarSize > 15.0 )
330  fakeStarSize = 15.0;
331 
332  float size = planet->angSize() * dms::PI * Options::zoomFactor()/10800.0;
333  if( size < fakeStarSize && planet->name() != "Sun" && planet->name() != "Moon" ) {
334  // Draw them as bright stars of appropriate color instead of images
335  char spType;
336  //FIXME: do these need i18n?
337  if( planet->name() == i18n("Mars") ) {
338  spType = 'K';
339  } else if( planet->name() == i18n("Jupiter") || planet->name() == i18n("Mercury") || planet->name() == i18n("Saturn") ) {
340  spType = 'F';
341  } else {
342  spType = 'B';
343  }
344  drawPointSource(pos,fakeStarSize,spType);
345  } else {
346  float sizemin = 1.0;
347  if( planet->name() == "Sun" || planet->name() == "Moon" )
348  sizemin = 8.0;
349 
350  float size = planet->angSize() * dms::PI * Options::zoomFactor()/10800.0;
351  if( size < sizemin )
352  size = sizemin;
353  if( Options::showPlanetImages() && !planet->image().isNull() ) {
354  //Because Saturn has rings, we inflate its image size by a factor 2.5
355  if( planet->name() == "Saturn" )
356  size = int(2.5*size);
357 
358  save();
359  translate(pos);
360  rotate( m_proj->findPA( planet, pos.x(), pos.y() ) );
361  drawImage( QRect(-0.5*size, -0.5*size, size, size),
362  planet->image() );
363  restore();
364  } else { //Otherwise, draw a simple circle.
365  drawEllipse( pos, size, size );
366  }
367  }
368  return true;
369 }
370 
371 bool SkyQPainter::drawPointSource(SkyPoint* loc, float mag, char sp)
372 {
373  //Check if it's even visible before doing anything
374  if( !m_proj->checkVisibility(loc) ) return false;
375 
376  bool visible = false;
377  QPointF pos = m_proj->toScreen(loc,true,&visible);
378  if( visible && m_proj->onScreen(pos) ) { // FIXME: onScreen here should use canvas size rather than SkyMap size, especially while printing in portrait mode!
379  drawPointSource(pos, starWidth(mag), sp);
380  return true;
381  } else {
382  return false;
383  }
384 }
385 
386 void SkyQPainter::drawPointSource(const QPointF& pos, float size, char sp)
387 {
388  int isize = qMin(static_cast<int>(size), 14);
389  if( !m_vectorStars || ( starColorMode <=0 || starColorMode > 3 ) ) {
390  // Draw stars as bitmaps, either because we were asked to, or because we're painting real colors
391  QPixmap* im = imageCache[ harvardToIndex(sp) ][isize];
392  float offset = 0.5 * im->width();
393  drawPixmap( QPointF(pos.x()-offset, pos.y()-offset), *im );
394  }
395  else {
396  // Draw stars as vectors, for better printing / SVG export etc.
397  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.
398  switch( Options::starColorMode() ) {
399  case 1:
400  color = QColor::fromRgb(255, 0, 0);
401  break;
402  case 2:
403  color = QColor::fromRgb(0, 0, 0);
404  break;
405  case 3:
406  color = QColor::fromRgb(255, 255, 255);
407  break;
408  default:
409  Q_ASSERT( false );
410  }
411  setPen( color );
412  setBrush( color );
413 
414  // Be consistent with old raster representation
415  if( size > 14 )
416  size = 14;
417  if( size >= 2 )
418  drawEllipse( pos.x() - 0.5 * size, pos.y() - 0.5 * size, int(size), int(size) );
419  else if( size >= 1 )
420  drawPoint( pos.x(), pos.y() );
421  }
422 }
423 
424 bool SkyQPainter::drawDeepSkyObject(DeepSkyObject* obj, bool drawImage)
425 {
426  if( !m_proj->checkVisibility(obj) ) return false;
427 
428  bool visible = false;
429  QPointF pos = m_proj->toScreen(obj, true, &visible);
430  if( !visible || !m_proj->onScreen(pos) ) return false;
431 
432  // if size is 0.0 set it to 1.0, this are normally stars (type 0 and 1)
433  // if we use size 0.0 the star wouldn't be drawn
434  float majorAxis = obj->a();
435  if ( majorAxis == 0.0 ) { majorAxis = 1.0; }
436 
437  float size = majorAxis * dms::PI * Options::zoomFactor() / 10800.0;
438 
439  //FIXME: this is probably incorrect
440  float positionAngle = m_proj->findPA( obj, pos.x(), pos.y() );
441 
442  //Draw Image
443  if ( drawImage && Options::zoomFactor() > 5.*MINZOOM )
444  drawDeepSkyImage(pos, obj, positionAngle);
445 
446  //Draw Symbol
447  drawDeepSkySymbol(pos, obj->type(), size, obj->e(), positionAngle);
448 
449  return true;
450 }
451 
452 bool SkyQPainter::drawDeepSkyImage(const QPointF& pos, DeepSkyObject* obj, float positionAngle)
453 {
454  double zoom = Options::zoomFactor();
455  double w = obj->a() * dms::PI * zoom/10800.0;
456  double h = obj->e() * w;
457 
458  save();
459  translate(pos);
460  rotate( positionAngle );
461  drawImage( QRect(-0.5*w, -0.5*h, w, h), obj->image() );
462  restore();
463 
464  return true;
465 }
466 
467 //FIXME: Do we really need two versions of all of this code? (int/float)
468 void SkyQPainter::drawDeepSkySymbol(const QPointF &pos, int type, float size, float e, float positionAngle)
469 {
470  float x = pos.x();
471  float y = pos.y();
472  float zoom = Options::zoomFactor();
473 
474  int isize = int(size);
475 
476  float dx1 = -0.5*size;
477  float dx2 = 0.5*size;
478  float dy1 = -1.0*e*size/2.;
479  float dy2 = e*size/2.;
480  float x1 = x + dx1;
481  float x2 = x + dx2;
482  float y1 = y + dy1;
483  float y2 = y + dy2;
484 
485  float dxa = -size/4.;
486  float dxb = size/4.;
487  float dya = -1.0*e*size/4.;
488  float dyb = e*size/4.;
489  float xa = x + dxa;
490  float xb = x + dxb;
491  float ya = y + dya;
492  float yb = y + dyb;
493 
494  float psize;
495 
496  QBrush tempBrush;
497 
498  switch ( type ) {
499  case 0:
500  case 1: //catalog star
501  //Some NGC/IC objects are stars...changed their type to 1 (was double star)
502  if (size<2.) size = 2.;
503  if ( Options::useAntialias() )
504  drawEllipse( QRectF(x1, y1, size/2., size/2.) );
505  else
506  drawEllipse( QRect(int(x1), int(y1), int(size/2), int(size/2)) );
507  break;
508  case 2: //Planet
509  break;
510  case 3: //Open cluster; draw circle of points
511  case 13: // Asterism
512  tempBrush = brush();
513  setBrush( pen().color() );
514  psize = 2.;
515  if ( size > 50. ) psize *= 2.;
516  if ( size > 100. ) psize *= 2.;
517  if ( Options::useAntialias() ) {
518  drawEllipse( QRectF(xa, y1, psize, psize) );
519  drawEllipse( QRectF(xb, y1, psize, psize) );
520  drawEllipse( QRectF(xa, y2, psize, psize) );
521  drawEllipse( QRectF(xb, y2, psize, psize) );
522  drawEllipse( QRectF(x1, ya, psize, psize) );
523  drawEllipse( QRectF(x1, yb, psize, psize) );
524  drawEllipse( QRectF(x2, ya, psize, psize) );
525  drawEllipse( QRectF(x2, yb, psize, psize) );
526  } else {
527  int ix1 = int(x1); int iy1 = int(y1);
528  int ix2 = int(x2); int iy2 = int(y2);
529  int ixa = int(xa); int iya = int(ya);
530  int ixb = int(xb); int iyb = int(yb);
531  drawEllipse( QRect(ixa, iy1, int(psize), int(psize)) );
532  drawEllipse( QRect(ixb, iy1, int(psize), int(psize)) );
533  drawEllipse( QRect(ixa, iy2, int(psize), int(psize)) );
534  drawEllipse( QRect(ixb, iy2, int(psize), int(psize)) );
535  drawEllipse( QRect(ix1, iya, int(psize), int(psize)) );
536  drawEllipse( QRect(ix1, iyb, int(psize), int(psize)) );
537  drawEllipse( QRect(ix2, iya, int(psize), int(psize)) );
538  drawEllipse( QRect(ix2, iyb, int(psize), int(psize)) );
539  }
540  setBrush( tempBrush );
541  break;
542  case 4: //Globular Cluster
543  if (size<2.) size = 2.;
544  save();
545  translate( x, y );
546  rotate( positionAngle ); //rotate the coordinate system
547 
548  if ( Options::useAntialias() ) {
549  drawEllipse( QRectF(dx1, dy1, size, e*size) );
550  drawLine( QPointF(0., dy1), QPointF(0., dy2) );
551  drawLine( QPointF(dx1, 0.), QPointF(dx2, 0.) );
552  restore(); //reset coordinate system
553  } else {
554  int idx1 = int(dx1); int idy1 = int(dy1);
555  int idx2 = int(dx2); int idy2 = int(dy2);
556  drawEllipse( QRect(idx1, idy1, isize, int(e*size)) );
557  drawLine( QPoint(0, idy1), QPoint(0, idy2) );
558  drawLine( QPoint(idx1, 0), QPoint(idx2, 0) );
559  restore(); //reset coordinate system
560  }
561  break;
562 
563  case 5: //Gaseous Nebula
564  case 15: // Dark Nebula
565  if (size <2.) size = 2.;
566  save();
567  translate( x, y );
568  rotate( positionAngle ); //rotate the coordinate system
569 
570  if ( Options::useAntialias() ) {
571  drawLine( QPointF(dx1, dy1), QPointF(dx2, dy1) );
572  drawLine( QPointF(dx2, dy1), QPointF(dx2, dy2) );
573  drawLine( QPointF(dx2, dy2), QPointF(dx1, dy2) );
574  drawLine( QPointF(dx1, dy2), QPointF(dx1, dy1) );
575  } else {
576  int idx1 = int(dx1); int idy1 = int(dy1);
577  int idx2 = int(dx2); int idy2 = int(dy2);
578  drawLine( QPoint(idx1, idy1), QPoint(idx2, idy1) );
579  drawLine( QPoint(idx2, idy1), QPoint(idx2, idy2) );
580  drawLine( QPoint(idx2, idy2), QPoint(idx1, idy2) );
581  drawLine( QPoint(idx1, idy2), QPoint(idx1, idy1) );
582  }
583  restore(); //reset coordinate system
584  break;
585  case 6: //Planetary Nebula
586  if (size<2.) size = 2.;
587  save();
588  translate( x, y );
589  rotate( positionAngle ); //rotate the coordinate system
590 
591  if ( Options::useAntialias() ) {
592  drawEllipse( QRectF(dx1, dy1, size, e*size) );
593  drawLine( QPointF(0., dy1), QPointF(0., dy1 - e*size/2. ) );
594  drawLine( QPointF(0., dy2), QPointF(0., dy2 + e*size/2. ) );
595  drawLine( QPointF(dx1, 0.), QPointF(dx1 - size/2., 0.) );
596  drawLine( QPointF(dx2, 0.), QPointF(dx2 + size/2., 0.) );
597  } else {
598  int idx1 = int(dx1); int idy1 = int(dy1);
599  int idx2 = int(dx2); int idy2 = int(dy2);
600  drawEllipse( QRect( idx1, idy1, isize, int(e*size) ) );
601  drawLine( QPoint(0, idy1), QPoint(0, idy1 - int(e*size/2) ) );
602  drawLine( QPoint(0, idy2), QPoint(0, idy2 + int(e*size/2) ) );
603  drawLine( QPoint(idx1, 0), QPoint(idx1 - int(size/2), 0) );
604  drawLine( QPoint(idx2, 0), QPoint(idx2 + int(size/2), 0) );
605  }
606 
607  restore(); //reset coordinate system
608  break;
609  case 7: //Supernova remnant
610  if (size<2) size = 2;
611  save();
612  translate( x, y );
613  rotate( positionAngle ); //rotate the coordinate system
614 
615  if ( Options::useAntialias() ) {
616  drawLine( QPointF(0., dy1), QPointF(dx2, 0.) );
617  drawLine( QPointF(dx2, 0.), QPointF(0., dy2) );
618  drawLine( QPointF(0., dy2), QPointF(dx1, 0.) );
619  drawLine( QPointF(dx1, 0.), QPointF(0., dy1) );
620  } else {
621  int idx1 = int(dx1); int idy1 = int(dy1);
622  int idx2 = int(dx2); int idy2 = int(dy2);
623  drawLine( QPoint(0, idy1), QPoint(idx2, 0) );
624  drawLine( QPoint(idx2, 0), QPoint(0, idy2) );
625  drawLine( QPoint(0, idy2), QPoint(idx1, 0) );
626  drawLine( QPoint(idx1, 0), QPoint(0, idy1) );
627  }
628 
629  restore(); //reset coordinate system
630  break;
631  case 8: //Galaxy
632  case 16: // Quasar
633  if ( size <1. && zoom > 20*MINZOOM ) size = 3.; //force ellipse above zoomFactor 20
634  if ( size <1. && zoom > 5*MINZOOM ) size = 1.; //force points above zoomFactor 5
635  if ( size>2. ) {
636  save();
637  translate( x, y );
638  rotate( positionAngle ); //rotate the coordinate system
639 
640  if ( Options::useAntialias() ) {
641  drawEllipse( QRectF(dx1, dy1, size, e*size) );
642  } else {
643  int idx1 = int(dx1); int idy1 = int(dy1);
644  drawEllipse( QRect(idx1, idy1, isize, int(e*size)) );
645  }
646 
647  restore(); //reset coordinate system
648 
649  } else if ( size>0. ) {
650  drawPoint( QPointF(x, y) );
651  }
652  break;
653  case 14: // Galaxy cluster - draw a circle of + marks
654  tempBrush = brush();
655  setBrush( pen().color() );
656  psize = 1.;
657  if ( size > 50. ) psize *= 2.;
658 
659  if ( Options::useAntialias() ) {
660  drawLine( QLineF( xa - psize, y1, xa + psize, y1 ) );
661  drawLine( QLineF( xa, y1 - psize, xa, y1 + psize ) );
662  drawLine( QLineF( xb - psize, y1, xb + psize, y1 ) );
663  drawLine( QLineF( xb, y1 - psize, xb, y1 + psize ) );
664  drawLine( QLineF( xa - psize, y2, xa + psize, y2 ) );
665  drawLine( QLineF( xa, y2 - psize, xa, y2 + psize ) );
666  drawLine( QLineF( xb - psize, y2, xb + psize, y2 ) );
667  drawLine( QLineF( xb, y2 - psize, xb, y2 + psize ) );
668  drawLine( QLineF( x1 - psize, ya, x1 + psize, ya ) );
669  drawLine( QLineF( x1, ya - psize, x1, ya + psize ) );
670  drawLine( QLineF( x1 - psize, yb, x1 + psize, yb ) );
671  drawLine( QLineF( x1, yb - psize, x1, yb + psize ) );
672  drawLine( QLineF( x2 - psize, ya, x2 + psize, ya ) );
673  drawLine( QLineF( x2, ya - psize, x2, ya + psize ) );
674  drawLine( QLineF( x2 - psize, yb, x2 + psize, yb ) );
675  drawLine( QLineF( x2, yb - psize, x2, yb + psize ) );
676  } else {
677  int ix1 = int(x1); int iy1 = int(y1);
678  int ix2 = int(x2); int iy2 = int(y2);
679  int ixa = int(xa); int iya = int(ya);
680  int ixb = int(xb); int iyb = int(yb);
681  drawLine( QLineF( ixa - int(psize), iy1, ixa + int(psize), iy1 ) );
682  drawLine( QLineF( ixa, iy1 - int(psize), ixa, iy1 + int(psize) ) );
683  drawLine( QLineF( ixb - int(psize), iy1, ixb + int(psize), iy1 ) );
684  drawLine( QLineF( ixb, iy1 - int(psize), ixb, iy1 + int(psize) ) );
685  drawLine( QLineF( ixa - int(psize), iy2, ixa + int(psize), iy2 ) );
686  drawLine( QLineF( ixa, iy2 - int(psize), ixa, iy2 + int(psize) ) );
687  drawLine( QLineF( ixb - int(psize), iy2, ixb + int(psize), iy2 ) );
688  drawLine( QLineF( ixb, iy2 - int(psize), ixb, iy2 + int(psize) ) );
689  drawLine( QLineF( ix1 - int(psize), iya, ix1 + int(psize), iya ) );
690  drawLine( QLineF( ix1, iya - int(psize), ix1, iya + int(psize) ) );
691  drawLine( QLineF( ix1 - int(psize), iyb, ix1 + int(psize), iyb ) );
692  drawLine( QLineF( ix1, iyb - int(psize), ix1, iyb + int(psize) ) );
693  drawLine( QLineF( ix2 - int(psize), iya, ix2 + int(psize), iya ) );
694  drawLine( QLineF( ix2, iya - int(psize), ix2, iya + int(psize) ) );
695  drawLine( QLineF( ix2 - int(psize), iyb, ix2 + int(psize), iyb ) );
696  drawLine( QLineF( ix2, iyb - int(psize), ix2, iyb + int(psize) ) );
697  }
698  setBrush( tempBrush );
699  break;
700  }
701 }
702 
703 void SkyQPainter::drawObservingList(const QList< SkyObject* >& obs)
704 {
705  foreach ( SkyObject* obj, obs ) {
706  bool visible = false;
707  QPointF o = m_proj->toScreen( obj, true, &visible );
708  if( !visible || !m_proj->onScreen(o) ) continue;
709 
710  float size = 20.;
711  float x1 = o.x() - 0.5*size;
712  float y1 = o.y() - 0.5*size;
713  drawArc( QRectF(x1, y1, size, size), -60*16, 120*16 );
714  drawArc( QRectF(x1, y1, size, size), 120*16, 120*16 );
715  }
716 }
717 
718 void SkyQPainter::drawFlags()
719 {
720  KStarsData *data = KStarsData::Instance();
721  SkyPoint* point;
722  QImage image;
723  bool visible = false;
724  QPointF pos;
725  int i;
726 
727  for ( i=0;i<data->skyComposite()->flags()->size();i++ ) {
728  point = data->skyComposite()->flags()->pointList().at( i );
729  image = data->skyComposite()->flags()->image( i );
730 
731  // Set Horizontal coordinates
732  point->EquatorialToHorizontal( data->lst(), data->geo()->lat() );
733 
734  // Get flag position on screen
735  pos = m_proj->toScreen( point, true, &visible );
736 
737  // Return if flag is not visible
738  if( !visible || !m_proj->onScreen( pos ) ) continue;
739 
740  // Draw flag image
741  drawImage( pos.x()-0.5*image.width(), pos.y()-0.5*image.height(), image );
742 
743  // Draw flag label
744  setPen( data->skyComposite()->flags()->labelColor( i ) );
745  setFont( QFont( "Courier New", 10, QFont::Bold ) );
746  drawText( pos.x()+10, pos.y()-10, data->skyComposite()->flags()->label( i ) );
747  }
748 }
749 
750 void SkyQPainter::drawHorizon(bool filled, SkyPoint* labelPoint, bool* drawLabel)
751 {
752  QVector<Vector2f> ground = m_proj->groundPoly(labelPoint, drawLabel);
753  if( ground.size() ) {
754  QPolygonF groundPoly(ground.size());
755  for(int i = 0; i < ground.size(); ++i)
756  groundPoly[i] = KSUtils::vecToPoint(ground[i]);
757  if( filled )
758  drawPolygon(groundPoly);
759  else {
760  groundPoly.append( groundPoly.first() );
761  drawPolyline(groundPoly);
762  }
763  }
764 }
765 
766 void SkyQPainter::drawSatellite( Satellite* sat ) {
767  KStarsData *data = KStarsData::Instance();
768  QPointF pos;
769  bool visible = false;
770 
771  sat->HorizontalToEquatorial( data->lst(), data->geo()->lat() );
772 
773  pos = m_proj->toScreen( sat, true, &visible );
774 
775  if( !visible || !m_proj->onScreen( pos ) )
776  return;
777 
778  if ( Options::drawSatellitesLikeStars() ) {
779  drawPointSource(pos, 3.5, 'B');
780  } else {
781  if ( sat->isVisible() )
782  setPen( data->colorScheme()->colorNamed( "VisibleSatColor" ) );
783  else
784  setPen( data->colorScheme()->colorNamed( "SatColor" ) );
785 
786  drawLine( QPoint( pos.x() - 0.5, pos.y() - 0.5 ), QPoint( pos.x() + 0.5, pos.y() - 0.5 ) );
787  drawLine( QPoint( pos.x() + 0.5, pos.y() - 0.5 ), QPoint( pos.x() + 0.5, pos.y() + 0.5 ) );
788  drawLine( QPoint( pos.x() + 0.5, pos.y() + 0.5 ), QPoint( pos.x() - 0.5, pos.y() + 0.5 ) );
789  drawLine( QPoint( pos.x() - 0.5, pos.y() + 0.5 ), QPoint( pos.x() - 0.5, pos.y() - 0.5 ) );
790  }
791 
792  if ( Options::showSatellitesLabels() )
793  data->skyComposite()->satellites()->drawLabel( sat, pos );
794 }
795 
796 bool SkyQPainter::drawSupernova(Supernova* sup)
797 {
798  KStarsData *data = KStarsData::Instance();
799  if( !m_proj->checkVisibility(sup) ){ return false; }
800 
801  bool visible = false;
802  QPointF pos = m_proj->toScreen(sup,true,&visible);
803  //kDebug()<<"sup->ra() = "<<(sup->ra()).toHMSString()<<"sup->dec() = "<<sup->dec().toDMSString();
804  //kDebug()<<"pos = "<<pos<<"m_proj->onScreen(pos) = "<<m_proj->onScreen(pos);
805  if( !visible || !m_proj->onScreen(pos) ) return false;
806 
807  setPen( data->colorScheme()->colorNamed("SupernovaColor") );
808  //kDebug()<<"Here"<<endl;
809  drawLine ( QPoint( pos.x () - 2.0, pos.y() ), QPoint( pos.x() + 2.0, pos.y() ) );
810  drawLine ( QPoint( pos.x (), pos.y() - 2.0 ), QPoint( pos.x(), pos.y() + 2.0 ) );
811  return true;
812 }
813 
SkyQPainter::initStarImages
static void initStarImages()
Recalculates the star pixmaps.
Definition: skyqpainter.cpp:140
FlagComponent::size
int size()
Return the numbers of flags.
Definition: flagcomponent.cpp:213
SkyQPainter::drawSkyBackground
virtual void drawSkyBackground()
Draw the sky background.
Definition: skyqpainter.cpp:124
satellitescomponent.h
SkyQPainter::drawPointSource
virtual bool drawPointSource(SkyPoint *loc, float mag, char sp= 'A')
Draw a point source (e.g., a star).
Definition: skyqpainter.cpp:371
Projector::onScreen
bool onScreen(const QPointF &p) const
Check whether the projected point is on-screen.
Definition: projector.cpp:98
Projector::groundPoly
virtual QVector< Vector2f > groundPoly(SkyPoint *labelpoint=0, bool *drawLabel=0) const
Get the ground polygon.
Definition: projector.cpp:252
SkyList
QVector< SkyPoint * > SkyList
Definition: skycomponents/typedef.h:45
KStarsData
KStarsData is the backbone of KStars.
Definition: kstarsdata.h:66
supernova.h
skiplist.h
SkyQPainter::drawObservingList
virtual void drawObservingList(const QList< SkyObject * > &obs)
Draw the symbols for the observing list.
Definition: skyqpainter.cpp:703
KStarsData::colorScheme
ColorScheme * colorScheme()
Definition: kstarsdata.h:149
LineListLabel
Definition: linelistlabel.h:36
deepskyobject.h
KSUtils::vecToPoint
QPointF vecToPoint(const Vector2f &vec)
Convert a vector to a point.
Definition: ksutils.h:91
QWidget
KStarsData::lst
dms * lst()
Definition: kstarsdata.h:161
KStarsData::Instance
static KStarsData * Instance()
Definition: kstarsdata.h:92
SkyQPainter::drawDeepSkyObject
virtual bool drawDeepSkyObject(DeepSkyObject *obj, bool drawImage=false)
Draw a deep sky object.
Definition: skyqpainter.cpp:424
ColorScheme::colorNamed
QColor colorNamed(const QString &name) const
Retrieve a color by name.
Definition: colorscheme.cpp:97
SkyQPainter::setBrush
virtual void setBrush(const QBrush &brush)
Set the brush of the painter.
Definition: skyqpainter.cpp:135
KStarsData::geo
GeoLocation * geo()
Definition: kstarsdata.h:164
SkyQPainter::drawSkyLine
virtual void drawSkyLine(SkyPoint *a, SkyPoint *b)
Draw a line between points in the sky.
Definition: skyqpainter.cpp:231
SkyQPainter::drawSupernova
virtual bool drawSupernova(Supernova *sup)
Draw a Supernova.
Definition: skyqpainter.cpp:796
SkyQPainter::begin
virtual void begin()
Begin painting.
Definition: skyqpainter.cpp:110
SkyPainter::m_sm
SkyMap * m_sm
Definition: skypainter.h:158
LineList
Definition: linelist.h:35
Projector::checkVisibility
bool checkVisibility(SkyPoint *p) const
Determine if the skypoint p is likely to be visible in the display window.
Definition: projector.cpp:181
Options::showSatellitesLabels
static bool showSatellitesLabels()
Get Draw satellite labels?
Definition: Options.h:4369
SkyMapComposite::satellites
SatellitesComponent * satellites()
Definition: skymapcomposite.cpp:609
Projector::findPA
double findPA(SkyObject *o, float x, float y) const
Determine the on-screen position angle of a SkyObject.
Definition: projector.cpp:227
LineList::points
SkyList * points()
Definition: linelist.h:53
FlagComponent::image
QImage image(int index)
Get image.
Definition: flagcomponent.cpp:241
SkyPoint
The sky coordinates of a point in the sky.
Definition: skypoint.h:50
SkyMapComposite::flags
FlagComponent * flags()
Definition: skymapcomposite.cpp:605
SkyPainter::starWidth
float starWidth(float mag) const
Get the width of a star of magnitude mag.
Definition: skypainter.cpp:50
Projector::toScreen
QPointF toScreen(const SkyPoint *o, bool oRefract=true, bool *onVisibleHemisphere=0) const
This is exactly the same as toScreenVec but it returns a QPointF.
Definition: projector.cpp:93
DeepSkyObject::a
float a() const
Definition: deepskyobject.h:132
linelist.h
skymapcomposite.h
MINZOOM
#define MINZOOM
Definition: kstarsdata.h:38
FlagComponent::label
QString label(int index)
Get label.
Definition: flagcomponent.cpp:225
linelistlabel.h
KSPlanetBase::angSize
double angSize() const
Definition: ksplanetbase.h:171
Options::starColorIntensity
static uint starColorIntensity()
Get Saturation level of star colors.
Definition: Options.h:2944
SkyQPainter::drawFlags
virtual void drawFlags()
Draw flags.
Definition: skyqpainter.cpp:718
Supernova
Represents the supernova object.
Definition: supernova.h:44
SkyMap::isSlewing
bool isSlewing() const
Definition: skymap.cpp:1133
skymap.h
SkyQPainter::drawHorizon
virtual void drawHorizon(bool filled, SkyPoint *labelPoint=0, bool *drawLabel=0)
Definition: skyqpainter.cpp:750
SkyQPainter::~SkyQPainter
virtual ~SkyQPainter()
Definition: skyqpainter.cpp:106
SkyPoint::HorizontalToEquatorial
void HorizontalToEquatorial(const dms *LST, const dms *lat)
Determine the (RA, Dec) coordinates of the SkyPoint from its (Altitude, Azimuth) coordinates, given the local sidereal time and the observer's latitude.
Definition: skypoint.cpp:102
trailobject.h
KStarsData::skyComposite
SkyMapComposite * skyComposite()
Definition: kstarsdata.h:146
SkyQPainter::drawSatellite
virtual void drawSatellite(Satellite *sat)
Draw a satellite.
Definition: skyqpainter.cpp:766
Projector::clipLine
QPointF clipLine(SkyPoint *p1, SkyPoint *p2) const
ASSUMES *p1 did not clip but *p2 did.
Definition: projector.cpp:110
SkyQPainter::drawSkyPolygon
virtual void drawSkyPolygon(LineList *list)
Draw a polygon in the sky.
Definition: skyqpainter.cpp:282
SkyQPainter::drawSkyPolyline
virtual void drawSkyPolyline(LineList *list, SkipList *skipList=0, LineListLabel *label=0)
Draw a polyline in the sky.
Definition: skyqpainter.cpp:249
PointListComponent::pointList
QList< SkyPoint * > & pointList()
Definition: pointlistcomponent.h:58
SkyPoint::EquatorialToHorizontal
void EquatorialToHorizontal(const dms *LST, const dms *lat)
Determine the (Altitude, Azimuth) coordinates of the SkyPoint from its (RA, Dec) coordinates, given the local sidereal time and the observer's latitude.
Definition: skypoint.cpp:55
DeepSkyObject::image
const QImage & image() const
Definition: deepskyobject.h:161
Options.h
SkyObject::mag
float mag(void) const
Definition: skyobject.h:182
DeepSkyObject
Provides all necessary information about a deep-sky object: data inherited from SkyObject (coordinate...
Definition: deepskyobject.h:43
SkyQPainter::setPen
virtual void setPen(const QPen &pen)
Set the pen of the painter.
Definition: skyqpainter.cpp:130
SkyQPainter::SkyQPainter
SkyQPainter(QPaintDevice *pd, const QSize &canvasSize)
Creates a SkyQPainter with the given QPaintDevice and uses the dimensions of the paint device as canv...
Definition: skyqpainter.cpp:87
SkyQPainter::drawDeepSkySymbol
virtual void drawDeepSkySymbol(const QPointF &pos, int type, float size, float e, float positionAngle)
Definition: skyqpainter.cpp:468
GeoLocation::lat
const dms * lat() const
Definition: geolocation.h:79
Options::drawSatellitesLikeStars
static bool drawSatellitesLikeStars()
Get If selected, satellites will be draw like stars, otherwise, draw satellites as small colored squa...
Definition: Options.h:4350
SatellitesComponent::drawLabel
void drawLabel(Satellite *sat, QPointF pos)
Draw label of a satellite.
Definition: satellitescomponent.cpp:100
SkyObject::type
int type(void) const
Definition: skyobject.h:164
kscomet.h
Satellite::isVisible
bool isVisible()
Definition: satellite.cpp:1196
FlagComponent::labelColor
QColor labelColor(int index)
Get label color.
Definition: flagcomponent.cpp:233
PI
#define PI
Definition: satellite.cpp:43
SkipList::skip
bool skip(int i)
Definition: skiplist.h:51
Options::zoomFactor
static double zoomFactor()
Get Zoom Factor, in pixels per radian.
Definition: Options.h:2531
skyqpainter.h
satellite.h
Options::starColorMode
static uint starColorMode()
Get Mode for rendering stars.
Definition: Options.h:2918
projector.h
Satellite
Represents an artificial satellites.
Definition: satellite.h:35
KSPlanetBase
A subclass of TrailObject that provides additional information needed for most solar system objects...
Definition: ksplanetbase.h:63
ksasteroid.h
kstarsdata.h
DeepSkyObject::e
float e() const
Definition: deepskyobject.cpp:81
KSPlanetBase::image
const QImage & image()
Definition: ksplanetbase.h:123
SkyObject::name
virtual QString name(void) const
Definition: skyobject.h:124
SkyQPainter::drawPlanet
virtual bool drawPlanet(KSPlanetBase *planet)
Draw a planet.
Definition: skyqpainter.cpp:320
ksutils.h
SkyObject
Provides all necessary information about an object in the sky: its coordinates, name(s), type, magnitude, and QStringLists of URLs for images and webpages regarding the object.
Definition: skyobject.h:46
SkyMap::projector
const Projector * projector() const
Get the current projector.
Definition: skymap.h:264
SkyPainter
Draws things on the sky, without regard to backend.
Definition: skypainter.h:47
flagcomponent.h
Options::useAntialias
static bool useAntialias()
Get Use antialiasing when drawing the screen?
Definition: Options.h:2500
Options::showPlanetImages
static bool showPlanetImages()
Get Draw planets as images in the sky map?
Definition: Options.h:1949
SkyQPainter::end
virtual void end()
End and finalize painting.
Definition: skyqpainter.cpp:119
SkipList
Definition: SkipList.h:17
QList
LineListLabel::updateLabelCandidates
void updateLabelCandidates(qreal x, qreal y, LineList *lineList, int i)
Definition: linelistlabel.cpp:62
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:21 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

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

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal