From fd8ea3adb23eede48eae5bfea320805992393473 Mon Sep 17 00:00:00 2001 From: Snolandia <64045395+Snolandia@users.noreply.github.com> Date: Wed, 16 Oct 2024 04:24:50 -0700 Subject: [PATCH] BugFix (#139) When right clicking during a ScribbleForEvent/MouseDragAction, and the right click is outside the plot, the last scribble event was not being generated. --- lib/jkqtplotter/jkqtplotter.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/jkqtplotter/jkqtplotter.cpp b/lib/jkqtplotter/jkqtplotter.cpp index 3bd63aac16..20573adc97 100644 --- a/lib/jkqtplotter/jkqtplotter.cpp +++ b/lib/jkqtplotter/jkqtplotter.cpp @@ -888,6 +888,7 @@ void JKQTPlotter::mouseMoveEvent ( QMouseEvent * event ) { void JKQTPlotter::mousePressEvent ( QMouseEvent * event ){ + MouseDragAction prevAction = currentMouseDragAction; currentMouseDragAction.clear(); mouseDragMarkers.clear(); @@ -906,11 +907,18 @@ void JKQTPlotter::mousePressEvent ( QMouseEvent * event ){ oldImage=image; if (currentMouseDragAction.mode==jkqtpmdaScribbleForEvents) emit userScribbleClick(mouseDragRectXStart, mouseDragRectYStart, event->modifiers(), true, false); event->accept(); - } else if (event->button()==Qt::RightButton && event->modifiers()==Qt::NoModifier && contextMenuMode!=jkqtpcmmNoContextMenu) { - mouseLastClickX=event->pos().x(); - mouseLastClickY=event->pos().y(); - openContextMenu(event->pos().x(), event->pos().y()); - event->accept(); + } else if (event->button()==Qt::RightButton) { + if (prevAction.mode==jkqtpmdaScribbleForEvents){ + mouseDragRectXStart=plotter->p2x(event->pos().x()/magnification); + mouseDragRectYStart=plotter->p2y((event->pos().y()-getPlotYOffset())/magnification); + emit userScribbleClick(mouseDragRectXStart, mouseDragRectYStart, event->modifiers(), false, true); + } + if(event->modifiers()==Qt::NoModifier && contextMenuMode!=jkqtpcmmNoContextMenu){ + mouseLastClickX=event->pos().x(); + mouseLastClickY=event->pos().y(); + openContextMenu(event->pos().x(), event->pos().y()); + event->accept(); + } } // emit clicked signal, if event occured inside plot only