Kstars

constellationnamescomponent.cpp
1/*
2 SPDX-FileCopyrightText: 2005 Thomas Kabelmann <thomas.kabelmann@gmx.de>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "constellationnamescomponent.h"
8
9#include "ksfilereader.h"
10#include "kstarsdata.h"
11#include "Options.h"
12#include "skylabeler.h"
13#ifndef KSTARS_LITE
14#include "skymap.h"
15#endif
16#include "projections/projector.h"
17#include "skycomponents/culturelist.h"
18
19#include <QtConcurrent>
20
22 : ListComponent(parent)
23{
24 QtConcurrent::run(this, &ConstellationNamesComponent::loadData, cultures);
25}
26
27void ConstellationNamesComponent::loadData(CultureList *cultures)
28{
29 uint i = 0;
30 bool culture = false;
32 QString cultureName;
33
34 if (!fileReader.open("cnames.dat"))
35 return;
36
37 emitProgressText(i18n("Loading constellation names"));
38
39 localCNames = Options::useLocalConstellNames();
40
41 while (fileReader.hasMoreLines())
42 {
43 QString line, name, abbrev;
44 int rah, ram, ras, dd, dm, ds;
45 QChar sgn, mode;
46
47 line = fileReader.readLine();
48
49 mode = line.at(0);
50 if (mode == 'C')
51 {
52 cultureName = line.mid(2).trimmed();
53 culture = cultureName == cultures->current();
54 i++;
55 continue;
56 }
57
58 if (culture)
59 {
60 rah = line.midRef(0, 2).toInt();
61 ram = line.midRef(2, 2).toInt();
62 ras = line.midRef(4, 2).toInt();
63
64 sgn = line.at(6);
65 dd = line.midRef(7, 2).toInt();
66 dm = line.midRef(9, 2).toInt();
67 ds = line.midRef(11, 2).toInt();
68
69 abbrev = line.mid(13, 3);
70 name = line.mid(17).trimmed();
71
72 if (Options::useLocalConstellNames())
73 name = i18nc("Constellation name (optional)", name.toLocal8Bit().data());
74
75 dms r;
76 r.setH(rah, ram, ras);
77 dms d(dd, dm, ds);
78
79 if (sgn == '-')
80 d.setD(-1.0 * d.Degrees());
81
82 SkyObject *o = new SkyObject(SkyObject::CONSTELLATION, r, d, 0.0, name, abbrev);
83 o->EquatorialToHorizontal(KStarsData::Instance()->lst(), KStarsData::Instance()->geo()->lat());
85
86 //Add name to the list of object names
87 objectNames(SkyObject::CONSTELLATION).append(name);
88 objectLists(SkyObject::CONSTELLATION).append(QPair<QString, const SkyObject *>(name, o));
89 }
90 }
91}
92
94{
95#ifndef KSTARS_LITE
96 return Options::showCNames() && !(Options::hideOnSlew() && Options::hideCNames() && SkyMap::IsSlewing());
97#else
98 return Options::showCNames() && !(Options::hideOnSlew() && Options::hideCNames() && SkyMapLite::IsSlewing());
99#endif
100}
101
102// Don't precess the location of the names
104{
105 if (!selected())
106 return;
107 KStarsData *data = KStarsData::Instance();
108 foreach (SkyObject *o, m_ObjectList)
109 o->EquatorialToHorizontal(data->lst(), data->geo()->lat());
110}
111
113{
114 Q_UNUSED(skyp);
115#ifndef KSTARS_LITE
116 if (!selected())
117 return;
118
119 const Projector *proj = SkyMap::Instance()->projector();
120 SkyLabeler *skyLabeler = SkyLabeler::Instance();
121 //skyLabeler->useStdFont();
122 // Subjective change, but constellation names really need to stand out against everything else
123 skyLabeler->setFont(QFont("Arial", 14));
124 skyLabeler->setPen(QColor(KStarsData::Instance()->colorScheme()->colorNamed("CNameColor")));
125
126 QString name;
127 foreach (SkyObject *p, m_ObjectList)
128 {
129 if (!proj->checkVisibility(p))
130 continue;
131
132 bool visible = false;
133 QPointF o = proj->toScreen(p, false, &visible);
134 if (!visible || !proj->onScreen(o))
135 continue;
136
137 if (Options::useLatinConstellNames() || Options::useLocalConstellNames())
138 name = p->name();
139 else
140 name = p->name2();
141
142 o.setX(o.x() - 5.0 * name.length());
143 skyLabeler->drawGuideLabel(o, name, 0.0);
144 }
145
146 skyLabeler->resetFont();
147#endif
148}
ConstellationNamesComponent(SkyComposite *parent, CultureList *cultures)
Constructor parent Pointer to the parent SkyComposite object.
void update(KSNumbers *num) override
we need a custom routine (for now) so we don't precess the locations of the names.
void draw(SkyPainter *skyp) override
Draw constellation names on the sky map.
A list of all cultures FIXME: Why not use a QStringList?
Definition culturelist.h:17
const CachingDms * lat() const
Definition geolocation.h:70
I totally rewrote this because the earlier scheme of reading all the lines of a file into a buffer be...
There are several time-dependent values used in position calculations, that are not specific to an ob...
Definition ksnumbers.h:43
KStarsData is the backbone of KStars.
Definition kstarsdata.h:72
CachingDms * lst()
Definition kstarsdata.h:224
GeoLocation * geo()
Definition kstarsdata.h:230
An abstract parent class, to be inherited by SkyComponents that store a QList of SkyObjects.
void appendListObject(SkyObject *object)
Add an object to the Object list.
The Projector class is the primary class that serves as an interface to handle projections.
Definition projector.h:58
virtual void emitProgressText(const QString &message)
Emit signal about progress.
SkyComposite is a kind of container class for SkyComponent objects.
The purpose of this class is to prevent labels from overlapping.
Definition skylabeler.h:99
void resetFont()
sets the font in SkyLabeler and in psky back to the zoom dependent value that was set in reset().
void setFont(const QFont &font)
tells the labeler the font you will be using so it can figure out the height and width of the labels.
bool drawGuideLabel(QPointF &o, const QString &text, double angle)
Tries to draw the text at the position and angle specified.
void setPen(const QPen &pen)
sets the pen used for drawing labels on the sky.
Provides all necessary information about an object in the sky: its coordinates, name(s),...
Definition skyobject.h:42
virtual QString name(void) const
Definition skyobject.h:145
QString name2(void) const
Definition skyobject.h:156
Draws things on the sky, without regard to backend.
Definition skypainter.h:40
void EquatorialToHorizontal(const CachingDms *LST, const CachingDms *lat)
Determine the (Altitude, Azimuth) coordinates of the SkyPoint from its (RA, Dec) coordinates,...
Definition skypoint.cpp:77
An angle, stored as degrees, but expressible in many ways.
Definition dms.h:38
virtual void setH(const double &x)
Sets floating-point value of angle, in hours.
Definition dms.h:210
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
GeoCoordinates geo(const QVariant &location)
QString name(StandardAction id)
char * data()
void setX(qreal x)
qreal x() const const
const QChar at(qsizetype position) const const
qsizetype length() const const
QString mid(qsizetype position, qsizetype n) const const
int toInt(bool *ok, int base) const const
QByteArray toLocal8Bit() const const
QString trimmed() const const
QFuture< T > run(Function function,...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:48:27 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.