[kstars] kstars: This patch fixes several things you asked me to take a look at.

Jasem Mutlaq null at kde.org
Mon Feb 20 07:19:51 UTC 2017


Git commit ddc789ba0f02e04a412d2155367f809402bffe3e by Jasem Mutlaq, on behalf of Robert Lancaster.
Committed on 20/02/2017 at 07:17.
Pushed by mutlaqja into branch 'master'.

This patch fixes several things you asked me to take a look at.
First, it changes the color of the center telescope cursor to red to make it more visible when trying to center the telescope.
Second, it makes the center Telescope Cursor switch back to whatever cursor you had before after you start a slew and will reset whatever button was checked to make the center telescope function work.
Third, the floating toolbar looked like buttons were not checked when in fact they were checked, so I adjusted the colors a bit. This fix had an extra benefit of making the toolbar a little smaller, matching the button size.
Finally, I changed the mouse cursor for the Preview view to be drag mouse, just like the fits viewer.

CCMAIL:kstars-devel at kde.org

M  +1    -0    kstars/CMakeLists.txt
A  +64   -0    kstars/data/icons/center_telescope_red.svg
M  +1    -0    kstars/data/kstars.qrc
M  +1    -0    kstars/ekos/ekosmanager.cpp
M  +127  -443  kstars/fitsviewer/fitsview.cpp
M  +19   -54   kstars/fitsviewer/fitsview.h
M  +3    -1    kstars/fitsviewer/fitsviewer.cpp

https://commits.kde.org/kstars/ddc789ba0f02e04a412d2155367f809402bffe3e

diff --git a/kstars/CMakeLists.txt b/kstars/CMakeLists.txt
index 16ac8dd30..7baebad8d 100644
--- a/kstars/CMakeLists.txt
+++ b/kstars/CMakeLists.txt
@@ -42,6 +42,7 @@ if(NOT BUILD_KSTARS_LITE)
             fitsviewer/fitshistogram.cpp
             fitsviewer/fitsdata.cpp
             fitsviewer/fitsview.cpp
+            fitsviewer/fitslabel.cpp
             fitsviewer/fitsviewer.cpp
             fitsviewer/fitstab.cpp
             fitsviewer/fitsdebayer.cpp
