summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtem Fedoskin <afedoskin3@gmail.com>2016-05-27 20:46:30 (GMT)
committerArtem Fedoskin <afedoskin3@gmail.com>2016-05-27 20:50:24 (GMT)
commit762487c3f9bea82d17e9a7e66a1dd7317165fe2e (patch)
tree2501b515f6b27c9e8526feffd3b00c0e61d570f4
parentcd3def577ca366cc0006ee3357e6b9bc538b657c (diff)
Added support of planet moons in SkyMapLite. SkyMapLite now can handle
rotation using two fingers and pinch-to-zoom into specific area.
-rw-r--r--kstars/CMakeLists.txt8
-rw-r--r--kstars/kstars.kcfg18
-rw-r--r--kstars/kstarslite.cpp10
-rw-r--r--kstars/kstarslite.h3
-rw-r--r--kstars/kstarslite/qml/modules/BottomMenu.qml5
-rw-r--r--kstars/kstarslite/qml/modules/TopMenu.qml24
-rw-r--r--kstars/kstarslite/skyitems/nodes/planetmoonsnode.cpp67
-rw-r--r--kstars/kstarslite/skyitems/nodes/planetmoonsnode.h72
-rw-r--r--kstars/kstarslite/skyitems/nodes/planetnode.cpp89
-rw-r--r--kstars/kstarslite/skyitems/nodes/planetnode.h11
-rw-r--r--kstars/kstarslite/skyitems/nodes/pointsourcenode.cpp2
-rw-r--r--kstars/kstarslite/skyitems/nodes/rootnode.cpp12
-rw-r--r--kstars/kstarslite/skyitems/nodes/rootnode.h14
-rw-r--r--kstars/kstarslite/skyitems/nodes/skynode.h4
-rw-r--r--kstars/kstarslite/skyitems/planetsitem.cpp66
-rw-r--r--kstars/kstarslite/skyitems/planetsitem.h19
-rw-r--r--kstars/main.cpp2
-rw-r--r--kstars/skycomponents/equator.h2
-rw-r--r--kstars/skycomponents/planetmoonscomponent.cpp15
-rw-r--r--kstars/skycomponents/planetmoonscomponent.h8
-rw-r--r--kstars/skycomponents/solarsystemsinglecomponent.cpp2
-rw-r--r--kstars/skymaplite.cpp126
-rw-r--r--kstars/skymaplite.h18
-rw-r--r--kstars/skymaplitevents.cpp188
24 files changed, 627 insertions, 158 deletions
diff --git a/kstars/CMakeLists.txt b/kstars/CMakeLists.txt
index 4564643..df3ac98 100644
--- a/kstars/CMakeLists.txt
+++ b/kstars/CMakeLists.txt
@@ -557,6 +557,7 @@ if(BUILD_KSTARS_LITE)
kstarslite/skyitems/nodes/pointnode.cpp
kstarslite/skyitems/nodes/skynode.cpp
kstarslite/skyitems/nodes/pointsourcenode.cpp
+ kstarslite/skyitems/nodes/planetmoonsnode.cpp
)
#Qml files will be probably moved to user's data dir, but for use
#with QtCreator it is more convenient to have them here
@@ -635,8 +636,11 @@ set(kstars_SRCS ${indi_SRCS} ${fits_SRCS} ${ekos_SRCS} ${onlineparser_SRCS}
${kstars_options_SRCS} ${kstars_skyobjects_SRCS} ${kstars_dialogs_SRCS} ${oal_SRCS}
${printing_SRCS} ${kstarslite_SRCS} ${kstarslite_RESOURCE}
)
-
-kconfig_add_kcfg_files(kstars_SRCS ${kstars_KCFG_SRCS})
+if(BUILD_KSTARS_LITE)
+ kconfig_add_kcfg_files(kstars_SRCS GENERATE_MOC ${kstars_KCFG_SRCS})
+else()
+ kconfig_add_kcfg_files(kstars_SRCS ${kstars_KCFG_SRCS})
+endif()
if(NOT BUILD_KSTARS_LITE)
qt5_add_dbus_adaptor(kstars_SRCS org.kde.kstars.xml kstars.h KStars)
diff --git a/kstars/kstars.kcfg b/kstars/kstars.kcfg
index fb0322a..c772db9 100644
--- a/kstars/kstars.kcfg
+++ b/kstars/kstars.kcfg
@@ -60,19 +60,19 @@
<label>Time InfoBox anchor flag</label>
<whatsthis>Is the Time InfoBox anchored to a window edge? 0 = not anchored; 1 = anchored to right edge; 2 = anchored to bottom edge; 3 = anchored to bottom and right edges.</whatsthis>
<default>0</default>
- <min>0</min><max>3</max>
+ <!--<min>0</min><max>3</max>-->
</entry>
<entry name="StickyFocusBox" type="Int">
<label>Time InfoBox anchor flag</label>
<whatsthis>Is the Focus InfoBox anchored to a window edge? 0 = not anchored; 1 = anchored to right edge; 2 = anchored to bottom edge; 3 = anchored to bottom and right edges.</whatsthis>
<default>1</default>
- <min>0</min><max>3</max>
+ <!--<min>0</min><max>3</max>-->
</entry>
<entry name="StickyGeoBox" type="Int">
<label>Geographic InfoBox anchor flag</label>
<whatsthis>Is the Geographic Location InfoBox anchored to a window edge? 0 = not anchored; 1 = anchored to right edge; 2 = anchored to bottom edge; 3 = anchored to bottom and right edges.</whatsthis>
<default>2</default>
- <min>0</min><max>3</max>
+ <!--<min>0</min><max>3</max>-->
</entry>
<entry name="ShowStatusBar" type="Bool">
<label>Display the statusbar?</label>
@@ -125,7 +125,7 @@
</entry>
</group>
- <group name="indi">
+ <group name="indi">
<entry name="useGeographicUpdate" type="Bool">
<label>Automatically updates geographic location?</label>
<default>true</default>
@@ -143,7 +143,7 @@
<label>Display INDI messages in the statusbar?</label>
<whatsthis>Toggle display of INDI messages in the KStars statusbar.</whatsthis>
<default>true</default>
- </entry>
+ </entry>
<entry name="useComputerSource" type="Bool">
<label>Use computer time and location for synchronization?</label>
<default>true</default>
@@ -644,7 +644,7 @@
<label>Zoom Factor, in pixels per radian</label>
<whatsthis>The zoom level, measured in pixels per radian.</whatsthis>
<default>1000.</default>
- <min>200.</min><max>5000000.</max>
+ <!--<min>200.</min><max>5000000.</max>-->
</entry>
<entry name="MagLimitAsteroid" type="Double">
<label>Faint limit for asteroids</label>
@@ -762,13 +762,13 @@
<label>Mode for rendering stars</label>
<whatsthis>The method for rendering stars: 0="realistic colors"; 1="solid red"; 2="solid black"; 3="solid white"</whatsthis>
<default>0</default>
- <max>3</max>
+ <!--<max>3</max>-->
</entry>
<entry name="StarColorIntensity" type="UInt">
<label>Saturation level of star colors</label>
<whatsthis>The color saturation level of stars (only applicable when using "realistic colors" mode).</whatsthis>
<default>6</default>
- <max>10</max>
+ <!--<max>10</max>-->
</entry>
<entry name="AngularRulerColor" type="String">
<label>Color of angular distance ruler</label>
@@ -1538,7 +1538,7 @@
<entry name="PHD2Port" type="UInt">
<label>PHD2 Event Monitoring Port</label>
<default>4400</default>
- </entry>
+ </entry>
<entry name="CalibrationPulseDuration" type="UInt">
<label>Pulse duration in milliseconds used for guiding pulses during calibration stage.</label>
<default>1000</default>
diff --git a/kstars/kstarslite.cpp b/kstars/kstarslite.cpp
index cb21bf7..7aa1bf7 100644
--- a/kstars/kstarslite.cpp
+++ b/kstars/kstarslite.cpp
@@ -41,7 +41,6 @@ KStarsLite::KStarsLite( bool doSplash, bool startClock, const QString &startDate
//Make instance of KStarsLite and KStarsData available to QML
m_Engine.rootContext()->setContextProperty("KStarsLite", this);
m_Engine.rootContext()->setContextProperty("KStarsData", m_KStarsData);
-
m_Engine.rootContext()->setContextProperty("Options", Options::self());
/*Register SkyMapLite for use within QML
@@ -63,6 +62,8 @@ KStarsLite::KStarsLite( bool doSplash, bool startClock, const QString &startDate
have to add SkyItems to the SkyMapLite*/
m_SkyMapLite = SkyMapLite::createInstance(skyMapLiteWrapper);
+ m_Engine.rootContext()->setContextProperty("SkyMapLite", m_SkyMapLite);
+
// Set pinstance to yourself
pinstance = this;
@@ -118,6 +119,13 @@ KStarsLite *KStarsLite::createInstance( bool doSplash, bool clockrunning, const
return nullptr;
}
+void KStarsLite::fullUpdate() {
+ m_KStarsData->setFullTimeUpdate();
+ updateTime();
+
+ m_SkyMapLite->forceUpdate();
+}
+
void KStarsLite::updateTime( const bool automaticDSTchange ) {
// Due to frequently use of this function save data and map pointers for speedup.
// Save options and geo() to a pointer would not speedup because most of time options
diff --git a/kstars/kstarslite.h b/kstars/kstarslite.h
index 83d3550..1e6ca9f 100644
--- a/kstars/kstarslite.h
+++ b/kstars/kstarslite.h
@@ -78,6 +78,9 @@ public:
/** @return pointer to KStarsData object which contains application data. */
inline KStarsData* data() const { return m_KStarsData; }
+ /** @short used from QML to update positions of sky objects and update SkyMapLite */
+ Q_INVOKABLE void fullUpdate();
+
signals:
/** Sent when KStarsData finishes loading data */
void dataLoadFinished();
diff --git a/kstars/kstarslite/qml/modules/BottomMenu.qml b/kstars/kstarslite/qml/modules/BottomMenu.qml
index 5e756cd..3519523 100644
--- a/kstars/kstarslite/qml/modules/BottomMenu.qml
+++ b/kstars/kstarslite/qml/modules/BottomMenu.qml
@@ -168,6 +168,11 @@ ColumnLayout {
}
TopMenuButton {
iconSrc: num.iconpath + "media-playback-start.png"
+ MouseArea {
+ onClicked: {
+ Options.setRunClock(false);
+ }
+ }
}
TopMenuButton {
iconSrc: num.iconpath + "media-skip-forward.png"
diff --git a/kstars/kstarslite/qml/modules/TopMenu.qml b/kstars/kstarslite/qml/modules/TopMenu.qml
index 41c7a29..e28daf7 100644
--- a/kstars/kstarslite/qml/modules/TopMenu.qml
+++ b/kstars/kstarslite/qml/modules/TopMenu.qml
@@ -86,13 +86,21 @@ ColumnLayout {
}
TopMenuButton {
iconSrc: num.iconpath + "/sc-actions-kstars_deepsky.png"
+ MouseArea {
+ anchors.fill: parent
+ onClicked: {
+ Options.showJupiter = !Options.showJupiter
+ KStarsLite.fullUpdate()
+ }
+ }
}
TopMenuButton {
iconSrc: num.iconpath + "/sc-actions-kstars_planets.png"
MouseArea {
anchors.fill: parent
onClicked: {
- Options.setShowSolarSystem(false);
+ Options.showSolarSystem = !Options.showSolarSystem
+ KStarsLite.fullUpdate()
}
}
}
@@ -109,9 +117,23 @@ ColumnLayout {
iconSrc: num.iconpath + "/sc-actions-kstars_mw.png"
}
TopMenuButton {
+ MouseArea {
+ anchors.fill: parent
+ onClicked: {
+ SkyMapLite.slotZoomIn()
+ KStarsLite.fullUpdate()
+ }
+ }
iconSrc: num.iconpath + "/sc-actions-kstars_grid.png"
}
TopMenuButton {
+ MouseArea {
+ anchors.fill: parent
+ onClicked: {
+ SkyMapLite.slotZoomOut()
+ KStarsLite.fullUpdate()
+ }
+ }
iconSrc: num.iconpath + "/sc-actions-kstars_horizon.png"
}
}
diff --git a/kstars/kstarslite/skyitems/nodes/planetmoonsnode.cpp b/kstars/kstarslite/skyitems/nodes/planetmoonsnode.cpp
new file mode 100644
index 0000000..3073db4
--- /dev/null
+++ b/kstars/kstarslite/skyitems/nodes/planetmoonsnode.cpp
@@ -0,0 +1,67 @@
+#include "planetnode.h"
+#include "pointsourcenode.h"
+#include "planetmoonsnode.h"
+#include "planetmoons.h"
+#include "ksplanetbase.h"
+
+PlanetMoonsNode::PlanetMoonsNode(KSPlanetBase* planet, RootNode* parentNode)
+ :SkyNode(planet), m_rootNode(parentNode), pmoons(0),
+ m_planetNode(new PlanetNode(planet, parentNode))
+{
+ appendChildNode(m_planetNode);
+}
+
+void PlanetMoonsNode::update() {
+ if(pmoons) updateMoons();
+ m_planetNode->update();
+}
+
+void PlanetMoonsNode::hide() {
+ m_planetNode->hide();
+
+ foreach(PointSourceNode *moon, m_moonNodes) {
+ moon->hide();
+ }
+}
+
+//TODO updateMoons and destructor
+void PlanetMoonsNode::updateMoons() {
+ //In order to get the z-order right for the moons and the planet,
+ //we need to first append the planet (both m_point and m_planetPic) then append all nodes for moons
+ //that are nearer than the planet and then prepend nodes for moons that are further than the planet
+ int nmoons = pmoons->nMoons();
+
+ 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));
+ }
+ }
+
+ removeAllChildNodes(); // Clear all child nodes so that we can render moons according to z-order
+
+ // We need to reappend node that draws the planet
+ appendChildNode(m_planetNode);
+
+ for ( int i=0; i<nmoons; ++i ) {
+ if ( pmoons->z(i) < 0.0 ) { //Moon is nearer than the planet
+ appendChildNode(m_moonNodes[i]);
+ m_moonNodes[i]->update();
+ } else {
+ //Draw Moons that are further than the planet
+ //skyp->drawPointSource( pmoons->moon(i), pmoons->moon(i)->mag() );
+ prependChildNode(m_moonNodes[i]);
+ m_moonNodes[i]->update();
+ }
+ }
+
+/* //Draw Moon name labels if at high zoom
+ /*if ( ! (Options::showPlanetNames() && Options::zoomFactor() > 50.*MINZOOM) ) return;
+ for ( int i=0; i<nmoons; ++i ) {
+ /*
+ if (planet ==KSPlanetBase::SATURN)
+ SkyLabeler::AddLabel( pmoons->moon(i), SkyLabeler::SATURN_MOON_LABEL );
+ else
+
+ SkyLabeler::AddLabel( pmoons->moon(i), SkyLabeler::JUPITER_MOON_LABEL );
+ }*/
+}
diff --git a/kstars/kstarslite/skyitems/nodes/planetmoonsnode.h b/kstars/kstarslite/skyitems/nodes/planetmoonsnode.h
new file mode 100644
index 0000000..de6e114
--- /dev/null
+++ b/kstars/kstarslite/skyitems/nodes/planetmoonsnode.h
@@ -0,0 +1,72 @@
+/** *************************************************************************
+ planetmoonsnode.h - K Desktop Planetarium
+ -------------------
+ begin : 24/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 PLANETMOONSNODE_H_
+#define PLANETMOONSNODE_H_
+#include "skynode.h"
+
+class PlanetNode;
+class PlanetMoons;
+class RootNode;
+class PointSourceNode;
+class KSPlanetBase;
+
+/** @class PlanetMoonsNode
+ *
+ * A SkyNode derived class used as a container for displaying a planet with its moons (if any). Unlike
+ * PlanetMoons in SkyComponents PlanetMoonsNode represents both planet and moons. Thus the planet has to
+ * be created only using this class that in turn will create an object of type PlanetNode. Although all
+ * SkyNodes are "movable" objects this class is just a container that provides z-order for moons and
+ * planets, which changes their positions on their own.
+ *
+ *@short A container for planets and moons that provides z-order.
+ *@author Artem Fedoskin
+ *@version 1.0
+ */
+
+class PlanetMoonsNode : public SkyNode {
+public:
+ PlanetMoonsNode(KSPlanetBase* planet, RootNode* parentNode);
+
+ /**
+ * @short Add object of type PlanetMoons to this node
+ * @param planetMoons PlanetMoons component
+ */
+ inline void addMoons(PlanetMoons * planetMoons) { pmoons = planetMoons; }
+
+ virtual void update() override;
+ virtual void hide() override;
+ /**
+ * @note PlanetMoonsNode is not meant to be moved. PlanetNode and PointSourceNodes handle this on
+ * their own.
+ */
+ virtual void changePos(QPointF pos) { }
+
+ /**
+ * @short update position of moons if planet has them
+ */
+ void updateMoons();
+
+private:
+ PlanetNode *m_planetNode;
+ PlanetMoons *pmoons;
+
+ QList<PointSourceNode *> m_moonNodes;
+ RootNode *m_rootNode;
+};
+
+
+#endif
+
diff --git a/kstars/kstarslite/skyitems/nodes/planetnode.cpp b/kstars/kstarslite/skyitems/nodes/planetnode.cpp
index 66fc47f..297f3d7 100644
--- a/kstars/kstarslite/skyitems/nodes/planetnode.cpp
+++ b/kstars/kstarslite/skyitems/nodes/planetnode.cpp
@@ -22,7 +22,9 @@
#include "ksplanetbase.h"
#include "Options.h"
#include "projections/projector.h"
+
#include "planetnode.h"
+#include "pointnode.h"
PlanetNode::PlanetNode(KSPlanetBase* pb, RootNode* parentNode)
:SkyNode(pb), m_planetPic(new QSGSimpleTextureNode), m_planetOpacity(new QSGOpacityNode)
@@ -40,8 +42,8 @@ PlanetNode::PlanetNode(KSPlanetBase* pb, RootNode* parentNode)
m_point = new PointNode(parentNode, spType);
appendChildNode(m_point);
-
appendChildNode(m_planetOpacity);
+
//Add planet to opacity node so that we could hide the planet
m_planetOpacity->appendChildNode(m_planetPic);
m_planetPic->setTexture(SkyMapLite::Instance()->window()->createTextureFromImage(
@@ -49,56 +51,51 @@ PlanetNode::PlanetNode(KSPlanetBase* pb, RootNode* parentNode)
}
void PlanetNode::update() {
- if(0) {
- //if(!pNode->planet()->select) {
- // pNode->hide(); //TODO
- } else {
- KSPlanetBase * planet = static_cast<KSPlanetBase *>(m_skyObject);
- const Projector * proj = projector();
+ KSPlanetBase * planet = static_cast<KSPlanetBase *>(m_skyObject);
+ const Projector * proj = projector();
- if( !proj->checkVisibility(planet) ) {
- hide();
- return;
- }
+ if( !proj->checkVisibility(planet) ) {
+ hide();
+ return;
+ }
- bool visible = false;
- QPointF pos = proj->toScreen(planet,true,&visible);
- if( !visible || !proj->onScreen(pos) ) {
- hide();
- return;
- }
- float fakeStarSize = ( 10.0 + log10( Options::zoomFactor() ) - log10( MINZOOM ) ) * ( 10 - planet->mag() ) / 10;
- if( fakeStarSize > 15.0 )
- fakeStarSize = 15.0;
+ bool visible = false;
+ QPointF pos = proj->toScreen(planet,true,&visible);
+ if( !visible || !proj->onScreen(pos) ) {
+ hide();
+ return;
+ }
+ float fakeStarSize = ( 10.0 + log10( Options::zoomFactor() ) - log10( MINZOOM ) ) * ( 10 - planet->mag() ) / 10;
+ if( fakeStarSize > 15.0 )
+ fakeStarSize = 15.0;
+
+ float size = planet->angSize() * dms::PI * Options::zoomFactor()/10800.0;
+ if( size < fakeStarSize && planet->name() != "Sun" && planet->name() != "Moon" ) {
+ setPointSize(fakeStarSize);
+ changePos(pos);
+ showPoint();
+ } else {
+ float sizemin = 1.0;
+ if( planet->name() == "Sun" || planet->name() == "Moon" )
+ sizemin = 8.0;
float size = planet->angSize() * dms::PI * Options::zoomFactor()/10800.0;
- if( size < fakeStarSize && planet->name() != "Sun" && planet->name() != "Moon" ) {
- setPointSize(fakeStarSize);
+ if( size < sizemin )
+ size = sizemin;
+ //Options::showPlanetImages() &&
+ if( !planet->image().isNull() ) {
+ //Because Saturn has rings, we inflate its image size by a factor 2.5
+ if( planet->name() == "Saturn" )
+ size = int(2.5*size);
+ // Scale size exponentially so it is visible at large zooms
+ else if (planet->name() == "Pluto")
+ size = int(size*exp(1.5*size));
+
+ setPlanetPicSize(size);
changePos(pos);
- showPoint();
- } else {
- float sizemin = 1.0;
- if( planet->name() == "Sun" || planet->name() == "Moon" )
- sizemin = 8.0;
-
- float size = planet->angSize() * dms::PI * Options::zoomFactor()/10800.0;
- if( size < sizemin )
- size = sizemin;
- //Options::showPlanetImages() &&
- if( !planet->image().isNull() ) {
- //Because Saturn has rings, we inflate its image size by a factor 2.5
- if( planet->name() == "Saturn" )
- size = int(2.5*size);
- // Scale size exponentially so it is visible at large zooms
- else if (planet->name() == "Pluto")
- size = int(size*exp(1.5*size));
-
- setPlanetPicSize(size);
- changePos(pos);
- showPlanetPic();
- } else { //Otherwise, draw a simple circle.
- //drawEllipse( pos, size, size );
- }
+ showPlanetPic();
+ } else { //Otherwise, draw a simple circle. Do we need it?
+ //drawEllipse( pos, size, size );
}
}
}
diff --git a/kstars/kstarslite/skyitems/nodes/planetnode.h b/kstars/kstarslite/skyitems/nodes/planetnode.h
index de9b7b2..eba84b2 100644
--- a/kstars/kstarslite/skyitems/nodes/planetnode.h
+++ b/kstars/kstarslite/skyitems/nodes/planetnode.h
@@ -15,15 +15,13 @@
***************************************************************************/
#ifndef PLANETNODE_H_
#define PLANETNODE_H_
-#include <QSGNode>
-#include "pointnode.h"
#include "skynode.h"
class QSGSimpleTextureNode;
class QImage;
class KSPlanetBase;
class RootNode;
-
+class PointNode;
/** @class PlanetNode
*
@@ -70,14 +68,15 @@ public:
virtual void changePos(QPointF pos) override;
virtual void update() override;
+
virtual void hide() override;
private:
- PointNode* m_point;
+ PointNode *m_point;
// This opacity node is used to hide m_planetPic. m_point is subclass of QSGOpacityNode so it needs
// no explicit opacity node here.
- QSGOpacityNode* m_planetOpacity;
- QSGSimpleTextureNode* m_planetPic;
+ QSGOpacityNode *m_planetOpacity;
+ QSGSimpleTextureNode *m_planetPic;
};
diff --git a/kstars/kstarslite/skyitems/nodes/pointsourcenode.cpp b/kstars/kstarslite/skyitems/nodes/pointsourcenode.cpp
index 69a70cf..450fb42 100644
--- a/kstars/kstarslite/skyitems/nodes/pointsourcenode.cpp
+++ b/kstars/kstarslite/skyitems/nodes/pointsourcenode.cpp
@@ -26,7 +26,7 @@
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
{
- m_point = new PointNode(p,sp,starWidth(size));
+ m_point = new PointNode(p,starWidth(size),sp);
appendChildNode(m_point);
}
diff --git a/kstars/kstarslite/skyitems/nodes/rootnode.cpp b/kstars/kstarslite/skyitems/nodes/rootnode.cpp
index a909b08..49dc267 100644
--- a/kstars/kstarslite/skyitems/nodes/rootnode.cpp
+++ b/kstars/kstarslite/skyitems/nodes/rootnode.cpp
@@ -35,11 +35,21 @@ QSGTexture* RootNode::getCachedTexture(int size, char spType) {
return m_textureCache[SkyMapLite::Instance()->harvardToIndex(spType)][size];
}
-void RootNode::appendSkyNode(SkyNode * skyNode) {
+void RootNode::appendSkyNode(SkyNode *skyNode) {
m_skyNodes.append(skyNode);
appendChildNode(skyNode);
}
+void RootNode::prependSkyNode(SkyNode *skyNode) {
+ m_skyNodes.append(skyNode);
+ prependChildNode(skyNode);
+}
+
+void RootNode::removeSkyNode(SkyNode *skyNode) {
+ removeChildNode(skyNode);
+ m_skyNodes.removeOne(skyNode);
+}
+
void RootNode::removeAllSkyNodes() {
for(int i = 0; i < m_skyNodes.length(); ++i) {
removeChildNode(m_skyNodes[i]);
diff --git a/kstars/kstarslite/skyitems/nodes/rootnode.h b/kstars/kstarslite/skyitems/nodes/rootnode.h
index 0c5e210..e8c045c 100644
--- a/kstars/kstarslite/skyitems/nodes/rootnode.h
+++ b/kstars/kstarslite/skyitems/nodes/rootnode.h
@@ -57,17 +57,25 @@ public:
inline int skyNodesCount() { return m_skyNodes.length(); }
/**
- * @short returns a SkyNode in m_skyNodes with i index
+ * @short returns a SkyNode in m_skyNodes with index i
* @param i index of SkyNode
* @return desired SkyNode
*/
- inline SkyNode * skyNodeAtIndex(int i) { return m_skyNodes[i]; }
+ inline SkyNode *skyNodeAtIndex(int i) { return m_skyNodes[i]; }
/**
* @brief Adds node to m_skyNodes and node tree
* @param skyNode pointer to skyNode that has to be added
*/
- void appendSkyNode(SkyNode * skyNode);
+ void appendSkyNode(SkyNode *skyNode);
+
+ void prependSkyNode(SkyNode *skyNode);
+
+ /**
+ * @short remove given skyNode from m_skyNodes and a node tree
+ * @param skyNode pointer to skyNode that needs to be deleted
+ */
+ void removeSkyNode(SkyNode *skyNode);
/**
* @short deletes all SkyNodes from m_skyNodes and node tree
diff --git a/kstars/kstarslite/skyitems/nodes/skynode.h b/kstars/kstarslite/skyitems/nodes/skynode.h
index 90e6147..5954e50 100644
--- a/kstars/kstarslite/skyitems/nodes/skynode.h
+++ b/kstars/kstarslite/skyitems/nodes/skynode.h
@@ -44,6 +44,10 @@ public:
/** @short short function that returns pointer to the current projector
* @return pointer to current projector of SkyMapLite
*/
+
+ // All children nodes allocated on heap are deleted automatically
+ //virtual ~SkyNode() { }
+
inline const Projector* projector() { return SkyMapLite::Instance()->projector(); }
/** @short short function to access SkyMapLite
diff --git a/kstars/kstarslite/skyitems/planetsitem.cpp b/kstars/kstarslite/skyitems/planetsitem.cpp
index b46cfde..32f810d 100644
--- a/kstars/kstarslite/skyitems/planetsitem.cpp
+++ b/kstars/kstarslite/skyitems/planetsitem.cpp
@@ -18,7 +18,9 @@
#include "projections/projector.h"
#include "solarsystemsinglecomponent.h"
#include "ksplanet.h"
+#include "planetmoonscomponent.h"
+#include "nodes/planetmoonsnode.h"
#include "nodes/planetnode.h"
#include "nodes/rootnode.h"
@@ -31,8 +33,15 @@ PlanetsItem::PlanetsItem(QQuickItem* parent)
}
void PlanetsItem::addPlanet(SolarSystemSingleComponent* planetComp) {
- if(!m_planetComponents.contains(planetComp) && !m_toAdd.contains(planetComp))
- m_toAdd.append(planetComp);
+ if(!m_planetComponents.contains(planetComp) && !m_planetsToAdd.contains(planetComp)) {
+ m_planetsToAdd.append(planetComp);
+ }
+}
+
+void PlanetsItem::addMoons(PlanetMoonsComponent * moonsComponent) {
+ if(!m_moonsComponents.contains(moonsComponent) && !m_moonsToAdd.contains(moonsComponent)) {
+ m_moonsToAdd.append(moonsComponent);
+ }
}
SolarSystemSingleComponent * PlanetsItem::getParentComponent(SkyObject * planet) {
@@ -57,26 +66,59 @@ QSGNode* PlanetsItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *upd
int pCompLen = m_planetComponents.length();
if(pCompLen > 0) {
/* If there are some planets that have been already displayed once then recreate them
- in new instance of PlanetRootNode*/
- for(int i = 0; i < pCompLen; ++i) {
- n->appendSkyNode(new PlanetNode(m_planetComponents[i]->planet(), n));
+ in the new instance of RootNode*/
+ int mCompLen = m_moonsComponents.length();
+ foreach(SolarSystemSingleComponent * planetComp, m_planetComponents) {
+ KSPlanetBase *planet = planetComp->planet();
+ PlanetMoonsNode *pNode = new PlanetMoonsNode(planet, n);
+ n->appendSkyNode(pNode);
+ /* If there are some moons that have been already displayed once then recreate them
+ in the new instance of RootNode*/
+ if(mCompLen > 0) {
+ foreach(PlanetMoonsComponent * moonsComp, m_moonsComponents) {
+ // Find planet of moons
+ if(planet == moonsComp->getPlanet()) {
+ pNode->addMoons(moonsComp->getMoons());
+ }
+ }
+ }
}
}
}
- int addLength = m_toAdd.length();
- if(addLength > 0) { // If there are some new planets to add
- for(int i = 0; i < addLength; ++i) {
- m_planetComponents.append(m_toAdd[i]);
- n->appendSkyNode(new PlanetNode(m_toAdd[i]->planet(), n));
+ int addPlanetLen = m_planetsToAdd.length();
+ if(addPlanetLen > 0) { // If there are some new planets to add
+ foreach(SolarSystemSingleComponent * planetComp, m_planetsToAdd) {
+ m_planetComponents.append(planetComp);
+
+ KSPlanetBase *planet = planetComp->planet();
+ PlanetMoonsNode *pNode = new PlanetMoonsNode(planet, n);
+ n->appendSkyNode(pNode);
}
- m_toAdd.clear();
+ m_planetsToAdd.clear();
}
+
+ int addMoonLen = m_moonsToAdd.length();
+
//Update clipping geometry. If m_clipPoly in SkyMapLite wasn't changed, geometry is not updated
n->updateClipPoly();
//Traverse all children nodes of RootNode
for(int i = 0; i < n->skyNodesCount(); ++i) {
- PlanetNode* pNode = static_cast<PlanetNode*>(n->skyNodeAtIndex(i));
+ PlanetMoonsNode *pNode = static_cast<PlanetMoonsNode *>(n->skyNodeAtIndex(i));
+
+ SkyObject * planet = pNode->getSkyObject();
+
+ if(addMoonLen > 0) { // If there are moons to add
+ foreach(PlanetMoonsComponent * moonsComp, m_moonsToAdd) {
+ if(planet == moonsComp->getPlanet()) {
+ pNode->addMoons(moonsComp->getMoons());
+
+ m_moonsComponents.append(moonsComp);
+ m_moonsToAdd.removeOne(moonsComp);
+ }
+ }
+ }
+
bool selected = getParentComponent(pNode->getSkyObject())->selected();
if(selected) pNode->update();
else pNode->hide();
diff --git a/kstars/kstarslite/skyitems/planetsitem.h b/kstars/kstarslite/skyitems/planetsitem.h
index 562d6f0..2aeb6e4 100644
--- a/kstars/kstarslite/skyitems/planetsitem.h
+++ b/kstars/kstarslite/skyitems/planetsitem.h
@@ -19,13 +19,13 @@
#include "skyitem.h"
class SolarSystemSingleComponent;
+class PlanetMoonsComponent;
class SkyObject;
-
class PlanetsItem : public SkyItem {
public:
PlanetsItem(QQuickItem* parent = 0);
- /** Adds an object of type SolarSystemSingleComponent to m_toAdd. In the next call to
+ /** Add a pointer to an object of type SolarSystemSingleComponent to m_toAdd. In the next call to
* updatePaintNode() the object of type PlanetNode will be created and planetComponent
* will be moved to m_planetComponents. PlanetNode represents graphically KSPlanetBase on SkyMapLite.
* This function should be called whenever an object of class SolarSystemSingleComponent is
@@ -36,12 +36,23 @@ public:
void addPlanet(SolarSystemSingleComponent* planetComp);
+ /**
+ * Add a pointer to an object of type PlanetMoonsComponent to m_moonsToAdd. In the next call to
+ * updatePaintNode() PlanetMoons will be added to existing PlanetMoonsNode, which will then control
+ * the drawing of moons and planet.
+ * @param pMoons pointer to PlanetMoonsComponent which moons should be displayed on SkyMapLite
+ */
+ void addMoons(PlanetMoonsComponent * pMoons);
+
SolarSystemSingleComponent * getParentComponent(SkyObject * planet);
protected:
virtual QSGNode* updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData) override;
private:
- QList<SolarSystemSingleComponent*> m_planetComponents;
- QList<SolarSystemSingleComponent*> m_toAdd;
+ QList<SolarSystemSingleComponent *> m_planetComponents;
+ QList<SolarSystemSingleComponent *> m_planetsToAdd;
+
+ QList<PlanetMoonsComponent *> m_moonsComponents;
+ QList<PlanetMoonsComponent *> m_moonsToAdd;
};
#endif
diff --git a/kstars/main.cpp b/kstars/main.cpp
index c4590dc..9cf400a 100644
--- a/kstars/main.cpp
+++ b/kstars/main.cpp
@@ -317,6 +317,8 @@ int main(int argc, char *argv[])
Options::setXplanetBackgroundColorValue("#000000");
Options::setXplanetColor("#ff0000");
#endif
+ Options::setShowGround(false);
+
#endif
// Create writable data dir if it does not exist
diff --git a/kstars/skycomponents/equator.h b/kstars/skycomponents/equator.h
index ae22a58..213f255 100644
--- a/kstars/skycomponents/equator.h
+++ b/kstars/skycomponents/equator.h
@@ -42,7 +42,7 @@ public:
virtual bool selected();
virtual void draw( SkyPainter *skyp );
virtual void drawCompassLabels();
- virtual LineListLabel* label() {return &m_label;};
+ virtual LineListLabel* label() {return &m_label;}
protected:
virtual void preDraw( SkyPainter *skyp );
diff --git a/kstars/skycomponents/planetmoonscomponent.cpp b/kstars/skycomponents/planetmoonscomponent.cpp
index f12ecdf..309641c 100644
--- a/kstars/skycomponents/planetmoonscomponent.cpp
+++ b/kstars/skycomponents/planetmoonscomponent.cpp
@@ -23,7 +23,9 @@
#include "skyobjects/jupitermoons.h"
#include "skyobjects/ksplanetbase.h"
#include "kstarsdata.h"
-#ifndef KSTARS_LITE
+#ifdef KSTARS_LITE
+#include "skymaplite.h"
+#else
#include "skymap.h"
#endif
#include "skyobjects/skypoint.h"
@@ -57,6 +59,11 @@ PlanetMoonsComponent::PlanetMoonsComponent( SkyComposite *p,
int nmoons = pmoons->nMoons();
for ( int i=0; i<nmoons; ++i )
objectNames(SkyObject::MOON).append( pmoons->name(i) );
+
+#ifdef KSTARS_LITE
+ SkyMapLite *map = SkyMapLite::Instance();
+ map->addPlanetMoons(this);
+#endif
}
PlanetMoonsComponent::~PlanetMoonsComponent()
@@ -96,6 +103,12 @@ SkyObject* PlanetMoonsComponent::findByName( const QString &name ) {
return 0;
}
+#ifdef KSTARS_LITE
+KSPlanetBase* PlanetMoonsComponent::getPlanet() const {
+ return m_Planet->planet();
+}
+#endif
+
SkyObject* PlanetMoonsComponent::objectNearest( SkyPoint *p, double &maxrad ) {
SkyObject *oBest = 0;
int nmoons = pmoons->nMoons();
diff --git a/kstars/skycomponents/planetmoonscomponent.h b/kstars/skycomponents/planetmoonscomponent.h
index 51d785f..349b4cb 100644
--- a/kstars/skycomponents/planetmoonscomponent.h
+++ b/kstars/skycomponents/planetmoonscomponent.h
@@ -67,6 +67,14 @@ public:
*/
SkyObject* findByName( const QString &name );
+#ifdef KSTARS_LITE
+ /** Return pointer to stored planet object. */
+ KSPlanetBase* getPlanet() const;
+
+ /** Return pointer to stored moons object. */
+ inline PlanetMoons* getMoons() const { return pmoons; }
+#endif
+
protected:
virtual void drawTrails( SkyPainter* skyp );
diff --git a/kstars/skycomponents/solarsystemsinglecomponent.cpp b/kstars/skycomponents/solarsystemsinglecomponent.cpp
index f74263e..f918124 100644
--- a/kstars/skycomponents/solarsystemsinglecomponent.cpp
+++ b/kstars/skycomponents/solarsystemsinglecomponent.cpp
@@ -51,7 +51,7 @@ SolarSystemSingleComponent::SolarSystemSingleComponent(SolarSystemComposite *par
objectNames(m_Planet->type()).append( m_Planet->longname() );
//Draw planet on the SkyMapLite
#ifdef KSTARS_LITE
- SkyMapLite::Instance()->addPlanetItem(this);
+ SkyMapLite::Instance()->addPlanet(this);
#endif
}
diff --git a/kstars/skymaplite.cpp b/kstars/skymaplite.cpp
index fa00922..e799973 100644
--- a/kstars/skymaplite.cpp
+++ b/kstars/skymaplite.cpp
@@ -87,7 +87,7 @@ int SkyMapLite::starColorMode = 0;
SkyMapLite::SkyMapLite(QQuickItem* parent)
:QQuickItem(parent), m_proj(0), count(0), data(KStarsData::Instance()),
nStarSizes(15), nSPclasses(7), m_planetsItem(new PlanetsItem(this)),
- m_asteroidsItem(new AsteroidsItem(this)), m_cometsItem(new CometsItem(this))
+ m_asteroidsItem(new AsteroidsItem(this)), m_cometsItem(new CometsItem(this)), pinch(false)
{
setAcceptHoverEvents(true);
setAcceptedMouseButtons(Qt::AllButtons);
@@ -207,6 +207,103 @@ void SkyMapLite::setFocusObject( SkyObject *o ) {
Options::setFocusObject( i18n( "nothing" ) );
}
+void SkyMapLite::slewFocus() {
+ //Don't slew if the mouse button is pressed
+ //Also, no animated slews if the Manual Clock is active
+ //08/2002: added possibility for one-time skipping of slew with snapNextFocus
+ if ( !mouseButtonDown ) {
+ bool goSlew = ( Options::useAnimatedSlewing() && ! data->snapNextFocus() ) &&
+ !( data->clock()->isManualMode() && data->clock()->isActive() );
+ if ( goSlew ) {
+ double dX, dY;
+ double maxstep = 10.0;
+ if ( Options::useAltAz() ) {
+ dX = destination()->az().Degrees() - focus()->az().Degrees();
+ dY = destination()->alt().Degrees() - focus()->alt().Degrees();
+ } else {
+ dX = destination()->ra().Degrees() - focus()->ra().Degrees();
+ dY = destination()->dec().Degrees() - focus()->dec().Degrees();
+ }
+
+ //switch directions to go the short way around the celestial sphere, if necessary.
+ dX = KSUtils::reduceAngle(dX, -180.0, 180.0);
+
+ double r0 = sqrt( dX*dX + dY*dY );
+ if ( r0 < 20.0 ) { //smaller slews have smaller maxstep
+ maxstep *= (10.0 + 0.5*r0)/20.0;
+ }
+ double step = 0.5;
+ double r = r0;
+ while ( r > step ) {
+ //DEBUG
+ //qDebug() << step << ": " << r << ": " << r0 << endl;
+ double fX = dX / r;
+ double fY = dY / r;
+
+ if ( Options::useAltAz() ) {
+ focus()->setAlt( focus()->alt().Degrees() + fY*step );
+ focus()->setAz( dms( focus()->az().Degrees() + fX*step ).reduce() );
+ focus()->HorizontalToEquatorial( data->lst(), data->geo()->lat() );
+ } else {
+ fX = fX/15.; //convert RA degrees to hours
+ SkyPoint newFocus( focus()->ra().Hours() + fX*step, focus()->dec().Degrees() + fY*step );
+ setFocus( &newFocus );
+ focus()->EquatorialToHorizontal( data->lst(), data->geo()->lat() );
+ }
+
+ slewing = true;
+
+ forceUpdate();
+ qApp->processEvents(); //keep up with other stuff
+
+ if ( Options::useAltAz() ) {
+ dX = destination()->az().Degrees() - focus()->az().Degrees();
+ dY = destination()->alt().Degrees() - focus()->alt().Degrees();
+ } else {
+ dX = destination()->ra().Degrees() - focus()->ra().Degrees();
+ dY = destination()->dec().Degrees() - focus()->dec().Degrees();
+ }
+
+ //switch directions to go the short way around the celestial sphere, if necessary.
+ dX = KSUtils::reduceAngle(dX, -180.0, 180.0);
+ r = sqrt( dX*dX + dY*dY );
+
+ //Modify step according to a cosine-shaped profile
+ //centered on the midpoint of the slew
+ //NOTE: don't allow the full range from -PI/2 to PI/2
+ //because the slew will never reach the destination as
+ //the speed approaches zero at the end!
+ double t = dms::PI*(r - 0.5*r0)/(1.05*r0);
+ step = cos(t)*maxstep;
+ }
+ }
+
+ //Either useAnimatedSlewing==false, or we have slewed, and are within one step of destination
+ //set focus=destination.
+ if ( Options::useAltAz() ) {
+ setFocusAltAz( destination()->alt(), destination()->az() );
+ focus()->HorizontalToEquatorial( data->lst(), data->geo()->lat() );
+ } else {
+ setFocus( destination() );
+ focus()->EquatorialToHorizontal( data->lst(), data->geo()->lat() );
+ }
+
+ slewing = false;
+
+ //Turn off snapNextFocus, we only want it to happen once
+ if ( data->snapNextFocus() ) {
+ data->setSnapNextFocus(false);
+ }
+
+ //Start the HoverTimer. if the user leaves the mouse in place after a slew,
+ //we want to attach a label to the nearest object.
+ if ( Options::useHoverLabel() )
+ m_HoverTimer.start( HOVER_INTERVAL );
+
+ forceUpdate();
+ }
+}
+
void SkyMapLite::slotClockSlewing() {
//If the current timescale exceeds slewTimeScale, set clockSlewing=true, and stop the clock.
if( (fabs( data->clock()->scale() ) > Options::slewTimeScale()) ^ clockSlewing ) {
@@ -254,8 +351,12 @@ void SkyMapLite::slotClockSlewing() {
}
}*/
-void SkyMapLite::addPlanetItem(SolarSystemSingleComponent* parentComp) {
- m_planetsItem->addPlanet(parentComp);
+void SkyMapLite::addPlanet(SolarSystemSingleComponent *planetComp) {
+ m_planetsItem->addPlanet(planetComp);
+}
+
+void SkyMapLite::addPlanetMoons(PlanetMoonsComponent *moonsComp) {
+ m_planetsItem->addMoons(moonsComp);
}
void SkyMapLite::resizeItem() {
@@ -284,9 +385,22 @@ void SkyMapLite::setZoomFactor(double factor) {
void SkyMapLite::forceUpdate() {
setupProjector();
- m_planetsItem->update();
- m_asteroidsItem->update();
- m_cometsItem->update();
+
+ //TODO: Move this check somewhere else (create a separate function)
+ if(Options::showSolarSystem()) {
+ if(!m_planetsItem->property("visible").toBool()) {
+ m_planetsItem->setVisible(true);
+ m_asteroidsItem->setVisible(true);
+ m_cometsItem->setVisible(true);
+ }
+ m_planetsItem->update();
+ m_asteroidsItem->update();
+ m_cometsItem->update();
+ } else {
+ m_planetsItem->setVisible(false);
+ m_asteroidsItem->setVisible(false);
+ m_cometsItem->setVisible(false);
+ }
}
void SkyMapLite::setupProjector() {
diff --git a/kstars/skymaplite.h b/kstars/skymaplite.h
index 2ed936e..4f0b8f9 100644
--- a/kstars/skymaplite.h
+++ b/kstars/skymaplite.h
@@ -35,6 +35,7 @@ class SolarSystemSingleComponent;
class PlanetsItem;
class AsteroidsItem;
class CometsItem;
+class PlanetMoonsComponent;
class QSGTexture;
@@ -228,10 +229,17 @@ public:
*/
void setZoomFactor(double factor);
- /** @short Adds object of type KSPlanetBase to the PlanetsItem
- *@param parentComp pointer to the KSPlanetBase that is to be displayed on SkyMapLite
+ /** @short Adds object of type SolarSystemSingleComponent that needs to be displayed on
+ * SkyMapLite to PlanetsItem
+ *@param planetComp pointer to object of type SolarSystemSingleComponent
*/
- void addPlanetItem(SolarSystemSingleComponent* parentComp);
+ void addPlanet(SolarSystemSingleComponent *planetComp);
+
+ /** @short Adds object of type PlanetMoonsComponent that needs to be displayed on
+ * SkyMapLite to PlanetsItem
+ *@param moonsComp pointer to object of type PlanetMoonsComponent
+ */
+ void addPlanetMoons(PlanetMoonsComponent *moonsComp);
/** @short Call to set up the projector before update of SkyItems positions begins. */
void setupProjector();
@@ -339,7 +347,7 @@ public slots:
* Map after each step, until the Focus point is within 1 step of the Destination point.
* For the final step, snap directly to Destination, and redraw the map.
*/
- //void slewFocus();
+ void slewFocus();
/** @short Center the display at the point ClickedPoint.
*
@@ -540,6 +548,8 @@ private:
// true if mouseMoveEvent; needed by setMouseMoveCursor
bool mouseMoveCursor;
bool slewing, clockSlewing;
+ // true if pinch to zoom or pinch to rotate is performed
+ bool pinch;
//if false only old pixmap will repainted with bitBlt(), this
// saves a lot of cpu usage
bool computeSkymap;
diff --git a/kstars/skymaplitevents.cpp b/kstars/skymaplitevents.cpp
index 1f961cd..258ca4a 100644
--- a/kstars/skymaplitevents.cpp
+++ b/kstars/skymaplitevents.cpp
@@ -2,6 +2,8 @@
#include "kstarsdata.h"
#include "kstarslite.h"
+#include <QtMath>
+
#include "kstarslite/skyitems/planetsitem.h"
#include "Options.h"
#include "projections/projector.h"
@@ -48,17 +50,17 @@ void SkyMapLite::mousePressEvent( QMouseEvent *e ) {
switch( e->button() ) {
case Qt::LeftButton:
- {
- QString name;
- if( clickedObject() )
- name = clickedObject()->translatedLongName();
- else
- name = i18n( "Empty sky" );
- //kstars->statusBar()->changeItem(name, 0 );
- //kstars->statusBar()->showMessage(name, 0 );
-
- emit positionClicked(&m_MousePoint);
- }
+ {
+ QString name;
+ if( clickedObject() )
+ name = clickedObject()->translatedLongName();
+ else
+ name = i18n( "Empty sky" );
+ //kstars->statusBar()->changeItem(name, 0 );
+ //kstars->statusBar()->showMessage(name, 0 );
+
+ emit positionClicked(&m_MousePoint);
+ }
break;
case Qt::RightButton:
@@ -66,13 +68,13 @@ void SkyMapLite::mousePressEvent( QMouseEvent *e ) {
// Compute angular distance.
slotEndRulerMode();
} else {*/
- // Show popup menu
- if( clickedObject() ) {
- //clickedObject()->showPopupMenu( pmenu, QCursor::pos() );
- } else {
- /* pmenu->createEmptyMenu( clickedPoint() );
+ // Show popup menu
+ if( clickedObject() ) {
+ //clickedObject()->showPopupMenu( pmenu, QCursor::pos() );
+ } else {
+ /* pmenu->createEmptyMenu( clickedPoint() );
pmenu->popup( QCursor::pos() );*/
- }
+ }
//}
break;
default: ;
@@ -180,10 +182,10 @@ void SkyMapLite::mouseMoveEvent( QMouseEvent *e ) {
// set the mouseMoveCursor and set slewing=true, if they are not set yet
if( !mouseMoveCursor )
//setMouseMoveCursor();
- if( !slewing ) {
- slewing = true;
- //stopTracking(); //toggle tracking off
- }
+ if( !slewing ) {
+ slewing = true;
+ //stopTracking(); //toggle tracking off
+ }
//Update focus such that the sky coords at mouse cursor remain approximately constant
if ( Options::useAltAz() ) {
@@ -194,7 +196,7 @@ void SkyMapLite::mouseMoveEvent( QMouseEvent *e ) {
focus()->setAz( focus()->az().Degrees() - dAz.Degrees() ); //move focus in opposite direction
focus()->setAz( focus()->az().reduce() );
focus()->setAlt(
- KSUtils::clamp( focus()->alt().Degrees() - dAlt.Degrees() , -90.0 , 90.0 ) );
+ KSUtils::clamp( focus()->alt().Degrees() - dAlt.Degrees() , -90.0 , 90.0 ) );
focus()->HorizontalToEquatorial( data->lst(), data->geo()->lat() );
} else {
dms dRA = m_MousePoint.ra() - clickedPoint()->ra();
@@ -202,7 +204,7 @@ void SkyMapLite::mouseMoveEvent( QMouseEvent *e ) {
focus()->setRA( focus()->ra().Hours() - dRA.Hours() ); //move focus in opposite direction
focus()->setRA( focus()->ra().reduce() );
focus()->setDec(
- KSUtils::clamp( focus()->dec().Degrees() - dDec.Degrees() , -90.0 , 90.0 ) );
+ KSUtils::clamp( focus()->dec().Degrees() - dDec.Degrees() , -90.0 , 90.0 ) );
focus()->EquatorialToHorizontal( data->lst(), data->geo()->lat() );
}
//showFocusCoords();
@@ -228,54 +230,116 @@ void SkyMapLite::wheelEvent( QWheelEvent *e ) {
}
void SkyMapLite::touchEvent( QTouchEvent *e) {
- //Under construction. Don't take this mess seriously
- qDebug() << "TOUCH EVENT!";
-
QList<QTouchEvent::TouchPoint> points = e->touchPoints();
- QPointF newPoint = points[0].pos();
+ if(points.length() == 2) {
+ if ( projector()->unusablePoint( points[0].pos() ) ||
+ projector()->unusablePoint( points[1].pos() ))
+ return;
- if(points.length() >= 2) {
- double xdiff = abs(points[1].pos().x() - points[0].pos().x());
- double ydiff = abs(points[1].pos().y() - points[0].pos().y());
- double xmax = points[1].pos().x() < points[0].pos().x() ? points[1].pos().x() : points[0].pos().x();
- double ymax = points[1].pos().y() < points[0].pos().y() ? points[1].pos().y() : points[0].pos().y();
- double md_new = xdiff + ydiff;
- qDebug() << md_new << "MD NEW";
+ //Pinch to zoom
- double xolddiff = abs(points[1].lastPos().x() - points[0].lastPos().x());
- double yolddiff = abs(points[1].lastPos().y() - points[0].lastPos().y());
- double md_old = xolddiff + yolddiff;
- qDebug() << xolddiff + yolddiff << "MD OLD";
+ double x_old_diff = abs(points[1].lastPos().x() - points[0].lastPos().x());
+ double y_old_diff = abs(points[1].lastPos().y() - points[0].lastPos().y());
- if(md_old - md_new < 0) zoomInOrMagStep(Qt::ControlModifier);
- else if(md_old - md_new > 0) zoomOutOrMagStep(Qt::ControlModifier);
- qDebug() << Options::showGround();
- qDebug() << "NEW1" << points[0].pos() << "MID" << QPointF(xmax+ xdiff/2,ymax + ydiff/2) << "NEW2" << points[1].pos();
+ //Manhattan distance of old points
+ double md_old = x_old_diff + y_old_diff;
- //newPoint = QPointF(xmax + xdiff/2,ymax + ydiff/2);
- }
+ double x_diff = abs(points[1].pos().x() - points[0].pos().x());
+ double y_diff = abs(points[1].pos().y() - points[0].pos().y());
+
+ //Manhattan distance of new points
+ double md_new = x_diff + y_diff;
+
+ int zoomThreshold = 5;
+
+ if(md_old - md_new < -zoomThreshold) zoomInOrMagStep(Qt::MetaModifier);
+ else if(md_old - md_new > zoomThreshold) zoomOutOrMagStep(Qt::MetaModifier);
+
+ double x_min = points[1].pos().x() < points[0].pos().x() ? points[1].pos().x() : points[0].pos().x();
+ double y_min = points[1].pos().y() < points[0].pos().y() ? points[1].pos().y() : points[0].pos().y();
+
+ //Center point on the line between 2 touch points used for moveEvent
+ QPointF pinchCenter(x_min + x_diff/2,y_min + y_diff/2);
+
+ //Pinch(turn) to rotate
+ QPointF old_vec = points[1].lastPos() - points[0].lastPos();
+ QPointF new_vec = points[1].pos() - points[0].pos();
- //This is ugly but it reduces the amount of duplicate code
- QMouseEvent *event = new QMouseEvent(QEvent::MouseButtonPress, newPoint,
- Qt::LeftButton, Qt::LeftButton, Qt::ControlModifier);
- mousePressEvent(event);
- mouseMoveEvent(event);
+ double old_vec_len = sqrt((old_vec.x() * old_vec.x()) + (old_vec.y() * old_vec.y()));
+ double new_vec_len = sqrt((new_vec.x() * new_vec.x()) + (new_vec.y() * new_vec.y()));
- if(e->type() == QEvent::TouchEnd) {
- if (mouseButtonDown) {
+ //Normalize vectors
+ old_vec = QPointF(old_vec.x()/old_vec_len, old_vec.y()/old_vec_len);
+ new_vec = QPointF(new_vec.x()/new_vec_len, new_vec.y()/new_vec_len);
+
+ if(rotation() > 360) {
+ setRotation(0);
+ } else if(rotation() < 0) {
+ setRotation(360);
+ }
+
+ double old_atan = qAtan2(old_vec.y(), old_vec.x());
+ double new_atan = qAtan2(new_vec.y(), new_vec.x());
+
+ /*Workaround to solve the strange bug when sometimes signs of qAtan2 results
+ for 2 vectors are different*/
+ if((new_atan > 0 && old_atan < 0) || (new_atan < 0 && old_atan > 0)) {
+ old_atan *= -1;
+ }
+
+ //Get the angle between two vectors
+ double delta = new_atan - old_atan;
+
+ //Scale the angle to speed up the rotation
+ delta *= 100;
+ setRotation(rotation() + delta);
+ update(); //Apply rotation
+
+ //Allow movement of SkyMapLite while rotating or zooming
+ QMouseEvent *event = new QMouseEvent(QEvent::MouseButtonPress, pinchCenter,
+ Qt::LeftButton, Qt::LeftButton, Qt::ControlModifier);
+ if(!pinch) {
+ m_MousePoint = projector()->fromScreen( pinchCenter, data->lst(), data->geo()->lat() );
+ setClickedPoint( &m_MousePoint );
+ mouseButtonDown = true;
+ pinch = true;
+ }
+ mouseMoveEvent(event);
+
+ delete event;
+
+ } else {
+ if(pinch) {
+ pinch = false;
mouseButtonDown = false;
- if ( slewing ) {
- slewing = false;
- if ( Options::useAltAz() )
- setDestinationAltAz( focus()->alt(), focus()->az() );
- else
- setDestination( *focus() );
+ } else {
+ //If only pan is needed we just use the first touch point
+ QPointF newFocus = points[0].pos();
+ QMouseEvent *event = new QMouseEvent(QEvent::MouseButtonPress, newFocus,
+ Qt::LeftButton, Qt::LeftButton, Qt::ControlModifier);
+ if(e->type() == QEvent::TouchBegin) {
+ if(mouseButtonDown) mouseButtonDown = false;
}
- //forceUpdate(); // is needed because after moving the sky not all stars are shown
+
+ mousePressEvent(event);
+ mouseMoveEvent(event);
+
+ if(e->type() == QEvent::TouchEnd) {
+ if (mouseButtonDown) {
+ mouseButtonDown = false;
+ if ( slewing ) {
+ slewing = false;
+ if ( Options::useAltAz() )
+ setDestinationAltAz( focus()->alt(), focus()->az() );
+ else
+ setDestination( *focus() );
+ }
+ }
+ }
+ delete event;
}
}
- delete event;
}
double SkyMapLite::zoomFactor( const int modifier ) {
@@ -288,6 +352,9 @@ double SkyMapLite::zoomFactor( const int modifier ) {
void SkyMapLite::zoomInOrMagStep( const int modifier ) {
if ( modifier & Qt::AltModifier )
incMagLimit( modifier );
+ else if( modifier & Qt::MetaModifier) {//Used in pinch-to-zoom gesture
+ setZoomFactor (Options::zoomFactor() + Options::zoomFactor()*0.04);
+ }
else
setZoomFactor( Options::zoomFactor() * zoomFactor( modifier ) );
}
@@ -296,6 +363,9 @@ void SkyMapLite::zoomInOrMagStep( const int modifier ) {
void SkyMapLite::zoomOutOrMagStep( const int modifier ) {
if ( modifier & Qt::AltModifier )
decMagLimit( modifier );
+ else if( modifier & Qt::MetaModifier) {//Used in pinch-to-zoom gesture
+ setZoomFactor (Options::zoomFactor() - Options::zoomFactor()*0.04);
+ }
else
setZoomFactor( Options::zoomFactor() / zoomFactor (modifier ) );
}