• 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
  • skycomponents
constellationnamescomponent.cpp
Go to the documentation of this file.
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  * *
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. *
15  * *
16  ***************************************************************************/
17 #include "constellationnamescomponent.h"
18 
19 #include <QTextStream>
20 
21 #include "kstarsdata.h"
22 #include "skymap.h"
23 #include "skyobjects/skyobject.h"
24 #include "skycomponents/culturelist.h"
25 #include "Options.h"
26 
27 #include "ksfilereader.h"
28 #include "skylabeler.h"
29 #include "projections/projector.h"
30 
31 ConstellationNamesComponent::ConstellationNamesComponent(SkyComposite *parent, CultureList* cultures )
32  : ListComponent(parent )
33 {
34  uint i = 0;
35  bool culture = false;
36  KSFileReader fileReader;
37  QString cultureName;
38 
39  if ( ! fileReader.open( "cnames.dat" ) )
40  return;
41 
42  emitProgressText( i18n("Loading constellation names" ) );
43 
44  localCNames = Options::useLocalConstellNames();
45 
46  while ( fileReader.hasMoreLines() ) {
47  QString line, name, abbrev;
48  int rah, ram, ras, dd, dm, ds;
49  QChar sgn, mode;
50 
51  line = fileReader.readLine();
52 
53  mode = line.at( 0 );
54  if ( mode == 'C') {
55  cultureName = line.mid( 2 ).trimmed();
56  culture = cultureName == cultures->current();
57  i++;
58  continue;
59  }
60 
61  if ( culture ) {
62  rah = line.mid( 0, 2 ).toInt();
63  ram = line.mid( 2, 2 ).toInt();
64  ras = line.mid( 4, 2 ).toInt();
65 
66  sgn = line.at( 6 );
67  dd = line.mid( 7, 2 ).toInt();
68  dm = line.mid( 9, 2 ).toInt();
69  ds = line.mid( 11, 2 ).toInt();
70 
71  abbrev = line.mid( 13, 3 );
72  name = line.mid( 17 ).trimmed();
73 
74  if( Options::useLocalConstellNames() )
75  name = i18nc( "Constellation name (optional)", name.toLocal8Bit().data() );
76 
77  dms r; r.setH( rah, ram, ras );
78  dms d( dd, dm, ds );
79 
80  if ( sgn == '-' )
81  d.setD( -1.0*d.Degrees() );
82 
83  SkyObject *o = new SkyObject( SkyObject::CONSTELLATION, r, d, 0.0, name, abbrev );
84  m_ObjectList.append( o );
85 
86  //Add name to the list of object names
87  objectNames(SkyObject::CONSTELLATION).append( name );
88  }
89  }
90 }
91 
92 ConstellationNamesComponent::~ConstellationNamesComponent()
93 {}
94 
95 bool ConstellationNamesComponent::selected()
96 {
97  return Options::showCNames() &&
98  !( Options::hideOnSlew() && Options::hideCNames() && SkyMap::IsSlewing() );
99 }
100 
101 // Don't precess the location of the names
102 void ConstellationNamesComponent::update( KSNumbers* )
103 {
104  if ( ! selected() )
105  return;
106  KStarsData *data = KStarsData::Instance();
107  foreach(SkyObject* o, m_ObjectList)
108  o->EquatorialToHorizontal( data->lst(), data->geo()->lat() );
109 }
110 
111 void ConstellationNamesComponent::draw( SkyPainter *skyp )
112 {
113  Q_UNUSED(skyp);
114  if ( ! selected() )
115  return;
116 
117  const Projector *proj = SkyMap::Instance()->projector();
118  SkyLabeler* skyLabeler = SkyLabeler::Instance();
119  skyLabeler->useStdFont();
120  skyLabeler->setPen( QColor( KStarsData::Instance()->colorScheme()->colorNamed( "CNameColor" ) ) );
121 
122  QString name;
123  foreach(SkyObject *p, m_ObjectList) {
124  if( ! proj->checkVisibility( p ) )
125  continue;
126 
127  bool visible = false;
128  QPointF o = proj->toScreen( p, false, &visible );
129  if( !visible || !proj->onScreen( o ) )
130  continue;
131 
132  if( Options::useLatinConstellNames() || Options::useLocalConstellNames() )
133  name = p->name();
134  else
135  name = p->name2();
136 
137  o.setX( o.x() - 5.0 * name.length() );
138  skyLabeler->drawGuideLabel( o, name, 0.0 );
139  }
140 
141  skyLabeler->resetFont();
142 }
KSFileReader::hasMoreLines
bool hasMoreLines()
Definition: ksfilereader.h:108
Projector::onScreen
bool onScreen(const QPointF &p) const
Check whether the projected point is on-screen.
Definition: projector.cpp:98
ConstellationNamesComponent::selected
virtual bool selected()
Definition: constellationnamescomponent.cpp:95
KStarsData
KStarsData is the backbone of KStars.
Definition: kstarsdata.h:66
skyobject.h
ListComponent::m_ObjectList
QList< SkyObject * > m_ObjectList
Definition: listcomponent.h:64
KStarsData::lst
dms * lst()
Definition: kstarsdata.h:161
KStarsData::Instance
static KStarsData * Instance()
Definition: kstarsdata.h:92
dms::Degrees
const double & Degrees() const
Definition: dms.h:98
KStarsData::geo
GeoLocation * geo()
Definition: kstarsdata.h:164
ListComponent
An abstract parent class, to be inherited by SkyComponents that store a QList of SkyObjects.
Definition: listcomponent.h:36
Options::hideOnSlew
static bool hideOnSlew()
Get Hide objects while moving?
Definition: Options.h:1094
culturelist.h
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
ConstellationNamesComponent::ConstellationNamesComponent
ConstellationNamesComponent(SkyComposite *parent, CultureList *cultures)
Constructor parent Pointer to the parent SkyComposite object.
Definition: constellationnamescomponent.cpp:31
KSFileReader::open
bool open(const QString &fname)
Definition: ksfilereader.cpp:46
SkyLabeler::Instance
static SkyLabeler * Instance()
Definition: skylabeler.cpp:49
Projector
This class serves as an interface to handle projections.
Definition: projector.h:49
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
SkyLabeler::useStdFont
void useStdFont()
sets the font in SkyLabeler and in psky to the font psky had originally when reset() was called...
Definition: skylabeler.cpp:185
Options::showCNames
static bool showCNames()
Get Draw constellation names in the sky map?
Definition: Options.h:1607
Options::useLatinConstellNames
static bool useLatinConstellNames()
Get Use Latin constellation names?
Definition: Options.h:2348
skymap.h
i18nc
i18nc("string from libindi, used in the config dialog","100x")
dms
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:42
SkyComposite
SkyComposite is a kind of container class for SkyComponent objects.
Definition: skycomposite.h:43
SkyLabeler::drawGuideLabel
bool drawGuideLabel(QPointF &o, const QString &text, double angle)
Tries to draw the text at the position and angle specified.
Definition: skylabeler.cpp:104
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
Options.h
SkyObject::name2
QString name2(void) const
Definition: skyobject.h:132
KSNumbers
There are several time-dependent values used in position calculations, that are not specific to an ob...
Definition: ksnumbers.h:43
constellationnamescomponent.h
GeoLocation::lat
const dms * lat() const
Definition: geolocation.h:79
ConstellationNamesComponent::update
virtual void update(KSNumbers *num)
we need a custom routine (for now) so we don't precess the locations of the names.
Definition: constellationnamescomponent.cpp:102
ksfilereader.h
KSFileReader::readLine
QString readLine()
Definition: ksfilereader.h:113
KSFileReader
Definition: ksfilereader.h:65
NaN::d
const double d
Definition: nan.h:35
SkyObject::CONSTELLATION
Definition: skyobject.h:110
SkyMap::IsSlewing
static bool IsSlewing()
Definition: skymap.h:91
projector.h
SkyMap::Instance
static SkyMap * Instance()
Definition: skymap.cpp:141
SkyLabeler::setPen
void setPen(const QPen &pen)
sets the pen used for drawing labels on the sky.
Definition: skylabeler.cpp:173
CultureList::current
QString current()
Return the current sky culture.
Definition: culturelist.h:33
SkyLabeler::resetFont
void resetFont()
sets the font in SkyLabeler and in psky back to the zoom dependent value that was set in reset()...
Definition: skylabeler.cpp:190
SkyComponent::emitProgressText
virtual void emitProgressText(const QString &message)
Emit signal about progress.
Definition: skycomponent.cpp:35
kstarsdata.h
ConstellationNamesComponent::draw
virtual void draw(SkyPainter *skyp)
Draw constellation names on the sky map.
Definition: constellationnamescomponent.cpp:111
skylabeler.h
dms::setD
void setD(const double &x)
Sets floating-point value of angle, in degrees.
Definition: dms.h:130
SkyLabeler
The purpose of this class is to prevent labels from overlapping.
Definition: skylabeler.h:112
SkyObject::name
virtual QString name(void) const
Definition: skyobject.h:124
SkyComponent::objectNames
QHash< int, QStringList > & objectNames()
Definition: skycomponent.h:127
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
ConstellationNamesComponent::~ConstellationNamesComponent
virtual ~ConstellationNamesComponent()
Destructor.
Definition: constellationnamescomponent.cpp:92
Options::useLocalConstellNames
static bool useLocalConstellNames()
Get Use localized constellation names?
Definition: Options.h:2367
CultureList
A list of all cultures.
Definition: culturelist.h:26
Options::hideCNames
static bool hideCNames()
Get Hide constellation names while moving?
Definition: Options.h:1170
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:19 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