PageRenderTime 48ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/kstars/skycomponents/constellationnamescomponent.cpp

https://gitlab.com/g10h4ck/kstars
C++ | 143 lines | 97 code | 29 blank | 17 comment | 18 complexity | cfd3653ba7cc657e63bae75db19b02ac MD5 | raw file
Possible License(s): GPL-2.0, CC-BY-SA-3.0
  1. /***************************************************************************
  2. constellationnamescomponent.cpp - K Desktop Planetarium
  3. -------------------
  4. begin : 2005/10/08
  5. copyright : (C) 2005 by Thomas Kabelmann
  6. email : thomas.kabelmann@gmx.de
  7. ***************************************************************************/
  8. /***************************************************************************
  9. * *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License as published by *
  12. * the Free Software Foundation; either version 2 of the License, or *
  13. * (at your option) any later version. *
  14. * *
  15. ***************************************************************************/
  16. #include "constellationnamescomponent.h"
  17. #include <QTextStream>
  18. #include "kstarsdata.h"
  19. #include "skymap.h"
  20. #include "skyobjects/skyobject.h"
  21. #include "skycomponents/culturelist.h"
  22. #include "Options.h"
  23. #include "ksfilereader.h"
  24. #include "skylabeler.h"
  25. #include "projections/projector.h"
  26. ConstellationNamesComponent::ConstellationNamesComponent(SkyComposite *parent, CultureList* cultures )
  27. : ListComponent(parent )
  28. {
  29. uint i = 0;
  30. bool culture = false;
  31. KSFileReader fileReader;
  32. QString cultureName;
  33. if ( ! fileReader.open( "cnames.dat" ) )
  34. return;
  35. emitProgressText( xi18n("Loading constellation names" ) );
  36. localCNames = Options::useLocalConstellNames();
  37. while ( fileReader.hasMoreLines() ) {
  38. QString line, name, abbrev;
  39. int rah, ram, ras, dd, dm, ds;
  40. QChar sgn, mode;
  41. line = fileReader.readLine();
  42. mode = line.at( 0 );
  43. if ( mode == 'C') {
  44. cultureName = line.mid( 2 ).trimmed();
  45. culture = cultureName == cultures->current();
  46. i++;
  47. continue;
  48. }
  49. if ( culture ) {
  50. rah = line.mid( 0, 2 ).toInt();
  51. ram = line.mid( 2, 2 ).toInt();
  52. ras = line.mid( 4, 2 ).toInt();
  53. sgn = line.at( 6 );
  54. dd = line.mid( 7, 2 ).toInt();
  55. dm = line.mid( 9, 2 ).toInt();
  56. ds = line.mid( 11, 2 ).toInt();
  57. abbrev = line.mid( 13, 3 );
  58. name = line.mid( 17 ).trimmed();
  59. if( Options::useLocalConstellNames() )
  60. name = i18nc( "Constellation name (optional)", name.toLocal8Bit().data() );
  61. dms r; r.setH( rah, ram, ras );
  62. dms d( dd, dm, ds );
  63. if ( sgn == '-' )
  64. d.setD( -1.0*d.Degrees() );
  65. SkyObject *o = new SkyObject( SkyObject::CONSTELLATION, r, d, 0.0, name, abbrev );
  66. o->EquatorialToHorizontal(KStarsData::Instance()->lst(),KStarsData::Instance()->geo()->lat());
  67. m_ObjectList.append( o );
  68. //Add name to the list of object names
  69. objectNames(SkyObject::CONSTELLATION).append( name );
  70. }
  71. }
  72. }
  73. ConstellationNamesComponent::~ConstellationNamesComponent()
  74. {}
  75. bool ConstellationNamesComponent::selected()
  76. {
  77. return Options::showCNames() &&
  78. !( Options::hideOnSlew() && Options::hideCNames() && SkyMap::IsSlewing() );
  79. }
  80. // Don't precess the location of the names
  81. void ConstellationNamesComponent::update( KSNumbers* )
  82. {
  83. if ( ! selected() )
  84. return;
  85. KStarsData *data = KStarsData::Instance();
  86. foreach(SkyObject* o, m_ObjectList)
  87. o->EquatorialToHorizontal( data->lst(), data->geo()->lat() );
  88. }
  89. void ConstellationNamesComponent::draw( SkyPainter *skyp )
  90. {
  91. Q_UNUSED(skyp);
  92. if ( ! selected() )
  93. return;
  94. const Projector *proj = SkyMap::Instance()->projector();
  95. SkyLabeler* skyLabeler = SkyLabeler::Instance();
  96. skyLabeler->useStdFont();
  97. skyLabeler->setPen( QColor( KStarsData::Instance()->colorScheme()->colorNamed( "CNameColor" ) ) );
  98. QString name;
  99. foreach(SkyObject *p, m_ObjectList) {
  100. if( ! proj->checkVisibility( p ) )
  101. continue;
  102. bool visible = false;
  103. QPointF o = proj->toScreen( p, false, &visible );
  104. if( !visible || !proj->onScreen( o ) )
  105. continue;
  106. if( Options::useLatinConstellNames() || Options::useLocalConstellNames() )
  107. name = p->name();
  108. else
  109. name = p->name2();
  110. o.setX( o.x() - 5.0 * name.length() );
  111. skyLabeler->drawGuideLabel( o, name, 0.0 );
  112. }
  113. skyLabeler->resetFont();
  114. }