jfjoch_viewer: Extra panel for ROI (tbd)

This commit is contained in:
2025-11-05 11:58:20 +01:00
parent b15d06c1b0
commit 78d4f21d4b
8 changed files with 141 additions and 49 deletions
+60 -1
View File
@@ -8,6 +8,7 @@
#include <QGraphicsScene>
#include <QWheelEvent>
#include <QScrollBar>
#include <QMenu>
#include <cmath>
// Constructor
@@ -107,6 +108,8 @@ void JFJochViewerImage::mousePressEvent(QMouseEvent *event) {
else
mouse_event_type = MouseEventType::Panning;
}
} else if (event->button() == Qt::RightButton) {
mouse_event_type = MouseEventType::RightClickMenu;
}
QGraphicsView::mousePressEvent(event); // Call base implementation
}
@@ -175,7 +178,9 @@ void JFJochViewerImage::mouseReleaseEvent(QMouseEvent *event) {
if (!scene() || !image) return;
setCursor(Qt::CursorShape::ArrowCursor);
if (mouse_event_type == MouseEventType::MovingROI) {
if (mouse_event_type == MouseEventType::RightClickMenu) {
ShowImageMenu(event);
} else if (mouse_event_type == MouseEventType::MovingROI) {
if (roi_type == RoiType::RoiBox) {
roiStartPos = RoundPoint(roiStartPos);
roiEndPos = RoundPoint(roiEndPos);
@@ -669,3 +674,57 @@ void JFJochViewerImage::highlightIceRings(bool input) {
highlight_ice_rings = input;
Redraw();
}
void JFJochViewerImage::ShowImageMenu(QMouseEvent *event) {
auto mouse_loc = mapToScene(event->pos());
float radius = roi_box.height() / 2.0;
QPointF center = roi_box.center();
bool mouse_in_roi = false;
if (roi_box.width() * roi_box.height() > 0) {
if (roi_box.contains(mouse_loc)) {
if (roi_type == RoiType::RoiCircle) {
float dx = mouse_loc.x() - center.x();
float dy = mouse_loc.y() - center.y();
float distance_sq = dx * dx + dy * dy;
if (distance_sq <= radius * radius) {
mouse_in_roi = true;
}
} else
mouse_in_roi = true;
}
}
if (mouse_in_roi) {
QMenu menu;
// Show ROI coordinates (read-only)
QString roi_coordinates;
if (roi_type == RoiType::RoiBox) {
roi_coordinates = QString("ROI Box x: [%1, %2] y: [%3, %4]")
.arg(roi_box.left())
.arg(roi_box.right())
.arg(roi_box.top())
.arg(roi_box.bottom());
} else {
roi_coordinates = QString("ROI Circle: center: [%1, %2] r: %3").arg(center.x()).arg(center.y()).arg(radius);
}
menu.addAction(roi_coordinates)->setDisabled(true);
// Add or remove from user mask
QAction *addMaskAction = menu.addAction("Add to user mask");
QAction *removeMaskAction = menu.addAction("Remove from user mask");
// Show the menu at the cursor's position
QAction *selectedAction = menu.exec(event->globalPos());
if (selectedAction == addMaskAction) {
// Implement "Add to user mask" functionality here
} else if (selectedAction == removeMaskAction) {
// Implement "Remove from user mask" functionality here
}
}
}