File indexing completed on 2025-01-19 09:45:58
0001 /* 0002 SPDX-FileCopyrightText: 2005 Thomas Kabelmann <thomas.kabelmann@gmx.de> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "constellationnamescomponent.h" 0008 0009 #include "ksfilereader.h" 0010 #include "kstarsdata.h" 0011 #include "Options.h" 0012 #include "skylabeler.h" 0013 #ifndef KSTARS_LITE 0014 #include "skymap.h" 0015 #endif 0016 #include "projections/projector.h" 0017 #include "skycomponents/culturelist.h" 0018 0019 #include <QtConcurrent> 0020 0021 ConstellationNamesComponent::ConstellationNamesComponent(SkyComposite *parent, CultureList *cultures) 0022 : ListComponent(parent) 0023 { 0024 QtConcurrent::run(this, &ConstellationNamesComponent::loadData, cultures); 0025 } 0026 0027 void ConstellationNamesComponent::loadData(CultureList *cultures) 0028 { 0029 uint i = 0; 0030 bool culture = false; 0031 KSFileReader fileReader; 0032 QString cultureName; 0033 0034 if (!fileReader.open("cnames.dat")) 0035 return; 0036 0037 emitProgressText(i18n("Loading constellation names")); 0038 0039 localCNames = Options::useLocalConstellNames(); 0040 0041 while (fileReader.hasMoreLines()) 0042 { 0043 QString line, name, abbrev; 0044 int rah, ram, ras, dd, dm, ds; 0045 QChar sgn, mode; 0046 0047 line = fileReader.readLine(); 0048 0049 mode = line.at(0); 0050 if (mode == 'C') 0051 { 0052 cultureName = line.mid(2).trimmed(); 0053 culture = cultureName == cultures->current(); 0054 i++; 0055 continue; 0056 } 0057 0058 if (culture) 0059 { 0060 rah = line.midRef(0, 2).toInt(); 0061 ram = line.midRef(2, 2).toInt(); 0062 ras = line.midRef(4, 2).toInt(); 0063 0064 sgn = line.at(6); 0065 dd = line.midRef(7, 2).toInt(); 0066 dm = line.midRef(9, 2).toInt(); 0067 ds = line.midRef(11, 2).toInt(); 0068 0069 abbrev = line.mid(13, 3); 0070 name = line.mid(17).trimmed(); 0071 0072 if (Options::useLocalConstellNames()) 0073 name = i18nc("Constellation name (optional)", name.toLocal8Bit().data()); 0074 0075 dms r; 0076 r.setH(rah, ram, ras); 0077 dms d(dd, dm, ds); 0078 0079 if (sgn == '-') 0080 d.setD(-1.0 * d.Degrees()); 0081 0082 SkyObject *o = new SkyObject(SkyObject::CONSTELLATION, r, d, 0.0, name, abbrev); 0083 o->EquatorialToHorizontal(KStarsData::Instance()->lst(), KStarsData::Instance()->geo()->lat()); 0084 appendListObject(o); 0085 0086 //Add name to the list of object names 0087 objectNames(SkyObject::CONSTELLATION).append(name); 0088 objectLists(SkyObject::CONSTELLATION).append(QPair<QString, const SkyObject *>(name, o)); 0089 } 0090 } 0091 } 0092 0093 bool ConstellationNamesComponent::selected() 0094 { 0095 #ifndef KSTARS_LITE 0096 return Options::showCNames() && !(Options::hideOnSlew() && Options::hideCNames() && SkyMap::IsSlewing()); 0097 #else 0098 return Options::showCNames() && !(Options::hideOnSlew() && Options::hideCNames() && SkyMapLite::IsSlewing()); 0099 #endif 0100 } 0101 0102 // Don't precess the location of the names 0103 void ConstellationNamesComponent::update(KSNumbers *) 0104 { 0105 if (!selected()) 0106 return; 0107 KStarsData *data = KStarsData::Instance(); 0108 foreach (SkyObject *o, m_ObjectList) 0109 o->EquatorialToHorizontal(data->lst(), data->geo()->lat()); 0110 } 0111 0112 void ConstellationNamesComponent::draw(SkyPainter *skyp) 0113 { 0114 Q_UNUSED(skyp); 0115 #ifndef KSTARS_LITE 0116 if (!selected()) 0117 return; 0118 0119 const Projector *proj = SkyMap::Instance()->projector(); 0120 SkyLabeler *skyLabeler = SkyLabeler::Instance(); 0121 //skyLabeler->useStdFont(); 0122 // Subjective change, but constellation names really need to stand out against everything else 0123 skyLabeler->setFont(QFont("Arial", 14)); 0124 skyLabeler->setPen(QColor(KStarsData::Instance()->colorScheme()->colorNamed("CNameColor"))); 0125 0126 QString name; 0127 foreach (SkyObject *p, m_ObjectList) 0128 { 0129 if (!proj->checkVisibility(p)) 0130 continue; 0131 0132 bool visible = false; 0133 QPointF o = proj->toScreen(p, false, &visible); 0134 if (!visible || !proj->onScreen(o)) 0135 continue; 0136 0137 if (Options::useLatinConstellNames() || Options::useLocalConstellNames()) 0138 name = p->name(); 0139 else 0140 name = p->name2(); 0141 0142 o.setX(o.x() - 5.0 * name.length()); 0143 skyLabeler->drawGuideLabel(o, name, 0.0); 0144 } 0145 0146 skyLabeler->resetFont(); 0147 #endif 0148 }