From 2c701581536d5c84c590d68027137b1dac4fe361 Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Tue, 10 Jul 2012 15:19:33 +0300 Subject: [PATCH] SANKORE-97 Delete an object with keyboard SANKORE-477 Erasing an object with the keyboard --- src/board/UBBoardView.cpp | 47 ++++++++++++++++++++++------------ src/domain/UBGraphicsScene.cpp | 3 +++ 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index ed2828ce..92e33bdb 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -481,9 +481,9 @@ bool UBBoardView::itemShouldReceiveSuspendedMousePressEvent(QGraphicsItem *item) case UBGraphicsPixmapItem::Type: case UBGraphicsTextItem::Type: case UBGraphicsW3CWidgetItem::Type: - if (currentTool != UBStylusTool::Play && !item->isSelected() && item->parentItem()) + if (currentTool == UBStylusTool::Selector && !item->isSelected() && item->parentItem()) return true; - if (currentTool != UBStylusTool::Play && !item->isSelected()) + if (currentTool == UBStylusTool::Selector && item->isSelected()) return true; break; @@ -580,11 +580,20 @@ void UBBoardView::handleItemMousePress(QMouseEvent *event) if (itemShouldReceiveMousePressEvent(movingItem)) QGraphicsView::mousePressEvent (event); else - if (itemShouldReceiveSuspendedMousePressEvent(movingItem)) { + if (movingItem) + movingItem->clearFocus(); + if (suspendedMousePressEvent) + { delete suspendedMousePressEvent; - suspendedMousePressEvent = new QMouseEvent(event->type(), event->pos(), event->button(), event->buttons(), event->modifiers()); + suspendedMousePressEvent = NULL; + } + + if (itemShouldReceiveSuspendedMousePressEvent(movingItem)) + { + suspendedMousePressEvent = new QMouseEvent(event->type(), event->pos(), event->button(), event->buttons(), event->modifiers()); + } } } @@ -917,30 +926,34 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event) scene ()->inputDeviceRelease (); if (currentTool == UBStylusTool::Selector) - { + { if (mWidgetMoved) { mWidgetMoved = false; movingItem = NULL; } else - if (movingItem) - { - if (suspendedMousePressEvent && !movingItem->data(UBGraphicsItemData::ItemLocked).toBool()) - { - QGraphicsView::mousePressEvent(suspendedMousePressEvent); // suspendedMousePressEvent is deleted by old Qt event loop - movingItem = NULL; - delete suspendedMousePressEvent; - suspendedMousePressEvent = NULL; - } + if (movingItem) + { + if (suspendedMousePressEvent && !movingItem->data(UBGraphicsItemData::ItemLocked).toBool()) + { + QGraphicsView::mousePressEvent(suspendedMousePressEvent); // suspendedMousePressEvent is deleted by old Qt event loop + movingItem = NULL; + delete suspendedMousePressEvent; + suspendedMousePressEvent = NULL; + } + else + { + movingItem->setSelected(true); } + } - if (mUBRubberBand && mUBRubberBand->isVisible()) { - mUBRubberBand->hide(); + if (mUBRubberBand && mUBRubberBand->isVisible()) { + mUBRubberBand->hide(); } QGraphicsView::mouseReleaseEvent (event); - } + } else if (currentTool == UBStylusTool::Play) { if (mWidgetMoved) diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index c62dd36d..0617f4ad 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -43,6 +43,7 @@ #include "board/UBBoardController.h" #include "board/UBDrawingController.h" +#include "board/UBBoardView.h" #include "UBGraphicsItemUndoCommand.h" #include "UBGraphicsTextItemUndoCommand.h" @@ -1453,6 +1454,8 @@ void UBGraphicsScene::addGraphicsWidget(UBGraphicsWidgetItem* graphicsWidget, co { UBApplication::boardController->moveGraphicsWidgetToControlView(graphicsWidget); } + + UBApplication::boardController->controlView()->setFocus(); } UBGraphicsW3CWidgetItem* UBGraphicsScene::addOEmbed(const QUrl& pContentUrl, const QPointF& pPos)