fix marker grab position

This commit is contained in:
Jan Käberich 2022-11-03 20:08:14 +01:00
parent e400f62f04
commit a0cacdfbef

View File

@ -138,7 +138,8 @@ std::vector<Trace *> TracePlot::orderedTraces()
void TracePlot::contextMenuEvent(QContextMenuEvent *event) void TracePlot::contextMenuEvent(QContextMenuEvent *event)
{ {
auto m = markerAtPosition(event->pos()); auto position = event->pos() - QPoint(marginLeft, marginTop);
auto m = markerAtPosition(position);
QMenu *menu; QMenu *menu;
if(m) { if(m) {
// right click on marker, execute its contextmenu // right click on marker, execute its contextmenu
@ -422,7 +423,6 @@ void TracePlot::wheelEvent(QWheelEvent *event)
Marker *TracePlot::markerAtPosition(QPoint p, bool onlyMovable) Marker *TracePlot::markerAtPosition(QPoint p, bool onlyMovable)
{ {
auto clickPoint = p - QPoint(marginLeft, marginTop);
// check if click was near a marker // check if click was near a marker
unsigned int closestDistance = numeric_limits<unsigned int>::max(); unsigned int closestDistance = numeric_limits<unsigned int>::max();
Marker *closestMarker = nullptr; Marker *closestMarker = nullptr;
@ -441,7 +441,7 @@ Marker *TracePlot::markerAtPosition(QPoint p, bool onlyMovable)
// invalid, skip // invalid, skip
continue; continue;
} }
auto diff = markerPoint - clickPoint; auto diff = markerPoint - p;
unsigned int distance = diff.x() * diff.x() + diff.y() * diff.y(); unsigned int distance = diff.x() * diff.x() + diff.y() * diff.y();
if(distance < closestDistance) { if(distance < closestDistance) {
closestDistance = distance; closestDistance = distance;