[kstars] kstars: Add Telescope Tool bar to manager common Telescope options. Currently, there are FOUR different way to control the telescope in KStars:

Jasem Mutlaq null at kde.org
Fri Aug 25 17:48:12 UTC 2017


Git commit 387fbcc0e50b8943219ce24710476bbff8012318 by Jasem Mutlaq.
Committed on 25/08/2017 at 17:46.
Pushed by mutlaqja into branch 'master'.

Add Telescope Tool bar to manager common Telescope options. Currently, there are FOUR different way to control the telescope in KStars:
1. INDI Control Panel
2. Mount Control Panel
3. Directly from Sky Map.
4. and now INDI Tool Bar.

The toolbar is hidden by default since most users will probably use 1 to 3 above, but it is provided as an extra layer of convenience for users.

CCMAIL:kstars-devel at kde.org

M  +11   -1    kstars/data/kstarsui.rc
M  +2    -0    kstars/indi/drivermanager.cpp
M  +0    -15   kstars/indi/guimanager.cpp
M  +8    -0    kstars/indi/indilistener.cpp
M  +49   -2    kstars/indi/inditelescope.cpp
M  +2    -0    kstars/kstars.cpp
M  +7    -0    kstars/kstars.h
M  +26   -7    kstars/kstarsactions.cpp
M  +12   -2    kstars/kstarsinit.cpp

https://commits.kde.org/kstars/387fbcc0e50b8943219ce24710476bbff8012318

diff --git a/kstars/data/kstarsui.rc b/kstars/data/kstarsui.rc
index ae0e9ea93..e6a1515fd 100644
--- a/kstars/data/kstarsui.rc
+++ b/kstars/data/kstarsui.rc
@@ -1,6 +1,6 @@
 <!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
 
-<kpartgui name="KStars" version="4">
+<kpartgui name="KStars" version="5">
 <MenuBar noMerge="1">
         <Menu name="file" noMerge="1"><text>&File</text>
                 <Action name="new_window" />
@@ -190,4 +190,14 @@
         <Action name="lock_telescope" />
 </ToolBar>
 
+<ToolBar hidden="1" noMerge="1" name="TelescopeToolBar" iconText="icononly">
+        <text>Telescope Toolbar</text>
+        <Action name="telescope_track" />
+        <Action name="telescope_slew" />
+        <Action name="telescope_sync" />
+        <Action name="telescope_park" />
+        <Action name="telescope_unpark" />
+        <Action name="telescope_abort" />
+</ToolBar>
+
 </kpartgui>
diff --git a/kstars/indi/drivermanager.cpp b/kstars/indi/drivermanager.cpp
index 735b1732a..f2f7c7efe 100644
--- a/kstars/indi/drivermanager.cpp
+++ b/kstars/indi/drivermanager.cpp
@@ -453,6 +453,8 @@ void DriverManager::stopDevices(const QList<DriverInfo *> &dList)
             cm->disconnectServer();
             clients.removeOne(cm);
             cm->deleteLater();
+
+            KStars::Instance()->slotSetTelescopeEnabled(false);
         }
     }
 
diff --git a/kstars/indi/guimanager.cpp b/kstars/indi/guimanager.cpp
index 36f954609..5d56f27e1 100644
--- a/kstars/indi/guimanager.cpp
+++ b/kstars/indi/guimanager.cpp
@@ -97,9 +97,6 @@ void GUIManager::closeEvent(QCloseEvent * /*event*/)
     {
         QAction *showINDIPanel = KStars::Instance()->actionCollection()->action("show_control_panel");
         showINDIPanel->setChecked(false);
-
-        QAction *centerTelescope = KStars::Instance()->actionCollection()->action("lock_telescope");
-        centerTelescope->setChecked(false);
     }
 
     Options::setINDIWindowWidth(width());
@@ -122,9 +119,6 @@ void GUIManager::showEvent(QShowEvent * /*event*/)
     QAction *a = KStars::Instance()->actionCollection()->action("show_control_panel");
     a->setEnabled(true);
     a->setChecked(true);