diff --git a/kstars/data/icons/center_telescope_red.svg b/kstars/data/icons/center_telescope_red.svg
new file mode 100644
index 000000000..ddad86a72
--- /dev/null
+++ b/kstars/data/icons/center_telescope_red.svg
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://creativecommons.org/ns#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   width="24"
+   height="24"
+   viewBox="0 0 24 24"
+   id="svg2"
+   version="1.1"
+   inkscape:version="0.91 r13725"
+   sodipodi:docname="center_telescope_red.svg">
+  <metadata
+     id="metadata10">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+        <dc:title></dc:title>
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <defs
+     id="defs8" />
+  <sodipodi:namedview
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1"
+     objecttolerance="10"
+     gridtolerance="10"
+     guidetolerance="10"
+     inkscape:pageopacity="0"
+     inkscape:pageshadow="2"
+     inkscape:window-width="1077"
+     inkscape:window-height="819"
+     id="namedview6"
+     showgrid="false"
+     inkscape:zoom="9.8333333"
+     inkscape:cx="26.745763"
+     inkscape:cy="12"
+     inkscape:window-x="173"
+     inkscape:window-y="20"
+     inkscape:window-maximized="0"
+     inkscape:current-layer="svg2" />
+  <path
+     d="M24 11h-2.051c-.469-4.725-4.224-8.48-8.949-8.95v-2.05h-2v2.05c-4.725.47-8.48 4.225-8.949 8.95h-2.051v2h2.051c.469 4.725 4.224 8.48 8.949 8.95v2.05h2v-2.05c4.725-.469 8.48-4.225 8.949-8.95h2.051v-2zm-11 8.931v-3.931h-2v3.931c-3.611-.454-6.478-3.32-6.931-6.931h3.931v-2h-3.931c.453-3.611 3.32-6.477 6.931-6.931v3.931h2v-3.931c3.611.454 6.478 3.319 6.931 6.931h-3.931v2h3.931c-.453 3.611-3.32 6.477-6.931 6.931zm1-7.931c0 1.104-.896 2-2 2s-2-.896-2-2 .896-2 2-2 2 .896 2 2z"
+     id="path4" />
+  <path
+     style="fill:#ff0000"
+     d="m 11.064407,22.93832 0,-1.000661 -0.737288,-0.130228 C 9.2673538,21.620245 7.7965804,21.070014 6.8563496,20.50898 5.8961343,19.936022 4.3770071,18.488796 3.7446924,17.544599 3.5057878,17.187857 3.1516793,16.55262 2.9577846,16.132961 2.6077195,15.37529 2.1152542,13.659276 2.1152542,13.19713 c 0,-0.237721 -0.014661,-0.241198 -1.0169491,-0.241198 l -1.01694917,0 0,-0.966101 0,-0.966102 1.00540227,0 1.0054023,0 0.067936,-0.483051 C 2.3759974,9.0055275 3.0504766,7.3926125 4.0253625,6.0801758 5.6045555,3.9541927 7.9044153,2.5891336 10.683051,2.1285704 l 0.381356,-0.06321 0,-1.0123411 0,-1.01234103 0.966101,0 0.966102,0 0,1.01501163 c 0,0.972138 0.0097,1.0168179 0.228814,1.0577733 0.125847,0.023519 0.572034,0.1173404 0.991525,0.2084922 3.67286,0.7980799 6.811024,3.9904744 7.501002,7.6306268 0.08516,0.4493001 0.169824,0.8741131 0.188135,0.9440281 0.02384,0.09103 0.322875,0.127119 1.053435,0.127119 l 1.02014,0 0,0.962544 0,0.962544 -1.03566,0.02898 -1.035661,0.02898 -0.133811,0.793397 c -0.395276,2.343683 -1.90579,4.748795 -3.910362,6.22626 -1.171672,0.86358 -2.738392,1.530814 -4.181116,1.780655 l -0.686441,0.118872 0,1.006509 0,1.00651 -0.966102,0 -0.966101,0 0,-1.000663 z m 0,-4.948489 0,-1.983051 0.966101,0 0.966102,0 0,1.987658 0,1.98766 0.381356,-0.06915 c 3.323421,-0.602619 5.9014,-3.167626 6.521919,-6.489101 l 0.08742,-0.467915 -1.969922,0 -1.969921,0 0,-0.966101 0,-0.966102 1.969168,0 1.969168,0 -0.09593,-0.527785 C 19.501026,8.3565903 18.01742,6.2334772 16.121623,5.1034017 15.415994,4.6827799 14.057598,4.173576 13.377966,4.0749231 l -0.381356,-0.055356 0,1.9766573 0,1.9766572 -0.966102,0 -0.966101,0 0,-1.987659 0,-1.9876589 -0.381356,0.068441 C 9.9426215,4.1988869 8.7680816,4.6209244 8.0892349,4.9980181 6.0312003,6.1412391 4.4473582,8.3603245 4.0887356,10.603027 l -0.067273,0.420702 1.9452008,0 1.9452008,0 0,0.966102 0,0.966101 -1.9437502,0 -1.9437503,0 0.068762,0.458536 c 0.098798,0.658831 0.5121478,1.821494 0.8822115,2.481467 1.0799767,1.926036 2.8685819,3.307125 5.021273,3.877224 1.1741198,0.310943 1.0677968,0.488513 1.0677968,-1.783328 z"
+     id="path4138"
+     inkscape:connector-curvature="0" />
+  <path
+     style="fill:#ff0000"
+     d="m 11.43915,13.869472 c -1.217482,-0.365438 -1.7568586,-1.876025 -1.050815,-2.942929 0.98509,-1.4885714 3.355153,-0.914891 3.501304,0.847501 0.0603,0.727118 -0.10802,1.193834 -0.586419,1.626039 -0.556534,0.502796 -1.207047,0.6666 -1.86407,0.469389 z"
+     id="path4140"
+     inkscape:connector-curvature="0" />
+</svg>
diff --git a/kstars/data/kstars.qrc b/kstars/data/kstars.qrc
index 5c7307a03..483dab992 100644
--- a/kstars/data/kstars.qrc
+++ b/kstars/data/kstars.qrc
@@ -131,6 +131,7 @@
         <file>icons/breeze/default/view-filter.svg</file>
         <file>icons/breeze/default/media-record.svg</file>
         <file>icons/breeze/default/camera-photo.svg</file>
+        <file>icons/center_telescope_red.svg</file>
     </qresource>
     <qresource prefix="/kconfig">
         <file>kstars.knsrc</file>
diff --git a/kstars/ekos/ekosmanager.cpp b/kstars/ekos/ekosmanager.cpp
index 4e6768fff..db31c5569 100644
--- a/kstars/ekos/ekosmanager.cpp
+++ b/kstars/ekos/ekosmanager.cpp
@@ -187,6 +187,7 @@ EkosManager::EkosManager(QWidget *parent) : QDialog(parent)
     previewView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
     previewView->setBaseSize(previewWidget->size());
     previewView->createFloatingToolBar();
