Kstars

constellationnamesitem.cpp
1/*
2 SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com>
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
17ConstellationName::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{
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}
Represents the constellation names on the sky map.
ConstellationNamesItem(ConstellationNamesComponent *constComp, RootNode *rootNode=nullptr)
Constructor.
virtual void update()
Update positions ConstellationName labels based on user settings and labels visibility.
void recreateList()
Delete all labels and recreate m_names according to object list of m_constelNamesComp.
void setLabelPos(QPointF pos)
set the position of label with the given offset from SkyObject's position and makes the label visible...
This class is in charge of labels in SkyMapLite.
Definition labelsitem.h:53
LabelNode * addLabel(SkyObject *skyObject, label_t labelType)
Create LabelNode with given skyObject and append it to LabelTypeNode that corresponds to type.
void deleteLabels(label_t labelType)
deletes all labels of type labelType
void hideLabels(label_t labelType)
hides all labels of type labelType
The Projector class is the primary class that serves as an interface to handle projections.
Definition projector.h:58
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
bool onScreen(const QPointF &p) const
Check whether the projected point is on-screen.
Definition projector.cpp:98
bool checkVisibility(const SkyPoint *p) const
Determine if the skypoint p is likely to be visible in the display window.
A QSGClipNode derived class used as a container for holding pointers to nodes and for clipping.
Definition rootnode.h:60
This is an interface for implementing SkyItems that represent SkyComponent derived objects on the Sky...
Definition skyitem.h:30
virtual void hide() override
hides this item and corresponding labels
Definition skyitem.cpp:37
RootNode * rootNode()
Definition skyitem.h:57
LabelsItem::label_t labelType()
Definition skyitem.h:60
virtual void show() override
makes this node visible
Definition skyitem.cpp:23
const Projector * projector() const
Get the current projector.
Definition skymaplite.h:323
virtual void hide()
hides all child nodes (sets opacity of m_opacity to 0)
Definition skynode.cpp:21
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:146
QString name2(void) const
Definition skyobject.h:157
void setX(qreal x)
qreal x() const const
qsizetype length() const const
The ConstellationName struct.
void hide()
hides both latin and secondary labels
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:46 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.