From cbee34aabd472a13fd79ef2bd014141fe6f9581d Mon Sep 17 00:00:00 2001 From: Alexandre Quessy Date: Tue, 14 Oct 2014 07:40:17 -0400 Subject: [PATCH] Feature: Select a shape with a click --- MapperGLCanvas.cpp | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/MapperGLCanvas.cpp b/MapperGLCanvas.cpp index 140fb65..1f4badd 100644 --- a/MapperGLCanvas.cpp +++ b/MapperGLCanvas.cpp @@ -128,14 +128,34 @@ void MapperGLCanvas::mousePressEvent(QMouseEvent* event) _mousePressedToDragVertex = true; } } + if (_mousePressedToDragVertex) { + return; + } } } - if (_mousePressedToDragVertex) { - return; + if (event->buttons() & Qt::LeftButton) + { + // Select a shape with a click + Shape* orig = getCurrentShape(); + MappingManager manager = getMainWindow()->getMappingManager(); + QVector mappings = manager.getVisibleMappings(); + for (QVector::const_iterator it = mappings.end() - 1; it >= mappings.begin(); --it) + { + Shape *shape = getShapeFromMappingId((*it)->getId()); + if (shape && shape->includesPoint(xmouse, ymouse)) + { + if (shape != orig) + { + getMainWindow()->setCurrentMapping((*it)->getId()); + } + break; + } + } } + // Drag the currently selected shape - if (event->buttons() & Qt::LeftButton) //Qt::RightButton) + if (event->buttons() & Qt::LeftButton) { Shape* shape = getCurrentShape(); if (shape && shape->includesPoint(xmouse, ymouse)) @@ -144,8 +164,6 @@ void MapperGLCanvas::mousePressEvent(QMouseEvent* event) _shapeFirstGrab = true; } } - - // TODO: Select a shape with a click } void MapperGLCanvas::mouseReleaseEvent(QMouseEvent* event) @@ -158,7 +176,6 @@ void MapperGLCanvas::mouseReleaseEvent(QMouseEvent* event) void MapperGLCanvas::mouseMoveEvent(QMouseEvent* event) { - if (_mousePressedToDragVertex) { // std::cout << "Move event " << std::endl; @@ -198,7 +215,6 @@ void MapperGLCanvas::mouseMoveEvent(QMouseEvent* event) // Update previous mouse position. prevMousePosition.setX( event->x() ); prevMousePosition.setY( event->y() ); - } }