summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Lancaster <rlancaste@gmail.com>2016-10-08 10:04:33 (GMT)
committerJasem Mutlaq <mutlaqja@ikarustech.com>2016-10-08 10:04:33 (GMT)
commiteb99d58da4ec759f5f9ef353af9852c950cdc3e3 (patch)
treee2ceee492dd8be980a768e8ef452f123d233a3ed
parentdfd322c407df8c397d9326e9ad932034691de5ae (diff)
Fix zoom to center to correctly reflect coordinates of the viewport
-rw-r--r--kstars/fitsviewer/fitstab.cpp8
-rw-r--r--kstars/fitsviewer/fitsview.cpp43
-rw-r--r--kstars/fitsviewer/fitsview.h6
3 files changed, 37 insertions, 20 deletions
diff --git a/kstars/fitsviewer/fitstab.cpp b/kstars/fitsviewer/fitstab.cpp
index 44abf5f..4cbb421 100644
--- a/kstars/fitsviewer/fitstab.cpp
+++ b/kstars/fitsviewer/fitstab.cpp
@@ -319,12 +319,16 @@ bool FITSTab::saveFileAs()
void FITSTab::ZoomIn()
{
- view->ZoomIn();
+ QPoint oldCenter=view->getImagePoint(view->viewport()->rect().center());
+ view->ZoomIn();
+ view->cleanUpZoom(oldCenter);
}
void FITSTab::ZoomOut()
{
- view->ZoomOut();
+ QPoint oldCenter=view->getImagePoint(view->viewport()->rect().center());
+ view->ZoomOut();
+ view->cleanUpZoom(oldCenter);
}
void FITSTab::ZoomDefault()
diff --git a/kstars/fitsviewer/fitsview.cpp b/kstars/fitsviewer/fitsview.cpp
index 4582069..0001826 100644
--- a/kstars/fitsviewer/fitsview.cpp
+++ b/kstars/fitsviewer/fitsview.cpp
@@ -822,6 +822,8 @@ void FITSView::setTrackingBoxEnabled(bool enable)
void FITSView::wheelEvent(QWheelEvent* event)
{
+ QPoint mouseCenter=getImagePoint(event->pos());
+
if (event->angleDelta().y() > 0)
ZoomIn();
else
@@ -829,30 +831,37 @@ void FITSView::wheelEvent(QWheelEvent* event)
event->accept();
- // Center toward marked crosshair
+ cleanUpZoom(mouseCenter);
+}
+
+void FITSView::cleanUpZoom(QPoint viewCenter)
+{
+ int x0=0;
+ int y0=0;
+ double scale = (currentZoom / ZOOM_DEFAULT);
if (markerCrosshair.isNull() == false)
{
- int x0 = markerCrosshair.x() * (currentZoom / ZOOM_DEFAULT);
- int y0 = markerCrosshair.y() * (currentZoom / ZOOM_DEFAULT);
-
- ensureVisible(x0,y0, image_width/2, image_height/2);
+ x0 = markerCrosshair.x() * scale;
+ y0 = markerCrosshair.y() * scale;
}
- // Otherwise tracking box
else if (trackingBoxEnabled)
{
- int x0 = trackingBox.x() * (currentZoom / ZOOM_DEFAULT);
- int y0 = trackingBox.y() * (currentZoom / ZOOM_DEFAULT);
-
- ensureVisible(x0,y0, image_width/2, image_height/2);
- }
- // Other just center
- else
+ x0 = trackingBox.center().x() * scale;
+ y0 = trackingBox.center().y() * scale;
+ } else
{
- QPoint center = viewport()->rect().center();
- int x0 = center.x() * (currentZoom / ZOOM_DEFAULT);
- int y0 = center.y() * (currentZoom / ZOOM_DEFAULT);
- ensureVisible(x0,y0, image_width/2, image_height/2);
+ x0 = viewCenter.x() * scale;
+ y0 = viewCenter.y() * scale;
}
+ ensureVisible(x0,y0, width()/2 , height()/2);
+}
+
+QPoint FITSView::getImagePoint(QPoint viewPortPoint)
+{
+ double scale = (currentZoom / ZOOM_DEFAULT);
+ QPoint widgetPoint = widget()->mapFromParent(viewPortPoint);
+ QPoint imagePoint = QPoint(widgetPoint.x() / scale , widgetPoint.y() / scale);
+ return imagePoint;
}
void FITSView::initDisplayImage()
diff --git a/kstars/fitsviewer/fitsview.h b/kstars/fitsviewer/fitsview.h
index e45eb10..89190fa 100644
--- a/kstars/fitsviewer/fitsview.h
+++ b/kstars/fitsviewer/fitsview.h
@@ -112,6 +112,10 @@ public:
void drawMarker(QPainter *);
void updateFrame();
+ // Zoom related
+ void cleanUpZoom(QPoint viewCenter);
+ QPoint getImagePoint(QPoint viewPortPoint);
+
// Star Detection
void toggleStars(bool enable);
@@ -127,7 +131,7 @@ protected:
public slots:
void ZoomIn();
void ZoomOut();
- void ZoomDefault();
+ void ZoomDefault();
void processPointSelection(int x, int y);
void processMarkerSelection(int x, int y);