File indexing completed on 2024-05-05 07:43:03
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 "skynode.h" 0009 #include "../labelsitem.h" 0010 0011 class PlanetItemNode; 0012 class SkyMapLite; 0013 class PointNode; 0014 class QSGSimpleTextureNode; 0015 class SkyLabeler; 0016 class RootNode; 0017 0018 /** 0019 * @class LabelNode 0020 * 0021 * @short A SkyNode derived class used for displaying labels 0022 * @author Artem Fedoskin 0023 * @version 1.0 0024 */ 0025 0026 class LabelNode : public SkyNode 0027 { 0028 public: 0029 /** 0030 * @short Constructor. Use name of skyObject as a text 0031 * @param skyObject - target object, for which this label is created. 0032 * @param type - type of label (corresponds to type of SkyObject) 0033 */ 0034 LabelNode(SkyObject *skyObject, LabelsItem::label_t type); 0035 0036 /** 0037 * @short Constructor. Use string parameter name as a text 0038 * @param name - text of label 0039 * @param type - type of label (corresponds to type of SkyObject) 0040 */ 0041 LabelNode(QString name, LabelsItem::label_t type); 0042 0043 /** 0044 * @short Destructor. 0045 */ 0046 virtual ~LabelNode(); 0047 0048 /** 0049 * @short Convenience function to not to repeat the same code in 2 constructors. Set parameters of label 0050 * based on its type 0051 */ 0052 void initialize(); 0053 0054 /** 0055 * @short Changes position of the label 0056 * @param pos - new position 0057 */ 0058 virtual void changePos(QPointF pos) override; 0059 0060 inline QString name() { return m_name; } 0061 0062 inline LabelsItem::label_t labelType() { return m_labelType; } 0063 0064 /** 0065 * @short Create texture from label's name 0066 * @param color - color of the label 0067 */ 0068 void createTexture(QColor color = QColor()); 0069 0070 /** 0071 * @return true if the size of text depends on zoom 0072 */ 0073 inline bool zoomFont() { return m_zoomFont; } 0074 0075 /** 0076 * @short set the position of label with the given offset from SkyObject's position and 0077 * makes the label visible if it was hidden 0078 * @warning Keep mind that to update labels position, you should first set it with setLabelPos() 0079 * and then call update() 0080 * @param pos position of label 0081 */ 0082 void setLabelPos(QPointF pos); 0083 0084 /** 0085 * @short Update position of label according to labelPos and recreate texture if label's size 0086 * depends on zoom level 0087 */ 0088 virtual void update() override; 0089 0090 QPointF labelPos; 0091 0092 private: 0093 QString m_name; 0094 QSGSimpleTextureNode *m_textTexture; 0095 QSize m_textSize; 0096 0097 LabelsItem::label_t m_labelType; 0098 int m_fontSize; 0099 bool m_zoomFont; 0100 QString m_schemeColor; 0101 QColor m_color; 0102 };