-
-    a = KStars::Instance()->actionCollection()->action("lock_telescope");
-    a->setEnabled(true);
 }
 
 /*********************************************************************
@@ -141,11 +135,6 @@ void GUIManager::updateStatus(bool toggle_behavior)
                                    "Device Manager in the devices menu."));
         showINDIPanel->setChecked(false);
         showINDIPanel->setEnabled(false);
-
-        QAction *centerTelescope = KStars::Instance()->actionCollection()->action("lock_telescope");
-        centerTelescope->setChecked(false);
-        centerTelescope->setEnabled(false);
-
         return;
     }
 
@@ -256,10 +245,6 @@ void GUIManager::removeDevice(DeviceInfo *di)
     {
         QAction *showINDIPanel = KStars::Instance()->actionCollection()->action("show_control_panel");
         showINDIPanel->setEnabled(false);
-
-        QAction *centerTelescope = KStars::Instance()->actionCollection()->action("lock_telescope");
-        centerTelescope->setChecked(false);
-        centerTelescope->setEnabled(false);
     }
 }
 
diff --git a/kstars/indi/indilistener.cpp b/kstars/indi/indilistener.cpp
index 5d6694468..947b5e182 100644
--- a/kstars/indi/indilistener.cpp
+++ b/kstars/indi/indilistener.cpp
@@ -76,8 +76,16 @@ INDIListener *INDIListener::_INDIListener = nullptr;
 INDIListener *INDIListener::Instance()
 {
     if (_INDIListener == nullptr)
+    {
         _INDIListener = new INDIListener(KStars::Instance());
 
+        connect(_INDIListener, &INDIListener::newTelescope, [&]()
+        {
+            KStars::Instance()->slotSetTelescopeEnabled(true);
+        });
+
+    }
+
     return _INDIListener;
 }
 
diff --git a/kstars/indi/inditelescope.cpp b/kstars/indi/inditelescope.cpp
index a840c706f..4d0ef2a22 100644
--- a/kstars/indi/inditelescope.cpp
+++ b/kstars/indi/inditelescope.cpp
@@ -18,6 +18,7 @@
 #include "skymapcomposite.h"
 
 #include <KNotification>
+#include <KActionCollection>
 
 #include <indi_debug.h>
 
@@ -99,9 +100,27 @@ void Telescope::registerProperty(INDI::Property *prop)
             if (sp)
             {
                 if ((sp->s == ISS_ON) && svp->s == IPS_OK)
+                {
                     parkStatus = PARK_PARKED;
+
+                    QAction *parkAction = KStars::Instance()->actionCollection()->action("telescope_park");
+                    if (parkAction)
+                        parkAction->setEnabled(false);
+                    QAction *unParkAction = KStars::Instance()->actionCollection()->action("telescope_unpark");
+                    if (unParkAction)
+                        unParkAction->setEnabled(true);
+                }
                 else if ((sp->s == ISS_OFF) && svp->s == IPS_OK)
+                {
                     parkStatus = PARK_UNPARKED;
+
+                    QAction *parkAction = KStars::Instance()->actionCollection()->action("telescope_park");
+                    if (parkAction)
+                        parkAction->setEnabled(true);
+                    QAction *unParkAction = KStars::Instance()->actionCollection()->action("telescope_unpark");
+                    if (unParkAction)
+                        unParkAction->setEnabled(false);
+                }
             }
         }
     }
@@ -176,7 +195,21 @@ void Telescope::processSwitch(ISwitchVectorProperty *svp)
 {
     bool manualMotionChanged = false;
 
-    if (!strcmp(svp->name, "TELESCOPE_PARK"))
+    if (!strcmp(svp->name, "CONNECTION"))
+    {
+        ISwitch *conSP = IUFindSwitch(svp, "CONNECT");
+        if (conSP)
+        {
+            // TODO We must allow for multiple mount drivers to be online, not just one
+            // For the actions taken, the user should be able to specifiy which mounts shall receive the commands. It could be one
+            // or more. For now, we enable/disable telescope group on the assumption there is only one mount present.
+            if (isConnected() == false && conSP->s == ISS_ON)
+                KStars::Instance()->slotSetTelescopeEnabled(true);
+            else if (isConnected() && conSP->s == ISS_OFF)
+                KStars::Instance()->slotSetTelescopeEnabled(false);
+        }
+    }
+    else if (!strcmp(svp->name, "TELESCOPE_PARK"))
     {
         ISwitch *sp = IUFindSwitch(svp, "PARK");
         if (sp)
@@ -208,12 +241,26 @@ void Telescope::processSwitch(ISwitchVectorProperty *svp)
                 parkStatus = PARK_PARKED;
                 KNotification::event(QLatin1String("MountParked"), i18n("Mount parked"));
                 currentObject = nullptr;
+
+                QAction *parkAction = KStars::Instance()->actionCollection()->action("telescope_park");
+                if (parkAction)
+                    parkAction->setEnabled(false);
+                QAction *unParkAction = KStars::Instance()->actionCollection()->action("telescope_unpark");
+                if (unParkAction)
+                    unParkAction->setEnabled(true);
             }
-            else if (svp->s == IPS_OK && sp->s == ISS_OFF && parkStatus != PARK_UNPARKED)
+            else if ( (svp->s == IPS_OK || svp->s == IPS_IDLE) && sp->s == ISS_OFF && parkStatus != PARK_UNPARKED)
             {
                 parkStatus = PARK_UNPARKED;
                 KNotification::event(QLatin1String("MountUnparked"), i18n("Mount unparked"));
                 currentObject = nullptr;
+
+                QAction *parkAction = KStars::Instance()->actionCollection()->action("telescope_park");
+                if (parkAction)
+                    parkAction->setEnabled(true);
+                QAction *unParkAction = KStars::Instance()->actionCollection()->action("telescope_unpark");
+                if (unParkAction)
+                    unParkAction->setEnabled(false);
             }
         }
     }
diff --git a/kstars/kstars.cpp b/kstars/kstars.cpp
index cdd718b1f..7b04a7516 100644
--- a/kstars/kstars.cpp
+++ b/kstars/kstars.cpp
@@ -158,6 +158,7 @@ KStars::KStars(bool doSplash, bool clockrun, const QString &startdate)
     projectionGroup = new QActionGroup(this);
     cschemeGroup    = new QActionGroup(this);
     hipsGroup       = new QActionGroup(this);
+    telescopeGroup  = new QActionGroup(this);
 
     m_KStarsData = KStarsData::Create();
     Q_ASSERT(m_KStarsData);
@@ -612,3 +613,4 @@ void KStars::closeEvent(QCloseEvent *event)
     KStars::Closing = true;
     QWidget::closeEvent(event);
 }
+
diff --git a/kstars/kstars.h b/kstars/kstars.h
index 9aabcc638..9844d6598 100644
--- a/kstars/kstars.h
+++ b/kstars/kstars.h
@@ -475,6 +475,12 @@ class KStars : public KXmlGuiWindow
     /** action slot: open dialog for selecting a new geographic location */
     void slotGeoLocator();
 
