From 9952edb9f85bec4c15d8e53b9b942da6ed10ba3e Mon Sep 17 00:00:00 2001 From: ArsenArsen Date: Wed, 12 Jul 2017 00:59:38 +0200 Subject: [PATCH] Fix some clicks and overrides --- cropeditor/cropscene.cpp | 22 ++++++++++++---------- cropeditor/cropscene.hpp | 1 + 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/cropeditor/cropscene.cpp b/cropeditor/cropscene.cpp index 1d69a7b..345d26d 100644 --- a/cropeditor/cropscene.cpp +++ b/cropeditor/cropscene.cpp @@ -142,6 +142,14 @@ void CropScene::setDrawingSelection(QString name, std::function dr if (!drawingSelection->init(this)) setDrawingSelection("None", [] { return nullptr; }); } +QGraphicsItem *CropScene::whichItem(QPointF scenePos) { + for (auto item : items()) { + if (item->sceneBoundingRect().contains(scenePos)) + if (item != polyItem && item != rect && item != cursorItem && item->zValue() != -1) return item; + } + return nullptr; +} + void CropScene::hide() { setVisible(false); } @@ -188,11 +196,8 @@ void CropScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) { auto buttons = e->buttons(); if (e->modifiers() & Qt::ControlModifier && buttons == Qt::LeftButton) { - QTransform stupidThing = views()[0]->transform(); - auto item = itemAt(cursorPos, stupidThing); - if (item && item != polyItem && item != rect && item->zValue() != -1) { - item->moveBy(delta.x(), delta.y()); - } + auto item = whichItem(cursorPos); + if (item) item->moveBy(delta.x(), delta.y()); return; } if (buttons == Qt::LeftButton || (prevButtons == Qt::NoButton && prevButtons != buttons)) { @@ -253,11 +258,8 @@ void CropScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) { void CropScene::mousePressEvent(QGraphicsSceneMouseEvent *e) { if (e->modifiers() & Qt::AltModifier) { - QTransform stupidThing = views()[0]->transform(); - auto item = itemAt(cursorPos, stupidThing); - if (item && item != polyItem && item != rect && item->zValue() != -1) { - removeItem(item); - } + auto item = whichItem(cursorItem->scenePos()); + if (item) removeItem(item); } } diff --git a/cropeditor/cropscene.hpp b/cropeditor/cropscene.hpp index 67b1323..2d4aa48 100644 --- a/cropeditor/cropscene.hpp +++ b/cropeditor/cropscene.hpp @@ -32,6 +32,7 @@ public: QGraphicsRectItem *selRect() { return rect; } + QGraphicsItem *whichItem(QPointF scenePos); void hide(); void show(); void setVisible(bool visible);