1 /*
2     SPDX-FileCopyrightText: 2009 Jerome SONRIER <jsid@emor3j.fr.eu.org>
3 
4     SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include "pointlistcomponent.h"
10 
11 #include <QColor>
12 #include <QImage>
13 #include <QObject>
14 #include <QStringList>
15 
16 class SkyPainter;
17 
18 /**
19  * @class FlagComponent
20  * @short Represents a flag on the sky map.
21  * Each flag is composed by a SkyPoint where coordinates are stored, an
22  * epoch and a label. This class also stores flag images and associates
23  * each flag with an image.
24  * When FlagComponent is created, it seeks all file names beginning with
25  * "_flag" in the user directory and *consider* them as flag images.
26  *
27  * The file flags.dat stores coordinates, epoch, image name and label of each
28  * flags and is read to init FlagComponent
29  *
30  * @author Jerome SONRIER
31  * @version 1.1
32  */
33 class FlagComponent : public QObject, public PointListComponent
34 {
35     Q_OBJECT
36 
37   public:
38     /** @short Constructor. */
39     explicit FlagComponent(SkyComposite *);
40 
41     virtual ~FlagComponent() override = default;
42 
43     void draw(SkyPainter *skyp) override;
44 
45     bool selected() override;
46 
47     void update(KSNumbers *num = nullptr) override;
48 
49     /**
50      * @short Add a flag.
51      * @param flagPoint Sky point in epoch coordinates
52      * @param epoch Moment for which celestial coordinates are specified
53      * @param image Image name
54      * @param label Label of the flag
55      * @param labelColor Color of the label
56      */
57     void add(const SkyPoint &flagPoint, QString epoch, QString image, QString label, QColor labelColor);
58 
59     /**
60      * @short Remove a flag.
61      * @param index Index of the flag to be remove.
62      */
63     void remove(int index);
64 
65     /**
66      * @short Update a flag.
67      * @param index index of the flag to be updated.
68      * @param flagPoint point of the flag.
69      * @param epoch new flag epoch.
70      * @param image new flag image.
71      * @param label new flag label.
72      * @param labelColor new flag label color.
73      */
74     void updateFlag(int index, const SkyPoint &flagPoint, QString epoch, QString image, QString label,
75                     QColor labelColor);
76 
77     /**
78      * @short Return image names.
79      * @return the list of all image names
80      */
81     QStringList getNames();
82 
83     /**
84      * @short Return the numbers of flags.
85      * @return the size of m_PointList
86      */
87     int size();
88 
89     /**
90      * @short Get epoch.
91      * @return the epoch as a string
92      * @param index Index of the flag
93      */
94     QString epoch(int index);
95 
96     /**
97      * @short Get label.
98      * @return the label as a string
99      * @param index Index of the flag
100      */
101     QString label(int index);
102 
103     /**
104      * @short Get label color.
105      * @return the label color
106      * @param index Index of the flag
107      */
108     QColor labelColor(int index);
109 
110     /**
111      * @short Get image.
112      * @return the image associated with the flag
113      * @param index Index of the flag
114      */
115     QImage image(int index);
116 
117     /**
118      * @short Get image name.
119      * @return the name of the image associated with the flag
120      * @param index Index of the flag
121      */
122     QString imageName(int index);
123 
124     /**
125      * @short Get images.
126      * @return all images that can be use
127      */
128     QList<QImage> imageList();
129 
130     /**
131      * @short Get image.
132      * @param index Index of the image in m_Images
133      * @return an image from m_Images
134      */
135     QImage imageList(int index);
136 
137     /**
138      * @brief epochCoords return coordinates recorded in original epoch
139      * @param index index of the flag
140      * @return pair of RA/DEC in original epoch
141      */
142     QPair<double, double> epochCoords(int index);
143 
144     /**
145      * @short Get list of flag indexes near specified SkyPoint with radius specified in pixels.
146      * @param point central SkyPoint.
147      * @param pixelRadius radius in pixels.
148      */
149     QList<int> getFlagsNearPix(SkyPoint *point, int pixelRadius);
150 
151     /** @short Load flags from flags.dat file. */
152     void loadFromFile();
153 
154     /** @short Save flags to flags.dat file. */
155     void saveToFile();
156 
157   private:
158     // Convert from given epoch to J2000. If epoch is already J2000, do nothing
159     void toJ2000(SkyPoint *p, QString epoch);
160 
161     /// List of epochs
162     QStringList m_Epoch;
163     /// RA/DEC stored in original epoch
164     QList<QPair<double, double>> m_EpochCoords;
165     /// List of image index
166     QList<int> m_FlagImages;
167     /// List of label
168     QStringList m_Labels;
169     /// List of label colors
170     QList<QColor> m_LabelColors;
171     /// List of image names
172     QStringList m_Names;
173     /// List of flag images
174     QList<QImage> m_Images;
175 };
176