| 413 | } |
| 414 | |
| 415 | void DatapickerImageView::mousePressEvent(QMouseEvent* event) { |
| 416 | // prevent the deselection of items when context menu event |
| 417 | // was triggered (right button click) |
| 418 | if (event->button() == Qt::RightButton) { |
| 419 | event->accept(); |
| 420 | return; |
| 421 | } |
| 422 | |
| 423 | if (event->button() == Qt::LeftButton && m_mouseMode == MouseMode::ZoomSelection) { |
| 424 | m_selectionStart = event->pos(); |
| 425 | m_selectionBandIsShown = true; |
| 426 | return; |
| 427 | } |
| 428 | |
| 429 | const auto eventPos = mapToScene(event->pos()); |
| 430 | const auto type = m_image->plotPointsType(); |
| 431 | bool entryMode = |
| 432 | (m_mouseMode == MouseMode::ReferencePointsEntry || m_mouseMode == MouseMode::CurvePointsEntry || m_mouseMode == MouseMode::CurveSegmentsEntry); |
| 433 | |
| 434 | // check whether there is a point item under the cursor |
| 435 | bool pointsUnderCursor = false; |
| 436 | const auto& items = this->items(event->pos()); |
| 437 | const auto& referencePoints = m_image->children<DatapickerPoint>(AbstractAspect::ChildIndexFlag::IncludeHidden); |
| 438 | for (auto* item : items) { |
| 439 | if (item == m_image->m_magnificationWindow) |
| 440 | continue; |
| 441 | |
| 442 | // when entering curve points, ignore the reference points under the cursor, |
| 443 | // it should be possible to place curve points close to or over the reference points. |
| 444 | if (type == DatapickerImage::PointsType::CurvePoints) { |
| 445 | bool referenceItem = false; |
| 446 | for (auto* point : referencePoints) { |
| 447 | if (point->graphicsItem() == item) { |
| 448 | referenceItem = true; |
| 449 | break; |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | if (referenceItem) |
| 454 | continue; |
| 455 | } |
| 456 | |
| 457 | pointsUnderCursor = true; |
| 458 | break; |
| 459 | } |
| 460 | |
| 461 | if (entryMode && !pointsUnderCursor && m_image->isLoaded && sceneRect().contains(eventPos)) { |
| 462 | if (type == DatapickerImage::PointsType::AxisPoints) { |
| 463 | int childCount = m_image->childCount<DatapickerPoint>(AbstractAspect::ChildIndexFlag::IncludeHidden); |
| 464 | if (childCount < 3) |
| 465 | m_datapicker->addNewPoint(eventPos, m_image); |
| 466 | } else if (type == DatapickerImage::PointsType::CurvePoints && m_datapicker->activeCurve()) |
| 467 | m_datapicker->addNewPoint(eventPos, m_datapicker->activeCurve()); |
| 468 | |
| 469 | if (m_image->m_magnificationWindow && m_image->m_magnificationWindow->isVisible()) |
| 470 | updateMagnificationWindow(); |
| 471 | } |
| 472 |
nothing calls this directly
no test coverage detected