Kstars

trailobject.cpp
1/*
2 SPDX-FileCopyrightText: 2007 Jason Harris <kstars@30doradus.org>
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
25TrailObject::TrailObject(int t, dms r, dms d, float m, const QString &n) : SkyObject(t, r, d, m, n)
26{
27}
28
29TrailObject::TrailObject(int t, double r, double d, float m, const QString &n) : SkyObject(t, r, d, m, n)
30{
31}
32
33TrailObject::~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
45void 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
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
102void 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}
QColor colorNamed(const QString &name) const
Retrieve a color by name.
The KStars Popup Menu.
Definition kspopupmenu.h:35
void createPlanetMenu(SkyObject *p)
Create a popup menu for a solar system body.
KStarsData is the backbone of KStars.
Definition kstarsdata.h:72
ColorScheme * colorScheme()
Definition kstarsdata.h:172
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
The purpose of this class is to prevent labels from overlapping.
Definition skylabeler.h:99
bool drawGuideLabel(QPointF &o, const QString &text, double angle)
Tries to draw the text at the position and angle specified.
void setPen(const QPen &pen)
sets the pen used for drawing labels on the sky.
const Projector * projector() const
Get the current projector.
Definition skymap.h:300
Provides all necessary information about an object in the sky: its coordinates, name(s),...
Definition skyobject.h:42
Draws things on the sky, without regard to backend.
Definition skypainter.h:40
virtual void drawSkyLine(SkyPoint *a, SkyPoint *b)=0
Draw a line between points in the sky.
virtual void setPen(const QPen &pen)=0
Set the pen of the painter.
The sky coordinates of a point in the sky.
Definition skypoint.h:45
SkyPoint()
Default constructor.
Definition skypoint.cpp:53
provides a SkyObject with an attachable Trail
Definition trailobject.h:22
TrailObject(int t=TYPE_UNKNOWN, dms r=dms(0.0), dms d=dms(0.0), float m=0.0, const QString &n=QString())
Constructor.
void clearTrail()
clear the Trail
void addToTrail(const QString &label=QString())
adds a point to the planet's trail
static void clearTrailsExcept(SkyObject *o)
Remove trail for all objects but one which is passed as parameter.
void initPopupMenu(KSPopupMenu *pmenu) override
Initialize the popup menut.
static QSet< TrailObject * > trailObjects
Store list of objects with trails.
Definition trailobject.h:74
void updateTrail(dms *LST, const dms *lat)
update Horizontal coords of the trail
void clipTrail()
removes the oldest point from the trail
TrailObject * clone() const override
Create copy of object.
An angle, stored as degrees, but expressible in many ways.
Definition dms.h:38
void setAlphaF(float alpha)
void append(QList< T > &&value)
void clear()
void removeFirst()
qsizetype size() const const
iterator insert(const T &value)
bool remove(const T &value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:38:44 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.