+    previewView->setMouseMode(FITSView::dragMouse);
     QVBoxLayout *vlayout = new QVBoxLayout();
     vlayout->addWidget(previewView);
     previewWidget->setLayout(vlayout);
diff --git a/kstars/fitsviewer/fitsview.cpp b/kstars/fitsviewer/fitsview.cpp
index 3c5a93ba6..e0434a42d 100644
--- a/kstars/fitsviewer/fitsview.cpp
+++ b/kstars/fitsviewer/fitsview.cpp
@@ -1,21 +1,13 @@
-/***************************************************************************
-                          FITSView.cpp  -  FITS Image
-                             -------------------
-    begin                : Thu Jan 22 2004
-    copyright            : (C) 2004 by Jasem Mutlaq
-    email                : mutlaqja at ikarustech.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.                                   *
- *                                                                         *
- *   Some code fragments were adapted from Peter Kirchgessner's FITS plugin*
- *   See http://members.aol.com/pkirchg for more details.                  *
- ***************************************************************************/
+/*  FITS View
+    Copyright (C) 2003-2017 Jasem Mutlaq <mutlaqja at ikarustech.com>
+    Copyright (C) 2016-2017 Robert Lancaster <rlancaste at gmail.com>
+
+    This application 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 <config-kstars.h>
 #include "fitsview.h"
@@ -52,9 +44,10 @@
 #include <KMessageBox>
 #include <KLocalizedString>
 
+#include "Options.h"
 #include "kstarsdata.h"
 #include "ksutils.h"
-#include "Options.h"
+#include "fitslabel.h"
 
 #ifdef HAVE_INDI
 #include "basedevice.h"
@@ -70,422 +63,6 @@
 #define ZOOM_LOW_INCR	10
 #define ZOOM_HIGH_INCR	50
 
-//#define FITS_DEBUG
-
-FITSLabel::FITSLabel(FITSView *img, QWidget *parent) : QLabel(parent)
-{
-    image = img;
-
-}
-
-void FITSLabel::setSize(double w, double h)
-{
-    width  = w;
-    height = h;
-    size   = w*h;
-}
-
-FITSLabel::~FITSLabel() {}
-
-/**
-This method looks at what mouse mode is currently selected and updates the cursor to match.
- */
-
-void FITSView::updateMouseCursor(){
-    if(mouseMode==dragMouse){
-        if(horizontalScrollBar()->maximum()>0||verticalScrollBar()->maximum()>0){
-            if(!image_frame->getMouseButtonDown())
-                viewport()->setCursor(Qt::PointingHandCursor);
-            else
-                viewport()->setCursor(Qt::ClosedHandCursor);
-        }
-        else
-            viewport()->setCursor(Qt::CrossCursor);
-    }
-    if(mouseMode==selectMouse){
-        viewport()->setCursor(Qt::CrossCursor);
-    }
-    if(mouseMode==scopeMouse){
-        QPixmap scope_pix=QPixmap(":/icons/center_telescope.svg").scaled(32,32,Qt::KeepAspectRatio,Qt::FastTransformation);
-        viewport()->setCursor(QCursor(scope_pix,10,10));
-    }
-}
-
-/**
-This is how the mouse mode gets set.
-The default for a FITSView in a FITSViewer should be the dragMouse
-The default for a FITSView in the Focus or Align module should be the selectMouse
-The different defaults are accomplished by putting making the dactual default mouseMode
-the selectMouse, but when a FITSViewer loads an image, it immediately makes it the dragMouse.
- */
-
-void FITSView::setMouseMode(int mode){
-    if(mode>-1&&mode<3){
-        mouseMode=mode;
-        updateMouseCursor();
-    }
-}
-
-bool FITSLabel::getMouseButtonDown(){
-    return mouseButtonDown;
-}
-
-int FITSView::getMouseMode(){
-    return mouseMode;
-}
-
-
-void FITSView::enterEvent(QEvent *)
-{
-    if(floatingToolBar&&imageData){
-        QGraphicsOpacityEffect *eff = new QGraphicsOpacityEffect(this);
-        floatingToolBar->setGraphicsEffect(eff);
-        QPropertyAnimation *a = new QPropertyAnimation(eff,"opacity");
-        a->setDuration(500);
-        a->setStartValue(0.2);
-        a->setEndValue(1);
-        a->setEasingCurve(QEasingCurve::InBack);
-        a->start(QPropertyAnimation::DeleteWhenStopped);
-    }
-}
-
-void FITSView::leaveEvent(QEvent *)
-{
-    if(floatingToolBar&&imageData){
-        QGraphicsOpacityEffect *eff = new QGraphicsOpacityEffect(this);
-        floatingToolBar->setGraphicsEffect(eff);
-        QPropertyAnimation *a = new QPropertyAnimation(eff,"opacity");
-        a->setDuration(500);
-        a->setStartValue(1);
-        a->setEndValue(0.2);
-        a->setEasingCurve(QEasingCurve::OutBack);
-        a->start(QPropertyAnimation::DeleteWhenStopped);
-    }
-
-}
-
-/**
-This method was added to make the panning function work.
-If the mouse button is released, it resets mouseButtonDown variable and the mouse cursor.
- */
-void FITSLabel::mouseReleaseEvent(QMouseEvent *e)
-{
-    Q_UNUSED(e);
-    if(image->getMouseMode()==FITSView::dragMouse){
-        mouseButtonDown=false;
-        image->updateMouseCursor();
-    }
-}
-/**
-I added some things to the top of this method to allow panning and Scope slewing to function.
-If you are in the dragMouse mode and the mousebutton is pressed, The method checks the difference
-between the location of the last point stored and the current event point to see how the mouse has moved.
-Then it moves the scrollbars and thus the image to the right location.
-Then it stores the current point so next time it can do it again.
- */
-void FITSLabel::mouseMoveEvent(QMouseEvent *e)
-{
-    float scale=(image->getCurrentZoom() / ZOOM_DEFAULT);
-
-    if(image->getMouseMode()==FITSView::dragMouse&&mouseButtonDown){
-        QPoint newPoint=e->globalPos();
-        int dx=newPoint.x()-lastMousePoint.x();
-        int dy=newPoint.y()-lastMousePoint.y();
-        image->horizontalScrollBar()->setValue(image->horizontalScrollBar()->value()-dx);
-        image->verticalScrollBar()->setValue(image->verticalScrollBar()->value()-dy);
-
-        lastMousePoint=newPoint;
-    }
-
-    double x,y;
-    FITSData *image_data = image->getImageData();
-
-    uint8_t *buffer = image_data->getImageBuffer();
-
-    if (buffer == NULL)
-        return;
-
-    x = round(e->x() / scale);
-    y = round(e->y() / scale);
-
-    x = KSUtils::clamp(x, 1.0, width);
-    y = KSUtils::clamp(y, 1.0, height);
-
-    emit newStatus(QString("X:%1 Y:%2").arg( (int)x ).arg( (int)y ), FITS_POSITION);
-
-    // Range is 0 to dim-1 when accessing array
-    x -= 1;
-    y -= 1;
-
-    QString stringValue;
-
-    switch (image_data->getDataType())
-    {
-        case TBYTE:
-            stringValue = QLocale().toString(buffer[(int) (y * width + x)]);
-            break;
-
-        case TSHORT:
-            stringValue = QLocale().toString( (reinterpret_cast<int16_t*>(buffer)) [(int) (y * width + x)]);
-            break;
-
-        case TUSHORT:
-            stringValue = QLocale().toString( (reinterpret_cast<uint16_t*>(buffer)) [(int) (y * width + x)]);
-            break;
-
-        case TLONG:
-            stringValue = QLocale().toString( (reinterpret_cast<int32_t*>(buffer)) [(int) (y * width + x)]);
-            break;
-
-        case TULONG:
-            stringValue = QLocale().toString( (reinterpret_cast<uint32_t*>(buffer)) [(int) (y * width + x)]);
-            break;
-
-        case TFLOAT:
-            stringValue = QLocale().toString( (reinterpret_cast<float*>(buffer)) [(int) (y * width + x)], 'f', 5);
-            break;
-
-        case TLONGLONG:
-            stringValue = QLocale().toString(static_cast<int>((reinterpret_cast<int64_t*>(buffer)) [(int) (y * width + x)]));
-            break;
-
-        case TDOUBLE:
-            stringValue = QLocale().toString( (reinterpret_cast<float*>(buffer)) [(int) (y * width + x)], 'f', 5);
-
-        break;
-
-        default:
-        break;
-    }
-
-    emit newStatus(stringValue, FITS_VALUE);
-
-    if (image_data->hasWCS()&&image->getMouseMode()!=FITSView::selectMouse)
-    {
-        int index = x + y * width;
-
-        wcs_point * wcs_coord = image_data->getWCSCoord();
-
-        if (wcs_coord)
-        {
-            if (index > size)
-                return;
-
-            ra.setD(wcs_coord[index].ra);
-            dec.setD(wcs_coord[index].dec);
-
-            emit newStatus(QString("%1 , %2").arg( ra.toHMSString()).arg(dec.toDMSString()), FITS_WCS);
-        }
-
-        bool objFound=false;
-        foreach(FITSSkyObject *listObject, image_data->objList){
-            if((std::abs(listObject->x()-x)<5/scale)&&(std::abs(listObject->y()-y)<5/scale)){
-                QToolTip::showText(e->globalPos(), listObject->skyObject()->name() +"\n"+listObject->skyObject()->longname() , this);
-                objFound=true;
-                break;
-            }
-        }
-        if(!objFound)
-            QToolTip::hideText();
-    }
-
-    double HFR = image->getImageData()->getHFR(x, y);
-
-    if (HFR > 0)
-        QToolTip::showText(e->globalPos(), i18nc("Half Flux Radius", "HFR: %1", QString::number(HFR, 'g' , 3)), this);
-
-    //setCursor(Qt::CrossCursor);
-
-    e->accept();
-}
-
-/**
-I added some things to the top of this method to allow panning and Scope slewing to function.
-If in dragMouse mode, the Panning function works by storing the cursor position when the mouse was pressed and setting
-the mouseButtonDown variable to true.
-If in ScopeMouse mode and the mouse is clicked, if there is WCS data and a scope is available, the method will verify that you actually
-do want to slew to the WCS coordinates associated with the click location.  If so, it calls the centerTelescope function.
- */
-
-void FITSLabel::mousePressEvent(QMouseEvent *e)
-{
-    float scale=(image->getCurrentZoom() / ZOOM_DEFAULT);
-
-    if(image->getMouseMode()==FITSView::dragMouse)
-    {
-        mouseButtonDown=true;
-        lastMousePoint=e->globalPos();
-        image->updateMouseCursor();
-    } else if(e->buttons() & Qt::LeftButton&&image->getMouseMode()==FITSView::scopeMouse)
-    {
-#ifdef HAVE_INDI
-        FITSData *image_data = image->getImageData();
-        if (image_data->hasWCS())
-        {
-
-            wcs_point * wcs_coord = image_data->getWCSCoord();
-            double x,y;
-            x = round(e->x() / scale);
-            y = round(e->y() / scale);
-
-            x = KSUtils::clamp(x, 1.0, width);
-            y = KSUtils::clamp(y, 1.0, height);
-            int index = x + y * width;
-            if(KMessageBox::Continue==KMessageBox::warningContinueCancel(NULL, "Slewing to Coordinates: \nRA: " + dms(wcs_coord[index].ra).toHMSString() + "\nDec: " + dms(wcs_coord[index].dec).toDMSString(),
-                                 i18n("Continue Slew"),  KStandardGuiItem::cont(), KStandardGuiItem::cancel(), "continue_slew_warning")){
-                centerTelescope(wcs_coord[index].ra/15.0, wcs_coord[index].dec);
-            }
-        }
-#endif
-    }
-
-    double x,y;
-
-    x = round(e->x() / scale);
-    y = round(e->y() / scale);
-
-    x = KSUtils::clamp(x, 1.0, width);
-    y = KSUtils::clamp(y, 1.0, height);
-
-#ifdef HAVE_INDI
-    FITSData *image_data = image->getImageData();
-
-    if (e->buttons() & Qt::RightButton&&image->getMouseMode()!=FITSView::scopeMouse)
-    {
-        mouseReleaseEvent(e);
-        if (image_data->hasWCS())
-        {
-            foreach(FITSSkyObject *listObject, image_data->objList){
-                if((std::abs(listObject->x()-x)<5/scale)&&(std::abs(listObject->y()-y)<5/scale)){
-                    SkyObject *object=listObject->skyObject();
-                    KSPopupMenu *pmenu;
-                    pmenu=new KSPopupMenu();
-                    object->initPopupMenu(pmenu);
-                    QList<QAction *> actions= pmenu->actions();
-                    foreach(QAction *action,actions){
-                        if(action->text().left(7)=="Starhop")
-                            pmenu->removeAction(action);
-                        if(action->text().left(7)=="Angular")
-                            pmenu->removeAction(action);
-                        if(action->text().left(8)=="Add flag")
-                            pmenu->removeAction(action);
-                        if(action->text().left(12)=="Attach Label")
-                            pmenu->removeAction(action);
-                    }
-                    pmenu->popup(e->globalPos());
-                    KStars::Instance()->map()->setClickedObject(object);
-                    break;
-                }
-            }
-        }
-
-        if (fabs(image->markerCrosshair.x()-x) <= 15 && fabs(image->markerCrosshair.y()-y) <= 15)
-            emit markerSelected(0, 0);
-    }
-#endif
-
-    if (e->buttons() & Qt::LeftButton&&image->getMouseMode()==FITSView::selectMouse)
-    {
-        emit pointSelected(x, y);
-    }
-
-}
-
-void FITSLabel::mouseDoubleClickEvent(QMouseEvent *e)
-{
-    double x,y;
-
-    x = round(e->x() / (image->getCurrentZoom() / ZOOM_DEFAULT));
-    y = round(e->y() / (image->getCurrentZoom() / ZOOM_DEFAULT));
-
-    x = KSUtils::clamp(x, 1.0, width);
-    y = KSUtils::clamp(y, 1.0, height);
-
-    emit markerSelected(x, y);
-
-    return;
-}
-
-/**
-This method just verifies if INDI is online, a telescope present, and is connected
- */
-
-bool FITSView::isTelescopeActive(){
-#ifdef HAVE_INDI
-    if (INDIListener::Instance()->size() == 0)
-    {
-        return false;
-    }
-
-    foreach(ISD::GDInterface *gd, INDIListener::Instance()->getDevices())
-    {
-        INDI::BaseDevice *bd = gd->getBaseDevice();
-
-        if (gd->getType() != KSTARS_TELESCOPE)
-            continue;
-
-        if (bd == NULL)
-            continue;
-
-        return bd->isConnected();
-    }
-    return false;
-#else
-    return false;
-#endif
-}
-
-void FITSLabel::centerTelescope(double raJ2000, double decJ2000)
-{
-#ifdef HAVE_INDI
-
-    if (INDIListener::Instance()->size() == 0)
-    {
-        KMessageBox::sorry(0, i18n("KStars did not find any active telescopes."));
-        return;
-    }
-
-    foreach(ISD::GDInterface *gd, INDIListener::Instance()->getDevices())
-    {
-        INDI::BaseDevice *bd = gd->getBaseDevice();
-
-        if (gd->getType() != KSTARS_TELESCOPE)
-            continue;
-
-        if (bd == NULL)
-            continue;
-
-        if (bd->isConnected() == false)
-        {
-            KMessageBox::error(0, i18n("Telescope %1 is offline. Please connect and retry again.", gd->getDeviceName()));
-            return;
-        }
-
-        ISD::GDSetCommand SlewCMD(INDI_SWITCH, "ON_COORD_SET", "TRACK", ISS_ON, this);
-
-        SkyObject selectedObject;
-
-        selectedObject.setRA0(raJ2000);
-        selectedObject.setDec0(decJ2000);
-
-        selectedObject.apparentCoord(J2000, KStarsData::Instance()->ut().djd());
-
-        gd->setProperty(&SlewCMD);
-        gd->runCommand(INDI_SEND_COORDS, &selectedObject);
-
-        return;
-    }
-
-    KMessageBox::sorry(0, i18n("KStars did not find any active telescopes."));
-
-#else
-
-    Q_UNUSED(raJ2000);
-    Q_UNUSED(decJ2000);
-
-#endif    
-}
-
 FITSView::FITSView(QWidget * parent, FITSMode fitsMode, FITSScale filterType) : QScrollArea(parent) , zoomFactor(1.2)
 {
 
@@ -525,6 +102,8 @@ FITSView::FITSView(QWidget * parent, FITSMode fitsMode, FITSScale filterType) :
     noImageLabel->setAlignment(Qt::AlignCenter);
     this->setWidget(noImageLabel);
 
+    scopePixmap = QPixmap(":/icons/center_telescope_red.svg").scaled(32,32,Qt::KeepAspectRatio,Qt::FastTransformation);
+
     //if (fitsMode == FITS_GUIDE)
     //connect(image_frame, SIGNAL(pointSelected(int,int)), this, SLOT(processPointSelection(int,int)));
 
@@ -541,6 +120,44 @@ FITSView::~FITSView()
     delete(display_image);
 }
 