+    /**
+     * @brief slotSetTelescopeEnabled call when telescope comes online or goes offline.
+     * @param enable True if telescope is online and connected, false otherwise.
+     */
+    void slotSetTelescopeEnabled(bool enable);
+
     /** Delete FindDialog because ObjNames list has changed in KStarsData due to
          * reloading star data. So list in FindDialog must be new filled with current data. */
     void clearCachedFindDialog();
@@ -774,6 +780,7 @@ class KStars : public KXmlGuiWindow
     QActionGroup *projectionGroup { nullptr };
     QActionGroup *cschemeGroup { nullptr };
     QActionGroup *hipsGroup { nullptr };
+    QActionGroup *telescopeGroup { nullptr };
 
     bool DialogIsObsolete { false };
     bool StartClockRunning { false };
diff --git a/kstars/kstarsactions.cpp b/kstars/kstarsactions.cpp
index c8328de44..b17e3145c 100644
--- a/kstars/kstarsactions.cpp
+++ b/kstars/kstarsactions.cpp
@@ -349,6 +349,18 @@ void KStars::slotINDIToolBar()
 #endif
 }
 
+void KStars::slotSetTelescopeEnabled(bool enable)
+{
+    telescopeGroup->setEnabled(enable);
+    if (enable == false)
+    {
+        for(QAction *a : telescopeGroup->actions())
+        {
+            a->setChecked(false);
+        }
+    }
+}
+
 /** Major Dialog Window Actions **/
 
 void KStars::slotCalculator()
@@ -738,10 +750,15 @@ void KStars::slotINDITelescopeTrack()
 
         if (telescope != nullptr && telescope->isConnected())
         {
-            KToggleAction *a = (KToggleAction *)sender();
+            KToggleAction *a = qobject_cast<KToggleAction*>(sender());
+            if (a != nullptr)
+            {
+                // Why this doesn't work? a->isChecked() always returns true!
+                //telescope->setTrackEnabled(a->isChecked());
+
+                telescope->setTrackEnabled(!telescope->isTracking());
+            }
 
-            if (a == actionCollection()->action("telescope_track"))
-            telescope->setTrackEnabled(a->isChecked());
             return;
         }
     }
