Kstars

guidelabelnode.cpp
1/*
2 SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com>
3 SPDX-License-Identifier: GPL-2.0-or-later
4*/
5
6#include "guidelabelnode.h"
7
8#include "Options.h"
9#include "skymaplite.h"
10#include "skyobject.h"
11
12#include <QSGSimpleTextureNode>
13
15 : m_textTexture(new QSGSimpleTextureNode), m_name(name)
16{
17 appendChildNode(&debugRect);
18 debugRect.setColor(QColor("green"));
19 QColor color;
20 switch (type)
21 {
22 case LabelsItem::label_t::CONSTEL_NAME_LABEL:
23 color = KStarsData::Instance()->colorScheme()->colorNamed("CNameColor");
24 break;
25 case LabelsItem::label_t::HORIZON_LABEL:
26 color = KStarsData::Instance()->colorScheme()->colorNamed("CompassColor");
27 break;
28 default:
29 color = KStarsData::Instance()->colorScheme()->colorNamed("UserLabelColor");
30 }
31
32 m_textTexture->setTexture(SkyMapLite::Instance()->textToTexture(name, color));
33 m_opacity->appendChildNode(m_textTexture);
34
35 m_textSize = m_textTexture->texture()->textureSize();
36 QRectF oldRect = m_textTexture->rect();
37 m_textTexture->setRect(QRect(oldRect.x(), oldRect.y(), m_textSize.width(), m_textSize.height()));
38}
39
41{
42 // otherwise draw the label and return true
43 //m_p.rotate( angle ); //rotate the coordinate system
44 //m_p.drawText( QPointF( -w2, h ), text );
45 //m_p.restore(); //reset coordinate system
46
47 //return true;*/
48
49 //QSizeF size = m_point->size();
50 QMatrix4x4 m(1, 0, 0, pos.x(), 0, 1, 0, pos.y(), 0, 0, 1, 0, 0, 0, 0, 1);
51 //m.translate(m_translatePos.x(), m_translatePos.y());
52 m.rotate(m_angle, 0, 0, 1);
53
54 setMatrix(m);
56}
57
59{
60 show();
61 //We need to subtract the height of texture from final y to follow the way QPainter draws the text
62 m_angle = angle;
63 m_translatePos = pos;
64
65 //QFontMetricsF fontMetrics = SkyLabeler::Instance()->fontMetrics();
66 // Create bounding rectangle by rotating the (height x width) rectangle
67 qreal h = m_textSize.height(); //fontMetrics.height();
68 qreal w = m_textSize.width(); //fontMetrics.width( m_name );
69
70 qreal s = sin(angle * dms::PI / 180.0);
71 qreal c = cos(angle * dms::PI / 180.0);
72
73 qreal w2 = w / 2.0;
74
75 // These numbers really do depend on the sign of the angle like this
76 if (angle >= 0.0)
77 {
78 top = pos.y() - s * w2;
79 bot = pos.y() + c * h + s * w2;
80 left = pos.x() - c * w2 - s * h;
81 right = pos.x() + c * w2;
82 }
83 else
84 {
85 top = pos.y() + s * w2;
86 bot = pos.y() + c * h - s * w2;
87 left = pos.x() - c * w2;
88 right = pos.x() + c * w2 - s * h;
89 }
90
91 //We need to translate matrix with the value of pos point
92
93 labelPos = QPointF(pos.x() - w2, pos.y() + h);
94
95 /*debugRect.setRect(QRectF(QPointF(left,top),QPointF(right,bot)));
96 debugRect.markDirty(QSGNode::DirtyGeometry);*/
97
98 // return false if label would overlap existing label
99 // if ( ! markRegion( left, right, top, bot) )
100}
101
103{
104 changePos(labelPos);
105}
QColor colorNamed(const QString &name) const
Retrieve a color by name.
virtual void changePos(QPointF pos) override
changePos changes the position m_point
void setLabelPos(QPointF pos, float angle)
setLabelPos sets the position of label with the given offset from SkyObject's position and makes the ...
GuideLabelNode(QString name, LabelsItem::label_t type)
Constructor.
virtual void update() override
Updates coordinate of the object on SkyMapLite.
ColorScheme * colorScheme()
Definition kstarsdata.h:174
label_t
The label_t enum.
Definition labelsitem.h:62
virtual void show()
shows all child nodes (sets opacity of m_opacity to 1)
Definition skynode.cpp:27
static constexpr double PI
PI is a const static member; it's public so that it can be used anywhere, as long as dms....
Definition dms.h:385
void rotate(const QQuaternion &quaternion)
qreal x() const const
qreal y() const const
qreal x() const const
qreal y() const const
void appendChildNode(QSGNode *node)
void markDirty(DirtyState bits)
NodeType type() const const
void setColor(const QColor &color)
QRectF rect() const const
void setRect(const QRectF &r)
void setTexture(QSGTexture *texture)
QSGTexture * texture() const const
virtual QSize textureSize() const const=0
void setMatrix(const QMatrix4x4 &matrix)
int height() const const
int width() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 27 2024 11:51:46 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.