From 52abf106a1089f2604739556e0cb2b837e5bc36b Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Fri, 10 Nov 2023 11:18:54 +0100 Subject: [PATCH] m_drawing_in_progress moved from MaskDrawingContext to MaskGraphicsScene --- GUI/View/Mask/MaskDrawingContext.cpp | 13 +------- GUI/View/Mask/MaskDrawingContext.h | 4 --- GUI/View/Mask/MaskGraphicsScene.cpp | 49 ++++++++++++++-------------- GUI/View/Mask/MaskGraphicsScene.h | 1 + 4 files changed, 27 insertions(+), 40 deletions(-) diff --git a/GUI/View/Mask/MaskDrawingContext.cpp b/GUI/View/Mask/MaskDrawingContext.cpp index adb8a9c4757..8b149e36b59 100644 --- a/GUI/View/Mask/MaskDrawingContext.cpp +++ b/GUI/View/Mask/MaskDrawingContext.cpp @@ -18,7 +18,6 @@ MaskDrawingContext::MaskDrawingContext() : m_current_activity(MaskEditorFlags::PAN_ZOOM_MODE) , m_mask_value(MaskEditorFlags::MASK_ON) - , m_drawing_in_progress(false) { } @@ -94,16 +93,6 @@ bool MaskDrawingContext::isROIMode() const return m_current_activity == MaskEditorFlags::ROI_MODE; } -bool MaskDrawingContext::isDrawingInProgress() const -{ - return m_drawing_in_progress; -} - -void MaskDrawingContext::setDrawingInProgress(bool value) -{ - m_drawing_in_progress = value; -} - bool MaskDrawingContext::getMaskValue() const { return bool(m_mask_value); @@ -114,7 +103,7 @@ bool MaskDrawingContext::getMaskValue() const bool MaskDrawingContext::isActivityRequiresDrawingCancel( MaskEditorFlags::Activity proposed_new_activity) const { - return isDrawingInProgress() && isPolygonMode() + return isPolygonMode() && proposed_new_activity >= MaskEditorFlags::PAN_ZOOM_MODE; } diff --git a/GUI/View/Mask/MaskDrawingContext.h b/GUI/View/Mask/MaskDrawingContext.h index 0b17164254a..95afbd3e32b 100644 --- a/GUI/View/Mask/MaskDrawingContext.h +++ b/GUI/View/Mask/MaskDrawingContext.h @@ -39,9 +39,6 @@ public: bool isMaskAllMode() const; bool isROIMode() const; - bool isDrawingInProgress() const; - void setDrawingInProgress(bool value); - bool getMaskValue() const; bool isActivityRequiresDrawingCancel(MaskEditorFlags::Activity proposed_new_activity) const; @@ -51,7 +48,6 @@ public: private: MaskEditorFlags::Activity m_current_activity; MaskEditorFlags::MaskValue m_mask_value; - bool m_drawing_in_progress; }; #endif // BORNAGAIN_GUI_VIEW_MASK_MASKDRAWINGCONTEXT_H diff --git a/GUI/View/Mask/MaskGraphicsScene.cpp b/GUI/View/Mask/MaskGraphicsScene.cpp index bba7e0a13ae..f36704766dd 100644 --- a/GUI/View/Mask/MaskGraphicsScene.cpp +++ b/GUI/View/Mask/MaskGraphicsScene.cpp @@ -37,6 +37,7 @@ const qreal min_distance_to_create_rect = 10; MaskGraphicsScene::MaskGraphicsScene(QObject* parent) : QGraphicsScene(parent) , m_colorMap(new ColorMap) + , m_drawing_in_progress(false) { setSceneRect(0, 0, 800, 600); connect(this, &MaskGraphicsScene::selectionChanged, this, @@ -103,7 +104,7 @@ void MaskGraphicsScene::onActivityChanged(MaskEditorFlags::Activity value) if (!m_proxy) return; - if (m_context.isActivityRequiresDrawingCancel(value)) + if (m_drawing_in_progress && m_context.isActivityRequiresDrawingCancel(value)) cancelCurrentDrawing(); m_context.setActivityType(value); @@ -134,10 +135,10 @@ void MaskGraphicsScene::onRowsAboutToBeRemoved(const QModelIndex&, int first, in void MaskGraphicsScene::cancelCurrentDrawing() { - if (isDrawingInProgress()) { + if (m_drawing_in_progress) { ASSERT(m_currentItem); m_maskContainerModel->removeMask(dynamic_cast<MaskItem*>(m_currentItem)); - setDrawingInProgress(false); + m_drawing_in_progress = false; } } @@ -232,7 +233,7 @@ void MaskGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent* event) m_mouse_is_pressed = true; if (event->buttons() & Qt::RightButton) { - if (isDrawingInProgress()) + if (m_drawing_in_progress) cancelCurrentDrawing(); else makeViewAtMousePosSelected(event); @@ -253,13 +254,13 @@ void MaskGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent* event) void MaskGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent* event) { - if (isDrawingInProgress() && m_context.isRectangleShapeMode()) { + if (m_drawing_in_progress && m_context.isRectangleShapeMode()) { processRectangleOrEllipseItem(event); return; } QGraphicsScene::mouseMoveEvent(event); - if ((isDrawingInProgress() && m_context.isPolygonMode()) || m_context.isLineMode()) { + if ((m_drawing_in_progress && m_context.isPolygonMode()) || m_context.isLineMode()) { m_currentMousePosition = event->scenePos(); invalidate(); } @@ -271,7 +272,7 @@ void MaskGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) { m_mouse_is_pressed = false; - if (isDrawingInProgress()) { + if (m_drawing_in_progress) { if (m_context.isRectangleShapeMode()) { clearSelection(); if (m_currentItem) { @@ -283,7 +284,7 @@ void MaskGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) // making item beneath of mouse release position to be selected makeViewAtMousePosSelected(event); } - setDrawingInProgress(false); + m_drawing_in_progress = false; } } else QGraphicsScene::mouseReleaseEvent(event); @@ -325,7 +326,7 @@ void MaskGraphicsScene::drawForeground(QPainter* painter, const QRectF&) void MaskGraphicsScene::contextMenuEvent(QGraphicsSceneContextMenuEvent* event) { - if (isDrawingInProgress()) + if (m_drawing_in_progress) return; if (dynamic_cast<IShapeDisplay*>(itemAt(event->scenePos(), QTransform()))) @@ -471,7 +472,7 @@ bool MaskGraphicsScene::isValidMouseClick(QGraphicsSceneMouseEvent* event) const bool MaskGraphicsScene::isValidForRectangleShapeDrawing(QGraphicsSceneMouseEvent* event) const { - if (isDrawingInProgress()) + if (m_drawing_in_progress) return false; if (!isValidMouseClick(event)) return false; @@ -496,7 +497,7 @@ bool MaskGraphicsScene::isValidForPolygonDrawing(QGraphicsSceneMouseEvent* event return false; if (!m_context.isPolygonMode()) return false; - if (!isDrawingInProgress()) { + if (!m_drawing_in_progress) { if (isAreaContains(event, MaskType::POLYGONPOINT)) return false; } @@ -509,7 +510,7 @@ bool MaskGraphicsScene::isValidForLineDrawing(QGraphicsSceneMouseEvent* event) c { if (!isValidMouseClick(event)) return false; - if (isDrawingInProgress()) + if (m_drawing_in_progress) return false; if (!m_context.isLineMode()) return false; @@ -527,7 +528,7 @@ bool MaskGraphicsScene::isValidForMaskAllDrawing(QGraphicsSceneMouseEvent* event { if (!isValidMouseClick(event)) return false; - if (isDrawingInProgress()) + if (m_drawing_in_progress) return false; if (!m_context.isMaskAllMode()) return false; @@ -550,12 +551,12 @@ bool MaskGraphicsScene::isAreaContains(QGraphicsSceneMouseEvent* event, MaskType bool MaskGraphicsScene::isDrawingInProgress() const { - return m_context.isDrawingInProgress(); + return m_drawing_in_progress; } void MaskGraphicsScene::setDrawingInProgress(bool value) { - m_context.setDrawingInProgress(value); + m_drawing_in_progress = value; if (value) gProjectDocument.value()->setModified(); // manual mask creation else @@ -603,8 +604,8 @@ void MaskGraphicsScene::makeViewAtMousePosSelected(QGraphicsSceneMouseEvent* eve void MaskGraphicsScene::processRectangleOrEllipseItem(QGraphicsSceneMouseEvent* event) { - if (!isDrawingInProgress()) - setDrawingInProgress(true); + if (!m_drawing_in_progress) + m_drawing_in_progress = true; QPointF click_pos = event->buttonDownScenePos(Qt::LeftButton); QPointF mouse_pos = event->scenePos(); @@ -660,7 +661,7 @@ void MaskGraphicsScene::processPolygonItem(QGraphicsSceneMouseEvent* event) ASSERT(m_context.isPolygonMode()); if (!m_currentItem) { - setDrawingInProgress(true); + m_drawing_in_progress = true; PolygonItem* new_poly = new PolygonItem; m_maskContainerModel->insertMask(0, new_poly); new_poly->setMaskValue(m_context.getMaskValue()); @@ -674,7 +675,7 @@ void MaskGraphicsScene::processPolygonItem(QGraphicsSceneMouseEvent* event) if (PolygonDisplay* polygon = currentPolygon()) { if (polygon->closePolygonIfNecessary()) { - setDrawingInProgress(false); + m_drawing_in_progress = false; m_currentMousePosition = {}; return; } @@ -689,7 +690,7 @@ void MaskGraphicsScene::processPolygonItem(QGraphicsSceneMouseEvent* event) void MaskGraphicsScene::processLineItem(QGraphicsSceneMouseEvent* event) { - setDrawingInProgress(true); + m_drawing_in_progress = true; QPointF click_pos = event->buttonDownScenePos(Qt::LeftButton); if (m_context.isVerticalLineMode()) @@ -706,7 +707,7 @@ void MaskGraphicsScene::processLineItem(QGraphicsSceneMouseEvent* event) emit lineItemProcessed(); - setDrawingInProgress(false); + m_drawing_in_progress = false; } void MaskGraphicsScene::processVerticalLineItem(const QPointF& pos) @@ -729,12 +730,12 @@ void MaskGraphicsScene::processHorizontalLineItem(const QPointF& pos) void MaskGraphicsScene::processMaskAllItem(QGraphicsSceneMouseEvent* event) { Q_UNUSED(event); - setDrawingInProgress(true); + m_drawing_in_progress = true; MaskAllItem* item = new MaskAllItem; m_maskContainerModel->insertMask(0, item); m_currentItem = item; m_selectionModel->clearSelection(); - setDrawingInProgress(false); + m_drawing_in_progress = false; } void MaskGraphicsScene::subscribeMaskItem(MaskRoot* item) @@ -769,7 +770,7 @@ void MaskGraphicsScene::setZValues() PolygonDisplay* MaskGraphicsScene::currentPolygon() const { - if (isDrawingInProgress() && m_context.isPolygonMode() && m_currentItem) + if (m_drawing_in_progress && m_context.isPolygonMode() && m_currentItem) return dynamic_cast<PolygonDisplay*>(m_ItemToView[m_currentItem]); return nullptr; } diff --git a/GUI/View/Mask/MaskGraphicsScene.h b/GUI/View/Mask/MaskGraphicsScene.h index 82972d20404..e5db2d56ac6 100644 --- a/GUI/View/Mask/MaskGraphicsScene.h +++ b/GUI/View/Mask/MaskGraphicsScene.h @@ -124,6 +124,7 @@ private: Data2DItem* m_data2DItem = nullptr; MaskRoot* m_currentItem = nullptr; QPointF m_currentMousePosition; + bool m_drawing_in_progress; MaskDrawingContext m_context; }; -- GitLab