File indexing completed on 2024-04-21 14:46:19
0001 /* 0002 SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #pragma once 0007 0008 #include "skylabeler.h" 0009 #include "typedef.h" 0010 #include "typedeflite.h" 0011 0012 #include "skyopacitynode.h" 0013 0014 class StarItem; 0015 class LabelNode; 0016 class GuideLabelNode; 0017 class RootNode; 0018 class TrixelNode; 0019 0020 class SkyObject; 0021 0022 typedef SkyOpacityNode LabelTypeNode; 0023 0024 /** 0025 * @class LabelsItem 0026 * 0027 * This class is in charge of labels in SkyMapLite. Labels can be instantiated by calling addLabel with 0028 * either SkyObject or plain QString as a name. There are two types of label nodes available - LabelNode 0029 * that can't be rotated and GuideLabelNode that supports rotation (but it is not used anywhere yet). 0030 * 0031 * To prevent labels from overlapping this class uses SkyLabeler. We check LabelNode for overlapping by 0032 * calling SkyLabeler::markText() (SkyLabeler::markRegion() for GuideLabelNode) and update(). 0033 * 0034 * Each of SkyItems that uses labels has its own label type in enum label_t (copied from SkyLabeler but 0035 * was extended). Labels of particular type are reparented to LabelTypeNode(QSGOpacityNode) so 0036 * to hide all labels of some type you just need to set opacity of LabelTypeNode that corresponds to 0037 * this type to 0. 0038 * 0039 * Order of drawing can be changed in LabelsItem's constructor. Order of labels update can be changed in 0040 * update(). 0041 * 0042 * This class is not derived from SkyItem as it doesn't have label type and SkyItem's header needs an 0043 * inclusion of this header to allow use of label_t enum. (Might be a good idea to fix this) 0044 * 0045 * @note font size is set in SkyLabeler::SkyLabeler() by initializing m_stdFont with default font 0046 * 0047 * @short Handles labels in SkyMapLite 0048 * @author Artem Fedoskin 0049 * @version 1.0 0050 */ 0051 0052 class LabelsItem : public SkyOpacityNode 0053 { 0054 public: 0055 /** 0056 * @brief Constructor 0057 */ 0058 LabelsItem(); 0059 0060 /** @short The label_t enum. Holds types of labels */ 0061 enum label_t 0062 { 0063 STAR_LABEL, 0064 ASTEROID_LABEL, 0065 COMET_LABEL, 0066 PLANET_LABEL, 0067 JUPITER_MOON_LABEL, 0068 SATURN_MOON_LABEL, 0069 DEEP_SKY_LABEL, 0070 DSO_MESSIER_LABEL, 0071 DSO_OTHER_LABEL, 0072 CONSTEL_NAME_LABEL, 0073 SATELLITE_LABEL, 0074 RUDE_LABEL, ///Rude labels block other labels FIXME: find a better solution 0075 NUM_LABEL_TYPES, 0076 HORIZON_LABEL, 0077 EQUATOR_LABEL, 0078 ECLIPTIC_LABEL, 0079 TELESCOPE_SYMBOL, 0080 CATALOG_STAR_LABEL, 0081 CATALOG_DSO_LABEL, 0082 NO_LABEL //used in LinesItem 0083 }; 0084 0085 /** 0086 * Create LabelNode with given skyObject and append it to LabelTypeNode that corresponds 0087 * to type 0088 * @param skyObject for which the label is created 0089 * @param labelType type of LabelTypeNode to which this label has to be reparented 0090 * @return pointer to newly created LabelNode 0091 */ 0092 LabelNode *addLabel(SkyObject *skyObject, label_t labelType); 0093 0094 /** 0095 * Create LabelNode and append it to corresponding TrixelNode so that all labels 0096 * can be hidden whenever Trixel is not displayed. Use for sky objects that are indexed by SkyMesh 0097 * @param skyObject for which the label is created 0098 * @param labelType type of LabelTypeNode to which this label has to be reparented 0099 * @param trixel id of trixel 0100 **/ 0101 LabelNode *addLabel(SkyObject *skyObject, label_t labelType, Trixel trixel); 0102 0103 /** @short does the same as above but with QString instead of SkyObject */ 0104 LabelNode *addLabel(QString name, label_t labelType); 0105 0106 /** 0107 * @short does the same as above but instead creates GuideLabelNode 0108 * @note currently GuideLabelNode is not used anywhere so it is not fully supported yet 0109 */ 0110 GuideLabelNode *addGuideLabel(QString name, label_t labelType); 0111 0112 /** 0113 * The order of labels update can be changed here. 0114 * @short updates all child labels 0115 */ 0116 void update(); 0117 0118 /** 0119 * @short updates child labels of LabelTypeNode that corresponds to type in m_labelsLists 0120 * Labels for stars and DSOs we update labels only if corresponding TrixelNode is visible. 0121 * @param labelType type of LabelTypeNode (see m_labelsLists) 0122 */ 0123 void updateChildLabels(label_t labelType); 0124 0125 /** @return LabelTypeNode that holds labels of labelType */ 0126 LabelTypeNode *getLabelNode(label_t labelType) { return m_labelsLists.value(labelType); } 0127 0128 /** @short deletes all labels of type labelType */ 0129 void deleteLabels(label_t labelType); 0130 0131 /** @short deletes particular label */ 0132 void deleteLabel(LabelNode *label); 0133 0134 /** @short hides all labels of type labelType */ 0135 void hideLabels(label_t labelType); 0136 0137 /** 0138 * @short shows all labels of type labelType 0139 */ 0140 0141 void showLabels(label_t labelType); 0142 0143 /** @short adds trixel to the node corresponding to labelType */ 0144 TrixelNode *addTrixel(label_t labelType, Trixel trixel); 0145 0146 /** 0147 * @short sets m_rootNode and appends to it this node 0148 * @param rootNode parent RootNode that instantiates this object 0149 */ 0150 void setRootNode(RootNode *rootNode); 0151 0152 /** @return pointer to RootNode that instantiated this object */ 0153 RootNode *rootNode() { return m_rootNode; } 0154 0155 private: 0156 QMap<label_t, LabelTypeNode *> m_labelsLists; 0157 0158 /** @short because this class is not derived from SkyItem it has to store pointer to RootNode */ 0159 RootNode *m_rootNode { nullptr }; 0160 SkyLabeler *skyLabeler { nullptr }; 0161 };