+/**
+This method looks at what mouse mode is currently selected and updates the cursor to match.
+ */
+
+void FITSView::updateMouseCursor(){
+    if(mouseMode==dragMouse){
+        if(horizontalScrollBar()->maximum()>0||verticalScrollBar()->maximum()>0){
+            if(!image_frame->getMouseButtonDown())
+                viewport()->setCursor(Qt::PointingHandCursor);
+            else
+                viewport()->setCursor(Qt::ClosedHandCursor);
+        }
+        else
+            viewport()->setCursor(Qt::CrossCursor);
+    }
+    if(mouseMode==selectMouse){
+        viewport()->setCursor(Qt::CrossCursor);
+    }
+    if(mouseMode==scopeMouse){
+        viewport()->setCursor(QCursor(scopePixmap,10,10));
+    }
+}
+
+/**
+This is how the mouse mode gets set.
+The default for a FITSView in a FITSViewer should be the dragMouse
+The default for a FITSView in the Focus or Align module should be the selectMouse
+The different defaults are accomplished by putting making the actual default mouseMode
+the selectMouse, but when a FITSViewer loads an image, it immediately makes it the dragMouse.
+ */
+
+void FITSView::setMouseMode(int mode){
+    if(mode>-1&&mode<3){
+        mouseMode=mode;
+        updateMouseCursor();
+    }
+}
+
 void FITSView::resizeEvent(QResizeEvent * event){
     if(!imageData&&noImageLabel){
         noImageLabel->setPixmap(noImage.scaled( width()-20, height()-20,Qt::KeepAspectRatio,Qt::FastTransformation));
@@ -718,6 +335,40 @@ int FITSView::rescale(FITSZoom type)
     return 0;
 }
 
+int FITSView::getMouseMode(){
+    return mouseMode;
+}
+
+
+void FITSView::enterEvent(QEvent *)
+{
+    if(floatingToolBar&&imageData){
+        QGraphicsOpacityEffect *eff = new QGraphicsOpacityEffect(this);
+        floatingToolBar->setGraphicsEffect(eff);
+        QPropertyAnimation *a = new QPropertyAnimation(eff,"opacity");
+        a->setDuration(500);
+        a->setStartValue(0.2);
+        a->setEndValue(1);
+        a->setEasingCurve(QEasingCurve::InBack);
+        a->start(QPropertyAnimation::DeleteWhenStopped);
+    }
+}
+
+void FITSView::leaveEvent(QEvent *)
+{
+    if(floatingToolBar&&imageData){
+        QGraphicsOpacityEffect *eff = new QGraphicsOpacityEffect(this);
+        floatingToolBar->setGraphicsEffect(eff);
+        QPropertyAnimation *a = new QPropertyAnimation(eff,"opacity");
+        a->setDuration(500);
+        a->setStartValue(1);
+        a->setEndValue(0.2);
+        a->setEasingCurve(QEasingCurve::OutBack);
+        a->start(QPropertyAnimation::DeleteWhenStopped);
+    }
+
+}
+
 template<typename T>  int FITSView::rescale(FITSZoom type)
 {
     double val=0;
@@ -1691,8 +1342,10 @@ void FITSView::createFloatingToolBar()
     eff->setOpacity(0.2);
     floatingToolBar->setVisible(false);
     floatingToolBar->setStyleSheet("QToolBar{background: rgba(150, 150, 150, 210); border:none; color: yellow}"
-                                   "QToolButton{background: transparent; color: yellow}"
-                                   "QToolButton:hover{background: rgba(200, 200, 200, 255); color: yellow}");
+                                   "QToolButton{background: transparent; border:none; color: yellow}"
+                                   "QToolButton:hover{background: rgba(200, 200, 200, 255);border:solid; color: yellow}"
+                                   "QToolButton:checked{background: rgba(110, 110, 110, 255);border:solid; color: yellow}"
+                                   );
     floatingToolBar->setFloatable(true);
     floatingToolBar->setIconSize(QSize(25,25));
     //floatingToolBar->setMovable(true);
@@ -1746,10 +1399,11 @@ void FITSView::centerTelescope()
     if(imageHasWCS()){
         if(getMouseMode()==FITSView::scopeMouse)
         {
-            setMouseMode(FITSView::selectMouse);
+            setMouseMode(lastMouseMode);
         }
         else
         {
+            lastMouseMode=getMouseMode();
             setMouseMode(FITSView::scopeMouse);
         }
         updateFrame();
@@ -1760,13 +1414,43 @@ void FITSView::centerTelescope()
 
 void FITSView::updateScopeButton()
 {
-    if(getMouseMode()==FITSView::scopeMouse)
+    if(centerTelescopeAction){
+        if(getMouseMode()==FITSView::scopeMouse)
+        {
+           centerTelescopeAction->setChecked(true);
+        }
+        else
+        {
+           centerTelescopeAction->setChecked(false);
+        }
+    }
+}
+
+/**
+This method just verifies if INDI is online, a telescope present, and is connected
+ */
+
+bool FITSView::isTelescopeActive(){
+#ifdef HAVE_INDI
+    if (INDIListener::Instance()->size() == 0)
     {
-       centerTelescopeAction->setChecked(true);
+        return false;
     }
-    else
+
+    foreach(ISD::GDInterface *gd, INDIListener::Instance()->getDevices())
     {
-       centerTelescopeAction->setChecked(false);
+        INDI::BaseDevice *bd = gd->getBaseDevice();
+
+        if (gd->getType() != KSTARS_TELESCOPE)
+            continue;
+
+        if (bd == NULL)
+            continue;
+
+        return bd->isConnected();
     }
+    return false;
+#else
+    return false;
+#endif
 }
-
diff --git a/kstars/fitsviewer/fitsview.h b/kstars/fitsviewer/fitsview.h
index 25ff07cc2..de0cf59c8 100644
--- a/kstars/fitsviewer/fitsview.h
+++ b/kstars/fitsviewer/fitsview.h
@@ -1,21 +1,13 @@
-/***************************************************************************
-                          FITSView.cpp  -  FITS Image
-                             -------------------
-    begin                : Tue Feb 24 2004
-    copyright            : (C) 2004 by Jasem Mutlaq
-    email                : mutlaqja at ikarustech.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.                                   *
- *                                                                         *
- *   Some code fragments were adapted from Peter Kirchgessner's FITS plugin*
- *   See http://members.aol.com/pkirchg for more details.                  *
- ***************************************************************************/
+/*  FITS Label
+    Copyright (C) 2003-2017 Jasem Mutlaq <mutlaqja at ikarustech.com>
+    Copyright (C) 2016-2017 Robert Lancaster <rlancaste at gmail.com>
+
+    This application 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 FITSView_H_
 #define FITSView_H_
@@ -53,39 +45,7 @@
 #define MINIMUM_PIXEL_RANGE 5
 #define MINIMUM_STDVAR  5
 
-class FITSView;
-
-
-class FITSLabel : public QLabel
-{
-     Q_OBJECT
-public:
-    explicit FITSLabel(FITSView *img, QWidget *parent=NULL);
-    virtual ~FITSLabel();
-    void setSize(double w, double h);
-    void centerTelescope(double raJ2000, double decJ2000);
-    bool getMouseButtonDown();
-
-protected:
-
-    virtual void mouseMoveEvent(QMouseEvent *e);
-    virtual void mousePressEvent(QMouseEvent *e);
-    virtual void mouseReleaseEvent(QMouseEvent *e);
-    virtual void mouseDoubleClickEvent(QMouseEvent *e);
-
-private:
-    bool mouseButtonDown=false;
-    QPoint lastMousePoint;
-    FITSView *image;
-    dms ra;
-    dms dec;
-    double width,height,size;
-
-signals:
-    void newStatus(const QString &msg, FITSBar id);
-    void pointSelected(int x, int y);
-    void markerSelected(int x, int y);
-};
+class FITSLabel;
 
 class FITSView : public QScrollArea
 {
@@ -148,6 +108,10 @@ public:
     static const int selectMouse=1;
     static const int scopeMouse=2;
 
+    void updateScopeButton();
+    void setScopeButton(QAction *action){centerTelescopeAction=action;}
+    int lastMouseMode;
+
     // Zoom related
     void cleanUpZoom(QPoint viewCenter);
     QPoint getImagePoint(QPoint viewPortPoint);
@@ -207,7 +171,7 @@ private:
     bool event(QEvent *event);
     bool gestureEvent(QGestureEvent *event);
     void pinchTriggered(QPinchGesture *gesture);
-    void updateScopeButton();
+
 
     template<typename T> int rescale(FITSZoom type);
 
@@ -253,8 +217,6 @@ private:
 
     QStack<FITSScale> filterStack;
 
-
-
     // Star selection algorithm
     StarAlgorithm starAlgorithm = ALGORITHM_GRADIENT;
 
@@ -264,6 +226,9 @@ private:
     QRect trackingBox;
     QPixmap trackingBoxPixmap;
 
+    // Scope pixmap
+    QPixmap scopePixmap;
+
     // Floating toolbar
     QToolBar *floatingToolBar = NULL;
     QAction *centerTelescopeAction = NULL;    
diff --git a/kstars/fitsviewer/fitsviewer.cpp b/kstars/fitsviewer/fitsviewer.cpp
index 52d41bd60..748f0806c 100644
--- a/kstars/fitsviewer/fitsviewer.cpp
+++ b/kstars/fitsviewer/fitsviewer.cpp
@@ -912,9 +912,11 @@ void FITSViewer::updateScopeButton(){
  */
 
 void FITSViewer::centerTelescope(){
+    getCurrentView()->setScopeButton(actionCollection()->action("center_telescope"));
     if(getCurrentView()->getMouseMode()==FITSView::scopeMouse){
-        getCurrentView()->setMouseMode(FITSView::dragMouse);
+        getCurrentView()->setMouseMode(getCurrentView()->lastMouseMode);
     } else{
+        getCurrentView()->lastMouseMode=getCurrentView()->getMouseMode();
         getCurrentView()->setMouseMode(FITSView::scopeMouse);
     }
     updateScopeButton();


More information about the Kstars-devel mailing list