Skip to content

Commit

Permalink
FIXED issue mentioned in #110: Lock the panning action to certain val…
Browse files Browse the repository at this point in the history
…ues: View zooms in, when panning close to AbosluteXY</a> (thanks to https://github.com/sim186 for reporting)
  • Loading branch information
jkriege2 committed Dec 21, 2023
1 parent 995ca92 commit 99ff39a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/dox/whatsnew.dox
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Changes, compared to \ref page_whatsnew_V4_0_0 "v4.0.0" include:
<li>FIXED: fixed impleentations of JKQTPlotter::beginGraphs(), which actually returned the end-iterator (COPY-PASTE-ERROR!!!)</li>
<li>FIXED issue <a href="https://github.com/jkriege2/JKQtPlotter/pull/99">#99: Clipping of Tick Labels</a>: for horizontal axes, additional space at the left and/or right of the plot is allowed so labels are no longer clipped (thanks to <a href="https://github.com/allenbarnett5">user:allenbarnett5/a> for reporting)</li>
<li>FIXED issue <a href="https://github.com/jkriege2/JKQtPlotter/pull/99">#99: Height of one-column key/legend was too large</a> (thanks to <a href="https://github.com/allenbarnett5">user:allenbarnett5/a> for reporting)</li>
<li>FIXED issue mentioned in <a href="https://github.com/jkriege2/JKQtPlotter/pull/110">#110: Lock the panning action to certain values: View zooms in, when panning close to AbosluteXY</a> (thanks to <a href="https://github.com/sim186">user:sim186</a> for reporting)</li>
<li>FIXED/IMPROVED issue <a href="https://github.com/jkriege2/JKQtPlotter/issues/100">#100: Add option to disable resize delay feature by setting the delay to zero</a> (thanks to <a href="https://github.com/fpalazzolo">user:fpalazzolo</a> for reporting)</li>
<li>FIXED/NEW: placement of plot-title (was not centerd in its box, but glued to the bottom) by adding a plotstyle parameter JKQTBasePlotterStyle::plotLabelOffset</li>
<li>FIXED/REWORKED issue <a href="https://github.com/jkriege2/JKQtPlotter/issues/111">#111: Can't write to PDF files with JKQTPlotter::saveImage() when passing a filename ending in ".pdf"</a> (thanks to <a href="https://github.com/fpalazzolo">user:fpalazzolo/a> for reporting):<br/>While fixing this issue, the functions JKQTBasePlotter::saveImage() etc. gained a bool return value to indicate whether sacing was successful.</li>
Expand Down
33 changes: 32 additions & 1 deletion lib/jkqtplotter/jkqtplotter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,33 @@ void JKQTPlotter::paintUserAction() {
}
}

void JKQTPlotter::correctZoomRectForPanning(QRectF &zoomRect) const
{
zoomRect=zoomRect.normalized();

// this code corrects for cases, where you pan over getAbsoluteXY().
// without this correction, the zoom rectangle size will be changed, instead of jus stopping at the absolute size
auto correctForAbsoluteLeft=[](double pos, double absPos) {
if (!JKQTPIsOKFloat(absPos)) return pos;
if (pos<absPos) return absPos;
return pos;
};
auto correctForAbsoluteRight=[](double pos, double absPos) {
if (!JKQTPIsOKFloat(absPos)) return pos;
if (pos>absPos) return absPos;
return pos;
};
const double absXMin=plotter->x2p(plotter->getAbsoluteXMin());
const double absYMin=plotter->y2p(plotter->getAbsoluteYMin());
const double absXMax=plotter->x2p(plotter->getAbsoluteXMax());
const double absYMax=plotter->y2p(plotter->getAbsoluteYMax());
if (JKQTPIsOKFloat(absXMin)&&JKQTPIsOKFloat(absXMax)) zoomRect.moveLeft(correctForAbsoluteLeft(zoomRect.left(), std::min<double>(absXMin, absXMax)));
if (JKQTPIsOKFloat(absYMin)&&JKQTPIsOKFloat(absYMax)) zoomRect.moveTop(correctForAbsoluteLeft(zoomRect.top(), std::min<double>(absYMin, absYMax)));
if (JKQTPIsOKFloat(absXMin)&&JKQTPIsOKFloat(absXMax)) zoomRect.moveRight(correctForAbsoluteRight(zoomRect.right(), std::max<double>(absXMin, absXMax)));
if (JKQTPIsOKFloat(absYMin)&&JKQTPIsOKFloat(absYMax)) zoomRect.moveBottom(correctForAbsoluteRight(zoomRect.bottom(), std::max<double>(absYMin, absYMax)));

}


