v1.0.0-rc.34
This commit is contained in:
@@ -63,26 +63,79 @@ void JFJochViewerImage::wheelEvent(QWheelEvent *event) {
|
||||
}
|
||||
}
|
||||
|
||||
// Handle start of panning on mouse press
|
||||
QPointF RoundPoint(const QPointF &input) {
|
||||
return QPointF(qRound(input.x()), qRound(input.y()));
|
||||
}
|
||||
|
||||
void JFJochViewerImage::mousePressEvent(QMouseEvent *event) {
|
||||
mouse_event_type = MouseEventType::None;
|
||||
|
||||
bool mouse_inside_roi = false;
|
||||
if (roiStartPos != roiEndPos) {
|
||||
QRectF roiRect = QRectF(roiStartPos, roiEndPos).normalized();
|
||||
mouse_inside_roi = roiRect.contains(mapToScene(event->pos()));
|
||||
}
|
||||
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
setCursor(Qt::ClosedHandCursor); // Change cursor to indicate panning
|
||||
lastMousePos = event->pos();
|
||||
|
||||
if (mouse_inside_roi)
|
||||
mouse_event_type = MouseEventType::MovingRectROI;
|
||||
else
|
||||
mouse_event_type = MouseEventType::Panning;
|
||||
|
||||
} else if (event->buttons() & Qt::RightButton) {
|
||||
setCursor(Qt::CursorShape::CrossCursor);
|
||||
if (mouse_inside_roi)
|
||||
roiEndPos = RoundPoint(mapToScene(event->pos()));
|
||||
else
|
||||
roiStartPos = RoundPoint(mapToScene(event->pos()));
|
||||
|
||||
mouse_event_type = MouseEventType::DrawingRectROI;
|
||||
}
|
||||
QGraphicsView::mousePressEvent(event); // Call base implementation
|
||||
}
|
||||
|
||||
// Handle panning while moving the mouse
|
||||
void JFJochViewerImage::mouseMoveEvent(QMouseEvent *event) {
|
||||
if (event->buttons() & Qt::LeftButton) {
|
||||
QPointF delta = mapToScene(event->pos()) - mapToScene(lastMousePos);
|
||||
lastMousePos = event->pos();
|
||||
translate(delta.x(), delta.y()); // Adjust the view's pan
|
||||
updateOverlay();
|
||||
QPointF delta;
|
||||
switch (mouse_event_type) {
|
||||
case MouseEventType::Panning:
|
||||
delta = mapToScene(event->pos()) - mapToScene(lastMousePos);
|
||||
lastMousePos = event->pos();
|
||||
translate(delta.x(), delta.y()); // Adjust the view's pan
|
||||
updateOverlay();
|
||||
break;
|
||||
case MouseEventType::DrawingRectROI:
|
||||
roiEndPos = RoundPoint(mapToScene(event->pos()));
|
||||
updateROI();
|
||||
break;
|
||||
case MouseEventType::MovingRectROI:
|
||||
delta = mapToScene(event->pos()) - mapToScene(lastMousePos);
|
||||
roiStartPos += delta;
|
||||
roiEndPos += delta;
|
||||
lastMousePos = event->pos();
|
||||
updateROI();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
QGraphicsView::mouseMoveEvent(event);
|
||||
}
|
||||
|
||||
void JFJochViewerImage::mouseReleaseEvent(QMouseEvent *event) {
|
||||
setCursor(Qt::CursorShape::ArrowCursor);
|
||||
if (mouse_event_type == MouseEventType::MovingRectROI) {
|
||||
roiStartPos = RoundPoint(roiStartPos);
|
||||
roiEndPos = RoundPoint(roiEndPos);
|
||||
updateROI();
|
||||
}
|
||||
|
||||
mouse_event_type = MouseEventType::None;
|
||||
|
||||
QGraphicsView::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
void JFJochViewerImage::LoadImageInternal() {
|
||||
if (!image || (image->dataset->image_size_x <= 0))
|
||||
@@ -242,13 +295,19 @@ void JFJochViewerImage::DrawTopPixels() {
|
||||
DrawCross(iter->second % image->dataset->image_size_x + 0.5, iter->second / image->dataset->image_size_x + 0.5, 15, 3);
|
||||
}
|
||||
|
||||
void JFJochViewerImage::updateOverlay() {
|
||||
if (!scene() || !image) return;
|
||||
void JFJochViewerImage::updateROI() {
|
||||
roi_box = QRectF(RoundPoint(roiStartPos), RoundPoint(roiEndPos)).normalized().toRect();
|
||||
emit roiUpdated(roi_box);
|
||||
updateOverlay();
|
||||
}
|
||||
|
||||
void JFJochViewerImage::updateOverlay() {
|
||||
for (auto &i: overlay)
|
||||
delete i;
|
||||
overlay.clear();
|
||||
|
||||
if (!scene() || !image) return;
|
||||
|
||||
QFont font("Arial", 1); // Font for pixel value text
|
||||
font.setPixelSize(1); // This will render very small text (1-pixel high).
|
||||
|
||||
@@ -298,6 +357,15 @@ void JFJochViewerImage::updateOverlay() {
|
||||
DrawTopPixels();
|
||||
if (show_saturation)
|
||||
DrawSaturation();
|
||||
|
||||
if (roi_box.width() * roi_box.height() > 0) {
|
||||
QPen pen(feature_color, 3);
|
||||
pen.setStyle(Qt::DashLine);
|
||||
pen.setCosmetic(true);
|
||||
QGraphicsRectItem *rectItem = scene()->addRect(roi_box, pen);
|
||||
|
||||
overlay.push_back(rectItem);
|
||||
}
|
||||
}
|
||||
|
||||
void JFJochViewerImage::resizeEvent(QResizeEvent *event) {
|
||||
@@ -347,6 +415,9 @@ void JFJochViewerImage::setColorMap(int color_map) {
|
||||
}
|
||||
|
||||
void JFJochViewerImage::noImage() {
|
||||
for (auto &i: overlay)
|
||||
delete i;
|
||||
overlay.clear();
|
||||
image.reset();
|
||||
if (scene())
|
||||
scene()->clear();
|
||||
|
||||
Reference in New Issue
Block a user