From kde-commits Fri Sep 30 20:38:34 2016 From: Jasem Mutlaq Date: Fri, 30 Sep 2016 20:38:34 +0000 To: kde-commits Subject: [kstars/bleeding] kstars/fitsviewer: Right-click now removes the crosshairs. Also, Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=147526792501775 Git commit cce4f3016357362cac2e977a3afa5312155d2e18 by Jasem Mutlaq. Committed on 29/09/2016 at 19:37. Pushed by mutlaqja into branch 'bleeding'. Right-click now removes the crosshairs. Also, if there is a crosshair prese= nt then zoom in or out will try to center the view on the crosshair location M +88 -68 kstars/fitsviewer/fitsview.cpp M +0 -3 kstars/fitsviewer/fitsview.h http://commits.kde.org/kstars/cce4f3016357362cac2e977a3afa5312155d2e18 diff --git a/kstars/fitsviewer/fitsview.cpp b/kstars/fitsviewer/fitsview.cpp index 90a6563..94a7d0e 100644 --- a/kstars/fitsviewer/fitsview.cpp +++ b/kstars/fitsviewer/fitsview.cpp @@ -56,9 +56,10 @@ #include "indi/driverinfo.h" #endif = +#define BASE_OFFSET 50 #define ZOOM_DEFAULT 100.0 -#define ZOOM_MIN 10 -#define ZOOM_MAX 400 +#define ZOOM_MIN 10 +#define ZOOM_MAX 400 #define ZOOM_LOW_INCR 10 #define ZOOM_HIGH_INCR 50 = @@ -143,36 +144,42 @@ void FITSLabel::mousePressEvent(QMouseEvent *e) #ifdef HAVE_INDI FITSData *image_data =3D image->getImageData(); = - if ( (e->buttons() & Qt::RightButton) && image_data->hasWCS()) + if (e->buttons() & Qt::RightButton) { - QMenu fitspopup; - QAction *trackAction =3D fitspopup.addAction(i18n("Center In Telesco= pe")); + if (image_data->hasWCS()) + { + QMenu fitspopup; + QAction *trackAction =3D fitspopup.addAction(i18n("Center In T= elescope")); + + if (fitspopup.exec(e->globalPos()) =3D=3D trackAction) + { + int index =3D x + y * width; = - if (fitspopup.exec(e->globalPos()) =3D=3D trackAction) - { - int index =3D x + y * width; + wcs_point * wcs_coord =3D image_data->getWCSCoord(); = - wcs_point * wcs_coord =3D image_data->getWCSCoord(); + if (wcs_coord) + { + if (index > size) + return; = - if (wcs_coord) - { - if (index > size) - return; + centerTelescope(wcs_coord[index].ra/15.0, wcs_coord[in= dex].dec); = - centerTelescope(wcs_coord[index].ra/15.0, wcs_coord[index].d= ec); + return; + } + } + } = - return; - } - } + if (fabs(image->markerCrosshair.x()-x) <=3D 15 && fabs(image->mark= erCrosshair.y()-y) <=3D 15) + emit markerSelected(0, 0); } #endif = - emit pointSelected(x, y); + emit pointSelected(x, y); = - double HFR =3D image->getImageData()->getHFR(x, y); + double HFR =3D image->getImageData()->getHFR(x, y); = - if (HFR > 0) - QToolTip::showText(e->globalPos(), i18nc("Half Flux Radius", "HFR: = %1", QString::number(HFR, 'g' , 3)), this); + if (HFR > 0) + QToolTip::showText(e->globalPos(), i18nc("Half Flux Radius", "HFR:= %1", QString::number(HFR, 'g' , 3)), this); = } = @@ -251,9 +258,9 @@ FITSView::FITSView(QWidget * parent, FITSMode fitsMode,= FITSScale filterType) : trackingBoxEnabled=3Dfalse; trackingBoxUpdated=3Dfalse; filter =3D filterType; - mode =3D fitsMode; = + mode =3D fitsMode; = - setBackgroundRole(QPalette::Dark); = + setBackgroundRole(QPalette::Dark); = markerCrosshair.setX(0); markerCrosshair.setY(0); @@ -261,6 +268,8 @@ FITSView::FITSView(QWidget * parent, FITSMode fitsMode,= FITSScale filterType) : currentZoom =3D 0.0; markStars =3D false; = + setBaseSize(640,480); + connect(image_frame, SIGNAL(newStatus(QString,FITSBar)), this, SIGNAL(= newStatus(QString,FITSBar))); connect(image_frame, SIGNAL(pointSelected(int,int)), this, SLOT(proces= sPointSelection(int,int))); connect(image_frame, SIGNAL(markerSelected(int,int)), this, SLOT(proce= ssMarkerSelection(int,int))); @@ -271,7 +280,7 @@ FITSView::FITSView(QWidget * parent, FITSMode fitsMode,= FITSScale filterType) : //connect(image_frame, SIGNAL(pointSelected(int,int)), this, SLOT(proc= essPointSelection(int,int))); = // Default size - resize(INITIAL_W, INITIAL_H); + //resize(INITIAL_W, INITIAL_H); } = FITSView::~FITSView() @@ -321,8 +330,8 @@ bool FITSView::loadFITS (const QString &inFilename , bo= ol silent) return false; else { - fitsProg.setValue(65); - qApp->processEvents(); + fitsProg.setValue(65); + qApp->processEvents(); } } = @@ -346,8 +355,8 @@ bool FITSView::loadFITS (const QString &inFilename , bo= ol silent) return false; else { - fitsProg.setValue(75); - qApp->processEvents(); + fitsProg.setValue(75); + qApp->processEvents(); } } = @@ -375,15 +384,15 @@ bool FITSView::loadFITS (const QString &inFilename , = bool silent) return false; else { - fitsProg.setValue(100); - qApp->processEvents(); + fitsProg.setValue(100); + qApp->processEvents(); } } = setAlignment(Qt::AlignCenter); = if (isVisible()) - emit newStatus(QString("%1x%2").arg(image_width).arg(image_height), FI= TS_RESOLUTION); + emit newStatus(QString("%1x%2").arg(image_width).arg(image_height)= , FITS_RESOLUTION); = return true; } @@ -507,12 +516,15 @@ int FITSView::rescale(FITSZoom type) case ZOOM_FIT_WINDOW: if ((display_image->width() > width() || display_image->height() >= height())) { + int w =3D baseSize().width() - BASE_OFFSET; + int h =3D baseSize().height() - BASE_OFFSET; + // Find the zoom level which will enclose the current FITS in = the default window size (640x480) - currentZoom =3D floor( (INITIAL_W / currentWidth) * 10.) * 10.; + currentZoom =3D floor( (w / currentWidth) * 10.) * 10.; = /* If width is not the problem, try height */ if (currentZoom > ZOOM_DEFAULT) - currentZoom =3D floor( (INITIAL_H / currentHeight) * 10.) = * 10.; + currentZoom =3D floor( (h / currentHeight) * 10.) * 10.; = currentWidth =3D image_width * (currentZoom / ZOOM_DEFAULT); currentHeight =3D image_height * (currentZoom / ZOOM_DEFAULT); @@ -547,8 +559,8 @@ int FITSView::rescale(FITSZoom type) setWidget(image_frame); = = - if (type !=3D ZOOM_KEEP_LEVEL) - emit newStatus(QString("%1%").arg(currentZoom), FITS_ZOOM); + if (type !=3D ZOOM_KEEP_LEVEL) + emit newStatus(QString("%1%").arg(currentZoom), FITS_ZOOM); = return 0; = @@ -613,9 +625,9 @@ void FITSView::updateFrame() return; = if (currentZoom !=3D ZOOM_DEFAULT) - ok =3D displayPixmap.convertFromImage(display_image->scaled( (= int) currentWidth, (int) currentHeight, Qt::KeepAspectRatio, Qt::SmoothTran= sformation)); - else - ok =3D displayPixmap.convertFromImage(*display_image); + ok =3D displayPixmap.convertFromImage(display_image->scaled( (int)= currentWidth, (int) currentHeight, Qt::KeepAspectRatio, Qt::SmoothTransfor= mation)); + else + ok =3D displayPixmap.convertFromImage(*display_image); = = if (ok =3D=3D false) @@ -650,7 +662,7 @@ void FITSView::ZoomDefault() void FITSView::drawOverlay(QPainter *painter) { if (markStars) - drawStarCentroid(painter); + drawStarCentroid(painter); = //if (mode =3D=3D FITS_GUIDE) if (trackingBoxEnabled) @@ -753,37 +765,37 @@ void FITSView::setTrackingBox(const QRect & rect) = void FITSView::toggleStars(bool enable) { - markStars =3D enable; - - if (markStars =3D=3D true) - { - QApplication::setOverrideCursor(Qt::WaitCursor); - emit newStatus(i18n("Finding stars..."), FITS_MESSAGE); - qApp->processEvents(); - int count =3D -1; - - if (trackingBoxEnabled) - { - count =3D image_data->findStars(trackingBox, trackingBoxUpdated= ); - trackingBoxUpdated=3Dfalse; - } - else - count =3D image_data->findStars(); - - - //QRectF boundary(0,0, image_data->getWidth(), image_data->getHeight()= ); - //count =3D image_data->findOneStar(boundary); - - if (count >=3D 0 && isVisible()) - emit newStatus(i18np("1 star detected.", "%1 stars detected= .", count), FITS_MESSAGE); - QApplication::restoreOverrideCursor(); - } + markStars =3D enable; + + if (markStars =3D=3D true) + { + QApplication::setOverrideCursor(Qt::WaitCursor); + emit newStatus(i18n("Finding stars..."), FITS_MESSAGE); + qApp->processEvents(); + int count =3D -1; + + if (trackingBoxEnabled) + { + count =3D image_data->findStars(trackingBox, trackingBoxUpdate= d); + trackingBoxUpdated=3Dfalse; + } + else + count =3D image_data->findStars(); + + + //QRectF boundary(0,0, image_data->getWidth(), image_data->getHeig= ht()); + //count =3D image_data->findOneStar(boundary); + + if (count >=3D 0 && isVisible()) + emit newStatus(i18np("1 star detected.", "%1 stars detected.",= count), FITS_MESSAGE); + QApplication::restoreOverrideCursor(); + } } = void FITSView::processPointSelection(int x, int y) { //if (mode !=3D FITS_GUIDE) - //return; + //return; = //image_data->getCenterSelection(&x, &y); = @@ -793,10 +805,10 @@ void FITSView::processPointSelection(int x, int y) = void FITSView::processMarkerSelection(int x, int y) { - markerCrosshair.setX(x); - markerCrosshair.setY(y); + markerCrosshair.setX(x); + markerCrosshair.setY(y); = - updateFrame(); + updateFrame(); } = void FITSView::setTrackingBoxEnabled(bool enable) @@ -816,6 +828,14 @@ void FITSView::wheelEvent(QWheelEvent* event) ZoomOut(); = event->accept(); + + if (markerCrosshair.isNull() =3D=3D false) + { + int x0 =3D markerCrosshair.x() * (currentZoom / ZOOM_DEFAULT); + int y0 =3D markerCrosshair.y() * (currentZoom / ZOOM_DEFAULT); + + ensureVisible(x0,y0, image_width/2, image_height/2); + } } = void FITSView::initDisplayImage() diff --git a/kstars/fitsviewer/fitsview.h b/kstars/fitsviewer/fitsview.h index 0f6074c..e45eb10 100644 --- a/kstars/fitsviewer/fitsview.h +++ b/kstars/fitsviewer/fitsview.h @@ -43,9 +43,6 @@ #include "dms.h" #include "fitsdata.h" = -#define INITIAL_W 640 -#define INITIAL_H 480 - #define MINIMUM_PIXEL_RANGE 5 #define MINIMUM_STDVAR 5 =