Commit bb4055f5 authored by Ian Humphrey's avatar Ian Humphrey
Browse files

Fixed qview's initially viewport zoom and fit to zoom functionality so the...

Fixed qview's initially viewport zoom and fit to zoom functionality so the image is no longer offset. Fixes #4756.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/trunk@7657 41f8697f-d340-4b68-9986-7bafba869bb8
parent e846dcbe
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -156,5 +156,9 @@
      Added shortcuts to Match Tool window for selecting right measures, registration, undo 
      registration, saving measures, saving the point, and saving the control network. Fixes #2324.
    </change>
    <change name="Ian Humphrey" date="2017-05-10">
      Fixed initial loading of viewport and Fit to viewport zoom to correctly zoom to the center
      of the image. Fixes #4756.
    </change>
  </history>
</application>
+23 −25
Original line number Diff line number Diff line
@@ -228,6 +228,9 @@ namespace Isis {
   * This method is called to initially show the viewport. It will set the
   * scale to show the entire cube and enable the gray buffer.
   *
   * @param QShowEvent *event Show event being received.
   *
   * @see http://doc.qt.io/qt-5/qwidget.html#showEvent
   */
  void CubeViewport::showEvent(QShowEvent *event) {
    if(p_scale == -1) {
@@ -237,7 +240,7 @@ namespace Isis {
      //double lineScale = (double) sizeHint().height() / (double) cubeLines();
      //double scale = sampScale < lineScale ? sampScale : lineScale;

      setScale(fitScale(), cubeSamples() / 2.0, cubeLines() / 2.0);
      setScale(fitScale(), cubeSamples() / 2.0 + 0.5, cubeLines() / 2.0 + 0.5);
    }

    if(p_grayBuffer && !p_grayBuffer->enabled()) {
@@ -693,7 +696,6 @@ namespace Isis {
    else {
      setScale(scale);
    }

    center(sample, line);

    if (p_grayBuffer){
@@ -731,19 +733,15 @@ namespace Isis {


  /**
   * Bring the cube sample/line the center
   *
   * Bring the cube sample/line the center.
   *
   * @param sample
   * @param line
   * @param sample Value of the sample to center on.
   * @param line Value of the line to center on.
   */
  void CubeViewport::center(double sample, double line) {
    int x, y;
    cubeToContents(sample, line, x, y);

    x ++;
    y ++;

    int panX = horizontalScrollBar()->value() - x;
    int panY = verticalScrollBar()->value() - y;

+6 −0
Original line number Diff line number Diff line
@@ -117,6 +117,12 @@ namespace Isis {
   *                          comboCount(), comboIndex(), setComboCount(), and setComboIndex()
   *                          accessors and setters to allow the BandTool class to retain the
   *                          settings for each cube viewport. Fixes #1612.
   *  @history 2017-05-10 Ian Humphrey - Modified showEvent() so that when the cube viewport is
   *                          initially shown, the image is centered properly in the viewport.
   *                          Modified center(double, double) to no longer increment the
   *                          cubeToContents x,y by 1. This was causing some images to be
   *                          off-centered by 1 pixel (the bottom and right side of viewport would
   *                          be a thin strip of non-pixel space). Fixes #4756.
   */
  class CubeViewport : public QAbstractScrollArea {
      Q_OBJECT
+25 −21
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
 *  http://isis.astrogeology.usgs.gov, and the USGS privacy and disclaimers on
 *  http://www.usgs.gov/privacy.html.
 */
#include <iostream>

#include <QAction>
#include <QApplication>
@@ -372,11 +373,13 @@ namespace Isis {
   * @internal
   *   @history 2010-07-12 Jeannie Walldren - Modified to call this object's
   *                          setScale method.
   *   @history 2017-05-10 Ian Humphrey - Modified so that the setScale() is accommodating the ISIS
   *                           pixel center definition (integer center) (+0.5). References #4756.
   */
  void ZoomTool::zoomFit() {
    MdiCubeViewport *d = cubeViewport();
    if (d == NULL) return;
    setScale(d, d->fitScale(), d->cubeSamples() / 2.0, d->cubeLines() / 2.0);
    setScale(d, d->fitScale(), d->cubeSamples() / 2.0 + 0.5, d->cubeLines() / 2.0 + 0.5);
    updateTool();

    if (d->isLinked()) {
@@ -384,7 +387,7 @@ namespace Isis {
        d = (*(cubeViewportList()))[i];
        if (d == cubeViewport()) continue;
        if (d->isLinked()) {
          setScale(d, d->fitScale(), d->cubeSamples() / 2.0, d->cubeLines() / 2.0);
          setScale(d, d->fitScale(), d->cubeSamples() / 2.0 + 0.5, d->cubeLines() / 2.0 + 0.5);
        }
      }
    }
@@ -402,7 +405,7 @@ namespace Isis {
  void ZoomTool::zoomFitWidth() {
    MdiCubeViewport *d = cubeViewport();
    if (d == NULL) return;
    setScale(d, d->fitScaleWidth(), d->cubeSamples() / 2.0, d->cubeLines() / 2.0);
    setScale(d, d->fitScaleWidth(), d->cubeSamples() / 2.0 + 0.5, d->cubeLines() / 2.0 + 0.5);
    updateTool();

    if (d->isLinked()) {
@@ -410,7 +413,7 @@ namespace Isis {
        d = (*(cubeViewportList()))[i];
        if (d == cubeViewport()) continue;
        if (d->isLinked()) {
          setScale(d, d->fitScaleWidth(), d->cubeSamples() / 2.0, d->cubeLines() / 2.0);
          setScale(d, d->fitScaleWidth(), d->cubeSamples() / 2.0 + 0.5, d->cubeLines() / 2.0 + 0.5);
        }
      }
    }
@@ -428,7 +431,7 @@ namespace Isis {
  void ZoomTool::zoomFitHeight() {
    MdiCubeViewport *d = cubeViewport();
    if (d == NULL) return;
    setScale(d, d->fitScaleHeight(), d->cubeSamples() / 2.0, d->cubeLines() / 2.0);
    setScale(d, d->fitScaleHeight(), d->cubeSamples() / 2.0 + 0.5, d->cubeLines() / 2.0 + 0.5);
    updateTool();

    if (d->isLinked()) {
@@ -436,7 +439,8 @@ namespace Isis {
        d = (*(cubeViewportList()))[i];
        if (d == cubeViewport()) continue;
        if (d->isLinked()) {
          setScale(d, d->fitScaleHeight(), d->cubeSamples() / 2.0, d->cubeLines() / 2.0);
          setScale(d, d->fitScaleHeight(), d->cubeSamples() / 2.0 + 0.5,
              d->cubeLines() / 2.0 + 0.5);
        }
      }
    }
+2 −1
Original line number Diff line number Diff line
@@ -61,6 +61,8 @@ namespace Isis {
   *                           causing bugs. As a result, the mouseButtonRelease
   *                           method did nothing so I removed that too. Zooming
   *                           happens on the rubberBandComplete slot.
   *  @history 2017-05-10 Ian Humphrey - Modified zoomFit() so that when doing a "Fit in viewport"
   *                          zoom, the image is centered properly in the viewport. Fixes #4756. 
   */
  class ZoomTool : public Tool {
      Q_OBJECT
@@ -123,4 +125,3 @@ namespace Isis {
};

#endif