summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtem Fedoskin <afedoskin3@gmail.com>2016-06-10 23:39:41 (GMT)
committerArtem Fedoskin <afedoskin3@gmail.com>2016-06-10 23:39:41 (GMT)
commit4c02dbca790e031774b44a0ce1f41981842f21b6 (patch)
treefe74caed00d6fb77865c10b0c6c1784076975927
parent1aa79365420ac3374183e1945a939e4391d4d8d9 (diff)
Added labels for planets, asteroids, comets and stars
-rw-r--r--kstars/CMakeLists.txt4
-rw-r--r--kstars/kstarslite/skyitems/asteroidsitem.cpp41
-rw-r--r--kstars/kstarslite/skyitems/cometsitem.cpp32
-rw-r--r--kstars/kstarslite/skyitems/constellationnamesitem.cpp61
-rw-r--r--kstars/kstarslite/skyitems/constellationnamesitem.h55
-rw-r--r--kstars/kstarslite/skyitems/horizonitem.cpp3
-rw-r--r--kstars/kstarslite/skyitems/labelsitem.cpp129
-rw-r--r--kstars/kstarslite/skyitems/labelsitem.h66
-rw-r--r--kstars/kstarslite/skyitems/linesitem.cpp21
-rw-r--r--kstars/kstarslite/skyitems/planetsitem.cpp2
-rw-r--r--kstars/kstarslite/skyitems/rootnode.cpp51
-rw-r--r--kstars/kstarslite/skyitems/rootnode.h12
-rw-r--r--kstars/kstarslite/skyitems/skyitem.cpp27
-rw-r--r--kstars/kstarslite/skyitems/skyitem.h13
-rw-r--r--kstars/kstarslite/skyitems/skynodes/guidelabelnode.cpp112
-rw-r--r--kstars/kstarslite/skyitems/skynodes/guidelabelnode.h73
-rw-r--r--kstars/kstarslite/skyitems/skynodes/horizonnode.cpp1
-rw-r--r--kstars/kstarslite/skyitems/skynodes/labelnode.cpp71
-rw-r--r--kstars/kstarslite/skyitems/skynodes/labelnode.h73
-rw-r--r--kstars/kstarslite/skyitems/skynodes/planetmoonsnode.cpp5
-rw-r--r--kstars/kstarslite/skyitems/skynodes/planetmoonsnode.h2
-rw-r--r--kstars/kstarslite/skyitems/skynodes/planetnode.cpp12
-rw-r--r--kstars/kstarslite/skyitems/skynodes/planetnode.h2
-rw-r--r--kstars/kstarslite/skyitems/skynodes/pointsourcenode.cpp36
-rw-r--r--kstars/kstarslite/skyitems/skynodes/pointsourcenode.h11
-rw-r--r--kstars/kstarslite/skyitems/skynodes/skynode.cpp32
-rw-r--r--kstars/kstarslite/skyitems/skynodes/skynode.h26
-rw-r--r--kstars/kstarslite/skyitems/skynodes/trixelnode.cpp10
-rw-r--r--kstars/kstarslite/skyitems/skynodes/trixelnode.h2
-rw-r--r--kstars/skycomponents/constellationnamescomponent.cpp2
-rw-r--r--kstars/skycomponents/skylabel.h2
-rw-r--r--kstars/skycomponents/skylabeler.cpp65
-rw-r--r--kstars/skycomponents/skylabeler.h15
-rw-r--r--kstars/skymaplite.cpp37
-rw-r--r--kstars/skymaplite.h9
35 files changed, 1008 insertions, 107 deletions
diff --git a/kstars/CMakeLists.txt b/kstars/CMakeLists.txt
index 8e9991c..89f0bb3 100644
--- a/kstars/CMakeLists.txt
+++ b/kstars/CMakeLists.txt
@@ -553,6 +553,8 @@ if(BUILD_KSTARS_LITE)
kstarslite/skyitems/cometsitem.cpp
kstarslite/skyitems/horizonitem.cpp
kstarslite/skyitems/linesitem.cpp
+ kstarslite/skyitems/labelsitem.cpp
+ kstarslite/skyitems/constellationnamesitem.cpp
#SkyNodes
kstarslite/skyitems/skynodes/planetnode.cpp
kstarslite/skyitems/skynodes/skynode.cpp
@@ -560,6 +562,8 @@ if(BUILD_KSTARS_LITE)
kstarslite/skyitems/skynodes/planetmoonsnode.cpp
kstarslite/skyitems/skynodes/horizonnode.cpp
kstarslite/skyitems/skynodes/trixelnode.cpp
+ kstarslite/skyitems/skynodes/labelnode.cpp
+ kstarslite/skyitems/skynodes/guidelabelnode.cpp
#Nodes
kstarslite/skyitems/skynodes/nodes/pointnode.cpp
kstarslite/skyitems/skynodes/nodes/polynode.cpp
diff --git a/kstars/kstarslite/skyitems/asteroidsitem.cpp b/kstars/kstarslite/skyitems/asteroidsitem.cpp
index 05b08c3..00fe6c6 100644
--- a/kstars/kstarslite/skyitems/asteroidsitem.cpp
+++ b/kstars/kstarslite/skyitems/asteroidsitem.cpp
@@ -24,65 +24,54 @@
#include "skynodes/pointsourcenode.h"
#include "kstarslite/skyitems/rootnode.h"
+#include "labelsitem.h"
+
AsteroidsItem::AsteroidsItem(const QList<SkyObject*>& asteroidsList, RootNode *rootNode)
- :SkyItem(rootNode), m_asteroidsList(asteroidsList)
+ :SkyItem(LabelsItem::label_t::ASTEROID_LABEL, rootNode), m_asteroidsList(asteroidsList)
{
recreateList();
}
-/*void AsteroidsItem::setAsteroidsList(QList<SkyObject*> *asteroidsList) {
- m_asteroidsList = asteroidsList;
- m_addAsteroids = true;
-}*/
-
void AsteroidsItem::recreateList() {
removeAllChildNodes();
foreach(SkyObject *asteroid, m_asteroidsList) {
KSAsteroid *ast = static_cast<KSAsteroid *>(asteroid);
if (ast->image().isNull() == false) {
appendChildNode(new PlanetNode(ast, rootNode()));
- }
- else {
- appendChildNode(new PointSourceNode(ast, rootNode()));
+ } else {
+ appendChildNode(new PointSourceNode(ast, rootNode(),labelType()));
}
}
}
void AsteroidsItem::update() {
- if (!Options::showAsteroids()) {
- removeAllChildNodes();
- hide();
- return;
- } else if (!childCount()) {
- recreateList();
- }
- show();
-
QSGNode *n = firstChild();
while(n != 0) {
SkyNode* pNode = static_cast<SkyNode*>(n);
n = n->nextSibling();
- //bool hideLabels = ! Options::showAsteroidNames() ||
- //( SkyMapLite::Instance()->isSlewing() && Options::hideLabels() );
+ bool hideLabels = ! Options::showAsteroidNames() ||
+ ( SkyMapLite::Instance()->isSlewing() && Options::hideLabels() );
- /*double lgmin = log10(MINZOOM);
+ double lgmin = log10(MINZOOM);
double lgmax = log10(MAXZOOM);
double lgz = log10(Options::zoomFactor());
double labelMagLimit = 2.5 + Options::asteroidLabelDensity() / 5.0;
labelMagLimit += ( 15.0 - labelMagLimit ) * ( lgz - lgmin) / (lgmax - lgmin );
if ( labelMagLimit > 10.0 ) labelMagLimit = 10.0;
- //printf("labelMagLim = %.1f\n", labelMagLimit );*/
+ //printf("labelMagLim = %.1f\n", labelMagLimit );
KSAsteroid *ast = static_cast<KSAsteroid *>(pNode->skyObject());
+ bool drawLabel = false;
+
if ( ast->mag() > Options::magLimitAsteroid() || std::isnan(ast->mag()) != 0) {
pNode->hide();
continue;
}
- //bool drawn = false;
- pNode->update();
- //if ( drawn && !( hideLabels || ast->mag() >= labelMagLimit ) )
- // SkyLabeler::AddLabel( ast, SkyLabeler::ASTEROID_LABEL );
+ if (!( hideLabels || ast->mag() >= labelMagLimit ) ) {
+ drawLabel = true;
+ }
+ pNode->update(drawLabel);
}
}
diff --git a/kstars/kstarslite/skyitems/cometsitem.cpp b/kstars/kstarslite/skyitems/cometsitem.cpp
index 93336f5..f5e5163 100644
--- a/kstars/kstarslite/skyitems/cometsitem.cpp
+++ b/kstars/kstarslite/skyitems/cometsitem.cpp
@@ -20,37 +20,38 @@
#include "projections/projector.h"
#include "kscomet.h"
+#include "rootnode.h"
+#include "labelsitem.h"
+#include "skylabeler.h"
+
#include "skynodes/pointsourcenode.h"
CometsItem::CometsItem(const QList<SkyObject*>& cometsList, RootNode *rootNode)
- :SkyItem(rootNode), m_cometsList(cometsList)
+ :SkyItem(LabelsItem::label_t::COMET_LABEL, rootNode), m_cometsList(cometsList)
{
recreateList();
}
void CometsItem::update() {
- if (!Options::showComets() || Options::zoomFactor() < 10*MINZOOM ) {
- removeAllChildNodes();
+ if(Options::zoomFactor() < 10*MINZOOM) {
hide();
return;
- } else if (!childCount()) {
- show();
- recreateList();
}
+
show();
- /*bool hideLabels = ! Options::showCometNames() ||
- (SkyMap::Instance()->isSlewing() &&
+ bool hideLabels = ! Options::showCometNames() ||
+ (SkyMapLite::Instance()->isSlewing() &&
Options::hideLabels() );
double rsunLabelLimit = Options::maxRadCometName();
- //FIXME: Should these be config'able?
+ /*//FIXME: Should these be config'able?
skyp->setPen( QPen( QColor( "darkcyan" ) ) );
skyp->setBrush( QBrush( QColor( "darkcyan" ) ) );*/
//Traverse all children nodes
QSGNode *n = firstChild();
- while( n!= 0) {
+ while( n != 0) {
SkyNode* skyNode = static_cast<SkyNode*>(n);
n = n->nextSibling();
@@ -59,10 +60,11 @@ void CometsItem::update() {
double mag = com->mag();
if (std::isnan(mag) == 0)
{
- skyNode->update();
- //bool drawn = skyp->drawPointSource(com,mag);
- //if ( drawn && !(hideLabels || com->rsun() >= rsunLabelLimit) )
- // SkyLabeler::AddLabel( com, SkyLabeler::COMET_LABEL );
+ bool drawLabel = false;
+ if ( !(hideLabels || com->rsun() >= rsunLabelLimit) ) {
+ drawLabel = true;
+ }
+ skyNode->update(drawLabel);
} else {
skyNode->hide();
}
@@ -73,6 +75,6 @@ void CometsItem::recreateList() {
removeAllChildNodes();
foreach(SkyObject *comet, m_cometsList) {
KSComet *com = static_cast<KSComet *>(comet);
- appendChildNode(new PointSourceNode(com,rootNode()));
+ appendChildNode(new PointSourceNode(com, rootNode(),labelType()));
}
}
diff --git a/kstars/kstarslite/skyitems/constellationnamesitem.cpp b/kstars/kstarslite/skyitems/constellationnamesitem.cpp
new file mode 100644
index 0000000..ba4abf5
--- /dev/null
+++ b/kstars/kstarslite/skyitems/constellationnamesitem.cpp
@@ -0,0 +1,61 @@
+/** *************************************************************************
+ constellationnamesitem.cpp - K Desktop Planetarium
+ -------------------
+ begin : 10/06/2016
+ copyright : (C) 2016 by Artem Fedoskin
+ email : afedoskin3@gmail.com
+ ***************************************************************************/
+/** *************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+#include "constellationnamesitem.h"
+#include "constellationnamescomponent.h"
+
+ConstellationNamesItem::ConstellationNamesItem(const QList<SkyObject*>& namesList, RootNode* parent)
+ :SkyItem(LabelsItem::label_t::CONSTEL_NAME_LABEL, parent), m_namesList(namesList)
+{
+}
+
+void ConstellationNamesItem::update() {
+ /*if ( ! selected() )
+ return;
+
+ const Projector *proj = SkyMap::Instance()->projector();
+ SkyLabeler* skyLabeler = SkyLabeler::Instance();
+ skyLabeler->useStdFont();
+ skyLabeler->setPen( QColor( KStarsData::Instance()->colorScheme()->colorNamed( "CNameColor" ) ) );
+
+ QString name;
+ foreach(SkyObject *p, m_ObjectList) {
+ if( ! proj->checkVisibility( p ) )
+ continue;
+
+ bool visible = false;
+ QPointF o = proj->toScreen( p, false, &visible );
+ if( !visible || !proj->onScreen( o ) )
+ continue;
+
+ if( Options::useLatinConstellNames() || Options::useLocalConstellNames() )
+ name = p->name();
+ else
+ name = p->name2();
+
+ o.setX( o.x() - 5.0 * name.length() );
+ skyLabeler->drawGuideLabel( o, name, 0.0 );
+ }
+
+ skyLabeler->resetFont();*/
+}
+
+void ConstellationNamesItem::recreateList() {
+ removeAllChildNodes();
+ /*foreach(SkyObject *comet, m_namesList) {
+ appendChildNode(new PointSourceNode(com, rootNode(),labelType()));
+ }*/
+}
+
diff --git a/kstars/kstarslite/skyitems/constellationnamesitem.h b/kstars/kstarslite/skyitems/constellationnamesitem.h
new file mode 100644
index 0000000..90099b0
--- /dev/null
+++ b/kstars/kstarslite/skyitems/constellationnamesitem.h
@@ -0,0 +1,55 @@
+/** *************************************************************************
+ constellationnamesitem.h - K Desktop Planetarium
+ -------------------
+ begin : 10/06/2016
+ copyright : (C) 2016 by Artem Fedoskin
+ email : afedoskin3@gmail.com
+ ***************************************************************************/
+/** *************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef CONSTELLATIONNAMESITEM_H_
+#define CONSTELLATIONNAMESITEM_H_
+
+#include <QSGOpacityNode>
+#include "skyitem.h"
+
+class ConstellationNamesComponent;
+
+/** @class SkyItem
+ *
+ *This is an interface for implementing SkyItems that are used to display SkyComponent
+ *derived objects on the SkyMapLite.
+ *
+ *@short A base class that is used for displaying SkyComponents on SkyMapLite.
+ *@author Artem Fedoskin
+ *@version 1.0
+ */
+
+class ConstellationNamesItem : public SkyItem {
+
+public:
+ /**
+ *Constructor, add SkyItem to parent in a node tree
+ *
+ * @param parent a pointer to SkyItem's parent node
+ */
+
+ explicit ConstellationNamesItem(const QList<SkyObject*>& namesList, RootNode *rootNode = 0);
+
+ virtual void update();
+
+ void hide();
+ void show();
+ void recreateList();
+private:
+ const QList<SkyObject*>& m_namesList;
+};
+
+#endif
diff --git a/kstars/kstarslite/skyitems/horizonitem.cpp b/kstars/kstarslite/skyitems/horizonitem.cpp
index dfdd473..1a127dd 100644
--- a/kstars/kstarslite/skyitems/horizonitem.cpp
+++ b/kstars/kstarslite/skyitems/horizonitem.cpp
@@ -18,9 +18,10 @@
#include "horizoncomponent.h"
#include "skynodes/horizonnode.h"
+#include "labelsitem.h"
HorizonItem::HorizonItem(HorizonComponent * hComp, RootNode *rootNode)
- :SkyItem(rootNode), m_horizonComp(hComp)
+ :SkyItem(LabelsItem::label_t::RUDE_LABEL, rootNode), m_horizonComp(hComp)
{
appendChildNode(new HorizonNode(m_horizonComp->pointList()));
}
diff --git a/kstars/kstarslite/skyitems/labelsitem.cpp b/kstars/kstarslite/skyitems/labelsitem.cpp
new file mode 100644
index 0000000..4f26324
--- /dev/null
+++ b/kstars/kstarslite/skyitems/labelsitem.cpp
@@ -0,0 +1,129 @@
+/** *************************************************************************
+ labelsitem.cpp - K Desktop Planetarium
+ -------------------
+ begin : 09/06/2016
+ copyright : (C) 2016 by Artem Fedoskin
+ email : afedoskin3@gmail.com
+ ***************************************************************************/
+/** *************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "Options.h"
+#include <QSGNode>
+#include "labelsitem.h"
+#include "skylabeler.h"
+#include "skynodes/labelnode.h"
+
+#include "cometsitem.h"
+#include "rootnode.h"
+
+LabelsItem::LabelsItem(RootNode *rootNode)
+ :m_rootNode(rootNode)
+{
+ LabelTypeNode *stars = new LabelTypeNode;
+ appendChildNode(stars);
+ labelsLists.insert(label_t::STAR_LABEL, stars);
+
+ LabelTypeNode *asteroids = new LabelTypeNode;
+ appendChildNode(asteroids);
+ labelsLists.insert(label_t::ASTEROID_LABEL, asteroids);
+
+ LabelTypeNode *comets = new LabelTypeNode;
+ appendChildNode(comets);
+ labelsLists.insert(label_t::COMET_LABEL, comets);
+
+ LabelTypeNode *planets = new LabelTypeNode;
+ appendChildNode(planets);
+ labelsLists.insert(label_t::PLANET_LABEL, planets);
+
+ LabelTypeNode *jupiter_moons = new LabelTypeNode;
+ appendChildNode(jupiter_moons);
+ labelsLists.insert(label_t::JUPITER_MOON_LABEL, jupiter_moons);
+
+ LabelTypeNode *saturn_moons = new LabelTypeNode;
+ appendChildNode(saturn_moons);
+ labelsLists.insert(label_t::SATURN_MOON_LABEL, saturn_moons);
+
+ LabelTypeNode *deep_sky = new LabelTypeNode;
+ appendChildNode(deep_sky);
+ labelsLists.insert(label_t::DEEP_SKY_LABEL, deep_sky);
+
+ LabelTypeNode *constellation = new LabelTypeNode;
+ appendChildNode(constellation);
+ labelsLists.insert(label_t::CONSTEL_NAME_LABEL, constellation);
+
+ LabelTypeNode *satellite = new LabelTypeNode;
+ appendChildNode(satellite);
+ labelsLists.insert(label_t::SATELLITE_LABEL, satellite);
+
+ LabelTypeNode *rude = new LabelTypeNode;
+ appendChildNode(rude);
+ labelsLists.insert(label_t::RUDE_LABEL, rude);
+
+ LabelTypeNode *num_label = new LabelTypeNode;
+ appendChildNode(num_label);
+ labelsLists.insert(label_t::NUM_LABEL_TYPES, num_label);
+}
+
+LabelNode *LabelsItem::addLabel(SkyObject *skyObject, label_t type) {
+ LabelNode *label = new LabelNode(skyObject, type);
+ labelsLists.value(type)->appendChildNode(label);
+ return label;
+}
+
+void LabelsItem::update() {
+ SkyLabeler * skyLabeler = SkyLabeler::Instance();
+ skyLabeler->reset();
+
+ updateChildLabels(label_t::PLANET_LABEL);
+ updateChildLabels(label_t::SATURN_MOON_LABEL);
+ updateChildLabels(label_t::JUPITER_MOON_LABEL);
+ updateChildLabels(label_t::ASTEROID_LABEL);
+
+ if(rootNode()->cometsItem()->visible()) {
+ updateChildLabels(label_t::COMET_LABEL);
+ } else {
+ hideLabels(label_t::COMET_LABEL);
+ }
+}
+
+void LabelsItem::hideLabels(label_t type) {
+ QSGOpacityNode *node = labelsLists[type];
+ node->setOpacity(0);
+ node->markDirty(QSGNode::DirtyOpacity);
+}
+
+void LabelsItem::deleteLabels(label_t type) {
+ QSGOpacityNode *node = labelsLists[type];
+ QSGNode *n = node->firstChild();
+ while( n != 0) {
+ delete n;
+ n = n->nextSibling();
+ }
+ node->removeAllChildNodes();
+}
+
+void LabelsItem::updateChildLabels(label_t type) {
+ QSGOpacityNode *node = labelsLists[type];
+ node->setOpacity(1);
+ node->markDirty(QSGNode::DirtyOpacity);
+
+ QSGNode *n = node->firstChild();
+ while( n != 0) {
+ LabelNode *label = static_cast<LabelNode *>(n);
+ if(label->visible()) {
+ if(SkyLabeler::Instance()->markText(label->labelPos, label->skyObject()->name())) {
+ label->update();
+ } else {
+ label->hide();
+ }
+ }
+ n = n->nextSibling();
+ }
+}
diff --git a/kstars/kstarslite/skyitems/labelsitem.h b/kstars/kstarslite/skyitems/labelsitem.h
new file mode 100644
index 0000000..74befea
--- /dev/null
+++ b/kstars/kstarslite/skyitems/labelsitem.h
@@ -0,0 +1,66 @@
+/** *************************************************************************
+ asteroidsitem.h - K Desktop Planetarium
+ -------------------
+ begin : 16/05/2016
+ copyright : (C) 2016 by Artem Fedoskin
+ email : afedoskin3@gmail.com
+ ***************************************************************************/
+/** *************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+#ifndef LABELSITEM_H_
+#define LABELSITEM_H_
+
+#include "skylabeler.h"
+
+#include <QSGOpacityNode>
+
+typedef QSGOpacityNode LabelTypeNode;
+
+class KSAsteroid;
+class LineListIndex;
+class LabelNode;
+class SkyObject;
+class RootNode;
+
+class LabelsItem : public QSGOpacityNode {
+
+public:
+ LabelsItem(RootNode *rootNode);
+
+ enum label_t {
+ STAR_LABEL,
+ ASTEROID_LABEL,
+ COMET_LABEL,
+ PLANET_LABEL,
+ JUPITER_MOON_LABEL,
+ SATURN_MOON_LABEL,
+ DEEP_SKY_LABEL,
+ CONSTEL_NAME_LABEL,
+ SATELLITE_LABEL,
+ RUDE_LABEL, ///Rude labels block other labels FIXME: find a better solution
+ NUM_LABEL_TYPES,
+ };
+
+ LabelNode *addLabel(SkyObject *skyObject, label_t);
+ void update();
+ void updateChildLabels(label_t type);
+ QSGOpacityNode *getLabelNode(label_t type) { return labelsLists.value(type); }
+
+ void deleteLabels(label_t type);
+
+ void hideLabels(label_t type);
+
+ RootNode *rootNode() { return m_rootNode; }
+
+private:
+ QMap<label_t, LabelTypeNode *> labelsLists;
+ RootNode *m_rootNode;
+};
+#endif
+
diff --git a/kstars/kstarslite/skyitems/linesitem.cpp b/kstars/kstarslite/skyitems/linesitem.cpp
index 5827c90..ef37878 100644
--- a/kstars/kstarslite/skyitems/linesitem.cpp
+++ b/kstars/kstarslite/skyitems/linesitem.cpp
@@ -25,23 +25,32 @@
#include "skynodes/nodes/linenode.h"
LinesItem::LinesItem(RootNode *rootNode)
- :SkyItem(rootNode)
+ :SkyItem(LabelsItem::label_t::RUDE_LABEL, rootNode)
{
- Options::setHideCBounds(true);
+ //Under construction
Options::setShowCBounds(true);
Options::setShowCLines(true);
- Options::setHideOnSlew(true);
- Options::setHideCLines(false);
Options::setShowSolarSystem(true);
-
Options::setShowEcliptic(true);
Options::setShowEquator(true);
Options::setShowEquatorialGrid(true);
Options::setShowHorizontalGrid(true);
+ Options::setShowGround(true);
+
+ //Labels
+ Options::setShowCometNames(true);
+ Options::setShowAsteroidNames(true);
+ Options::setShowAsteroids(true);
+
+ Options::setAsteroidLabelDensity(10000);
+ Options::setMagLimitAsteroid(-10);
+
+ Options::setHideCBounds(true);
+ Options::setHideCLines(false);
+ Options::setHideOnSlew(true);
Options::setHideGrids(false);
Options::setRunClock(false);
- Options::setShowGround(true);
}
void LinesItem::addLinesComponent(LineListIndex *linesComp, QString color, int width, Qt::PenStyle style) {
diff --git a/kstars/kstarslite/skyitems/planetsitem.cpp b/kstars/kstarslite/skyitems/planetsitem.cpp
index d208147..b7ecf02 100644
--- a/kstars/kstarslite/skyitems/planetsitem.cpp
+++ b/kstars/kstarslite/skyitems/planetsitem.cpp
@@ -25,7 +25,7 @@
#include "Options.h"
PlanetsItem::PlanetsItem(QList<SolarSystemSingleComponent *> planets, QList<PlanetMoonsComponent *> moons, RootNode *rootNode)
- :SkyItem(rootNode), m_planetComponents(planets), m_moonsComponents(moons)
+ :SkyItem(LabelsItem::label_t::PLANET_LABEL, rootNode), m_planetComponents(planets), m_moonsComponents(moons)
{
foreach(SolarSystemSingleComponent * planetComp, m_planetComponents) {
KSPlanetBase *planet = planetComp->planet();
diff --git a/kstars/kstarslite/skyitems/rootnode.cpp b/kstars/kstarslite/skyitems/rootnode.cpp
index cfa44a4..b5436e5 100644
--- a/kstars/kstarslite/skyitems/rootnode.cpp
+++ b/kstars/kstarslite/skyitems/rootnode.cpp
@@ -23,6 +23,7 @@
#include "kstarslite/skyitems/cometsitem.h"
#include "kstarslite/skyitems/horizonitem.h"
#include "kstarslite/skyitems/linesitem.h"
+#include "kstarslite/skyitems/labelsitem.h"
RootNode::RootNode()
:m_skyMapLite(SkyMapLite::Instance()),
@@ -31,31 +32,33 @@ RootNode::RootNode()
genCachedTextures();
Options::setProjection(Projector::Lambert);
- SkyMapComposite *skyComposite = KStarsData::Instance()->skyComposite();
- SolarSystemComposite *solarSystem = skyComposite->solarSystemComposite();
-
- m_planetsItem = new PlanetsItem(solarSystem->planets(), solarSystem->planetMoonsComponent(), this);
- m_asteroidsItem = new AsteroidsItem(solarSystem->asteroids(), this);
- m_cometsItem = new CometsItem(solarSystem->comets(), this);
+ m_skyComposite = KStarsData::Instance()->skyComposite();
+ m_solarSystem = m_skyComposite->solarSystemComposite();
+ // LabelsItem needs to be created first so that other items could insert their labels in labelsList
+ m_labelsItem = new LabelsItem(this);
m_linesItem = new LinesItem(this);
- m_linesItem->addLinesComponent( skyComposite->constellationBoundary(), "CBoundColor", 1, Qt::SolidLine );
- m_linesItem->addLinesComponent( skyComposite->constellationLines(), "–°LineColor", 1, Qt::SolidLine );
+ m_linesItem->addLinesComponent( m_skyComposite->equatorialCoordGrid(), "EquatorialGridColor", 1, Qt::DotLine );
+ m_linesItem->addLinesComponent( m_skyComposite->horizontalCoordGrid(), "HorizontalGridColor", 1, Qt::DotLine );
+
+ m_linesItem->addLinesComponent( m_skyComposite->equator(), "EqColor", 1, Qt::SolidLine );
+ m_linesItem->addLinesComponent( m_skyComposite->ecliptic(), "EclColor", 1, Qt::SolidLine );
- m_linesItem->addLinesComponent( skyComposite->equator(), "EqColor", 1, Qt::SolidLine );
- m_linesItem->addLinesComponent( skyComposite->ecliptic(), "EclColor", 1, Qt::SolidLine );
+ m_linesItem->addLinesComponent( m_skyComposite->constellationBoundary(), "CBoundColor", 1, Qt::SolidLine );
+ m_linesItem->addLinesComponent( m_skyComposite->constellationLines(), "CLineColor", 1, Qt::SolidLine );
- m_linesItem->addLinesComponent( skyComposite->equatorialCoordGrid(), "EquatorialGridColor", 1, Qt::DotLine );
- m_linesItem->addLinesComponent( skyComposite->horizontalCoordGrid(), "HorizontalGridColor", 1, Qt::DotLine );
+ m_planetsItem = new PlanetsItem(m_solarSystem->planets(), m_solarSystem->planetMoonsComponent(), this);
+ m_asteroidsItem = new AsteroidsItem(m_solarSystem->asteroids(), this);
+ m_cometsItem = new CometsItem(m_solarSystem->comets(), this);
- m_horizonItem = new HorizonItem(skyComposite->horizon(), this);
+ m_horizonItem = new HorizonItem(m_skyComposite->horizon(), this);
setIsRectangular(false);
updateClipPoly();
- Options::setShowGround(true);
+ appendChildNode(m_labelsItem);
/*
m_linesItem(new LinesItem(this)), m_horizonItem(new HorizonItem(this))
@@ -120,16 +123,28 @@ void RootNode::update() {
//TODO: Move this check somewhere else (create a separate function)
if(Options::showSolarSystem()) {
m_planetsItem->update();
- m_asteroidsItem->update();
- m_cometsItem->update();
+ if (!Options::showAsteroids() ) {
+ if (m_asteroidsItem) delete m_asteroidsItem;
+ } else {
+ if(!m_asteroidsItem) m_asteroidsItem = new AsteroidsItem(m_solarSystem->asteroids(), this);
+ m_asteroidsItem->update();
+ }
+
+ if (!Options::showComets() ) {
+ if (m_cometsItem) delete m_cometsItem;
+ } else {
+ if(!m_cometsItem) m_cometsItem = new CometsItem(m_solarSystem->comets(), this);
+ m_cometsItem->update();
+ }
} else {
m_planetsItem->hide();
- m_asteroidsItem->hide();
- m_cometsItem->hide();
+ if(m_asteroidsItem) m_asteroidsItem->hide();
+ if(m_cometsItem) m_cometsItem->hide();
}
m_horizonItem->update();
m_linesItem->update();
+ m_labelsItem->update();
}
diff --git a/kstars/kstarslite/skyitems/rootnode.h b/kstars/kstarslite/skyitems/rootnode.h
index 1890b25..62ee48e 100644
--- a/kstars/kstarslite/skyitems/rootnode.h
+++ b/kstars/kstarslite/skyitems/rootnode.h
@@ -28,6 +28,10 @@ class CometsItem;
class HorizonItem;
class LinesItem;
+class LabelsItem;
+
+class SkyMapComposite;
+class SolarSystemComposite;
/** @class RootNode
*
@@ -59,6 +63,10 @@ public:
* @short update positions of all child SkyItems
*/
void update();
+
+ inline CometsItem *cometsItem() { return m_cometsItem; }
+
+ inline LabelsItem *labelsItem() { return m_labelsItem; }
private:
/**
* @short initializes textureCache with cached images of stars in SkyMapLite
@@ -76,6 +84,10 @@ private:
HorizonItem *m_horizonItem;
LinesItem *m_linesItem;
+ LabelsItem *m_labelsItem;
+
+ SkyMapComposite *m_skyComposite;
+ SolarSystemComposite *m_solarSystem;
//To hold nodes that represent sky objects
//QVector<SkyNode *> m_skyNodes;
diff --git a/kstars/kstarslite/skyitems/skyitem.cpp b/kstars/kstarslite/skyitems/skyitem.cpp
index f8b9c7b..97fde47 100644
--- a/kstars/kstarslite/skyitems/skyitem.cpp
+++ b/kstars/kstarslite/skyitems/skyitem.cpp
@@ -18,18 +18,33 @@
#include "rootnode.h"
#include "skynodes/skynode.h"
-SkyItem::SkyItem(RootNode* parent)
- :m_rootNode(parent)
+SkyItem::SkyItem(LabelsItem::label_t labelType, RootNode* parent)
+ :m_rootNode(parent), m_labelType(labelType)
{
parent->appendChildNode(this);
}
+SkyItem::~SkyItem() {
+ rootNode()->labelsItem()->deleteLabels(m_labelType);
+}
+
void SkyItem::hide() {
- setOpacity(0);
- markDirty(QSGNode::DirtyOpacity);
+ if(opacity()) {
+ setOpacity(0);
+ markDirty(QSGNode::DirtyOpacity);
+ }
}
void SkyItem::show() {
- setOpacity(1);
- markDirty(QSGNode::DirtyOpacity);
+ if(!opacity()) {
+ setOpacity(1);
+ markDirty(QSGNode::DirtyOpacity);
+ }
+}
+
+bool SkyItem::visible() {
+ if(opacity() != 0) {
+ return true;
+ }
+ return false;
}
diff --git a/kstars/kstarslite/skyitems/skyitem.h b/kstars/kstarslite/skyitems/skyitem.h
index 3ca42ef..37575cf 100644
--- a/kstars/kstarslite/skyitems/skyitem.h
+++ b/kstars/kstarslite/skyitems/skyitem.h
@@ -18,7 +18,7 @@
#define SKYITEM_H_
#include <QSGOpacityNode>
-//#include "skymaplite.h"
+#include "labelsitem.h"
class SkyComponent;
class SkyMapLite;
@@ -45,7 +45,8 @@ public:
* @param parent a pointer to SkyItem's parent node
*/
- explicit SkyItem(RootNode *rootNode = 0);
+ explicit SkyItem(LabelsItem::label_t labelType, RootNode *rootNode = 0);
+ virtual ~SkyItem();
virtual void update() =0;
@@ -54,9 +55,17 @@ public:
inline RootNode *rootNode() { return m_rootNode; }
+ inline LabelsItem::label_t labelType() { return m_labelType; }
+
+ bool visible();
+
private:
RootNode *m_rootNode;
QVector<SkyNode *>m_skyNodes;
+
+ //This node holds all labels that belongs to this SkyItem. See LabelsItem
+ LabelTypeNode *m_labels;
+ LabelsItem::label_t m_labelType;
};
#endif
diff --git a/kstars/kstarslite/skyitems/skynodes/guidelabelnode.cpp b/kstars/kstarslite/skyitems/skynodes/guidelabelnode.cpp
new file mode 100644
index 0000000..da4f86d
--- /dev/null
+++ b/kstars/kstarslite/skyitems/skynodes/guidelabelnode.cpp
@@ -0,0 +1,112 @@
+/** *************************************************************************
+ pointsourcenode.cpp - K Desktop Planetarium
+ -------------------
+ begin : 16/06/2016
+ copyright : (C) 2016 by Artem Fedoskin
+ email : afedoskin3@gmail.com
+ ***************************************************************************/
+/** *************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+#include "skyobject.h"
+#include "Options.h"
+
+#include <QSGSimpleTextureNode>
+
+#include "skymaplite.h"
+#include "guidelabelnode.h"
+
+GuideLabelNode::GuideLabelNode(SkyObject * skyObject, LabelsItem::label_t type)
+ :SkyNode(skyObject), m_textTexture(new QSGSimpleTextureNode)
+{
+ QColor color;
+ switch(type) {
+ case LabelsItem::label_t::CONSTEL_NAME_LABEL:
+ color = KStarsData::Instance()->colorScheme()->colorNamed( "CNameColor" );
+ break;
+ default:
+ color = KStarsData::Instance()->colorScheme()->colorNamed( "UserLabelColor" );
+ }
+
+ m_textTexture->setTexture(SkyMapLite::Instance()->textToTexture(skyObject->name(), color));
+ m_opacity->appendChildNode(m_textTexture);
+
+ m_textSize = m_textTexture->texture()->textureSize();
+ QRectF oldRect = m_textTexture->rect();
+ m_textTexture->setRect(QRect(oldRect.x(),oldRect.y(),m_textSize.width(),m_textSize.height()));
+}
+
+void GuideLabelNode::changePos(QPointF pos) {
+
+ /* QFontMetricsF fontMetrics = SkyLabeler::Instance()->fontMetrics();
+ // Create bounding rectangle by rotating the (height x width) rectangle
+ qreal h = fontMetrics.height();
+ qreal w = fontMetrics.width( text );
+
+ float angle = 0.0;
+ qreal s = 0;//sin( angle * dms::PI / 180.0 );
+ qreal c = 1;//cos( angle * dms::PI / 180.0 );
+
+ qreal w2 = w / 2.0;
+
+ qreal top, bot, left, right;
+
+ // These numbers really do depend on the sign of the angle like this
+ if ( angle >= 0.0 ) {
+ top = o.y() - s * w2;
+ bot = o.y() + c * h + s * w2;
+ left = o.x() - c * w2 - s * h;
+ right = o.x() + c * w2;
+ }
+ else {
+ top = o.y() + s * w2;
+ bot = o.y() + c * h - s * w2;
+ left = o.x() - c * w2;
+ right = o.x() + c * w2 - s * h;
+ }
+
+ // return false if label would overlap existing label
+ if ( ! markRegion( left, right, top, bot) )
+ return false;
+
+ // for debugging the bounding rectangle:
+ //psky.drawLine( QPointF( left, top ), QPointF( right, top ) );
+ //psky.drawLine( QPointF( right, top ), QPointF( right, bot ) );
+ //psky.drawLine( QPointF( right, bot ), QPointF( left, bot ) );
+ //psky.drawLine( QPointF( left, bot ), QPointF( left, top ) );
+
+ // otherwise draw the label and return true
+ m_p.save();
+ m_p.translate( o );
+
+ m_p.rotate( angle ); //rotate the coordinate system
+ m_p.drawText( QPointF( -w2, h ), text );
+ m_p.restore(); //reset coordinate system
+
+ return true;
+
+ //QSizeF size = m_point->size();
+ QMatrix4x4 m (1,0,0,pos.x(),
+ 0,1,0,pos.y(),
+ 0,0,1,0,
+ 0,0,0,1);
+ //m.translate(-0.5*size.width(), -0.5*size.height());
+
+ setMatrix(m);
+ markDirty(QSGNode::DirtyMatrix);*/
+}
+
+void GuideLabelNode::setLabelPos(QPointF pos) {
+ show();
+ //We need to subtract the height of texture from final y to follow the way QPainter draws the text
+ labelPos = QPointF(pos.x() + m_skyObject->labelOffset(), pos.y() + m_skyObject->labelOffset() - m_textSize.height());
+}
+
+void GuideLabelNode::update() {
+ changePos(labelPos);
+}
diff --git a/kstars/kstarslite/skyitems/skynodes/guidelabelnode.h b/kstars/kstarslite/skyitems/skynodes/guidelabelnode.h
new file mode 100644
index 0000000..94ef9ad
--- /dev/null
+++ b/kstars/kstarslite/skyitems/skynodes/guidelabelnode.h
@@ -0,0 +1,73 @@
+/** *************************************************************************
+ labelnode.h - K Desktop Planetarium
+ -------------------
+ begin : 09/06/2016
+ copyright : (C) 2016 by Artem Fedoskin
+ email : afedoskin3@gmail.com
+ ***************************************************************************/
+/** *************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+#ifndef LABELNODE_H_
+#define LABELNODE_H_
+
+#include "skynode.h"
+#include "../labelsitem.h"
+
+class PlanetItemNode;
+class SkyMapLite;
+class PointNode;
+class QSGSimpleTextureNode;
+class SkyLabeler;
+
+/** @class LabelNode
+ *
+ * A SkyNode derived class used for displaying PointNode with coordinates provided by SkyObject.
+ *
+ *@short A SkyNode derived class that represents stars and objects that are drawn as stars
+ *@author Artem Fedoskin
+ *@version 1.0
+ */
+
+class RootNode;
+
+class GuideLabelNode : public SkyNode {
+public:
+ /**
+ * @short Constructor
+ * @param skyObject pointer to SkyObject that has to be displayed on SkyMapLite
+ * @param parentNode pointer to the top parent node, which holds texture cache
+ * @param spType spectral class of PointNode
+ * @param size initial size of PointNode
+ */
+ GuideLabelNode(SkyObject * skyObject, LabelsItem::label_t type);
+
+ /**
+ * @short changePos changes the position m_point
+ * @param pos new position
+ */
+ virtual void changePos(QPointF pos) override;
+
+ /**
+ * @short setLabelPos sets the position of label with the given offset from SkyObject's position and
+ * makes the label visible if it was hidden
+ * @param pos position of label
+ */
+ void setLabelPos(QPointF pos);
+
+ void update();
+ QPointF labelPos;
+
+private:
+ QSGSimpleTextureNode *m_textTexture;
+ QSize m_textSize;
+};
+
+#endif
+
+
diff --git a/kstars/kstarslite/skyitems/skynodes/horizonnode.cpp b/kstars/kstarslite/skyitems/skynodes/horizonnode.cpp
index 526f2af..94b0938 100644
--- a/kstars/kstarslite/skyitems/skynodes/horizonnode.cpp
+++ b/kstars/kstarslite/skyitems/skynodes/horizonnode.cpp
@@ -33,6 +33,7 @@ void HorizonNode::update() {
}
} else {
m_polygonNode->hide();
+ return;
}
m_polygonNode->markDirty(QSGNode::DirtyGeometry);
diff --git a/kstars/kstarslite/skyitems/skynodes/labelnode.cpp b/kstars/kstarslite/skyitems/skynodes/labelnode.cpp
new file mode 100644
index 0000000..2a799d4
--- /dev/null
+++ b/kstars/kstarslite/skyitems/skynodes/labelnode.cpp
@@ -0,0 +1,71 @@
+/** *************************************************************************
+ pointsourcenode.cpp - K Desktop Planetarium
+ -------------------
+ begin : 16/06/2016
+ copyright : (C) 2016 by Artem Fedoskin
+ email : afedoskin3@gmail.com
+ ***************************************************************************/
+/** *************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+#include "skyobject.h"
+#include "Options.h"
+
+#include <QSGSimpleTextureNode>
+
+#include "skymaplite.h"
+#include "labelnode.h"
+
+LabelNode::LabelNode(SkyObject * skyObject, LabelsItem::label_t type)
+ :SkyNode(skyObject), m_textTexture(new QSGSimpleTextureNode)
+{
+ QColor color;
+ switch(type) {
+ case LabelsItem::label_t::PLANET_LABEL:
+ case LabelsItem::label_t::SATURN_MOON_LABEL:
+ case LabelsItem::label_t::JUPITER_MOON_LABEL:
+ case LabelsItem::label_t::COMET_LABEL:
+ case LabelsItem::label_t::RUDE_LABEL:
+ color = KStarsData::Instance()->colorScheme()->colorNamed( "PNameColor" );
+ break;
+ case LabelsItem::label_t::ASTEROID_LABEL:
+ color = QColor("gray");
+ break;
+ default:
+ color = KStarsData::Instance()->colorScheme()->colorNamed( "UserLabelColor" );
+ }
+
+ m_textTexture->setTexture(SkyMapLite::Instance()->textToTexture(skyObject->name(), color));
+ m_opacity->appendChildNode(m_textTexture);
+
+ m_textSize = m_textTexture->texture()->textureSize();
+ QRectF oldRect = m_textTexture->rect();
+ m_textTexture->setRect(QRect(oldRect.x(),oldRect.y(),m_textSize.width(),m_textSize.height()));
+}
+
+void LabelNode::changePos(QPointF pos) {
+ //QSizeF size = m_point->size();
+ QMatrix4x4 m (1,0,0,pos.x(),
+ 0,1,0,pos.y(),
+ 0,0,1,0,
+ 0,0,0,1);
+ //m.translate(-0.5*size.width(), -0.5*size.height());
+
+ setMatrix(m);
+ markDirty(QSGNode::DirtyMatrix);
+}
+
+void LabelNode::setLabelPos(QPointF pos) {
+ show();
+ //We need to subtract the height of texture from final y to follow the way QPainter draws the text
+ labelPos = QPointF(pos.x() + m_skyObject->labelOffset(), pos.y() + m_skyObject->labelOffset() - m_textSize.height());
+}
+
+void LabelNode::update() {
+ changePos(labelPos);
+}
diff --git a/kstars/kstarslite/skyitems/skynodes/labelnode.h b/kstars/kstarslite/skyitems/skynodes/labelnode.h
new file mode 100644
index 0000000..89c5233
--- /dev/null
+++ b/kstars/kstarslite/skyitems/skynodes/labelnode.h
@@ -0,0 +1,73 @@
+/** *************************************************************************
+ labelnode.h - K Desktop Planetarium
+ -------------------
+ begin : 09/06/2016
+ copyright : (C) 2016 by Artem Fedoskin
+ email : afedoskin3@gmail.com
+ ***************************************************************************/
+/** *************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+#ifndef LABELNODE_H_
+#define LABELNODE_H_
+
+#include "skynode.h"
+#include "../labelsitem.h"
+
+class PlanetItemNode;
+class SkyMapLite;
+class PointNode;
+class QSGSimpleTextureNode;
+class SkyLabeler;
+
+/** @class LabelNode
+ *
+ * A SkyNode derived class used for displaying PointNode with coordinates provided by SkyObject.
+ *
+ *@short A SkyNode derived class that represents stars and objects that are drawn as stars
+ *@author Artem Fedoskin
+ *@version 1.0
+ */
+
+class RootNode;
+
+class LabelNode : public SkyNode {
+public:
+ /**
+ * @short Constructor
+ * @param skyObject pointer to SkyObject that has to be displayed on SkyMapLite
+ * @param parentNode pointer to the top parent node, which holds texture cache
+ * @param spType spectral class of PointNode
+ * @param size initial size of PointNode
+ */
+ LabelNode(SkyObject * skyObject, LabelsItem::label_t type);
+
+ /**
+ * @short changePos changes the position m_point
+ * @param pos new position
+ */
+ virtual void changePos(QPointF pos) override;
+
+ /**
+ * @short setLabelPos sets the position of label with the given offset from SkyObject's position and
+ * makes the label visible if it was hidden
+ * @param pos position of label
+ */
+ void setLabelPos(QPointF pos);
+
+ void update();
+ QPointF labelPos;
+
+private:
+ QSGSimpleTextureNode *m_textTexture;
+ QSize m_textSize;
+};
+
+#endif
+
+
diff --git a/kstars/kstarslite/skyitems/skynodes/planetmoonsnode.cpp b/kstars/kstarslite/skyitems/skynodes/planetmoonsnode.cpp
index 3073db4..369829b 100644
--- a/kstars/kstarslite/skyitems/skynodes/planetmoonsnode.cpp
+++ b/kstars/kstarslite/skyitems/skynodes/planetmoonsnode.cpp
@@ -1,8 +1,11 @@
+#include <QSGSimpleTextureNode>
+
#include "planetnode.h"
#include "pointsourcenode.h"
#include "planetmoonsnode.h"
#include "planetmoons.h"
#include "ksplanetbase.h"
+#include "skylabeler.h"
PlanetMoonsNode::PlanetMoonsNode(KSPlanetBase* planet, RootNode* parentNode)
:SkyNode(planet), m_rootNode(parentNode), pmoons(0),
@@ -33,7 +36,7 @@ void PlanetMoonsNode::updateMoons() {
if(!m_moonNodes.length()) { //Initialize PointSourceNodes used for drawing moons
for ( int i=0; i<nmoons; ++i ) {
- m_moonNodes.append(new PointSourceNode(pmoons->moon(i), m_rootNode));
+ m_moonNodes.append(new PointSourceNode(pmoons->moon(i), m_rootNode,LabelsItem::label_t::JUPITER_MOON_LABEL));
}
}
diff --git a/kstars/kstarslite/skyitems/skynodes/planetmoonsnode.h b/kstars/kstarslite/skyitems/skynodes/planetmoonsnode.h
index de6e114..5def5a2 100644
--- a/kstars/kstarslite/skyitems/skynodes/planetmoonsnode.h
+++ b/kstars/kstarslite/skyitems/skynodes/planetmoonsnode.h
@@ -22,6 +22,7 @@ class PlanetMoons;
class RootNode;
class PointSourceNode;
class KSPlanetBase;
+class QSGSimpleTextureNode;
/** @class PlanetMoonsNode
*
@@ -65,6 +66,7 @@ private:
QList<PointSourceNode *> m_moonNodes;
RootNode *m_rootNode;
+
};
diff --git a/kstars/kstarslite/skyitems/skynodes/planetnode.cpp b/kstars/kstarslite/skyitems/skynodes/planetnode.cpp
index 0ebe885..ac5aaec 100644
--- a/kstars/kstarslite/skyitems/skynodes/planetnode.cpp
+++ b/kstars/kstarslite/skyitems/skynodes/planetnode.cpp
@@ -22,9 +22,12 @@
#include "ksplanetbase.h"
#include "Options.h"
#include "projections/projector.h"
+#include "../rootnode.h"
+#include "../labelsitem.h"
#include "planetnode.h"
#include "nodes/pointnode.h"
+#include "labelnode.h"
PlanetNode::PlanetNode(KSPlanetBase* pb, RootNode* parentNode)
:SkyNode(pb), m_planetPic(new QSGSimpleTextureNode), m_planetOpacity(new QSGOpacityNode)
@@ -48,6 +51,7 @@ PlanetNode::PlanetNode(KSPlanetBase* pb, RootNode* parentNode)
m_planetOpacity->appendChildNode(m_planetPic);
m_planetPic->setTexture(SkyMapLite::Instance()->window()->createTextureFromImage(
pb->image(), QQuickWindow::TextureCanUseAtlas));
+ m_label = parentNode->labelsItem()->addLabel(pb, LabelsItem::label_t::PLANET_LABEL);
}
void PlanetNode::update() {
@@ -61,10 +65,15 @@ void PlanetNode::update() {
bool visible = false;
QPointF pos = proj->toScreen(planet,true,&visible);
+
if( !visible || !proj->onScreen(pos) ) {
hide();
return;
}
+
+ //Set new position of the label
+ m_label->setLabelPos(pos);
+
float fakeStarSize = ( 10.0 + log10( Options::zoomFactor() ) - log10( MINZOOM ) ) * ( 10 - planet->mag() ) / 10;
if( fakeStarSize > 15.0 )
fakeStarSize = 15.0;
@@ -98,6 +107,7 @@ void PlanetNode::update() {
//drawEllipse( pos, size, size );
}
}
+
}
void PlanetNode::setPointSize(float size) {
@@ -131,10 +141,12 @@ void PlanetNode::hide() {
m_planetOpacity->markDirty(QSGNode::DirtyOpacity);
}
m_point->hide();
+ m_label->hide();
}
void PlanetNode::changePos(QPointF pos) {
QSizeF size;
+ //Check the bug with planet
QMatrix4x4 m (1,0,0,pos.x(),
0,1,0,pos.y(),
0,0,1,0,
diff --git a/kstars/kstarslite/skyitems/skynodes/planetnode.h b/kstars/kstarslite/skyitems/skynodes/planetnode.h
index eba84b2..cfaf16a 100644
--- a/kstars/kstarslite/skyitems/skynodes/planetnode.h
+++ b/kstars/kstarslite/skyitems/skynodes/planetnode.h
@@ -22,6 +22,7 @@ class QImage;
class KSPlanetBase;
class RootNode;
class PointNode;
+class LabelNode;
/** @class PlanetNode
*
@@ -77,6 +78,7 @@ private:
// no explicit opacity node here.
QSGOpacityNode *m_planetOpacity;
QSGSimpleTextureNode *m_planetPic;
+ LabelNode *m_label;
};
diff --git a/kstars/kstarslite/skyitems/skynodes/pointsourcenode.cpp b/kstars/kstarslite/skyitems/skynodes/pointsourcenode.cpp
index 3d445b1..3936548 100644
--- a/kstars/kstarslite/skyitems/skynodes/pointsourcenode.cpp
+++ b/kstars/kstarslite/skyitems/skynodes/pointsourcenode.cpp
@@ -21,10 +21,16 @@
#include "pointsourcenode.h"
#include "nodes/pointnode.h"
-PointSourceNode::PointSourceNode(SkyObject * skyObject, RootNode* p, char sp, float size)
- :SkyNode(skyObject), m_point(0), m_sizeMagLim(10.) // has to be changed when stars will be introduced
+#include "../rootnode.h"
+#include "../labelsitem.h"
+#include "labelnode.h"
+
+PointSourceNode::PointSourceNode(SkyObject * skyObject, RootNode * parentNode,
+ LabelsItem::label_t labelType, char spType, float size)
+ :SkyNode(skyObject), m_point(0), m_sizeMagLim(10.), // has to be changed when stars will be introduced
+ m_label(0), m_labelType(labelType), m_rootNode(parentNode)
{
- m_point = new PointNode(p,starWidth(size),sp);
+ m_point = new PointNode(parentNode,starWidth(size),spType);
appendChildNode(m_point);
}
@@ -60,21 +66,39 @@ void PointSourceNode::changePos(QPointF pos) {
void PointSourceNode::update() {
if( !projector()->checkVisibility(m_skyObject) ) {
- m_point->hide();
+ hide();
return;
}
bool visible = false;
- QPointF pos = projector()->toScreen(m_skyObject,true,&visible);
+ pos = projector()->toScreen(m_skyObject,true,&visible);
if( visible && projector()->onScreen(pos) ) { // FIXME: onScreen here should use canvas size rather than SkyMap size, especially while printing in portrait mode!
m_point->setSize(starWidth(m_skyObject->mag()));
changePos(pos);
m_point->show();
+
+ if(m_drawLabel) {
+ if(!m_label) { //This way labels will be created only when they are needed
+ m_label = m_rootNode->labelsItem()->addLabel(m_skyObject, m_labelType);
+ }
+ m_label->setLabelPos(pos);
+ } else {
+ if(m_label) m_label->hide();
+ }
+
+
} else {
- m_point->hide();
+ hide();
}
+
}
+/*void PointSourceNode::updateLabel() {
+ if(!m_label) m_label = m_rootNode->labelsItem()->addLabel(skyObject, labelType);
+ m_label->setLabelPos(pos);
+}*/
+
void PointSourceNode::hide() {
+ if(m_label) m_label->hide();
m_point->hide();
}
diff --git a/kstars/kstarslite/skyitems/skynodes/pointsourcenode.h b/kstars/kstarslite/skyitems/skynodes/pointsourcenode.h
index 1d1acba..7a0488f 100644
--- a/kstars/kstarslite/skyitems/skynodes/pointsourcenode.h
+++ b/kstars/kstarslite/skyitems/skynodes/pointsourcenode.h
@@ -16,10 +16,12 @@
#ifndef POINTSOURCENODE_H_
#define POINTSOURCENODE_H_
#include "skynode.h"
+#include "../labelsitem.h"
class PlanetItemNode;
class SkyMapLite;
class PointNode;
+class LabelNode;
/** @class PointSourceNode
*
@@ -41,7 +43,8 @@ public:
* @param spType spectral class of PointNode
* @param size initial size of PointNode
*/
- PointSourceNode(SkyObject * skyObject, RootNode * parentNode, char spType = 'A', float size = 1);
+ PointSourceNode(SkyObject * skyObject, RootNode * parentNode,
+ LabelsItem::label_t labelType = LabelsItem::label_t::STAR_LABEL, char spType = 'A', float size = 1);
/** @short Get the width of a star of magnitude mag */
float starWidth(float mag) const;
@@ -58,6 +61,12 @@ private:
PointNode * m_point;
//TODO deal setter for this when stars will be introduced
float m_sizeMagLim;
+ RootNode *m_rootNode;
+
+ LabelNode *m_label;
+ LabelsItem::label_t m_labelType;
+
+ QPointF pos;
};
#endif
diff --git a/kstars/kstarslite/skyitems/skynodes/skynode.cpp b/kstars/kstarslite/skyitems/skynodes/skynode.cpp
index 2d74a0c..c8db9c6 100644
--- a/kstars/kstarslite/skyitems/skynodes/skynode.cpp
+++ b/kstars/kstarslite/skyitems/skynodes/skynode.cpp
@@ -18,13 +18,39 @@
#include "skynode.h"
SkyNode::SkyNode(SkyObject * skyObject)
- :m_skyObject(skyObject)
+ :m_skyObject(skyObject), m_opacity(new QSGOpacityNode)
{
-
+ appendChildNode(m_opacity);
}
SkyNode::SkyNode()
- :m_skyObject(nullptr)
+ :m_skyObject(nullptr), m_opacity(new QSGOpacityNode)
{
}
+
+void SkyNode::update(bool drawLabel) {
+ m_drawLabel = drawLabel;
+ update();
+}
+
+void SkyNode::hide() {
+ if(m_opacity->opacity()) {
+ m_opacity->setOpacity(0);
+ m_opacity->markDirty(QSGNode::DirtyOpacity);
+ }
+}
+
+void SkyNode::show() {
+ if(!m_opacity->opacity()) {
+ m_opacity->setOpacity(1);
+ m_opacity->markDirty(QSGNode::DirtyOpacity);
+ }
+}
+
+bool SkyNode::visible() {
+ if(m_opacity->opacity() != 0) {
+ return true;
+ }
+ return false;
+}
diff --git a/kstars/kstarslite/skyitems/skynodes/skynode.h b/kstars/kstarslite/skyitems/skynodes/skynode.h
index a49652f..91f4803 100644
--- a/kstars/kstarslite/skyitems/skynodes/skynode.h
+++ b/kstars/kstarslite/skyitems/skynodes/skynode.h
@@ -59,11 +59,23 @@ public:
/**
* @short updates coordinate of the object on SkyMapLite
*/
- virtual void update() =0;
+ virtual void update() { }
+
+ /**
+ * @short sets m_drawLabel to true if it is needed to be drawn and calls update()
+ * @param drawLabel true of label has to be drawn
+ */
+ void update(bool drawLabel);
+
/**
- * @short hides all child nodes
+ * @short hides all child nodes (sets opacity of m_opacity to 0)
*/
- virtual void hide() =0;
+ virtual void hide();
+
+ /**
+ * @short shows all child nodes (sets opacity of m_opacity to 1)
+ */
+ virtual void show();
/**
* @short changes the position of SkyNode on SkyMapLite. Has to be overriden by the classes
@@ -73,12 +85,20 @@ public:
virtual void changePos(QPointF pos) { }
/**
+ * @return true if object is visible (m_opacity->opacity() != 0) else returns false
+ */
+ bool visible();
+
+ /**
* @short returns SkyObject associated with this SkyNode
* @return pointer to the object of type SkyObject
*/
SkyObject * skyObject() const { return m_skyObject; }
protected:
SkyObject * m_skyObject;
+ QSGOpacityNode *m_opacity;
+
+ bool m_drawLabel;
};
diff --git a/kstars/kstarslite/skyitems/skynodes/trixelnode.cpp b/kstars/kstarslite/skyitems/skynodes/trixelnode.cpp
index 03410cc..d79b811 100644
--- a/kstars/kstarslite/skyitems/skynodes/trixelnode.cpp
+++ b/kstars/kstarslite/skyitems/skynodes/trixelnode.cpp
@@ -63,13 +63,3 @@ void TrixelNode::update() {
lines->updateGeometry();
}
}
-
-void TrixelNode::hide() {
- m_opacity->setOpacity(0);
- m_opacity->markDirty(QSGNode::DirtyOpacity);
-}
-
-void TrixelNode::show() {
- m_opacity->setOpacity(1);
- m_opacity->markDirty(QSGNode::DirtyOpacity);
-}
diff --git a/kstars/kstarslite/skyitems/skynodes/trixelnode.h b/kstars/kstarslite/skyitems/skynodes/trixelnode.h
index 9ca0f00..73fe910 100644
--- a/kstars/kstarslite/skyitems/skynodes/trixelnode.h
+++ b/kstars/kstarslite/skyitems/skynodes/trixelnode.h
@@ -51,8 +51,6 @@ public:
virtual void changePos(QPointF pos) {}
virtual void update() override;
- virtual void hide() override;
- void show();
private:
QSGOpacityNode *m_opacity;
Trixel trixel;
diff --git a/kstars/skycomponents/constellationnamescomponent.cpp b/kstars/skycomponents/constellationnamescomponent.cpp
index 78f9843..9fb1528 100644
--- a/kstars/skycomponents/constellationnamescomponent.cpp
+++ b/kstars/skycomponents/constellationnamescomponent.cpp
@@ -102,7 +102,7 @@ bool ConstellationNamesComponent::selected()
!( Options::hideOnSlew() && Options::hideCNames() && SkyMap::IsSlewing() );
#else
return Options::showCNames() &&
- !( Options::hideOnSlew() && Options::hideCNames() );
+ !( Options::hideOnSlew() && Options::hideCNames() && SkyMapLite::IsSlewing());
#endif
}
diff --git a/kstars/skycomponents/skylabel.h b/kstars/skycomponents/skylabel.h
index f08ae74..22edce1 100644
--- a/kstars/skycomponents/skylabel.h
+++ b/kstars/skycomponents/skylabel.h
@@ -23,7 +23,7 @@
#include "skyobjects/skyobject.h"
class SkyLabel;
-typedef QList<SkyLabel> LabelList;
+typedef QList<SkyLabel> LabelList;
class SkyLabel {
diff --git a/kstars/skycomponents/skylabeler.cpp b/kstars/skycomponents/skylabeler.cpp
index a574906..f75a693 100644
--- a/kstars/skycomponents/skylabeler.cpp
+++ b/kstars/skycomponents/skylabeler.cpp
@@ -277,6 +277,66 @@ void SkyLabeler::reset( SkyMap* skyMap )
}
}
+#ifdef KSTARS_LITE
+void SkyLabeler::reset()
+{
+ SkyMapLite * skyMap = SkyMapLite::Instance();
+ // ----- Set up Projector ---
+ m_proj = skyMap->projector();
+
+ // ----- Set up Painter -----
+
+ m_stdFont = QFont( skyMap->skyFont() );
+ setZoomFont();
+ m_skyFont = skyMap->skyFont() ;
+ m_fontMetrics = QFontMetrics( m_skyFont );
+ m_minDeltaX = (int) m_fontMetrics.width("MMMMM");
+ // ----- Set up Zoom Dependent Offset -----
+ m_offset = SkyLabeler::ZoomOffset();
+
+ // ----- Prepare Virtual Screen -----
+ m_yScale = (m_fontMetrics.height() + 1.0);
+
+ int maxY = int( skyMap->height() / m_yScale );
+ if ( maxY < 1 ) maxY = 1; // prevents a crash below?
+
+ int m_maxX = skyMap->width();
+ m_size = (maxY + 1) * m_maxX;
+
+ // Resize if needed:
+ if ( maxY > m_maxY ) {
+ screenRows.resize( m_maxY );
+ for ( int y = m_maxY; y <= maxY; y++) {
+ screenRows.append( new LabelRow() );
+ }
+ //printf("resize: %d -> %d, size:%d\n", m_maxY, maxY, screenRows.size());
+ }
+
+ // Clear all pre-existing rows as needed
+
+ int minMaxY = (maxY < m_maxY) ? maxY : m_maxY;
+
+ for (int y = 0; y <= minMaxY; y++) {
+ LabelRow* row = screenRows[y];
+ for ( int i = 0; i < row->size(); i++) {
+ delete row->at(i);
+ }
+ row->clear();
+ }
+
+ // never decrease m_maxY:
+ if ( m_maxY < maxY ) m_maxY = maxY;
+
+ // reset the counters
+ m_marks = m_hits = m_misses = m_elements = 0;
+
+ //----- Clear out labelList -----
+ for (int i = 0; i < labelList.size(); i++) {
+ labelList[ i ].clear();
+ }
+}
+#endif
+
void SkyLabeler::draw(QPainter& p)
{
//FIXME: need a better soln. Apparently starting a painter
@@ -429,7 +489,6 @@ bool SkyLabeler::markRegion( qreal left, qreal right, qreal top, qreal bot )
return true;
}
-
void SkyLabeler::addLabel( SkyObject *obj, SkyLabeler::label_t type )
{
bool visible = false;
@@ -438,6 +497,10 @@ void SkyLabeler::addLabel( SkyObject *obj, SkyLabeler::label_t type )
labelList[ (int)type ].append( SkyLabel( p, obj ) );
}
+void SkyLabeler::addLabel(SkyObject *obj, QPointF pos, label_t type) {
+ labelList[ (int)type ].append( SkyLabel( pos, obj ) );
+}
+
void SkyLabeler::drawQueuedLabels()
{
KStarsData* data = KStarsData::Instance();
diff --git a/kstars/skycomponents/skylabeler.h b/kstars/skycomponents/skylabeler.h
index 581f1dc..2597d1a 100644
--- a/kstars/skycomponents/skylabeler.h
+++ b/kstars/skycomponents/skylabeler.h
@@ -167,6 +167,13 @@ public:
void reset( SkyMap* skyMap );
/**
+ * @short KStars Lite version of the function above
+ */
+#ifdef KSTARS_LITE
+ void reset();
+#endif
+
+ /**
* @short Draws labels using the given painter
* @param p the painter to draw labels with
*/
@@ -256,6 +263,12 @@ public:
void addLabel( SkyObject *obj, label_t type );
/**
+ * @short queues the label in the "type" buffer for later drawing. Doesn't calculate the position of
+ * SkyObject but uses pos as a position of label.
+ */
+ void addLabel(SkyObject *obj, QPointF pos, label_t type);
+
+ /**
*@short draws the labels stored in all the buffers. You can change the
* priority by editing the .cpp file and changing the order in which
* buffers are drawn. You can also change the fonts and colors there
@@ -317,7 +330,7 @@ public:
*/
void printInfo();
- int hits() { return m_hits; };
+ int hits() { return m_hits; }
int marks() { return m_marks; }
private:
diff --git a/kstars/skymaplite.cpp b/kstars/skymaplite.cpp
index 93539e2..f6fb132 100644
--- a/kstars/skymaplite.cpp
+++ b/kstars/skymaplite.cpp
@@ -121,9 +121,8 @@ QSGNode* SkyMapLite::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *upda
if(m_loadingFinished) {
if(!n) {
n = new RootNode();
- } else {
- n->update();
}
+ n->update();
}
return n;
@@ -505,6 +504,40 @@ QVector<QVector<QPixmap*>> SkyMapLite::getImageCache()
return imageCache;
}
+QSGTexture *SkyMapLite::textToTexture(QString text, QColor color, QFont font) {
+ QPainter painter;
+
+ QFontMetrics fm = painter.fontMetrics();
+ QFont f = painter.font();
+ if(font != f) {
+ fm = QFontMetrics(font);
+ }
+
+ if(m_skyFont != f) {
+ m_skyFont = f;
+ }
+
+ int width = fm.width(text);
+ int height = fm.height();
+
+ QImage label(width, height, QImage::Format_ARGB32_Premultiplied);
+ label.fill(0);
+ painter.begin(&label);
+
+ painter.setPen( color );
+ painter.drawText(0,height-fm.descent(),text);
+
+ painter.end();
+
+ QFile file("/home/polaris/label.png");
+ file.open(QIODevice::WriteOnly);
+ label.save(&file, "PNG");
+
+ QSGTexture *texture = window()->createTextureFromImage(label,
+ QQuickWindow::TextureCanUseAtlas & QQuickWindow::TextureHasAlphaChannel);
+ return texture;
+}
+
void SkyMapLite::initStarImages()
{
imageCache = QVector<QVector<QPixmap*>>(nSPclasses);
diff --git a/kstars/skymaplite.h b/kstars/skymaplite.h
index 7208c58..7d94488 100644
--- a/kstars/skymaplite.h
+++ b/kstars/skymaplite.h
@@ -242,6 +242,8 @@ public:
*/
QVector<QVector<QPixmap*>> getImageCache();
+ QSGTexture *textToTexture(QString text, QColor color = QColor(255,255,255), QFont font = QFont());
+
/**
* @short returns cached texture from textureCache.
*
@@ -271,6 +273,11 @@ public:
inline const Projector * projector() const { return m_proj; }
/**
+ * @return font of labels
+ */
+ inline QFont skyFont() const { return m_skyFont; }
+
+ /**
*@short Proxy method for SkyMapDrawAbstract::drawObjectLabels()
*/
//inline void drawObjectLabels( QList< SkyObject* >& labelObjects ) { dynamic_cast<SkyMapDrawAbstract *>(m_SkyMapDraw)->drawObjectLabels( labelObjects ); }
@@ -574,6 +581,8 @@ private:
static SkyMapLite *pinstance;
QQuickItem *m_SkyMapLiteWrapper;
+ QFont m_skyFont;
+
static int starColorMode;
const SkyPoint *m_rulerStartPoint; // Good to keep the original ruler start-point for purposes of dynamic_cast