jfjoch_viewer: mouse events are handled by JFJochImage, but this is not working properly for neither of the modes (TBD)
This commit is contained in:
@@ -12,57 +12,12 @@
|
||||
#include <cmath>
|
||||
#include <QMouseEvent>
|
||||
|
||||
#include "JFJochSimpleImage.h"
|
||||
|
||||
// Constructor
|
||||
JFJochDiffractionImage::JFJochDiffractionImage(QWidget *parent) : JFJochImage(parent) {}
|
||||
|
||||
|
||||
void JFJochDiffractionImage::mousePressEvent(QMouseEvent *event) {
|
||||
if (!scene() || !image) return;
|
||||
|
||||
mouse_event_type = MouseEventType::None;
|
||||
|
||||
bool mouse_inside_roi = false;
|
||||
if (roiStartPos != roiEndPos) {
|
||||
if (roi_type == RoiType::RoiBox) {
|
||||
QRectF roiRect = QRectF(roiStartPos, roiEndPos).normalized();
|
||||
mouse_inside_roi = roiRect.contains(mapToScene(event->pos()));
|
||||
} else {
|
||||
auto curr_position = mapToScene(event->pos());
|
||||
auto delta = roiStartPos - curr_position;
|
||||
auto radius_vec = roiStartPos - roiEndPos;
|
||||
auto radius_2 = radius_vec.x() * radius_vec.x() + radius_vec.y() * radius_vec.y();
|
||||
mouse_inside_roi = (delta.x() * delta.x() + delta.y() * delta.y() < radius_2);
|
||||
}
|
||||
}
|
||||
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
if (event->modifiers() & Qt::Modifier::SHIFT) {
|
||||
setCursor(Qt::CursorShape::CrossCursor);
|
||||
|
||||
if (mouse_inside_roi) {
|
||||
roiEndPos = RoundPoint(mapToScene(event->pos()));
|
||||
} else {
|
||||
roiStartPos = RoundPoint(mapToScene(event->pos()));
|
||||
roi_type = (event->modifiers() & Qt::Modifier::CTRL) ? RoiType::RoiCircle : RoiType::RoiBox;
|
||||
}
|
||||
mouse_event_type = MouseEventType::DrawingROI;
|
||||
} else {
|
||||
setCursor(Qt::ClosedHandCursor); // Change cursor to indicate panning
|
||||
lastMousePos = event->pos();
|
||||
|
||||
if (mouse_inside_roi)
|
||||
mouse_event_type = MouseEventType::MovingROI;
|
||||
else
|
||||
mouse_event_type = MouseEventType::Panning;
|
||||
}
|
||||
}
|
||||
QGraphicsView::mousePressEvent(event); // Call base implementation
|
||||
}
|
||||
|
||||
// Handle panning while moving the mouse
|
||||
void JFJochDiffractionImage::mouseMoveEvent(QMouseEvent *event) {
|
||||
if (!scene() || !image) return;
|
||||
|
||||
void JFJochDiffractionImage::mouseHover(QMouseEvent *event) {
|
||||
auto coord = mapToScene(event->pos());
|
||||
|
||||
if (image && (coord.x() >= 0)
|
||||
@@ -91,50 +46,9 @@ void JFJochDiffractionImage::mouseMoveEvent(QMouseEvent *event) {
|
||||
.arg(coord.y(), 0, 'f', 1)
|
||||
.arg(intensity_str)
|
||||
.arg(res, 0, 'f', 2));
|
||||
} else
|
||||
emit writeStatusBar("");
|
||||
} else
|
||||
emit writeStatusBar("");
|
||||
|
||||
QPointF delta;
|
||||
switch (mouse_event_type) {
|
||||
case MouseEventType::Panning:
|
||||
delta = coord - mapToScene(lastMousePos);
|
||||
lastMousePos = event->pos();
|
||||
translate(delta.x(), delta.y()); // Adjust the view's pan
|
||||
updateOverlay();
|
||||
break;
|
||||
case MouseEventType::DrawingROI:
|
||||
roiEndPos = RoundPoint(coord);
|
||||
updateROI();
|
||||
break;
|
||||
case MouseEventType::MovingROI:
|
||||
delta = coord - mapToScene(lastMousePos);
|
||||
roiStartPos += delta;
|
||||
roiEndPos += delta;
|
||||
lastMousePos = event->pos();
|
||||
updateROI();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
QGraphicsView::mouseMoveEvent(event);
|
||||
}
|
||||
|
||||
void JFJochDiffractionImage::mouseReleaseEvent(QMouseEvent *event) {
|
||||
if (!scene() || !image) return;
|
||||
|
||||
setCursor(Qt::CursorShape::ArrowCursor);
|
||||
|
||||
if (mouse_event_type == MouseEventType::MovingROI) {
|
||||
if (roi_type == RoiType::RoiBox) {
|
||||
roiStartPos = RoundPoint(roiStartPos);
|
||||
roiEndPos = RoundPoint(roiEndPos);
|
||||
}
|
||||
updateROI();
|
||||
}
|
||||
|
||||
mouse_event_type = MouseEventType::None;
|
||||
|
||||
QGraphicsView::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
void JFJochDiffractionImage::LoadImageInternal() {
|
||||
|
||||
Reference in New Issue
Block a user