Kstars

trailobject.cpp
1 /*
2  SPDX-FileCopyrightText: 2007 Jason Harris <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "trailobject.h"
8 
9 #include "kstarsdata.h"
10 #include "skymap.h"
11 #ifndef KSTARS_LITE
12 #include "kspopupmenu.h"
13 #endif
14 #include "skycomponents/skylabeler.h"
15 #include "skypainter.h"
16 #include "projections/projector.h"
17 #include "Options.h"
18 
19 #include <QPainter>
20 
21 #include <typeinfo>
22 
24 
25 TrailObject::TrailObject(int t, dms r, dms d, float m, const QString &n) : SkyObject(t, r, d, m, n)
26 {
27 }
28 
29 TrailObject::TrailObject(int t, double r, double d, float m, const QString &n) : SkyObject(t, r, d, m, n)
30 {
31 }
32 
33 TrailObject::~TrailObject()
34 {
35  trailObjects.remove(this);
36 }
37 
39 {
40  Q_ASSERT(typeid(this) ==
41  typeid(static_cast<const TrailObject *>(this))); // Ensure we are not slicing a derived class
42  return new TrailObject(*this);
43 }
44 
45 void TrailObject::updateTrail(dms *LST, const dms *lat)
46 {
47  for (auto & item : Trail)
48  item.EquatorialToHorizontal(LST, lat);
49 }
50 
52 {
53 #ifndef KSTARS_LITE
54  pmenu->createPlanetMenu(this);
55 #else
56  Q_UNUSED(pmenu);
57 #endif
58 }
59 
60 void TrailObject::addToTrail(const QString &label)
61 {
62  Trail.append(SkyPoint(*this));
63  m_TrailLabels.append(label);
64  trailObjects.insert(this);
65 }
66 
68 {
69  if (Trail.size())
70  {
71  Trail.removeFirst();
72  Q_ASSERT(m_TrailLabels.size());
73  m_TrailLabels.removeFirst();
74  }
75  if (Trail.size()) // Eh? Shouldn't this be if( !Trail.size() ) -- asimha
76  trailObjects.remove(this);
77 }
78 
80 {
81  Trail.clear();
82  m_TrailLabels.clear();
83  trailObjects.remove(this);
84 }
85 
87 {
88  TrailObject *keep = nullptr;
89  foreach (TrailObject *tr, trailObjects)
90  {
91  if (tr != o)
92  tr->clearTrail();
93  else
94  keep = tr;
95  }
96 
98  if (keep)
99  trailObjects.insert(keep);
100 }
101 
102 void TrailObject::drawTrail(SkyPainter *skyp) const
103 {
104  Q_UNUSED(skyp)
105 #ifndef KSTARS_LITE
106  if (!Trail.size())
107  return;
108 
109  KStarsData *data = KStarsData::Instance();
110 
111  QColor tcolor = QColor(data->colorScheme()->colorNamed("PlanetTrailColor"));
112  skyp->setPen(QPen(tcolor, 1));
113  SkyLabeler *labeler = SkyLabeler::Instance();
114  labeler->setPen(tcolor);
115  int n = Trail.size();
116  for (int i = 1; i < n; ++i)
117  {
118  if (Options::fadePlanetTrails())
119  {
120  tcolor.setAlphaF(static_cast<qreal>(i) / static_cast<qreal>(n));
121  skyp->setPen(QPen(tcolor, 1));
122  }
123  SkyPoint a = Trail[i - 1];
124  SkyPoint b = Trail[i];
125  skyp->drawSkyLine(&a, &b);
126  if (i % 5 == 1) // TODO: Make drawing of labels configurable, incl. frequency etc.
127  {
128  QPointF pt = SkyMap::Instance()->projector()->toScreen(&a);
129  labeler->drawGuideLabel(pt, m_TrailLabels[i - 1], 0.0);
130  }
131  }
132 #endif
133 }
void append(const T &value)
TrailObject * clone() const override
Create copy of object.
Definition: trailobject.cpp:38
static void clearTrailsExcept(SkyObject *o)
Remove trail for all objects but one which is passed as parameter.
Definition: trailobject.cpp:86
void clipTrail()
removes the oldest point from the trail
Definition: trailobject.cpp:67
bool remove(const T &value)
Stores dms coordinates for a point in the sky. for converting between coordinate systems.
Definition: skypoint.h:44
virtual void setPen(const QPen &pen)=0
Set the pen of the painter.
void setPen(const QPen &pen)
sets the pen used for drawing labels on the sky.
Definition: skylabeler.cpp:197
static QSet< TrailObject * > trailObjects
Store list of objects with trails.
Definition: trailobject.h:74
void addToTrail(const QString &label=QString())
adds a point to the planet's trail
Definition: trailobject.cpp:60
int size() const const
void clearTrail()
clear the Trail
Definition: trailobject.cpp:79
void updateTrail(dms *LST, const dms *lat)
update Horizontal coords of the trail
Definition: trailobject.cpp:45
TrailObject(int t=TYPE_UNKNOWN, dms r=dms(0.0), dms d=dms(0.0), float m=0.0, const QString &n=QString())
Constructor.
Definition: trailobject.cpp:25
virtual void drawSkyLine(SkyPoint *a, SkyPoint *b)=0
Draw a line between points in the sky.
void setAlphaF(qreal alpha)
bool drawGuideLabel(QPointF &o, const QString &text, double angle)
Tries to draw the text at the position and angle specified.
Definition: skylabeler.cpp:112
provides a SkyObject with an attachable Trail
Definition: trailobject.h:21
ColorScheme * colorScheme()
Definition: kstarsdata.h:171
void removeFirst()
SkyPoint()
Default constructor.
Definition: skypoint.cpp:53
Draws things on the sky, without regard to backend.
Definition: skypainter.h:37
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:37
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 clear()
QSet::iterator insert(const T &value)
const Projector * projector() const
Get the current projector.
Definition: skymap.h:299
void initPopupMenu(KSPopupMenu *pmenu) override
Initialize the popup menut.
Definition: trailobject.cpp:51
QColor colorNamed(const QString &name) const
Retrieve a color by name.
Definition: colorscheme.cpp:86
Information about an object in the sky.
Definition: skyobject.h:41
void createPlanetMenu(SkyObject *p)
Create a popup menu for a solar system body.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 12 2022 04:00:58 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.