From 61c6319579696980264c45427a1a6833fdb13814 Mon Sep 17 00:00:00 2001 From: Ilia Ryabokon Date: Mon, 27 Aug 2012 20:46:53 +0300 Subject: [PATCH] Sankore-1001 Background never get object zlayer anymore. BordView dropEvent fix --- src/board/UBBoardView.cpp | 124 +++++++++++++++++---------------- src/domain/UBGraphicsScene.cpp | 10 ++- src/domain/UBGraphicsScene.h | 1 + 3 files changed, 74 insertions(+), 61 deletions(-) diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index eb7341cb..483e955b 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -443,23 +443,23 @@ void UBBoardView::handleItemsSelection(QGraphicsItem *item) // // item selection managed by QGraphicsView::mousePressEvent(). It should be called later. - if (item) - { - // item has group as first parent - it is any item or UBGraphicsStrokesGroup. - if(item->parentItem() && UBGraphicsGroupContainerItem::Type == movingItem->parentItem()->type()) - return; - - // delegate buttons shouldn't selected - if (DelegateButton::Type == item->type()) - return; - - // click on svg items (images on Frame) shouldn't change selection. - if (QGraphicsSvgItem::Type == item->type()) - return; - - // Delegate frame shouldn't selected - if (UBGraphicsDelegateFrame::Type == item->type()) - return; + if (item) + { + // item has group as first parent - it is any item or UBGraphicsStrokesGroup. + if(item->parentItem() && UBGraphicsGroupContainerItem::Type == movingItem->parentItem()->type()) + return; + + // delegate buttons shouldn't selected + if (DelegateButton::Type == item->type()) + return; + + // click on svg items (images on Frame) shouldn't change selection. + if (QGraphicsSvgItem::Type == item->type()) + return; + + // Delegate frame shouldn't selected + if (UBGraphicsDelegateFrame::Type == item->type()) + return; // if we need to uwe multiple selection - we shouldn't deselect other items. @@ -591,9 +591,9 @@ bool UBBoardView::itemShouldBeMoved(QGraphicsItem *item) if (movingItem->data(UBGraphicsItemData::ItemLocked).toBool()) return false; - if (movingItem->parentItem() && UBGraphicsGroupContainerItem::Type == movingItem->parentItem()->type() && !movingItem->isSelected() && movingItem->parentItem()->isSelected()) - return false; - + if (movingItem->parentItem() && UBGraphicsGroupContainerItem::Type == movingItem->parentItem()->type() && !movingItem->isSelected() && movingItem->parentItem()->isSelected()) + return false; + UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController()->stylusTool(); switch(item->type()) @@ -617,7 +617,7 @@ bool UBBoardView::itemShouldBeMoved(QGraphicsItem *item) case UBGraphicsTextItem::Type: return !item->isSelected(); } - + return false; } @@ -625,9 +625,9 @@ bool UBBoardView::itemShouldBeMoved(QGraphicsItem *item) QGraphicsItem* UBBoardView::determineItemToPress(QGraphicsItem *item) { if(item) - { + { UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController()->stylusTool(); - + // groups should should be moved instead of strokes groups if (item->parentItem() && UBGraphicsStrokesGroup::Type == item->type()) return item->parentItem(); @@ -639,7 +639,7 @@ QGraphicsItem* UBBoardView::determineItemToPress(QGraphicsItem *item) && !item->parentItem()->isSelected()) return item->parentItem(); - // items like polygons placed in two groups nested, so we need to recursive call. + // items like polygons placed in two groups nested, so we need to recursive call. if(item->parentItem() && UBGraphicsStrokesGroup::Type == item->parentItem()->type()) return determineItemToPress(item->parentItem()); } @@ -653,33 +653,33 @@ QGraphicsItem* UBBoardView::determineItemToMove(QGraphicsItem *item) if(item) { UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController()->stylusTool(); - - //W3C widgets should take mouse move events from play tool. + + //W3C widgets should take mouse move events from play tool. if ((UBStylusTool::Play == currentTool) && (UBGraphicsW3CWidgetItem::Type == item->type())) return item; - // if item is in group + // if item is in group if(item->parentItem() && UBGraphicsGroupContainerItem::Type == item->parentItem()->type()) { - // play tool should move groups by any element + // play tool should move groups by any element if (UBStylusTool::Play == currentTool && item->parentItem()->isSelected()) return item->parentItem(); - - // groups should should be moved instead of strokes groups - if (UBGraphicsStrokesGroup::Type == item->type()) - return item->parentItem(); - - // selected groups should be moved by moving any element + + // groups should should be moved instead of strokes groups + if (UBGraphicsStrokesGroup::Type == item->type()) + return item->parentItem(); + + // selected groups should be moved by moving any element if (item->parentItem()->isSelected()) return item; - + if (item->isSelected()) return NULL; return item->parentItem(); } - // items like polygons placed in two groups nested, so we need to recursive call. + // items like polygons placed in two groups nested, so we need to recursive call. if(item->parentItem() && UBGraphicsStrokesGroup::Type == item->parentItem()->type()) return determineItemToMove(item->parentItem()); } @@ -724,10 +724,10 @@ void UBBoardView::handleItemMousePress(QMouseEvent *event) void UBBoardView::handleItemMouseMove(QMouseEvent *event) { - // determine item to move (maybee we need to move group of item or his parent. - movingItem = determineItemToMove(movingItem); + // determine item to move (maybee we need to move group of item or his parent. + movingItem = determineItemToMove(movingItem); - // items should be moved not every mouse move. + // items should be moved not every mouse move. if (movingItem && itemShouldBeMoved(movingItem) && (mMouseButtonIsPressed || mTabletStylusIsPressed)) { QPointF scenePos = mapToScene(event->pos()); @@ -753,8 +753,8 @@ void UBBoardView::handleItemMouseMove(QMouseEvent *event) mWidgetMoved = ((posAfterMove-posBeforeMove).manhattanLength() != 0); // a cludge for terminate moving of w3c widgets. - // in some cases w3c widgets catches mouse move and doesn't sends that events to web page, - // at simple - in google map widget - mouse move events doesn't comes to web page from rectangle of wearch bar on bottom right corner of widget. + // in some cases w3c widgets catches mouse move and doesn't sends that events to web page, + // at simple - in google map widget - mouse move events doesn't comes to web page from rectangle of wearch bar on bottom right corner of widget. if (mWidgetMoved && UBGraphicsW3CWidgetItem::Type == movingItem->type()) movingItem->setPos(posBeforeMove); @@ -1093,9 +1093,9 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event) { if (QGraphicsSvgItem::Type != movingItem->type() && UBGraphicsDelegateFrame::Type != movingItem->type() && - UBToolWidget::Type != movingItem->type() && - QGraphicsWebView::Type != movingItem->type() && // for W3C widgets as Tools. - !(!isMultipleSelectionEnabled() && movingItem->parentItem() && UBGraphicsWidgetItem::Type == movingItem->type() && UBGraphicsGroupContainerItem::Type == movingItem->parentItem()->type())) + UBToolWidget::Type != movingItem->type() && + QGraphicsWebView::Type != movingItem->type() && // for W3C widgets as Tools. + !(!isMultipleSelectionEnabled() && movingItem->parentItem() && UBGraphicsWidgetItem::Type == movingItem->type() && UBGraphicsGroupContainerItem::Type == movingItem->parentItem()->type())) { bReleaseIsNeed = false; if (movingItem->isSelected() && isMultipleSelectionEnabled()) @@ -1319,14 +1319,20 @@ void UBBoardView::dragMoveEvent(QDragMoveEvent *event) void UBBoardView::dropEvent (QDropEvent *event) { - if (!itemAt(event->pos().x(),event->pos().y())) { - if (!event->source() || dynamic_cast(event->source()) || dynamic_cast(event->source()) || dynamic_cast(event->source()) || dynamic_cast(event->source()) || dynamic_cast(event->source())) { - mController->processMimeData (event->mimeData (), mapToScene (event->pos ())); - event->acceptProposedAction(); + QGraphicsItem *onItem = itemAt(event->pos().x(),event->pos().y()); + if (onItem && onItem->type() == UBGraphicsWidgetItem::Type) { + QGraphicsView::dropEvent(event); + } else { + if (!event->source() + || qobject_cast(event->source()) + || qobject_cast(event->source()) + || qobject_cast(event->source()) + || qobject_cast(event->source()) + || qobject_cast(event->source())) { + mController->processMimeData (event->mimeData (), mapToScene (event->pos ())); + event->acceptProposedAction(); + } } - } - else - QGraphicsView::dropEvent(event); } void @@ -1515,11 +1521,11 @@ UBBoardView::setToolCursor (int tool) } -bool UBBoardView::hasSelectedParents(QGraphicsItem * item) -{ - if (item->isSelected()) - return true; - if (item->parentItem()==NULL) - return false; - return hasSelectedParents(item->parentItem()); -} +bool UBBoardView::hasSelectedParents(QGraphicsItem * item) +{ + if (item->isSelected()) + return true; + if (item->parentItem()==NULL) + return false; + return hasSelectedParents(item->parentItem()); +} diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 52ab6418..b4cbfc4e 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -249,6 +249,11 @@ itemLayerType::Enum UBZLayerController::typeForData(QGraphicsItem *item) const return result; } +void UBZLayerController::setLayerType(QGraphicsItem *pItem, itemLayerType::Enum pNewType) +{ + pItem->setData(UBGraphicsItemData::itemLayerType, QVariant(pNewType)); +} + UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent) : UBCoreGraphicsScene(parent) , mEraser(0) @@ -1637,8 +1642,6 @@ QGraphicsItem* UBGraphicsScene::setAsBackgroundObject(QGraphicsItem* item, bool item->setAcceptedMouseButtons(Qt::NoButton); item->setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::FixedBackground); - UBGraphicsItem::assignZValue(item, mZLayerController->generateZLevel(itemLayerType::BackgroundItem)); - if (pAdaptTransformation) { item = scaleToFitDocumentSize(item, true, 0, pExpand); @@ -1647,6 +1650,9 @@ QGraphicsItem* UBGraphicsScene::setAsBackgroundObject(QGraphicsItem* item, bool if (item->scene() != this) addItem(item); + mZLayerController->setLayerType(item, itemLayerType::BackgroundItem); + UBGraphicsItem::assignZValue(item, mZLayerController->generateZLevel(item)); + mBackgroundObject = item; } diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index 027ef706..738bd429 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -87,6 +87,7 @@ public: qreal changeZLevelTo(QGraphicsItem *item, moveDestination dest); itemLayerType::Enum typeForData(QGraphicsItem *item) const; + void setLayerType(QGraphicsItem *pItem, itemLayerType::Enum pNewType); private: ScopeMap scopeMap;