@@ -762,8 +779,10 @@ void KStars::slotINDITelescopeSlew()
         {
             if (m_SkyMap->focusObject() != nullptr)
                 telescope->Slew(m_SkyMap->focusObject());
-            else
-                telescope->Slew(m_SkyMap->mousePoint());
+            // FIXME This can cause havoc for end users so it should
+            // probably gets its own action
+            //else
+                //telescope->Slew(m_SkyMap->mousePoint());
             return;
         }
     }
@@ -784,8 +803,8 @@ void KStars::slotINDITelescopeSync()
         {
             if (m_SkyMap->focusObject() != nullptr)
                 telescope->Sync(m_SkyMap->focusObject());
-            else
-                telescope->Sync(m_SkyMap->mousePoint());
+            //else
+                //telescope->Sync(m_SkyMap->mousePoint());
             return;
         }
     }
diff --git a/kstars/kstarsinit.cpp b/kstars/kstarsinit.cpp
index 82351ee94..23fd97575 100644
--- a/kstars/kstarsinit.cpp
+++ b/kstars/kstarsinit.cpp
@@ -560,38 +560,48 @@ void KStars::initActions()
          << QIcon::fromTheme("kstars_fitsviewer", QIcon(":/icons/breeze/default/kstars_fitsviewer.svg"))
          << ToolTip(i18n("Toggle FITS Viewer"));
     ka->setEnabled(false);
+
     ka = actionCollection()->add<KToggleAction>("lock_telescope", this, SLOT(slotINDIToolBar()))
          << i18nc("Toggle the telescope center lock in display", "Center Telescope")
          << QIcon::fromTheme("center_telescope", QIcon(":/icons/center_telescope.svg"))
-         << ToolTip(i18n("Toggle Lock Telescope Center"));
-    ka->setEnabled(false);
+         << ToolTip(i18n("Toggle Lock Telescope Center"));    
+    telescopeGroup->addAction(ka);
 
     ka = actionCollection()->add<KToggleAction>("telescope_track", this, SLOT(slotINDITelescopeTrack()))
             << i18n("Toggle Telescope Tracking")
             << QIcon::fromTheme("object-locked", QIcon(":/icons/breeze/default/object-locked.svg"))
             << QKeySequence(Qt::SHIFT + Qt::META + Qt::Key_T);
+    telescopeGroup->addAction(ka);
     ka = actionCollection()->addAction("telescope_slew", this, SLOT(slotINDITelescopeSlew()))
             << i18n("Slew Telescope")
             << QIcon::fromTheme("object-rotate-right", QIcon(":/icons/breeze/default/object-rotate-right.svg"))
             << QKeySequence(Qt::SHIFT + Qt::META + Qt::Key_S);
+    telescopeGroup->addAction(ka);
     ka = actionCollection()->addAction("telescope_sync", this, SLOT(slotINDITelescopeSync()))
             << i18n("Sync Telescope")
             << QIcon::fromTheme("media-record", QIcon(":/icons/breeze/default/media-record.svg"))
             << QKeySequence(Qt::SHIFT + Qt::META + Qt::Key_Y);
+    telescopeGroup->addAction(ka);
     ka = actionCollection()->addAction("telescope_abort", this, SLOT(slotINDITelescopeAbort()))
             << i18n("Abort Telescope")
             << QIcon::fromTheme("process-stop", QIcon(":/icons/breeze/default/process-stop.svg"))
             << QKeySequence(Qt::SHIFT + Qt::META + Qt::Key_A);
     ka->setShortcutContext(Qt::ApplicationShortcut);
+    telescopeGroup->addAction(ka);
     ka = actionCollection()->addAction("telescope_park", this, SLOT(slotINDITelescopePark()))
             << i18n("Park Telescope")
             << QIcon::fromTheme("flag-red", QIcon(":/icons/breeze/default/kstars_flag.svg"))
             << QKeySequence(Qt::SHIFT + Qt::META + Qt::Key_P);
+    telescopeGroup->addAction(ka);
     ka = actionCollection()->addAction("telescope_unpark", this, SLOT(slotINDITelescopeUnpark()))
             << i18n("Unpark Telescope")
             << QIcon::fromTheme("flag-green", QIcon(":/icons/breeze/default/flag-green.svg"))
             << QKeySequence(Qt::SHIFT + Qt::META + Qt::Key_U);
     ka->setShortcutContext(Qt::ApplicationShortcut);
+    telescopeGroup->addAction(ka);
+
+    // Disable all telescope actions by default
+    telescopeGroup->setEnabled(false);
 #endif
 }
 


More information about the Kstars-devel mailing list