Kstars

constellationnamesitem.cpp
1 /*
2  SPDX-FileCopyrightText: 2016 Artem Fedoskin <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "constellationnamesitem.h"
8 
9 #include "constellationnamescomponent.h"
10 #include "labelsitem.h"
11 #include "Options.h"
12 #include "rootnode.h"
13 #include "skymaplite.h"
14 #include "projections/projector.h"
15 #include "skynodes/labelnode.h"
16 
17 ConstellationName::ConstellationName(SkyObject *skyObj) : obj(skyObj), latin(0), secondary(0)
18 {
19 }
20 
22 {
23  if (latin)
24  latin->hide();
25  if (secondary)
26  secondary->hide();
27 }
28 
30  : SkyItem(LabelsItem::label_t::CONSTEL_NAME_LABEL, parent), m_constelNamesComp(constComp)
31 {
32  recreateList();
33 }
34 
36 {
37  if (!m_constelNamesComp->selected())
38  {
39  hide();
40  rootNode()->labelsItem()->hideLabels(labelType());
41  return;
42  }
43 
44  show();
45 
46  const Projector *proj = SkyMapLite::Instance()->projector();
47 
48  foreach (ConstellationName *constName, m_names)
49  {
50  SkyObject *p = constName->obj;
51  if (!proj->checkVisibility(p))
52  {
53  constName->hide();
54  continue;
55  }
56 
57  bool visible = false;
58  QPointF o = proj->toScreen(p, false, &visible);
59  if (!visible || !proj->onScreen(o))
60  {
61  constName->hide();
62  continue;
63  }
64 
65  QString name;
66 
67  if (Options::useLatinConstellNames() || Options::useLocalConstellNames())
68  {
69  name = p->name();
70 
71  if (!constName->latin)
72  {
73  constName->latin = rootNode()->labelsItem()->addLabel(name, labelType());
74  }
75 
76  o.setX(o.x() - 5.0 * name.length());
77 
78  constName->latin->setLabelPos(o);
79  if (constName->secondary)
80  constName->secondary->hide();
81  }
82  else
83  {
84  name = p->name2();
85 
86  if (!constName->secondary)
87  {
88  constName->secondary = rootNode()->labelsItem()->addLabel(name, labelType());
89  }
90 
91  o.setX(o.x() - 5.0 * name.length());
92 
93  constName->secondary->setLabelPos(o);
94  if (constName->latin)
95  constName->latin->hide();
96  }
97  }
98 }
99 
101 {
102  rootNode()->labelsItem()->deleteLabels(labelType());
103  m_names.clear();
104 
105  foreach (SkyObject *skyObj, m_constelNamesComp->objectList())
106  {
107  m_names.append(new ConstellationName(skyObj));
108  }
109 }
ConstellationNamesItem(ConstellationNamesComponent *constComp, RootNode *rootNode=nullptr)
Constructor.
A base class that is used for displaying SkyComponents on SkyMapLite.
Definition: skyitem.h:29
A container for nodes that holds collection of textures for stars and provides clipping.
Definition: rootnode.h:59
void recreateList()
Delete all labels and recreate m_names according to object list of m_constelNamesComp.
LabelsItem::label_t labelType()
Definition: skyitem.h:60
void append(const T &value)
void deleteLabels(label_t labelType)
deletes all labels of type labelType
Definition: labelsitem.cpp:214
The ConstellationName struct.
virtual QString name(void) const
Definition: skyobject.h:145
void hide()
hides both latin and secondary labels
Handles labels in SkyMapLite.
Definition: labelsitem.h:52
virtual void show() override
makes this node visible
Definition: skyitem.cpp:23
bool onScreen(const QPointF &p) const
Check whether the projected point is on-screen.
Definition: projector.cpp:98
void clear()
void setX(qreal x)
const Projector * projector() const
Get the current projector.
Definition: skymaplite.h:323
virtual void update()
Update positions ConstellationName labels based on user settings and labels visibility.
int length() const const
void hideLabels(label_t labelType)
hides all labels of type labelType
Definition: labelsitem.cpp:190
virtual void hide() override
hides this item and corresponding labels
Definition: skyitem.cpp:37
qreal x() const const
QPointF toScreen(const SkyPoint *o, bool oRefract=true, bool *onVisibleHemisphere=nullptr) const
This is exactly the same as toScreenVec but it returns a QPointF.
Definition: projector.cpp:93
void setLabelPos(QPointF pos)
set the position of label with the given offset from SkyObject's position and makes the label visible...
Definition: labelnode.cpp:123
RootNode * rootNode()
Definition: skyitem.h:57
QString name2(void) const
Definition: skyobject.h:156
Information about an object in the sky.
Definition: skyobject.h:41
LabelNode * addLabel(SkyObject *skyObject, label_t labelType)
Create LabelNode with given skyObject and append it to LabelTypeNode that corresponds to type.
Definition: labelsitem.cpp:111
virtual void hide()
hides all child nodes (sets opacity of m_opacity to 0)
Definition: skynode.cpp:21
bool checkVisibility(const SkyPoint *p) const
Determine if the skypoint p is likely to be visible in the display window.
Definition: projector.cpp:183
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 19 2022 03:57:50 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.