Kstars

telescopesymbolsitem.cpp
1 /*
2  SPDX-FileCopyrightText: 2016 Artem Fedoskin <[email protected]>
3  SPDX-License-Identifier: GPL-2.0-or-later
4 */
5 
6 #include "telescopesymbolsitem.h"
7 
8 #include "kstarslite.h"
9 #include "labelsitem.h"
10 #include "Options.h"
11 #include "indi/clientmanagerlite.h"
12 #include "kstarslite/skyitems/rootnode.h"
13 #include "projections/projector.h"
14 #include "skynodes/crosshairnode.h"
15 
16 #include <basedevice.h>
17 
19  : SkyItem(LabelsItem::label_t::TELESCOPE_SYMBOL, rootNode)
20 {
21  m_clientManager = KStarsLite::Instance()->clientManagerLite();
22  m_KStarsData = KStarsData::Instance();
23 }
24 
25 void TelescopeSymbolsItem::addTelescope(INDI::BaseDevice *bd)
26 {
27  if (!m_telescopes.value(bd))
28  {
29  CrosshairNode *crossHair = new CrosshairNode(bd, rootNode());
30  appendChildNode(crossHair);
31 
32  m_telescopes.insert(bd, crossHair);
33  }
34 }
35 
36 void TelescopeSymbolsItem::removeTelescope(INDI::BaseDevice *bd)
37 {
38  CrosshairNode *crossHair = m_telescopes.value(bd);
39  if (crossHair)
40  {
41  removeChildNode(crossHair);
42  delete crossHair;
43  }
44  m_telescopes.remove(bd);
45 }
46 
48 {
50  bool deleteAll = !m_clientManager->isConnected();
51 
52  QColor color = m_KStarsData->colorScheme()->colorNamed("TargetColor");
53 
54  bool show = Options::showTargetCrosshair();
55  if (!show)
56  {
57  hide();
58  }
59 
60  for (i = m_telescopes.begin(); i != m_telescopes.end(); ++i)
61  {
62  CrosshairNode *crossHair = i.value();
63  INDI::BaseDevice *device = i.key();
64  if (crossHair)
65  {
66  if (deleteAll || !(device->isConnected()))
67  {
68  removeChildNode(crossHair);
69  delete crossHair;
70  m_telescopes.insert(device, nullptr);
71  }
72  else if (show)
73  {
74  if (device->isConnected())
75  {
76  crossHair->setColor(color);
77  crossHair->update();
78  }
79  else
80  {
81  crossHair->hide();
82  }
83  }
84  }
85  }
86  if (deleteAll)
87  {
88  m_telescopes.clear();
89  }
90 }
const T value(const Key &key) const const
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
QHash::iterator begin()
void appendChildNode(QSGNode *node)
void clear()
static KStarsLite * Instance()
Definition: kstarslite.h:77
Handles labels in SkyMapLite.
Definition: labelsitem.h:52
QHash::iterator insert(const Key &key, const T &value)
virtual void show() override
makes this node visible
Definition: skyitem.cpp:23
TelescopeSymbolsItem(RootNode *rootNode)
Constructor.
ColorScheme * colorScheme()
Definition: kstarsdata.h:171
const Key key(const T &value) const const
virtual void hide() override
hides this item and corresponding labels
Definition: skyitem.cpp:37
int remove(const Key &key)
RootNode * rootNode()
Definition: skyitem.h:57
ClientManagerLite * clientManagerLite() const
Definition: kstarslite.h:107
virtual void update() override
Updates position and visibility of CrosshairNodes that represent telescope symbols If client is no mo...
QColor colorNamed(const QString &name) const
Retrieve a color by name.
Definition: colorscheme.cpp:86
void removeChildNode(QSGNode *node)
void addTelescope(INDI::BaseDevice *bd)
Add telescope symbol for device bd.
QHash::iterator end()
void removeTelescope(INDI::BaseDevice *bd)
Remove telescope symbol of device bd.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Aug 15 2022 04:04:06 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.