void JKQTPlotter::mouseMoveEvent ( QMouseEvent * event ) {
if (plotterStyle.displayMousePosition) {
Expand Down Expand Up @@ -825,6 +852,7 @@ void JKQTPlotter::mouseMoveEvent ( QMouseEvent * event ) {
} else {
zoomRect.translate(mouseDragRectXStartPixel-mouseDragRectXEndPixel, mouseDragRectYStartPixel-mouseDragRectYEndPixel);
}
correctZoomRectForPanning(zoomRect);
setXY(plotter->p2x(zoomRect.left()), plotter->p2x(zoomRect.right()), plotter->p2y(zoomRect.bottom()), plotter->p2y(zoomRect.top()), true);
}

Expand Down Expand Up @@ -939,6 +967,7 @@ void JKQTPlotter::mouseReleaseEvent ( QMouseEvent * event ){
} else {
zoomRect.translate(mouseDragRectXStartPixel-mouseDragRectXEndPixel, mouseDragRectYStartPixel-mouseDragRectYEndPixel);
}
correctZoomRectForPanning(zoomRect);
setXY(plotter->p2x(zoomRect.left()), plotter->p2x(zoomRect.right()), plotter->p2y(zoomRect.bottom()), plotter->p2y(zoomRect.top()), true);
} else if (currentMouseDragAction.mode==jkqtpmdaDrawRectangleForEvent) {
emit userRectangleFinished(x1, y1, x2-x1, y2-y1, event->modifiers());
Expand Down Expand Up @@ -1094,7 +1123,7 @@ void JKQTPlotter::wheelEvent ( QWheelEvent * event ) {
acTodo=WheelActionType::Pan;
d=QPointF(angleDelta.x()/120.0*zoomRect.width()/10.0,
angleDelta.y()/120.0*zoomRect.height()/10.0);
// maximum shoft is 100 Pixels in either direction
// maximum shift is 100 Pixels in either direction
d.setX(jkqtp_bounded<double>(-100, d.x(), 100));
d.setY(jkqtp_bounded<double>(-100, d.y(), 100));
// minimmum shift is 10 pixels, unles |shift|<1
Expand Down Expand Up @@ -1130,6 +1159,8 @@ void JKQTPlotter::wheelEvent ( QWheelEvent * event ) {
} else {
zoomRect.translate(d.x(), d.y());
}
correctZoomRectForPanning(zoomRect);
// now apply the new range
setXY(plotter->p2x(zoomRect.left()), plotter->p2x(zoomRect.right()), plotter->p2y(zoomRect.bottom()), plotter->p2y(zoomRect.top()), true);
}

Expand Down
3 changes: 3 additions & 0 deletions lib/jkqtplotter/jkqtplotter.h
Original file line number Diff line number Diff line change
Expand Up @@ -1496,6 +1496,9 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPlotter: public QWidget {
/** \brief paint the user action (rectangle, ellipse, ... */
void paintUserAction();

/** \brief tool function, which corrects the given rectangle (in pixels!) during a panning action. The correction is necesary towards getAbsoluteXY() to prevent an unwanted zooming in. */
void correctZoomRectForPanning(QRectF& rect) const;


/** \brief event handler for a double click
*
Expand Down

0 comments on commit 99ff39a

Please sign in to comment.