File indexing completed on 2024-03-24 15:17:26
0001 /* 0002 SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "constellationnamesitem.h" 0008 0009 #include "constellationnamescomponent.h" 0010 #include "labelsitem.h" 0011 #include "Options.h" 0012 #include "rootnode.h" 0013 #include "skymaplite.h" 0014 #include "projections/projector.h" 0015 #include "skynodes/labelnode.h" 0016 0017 ConstellationName::ConstellationName(SkyObject *skyObj) : obj(skyObj), latin(0), secondary(0) 0018 { 0019 } 0020 0021 void ConstellationName::hide() 0022 { 0023 if (latin) 0024 latin->hide(); 0025 if (secondary) 0026 secondary->hide(); 0027 } 0028 0029 ConstellationNamesItem::ConstellationNamesItem(ConstellationNamesComponent *constComp, RootNode *parent) 0030 : SkyItem(LabelsItem::label_t::CONSTEL_NAME_LABEL, parent), m_constelNamesComp(constComp) 0031 { 0032 recreateList(); 0033 } 0034 0035 void ConstellationNamesItem::update() 0036 { 0037 if (!m_constelNamesComp->selected()) 0038 { 0039 hide(); 0040 rootNode()->labelsItem()->hideLabels(labelType()); 0041 return; 0042 } 0043 0044 show(); 0045 0046 const Projector *proj = SkyMapLite::Instance()->projector(); 0047 0048 foreach (ConstellationName *constName, m_names) 0049 { 0050 SkyObject *p = constName->obj; 0051 if (!proj->checkVisibility(p)) 0052 { 0053 constName->hide(); 0054 continue; 0055 } 0056 0057 bool visible = false; 0058 QPointF o = proj->toScreen(p, false, &visible); 0059 if (!visible || !proj->onScreen(o)) 0060 { 0061 constName->hide(); 0062 continue; 0063 } 0064 0065 QString name; 0066 0067 if (Options::useLatinConstellNames() || Options::useLocalConstellNames()) 0068 { 0069 name = p->name(); 0070 0071 if (!constName->latin) 0072 { 0073 constName->latin = rootNode()->labelsItem()->addLabel(name, labelType()); 0074 } 0075 0076 o.setX(o.x() - 5.0 * name.length()); 0077 0078 constName->latin->setLabelPos(o); 0079 if (constName->secondary) 0080 constName->secondary->hide(); 0081 } 0082 else 0083 { 0084 name = p->name2(); 0085 0086 if (!constName->secondary) 0087 { 0088 constName->secondary = rootNode()->labelsItem()->addLabel(name, labelType()); 0089 } 0090 0091 o.setX(o.x() - 5.0 * name.length()); 0092 0093 constName->secondary->setLabelPos(o); 0094 if (constName->latin) 0095 constName->latin->hide(); 0096 } 0097 } 0098 } 0099 0100 void ConstellationNamesItem::recreateList() 0101 { 0102 rootNode()->labelsItem()->deleteLabels(labelType()); 0103 m_names.clear(); 0104 0105 foreach (SkyObject *skyObj, m_constelNamesComp->objectList()) 0106 { 0107 m_names.append(new ConstellationName(skyObj)); 0108 } 0109 }