diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 3fd87fe3..e83414f7 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -611,18 +611,28 @@ void UBBoardController::duplicateItem(UBItem *item) { UBGraphicsGroupContainerItem* groupItem = dynamic_cast(item); if(groupItem){ + QTransform groupTransform = groupItem->transform(); + groupItem->resetTransform(); + QList children = groupItem->childItems(); foreach(QGraphicsItem* pIt, children){ UBItem* pItem = dynamic_cast(pIt); if(NULL != pItem){ - duplicateItem(pItem); // The duplication already copies the item parameters - if(NULL != mLastCreatedItem){ - mLastCreatedItem->setSelected(true); - } + duplicateItem(pItem); } } + groupItem->setTransform(groupTransform); groupItem->setSelected(false); UBApplication::mainWindow->actionGroupItems->trigger(); + QList selItems = mActiveScene->selectedItems(); + if(!selItems.empty()){ + // I don't like this solution but for now this is the only way I found. + // Normally, at this state, only the duplicated group should be selected + UBGraphicsGroupContainerItem* duplicatedGroup = dynamic_cast(selItems.at(0)); + if(NULL != duplicatedGroup){ + duplicatedGroup->setTransform(groupTransform); + } + } } return; break; @@ -635,7 +645,7 @@ void UBBoardController::duplicateItem(UBItem *item) { mActiveScene->addItem(gitem); gitem->setPos(itemPos); - mLastCreatedItem = gitem; + mLastCreatedItem = gitem; gitem->setSelected(true); } return; @@ -652,6 +662,7 @@ void UBBoardController::duplicateItem(UBItem *item) if (createdGitem) createdGitem->setPos(itemPos); mLastCreatedItem = dynamic_cast(createdItem); + mLastCreatedItem->setSelected(true); } } @@ -2176,7 +2187,10 @@ void UBBoardController::processMimeData(const QMimeData* pMimeData, const QPoint { foreach(UBItem* item, mimeData->items()) { - duplicateItem(item); + QGraphicsItem* pItem = dynamic_cast(item); + if(NULL != pItem){ + duplicateItem(item); + } } return; diff --git a/src/domain/UBGraphicsPolygonItem.cpp b/src/domain/UBGraphicsPolygonItem.cpp index e5dd4fd7..d6448e06 100644 --- a/src/domain/UBGraphicsPolygonItem.cpp +++ b/src/domain/UBGraphicsPolygonItem.cpp @@ -171,6 +171,7 @@ void UBGraphicsPolygonItem::copyItemParameters(UBItem *copy) const cp->setColorOnDarkBackground(this->colorOnDarkBackground()); cp->setColorOnLightBackground(this->colorOnLightBackground()); + //cp->setTransform(transform()); cp->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); } diff --git a/src/domain/UBGraphicsStrokesGroup.cpp b/src/domain/UBGraphicsStrokesGroup.cpp index e9993375..a55d203e 100644 --- a/src/domain/UBGraphicsStrokesGroup.cpp +++ b/src/domain/UBGraphicsStrokesGroup.cpp @@ -113,27 +113,33 @@ void UBGraphicsStrokesGroup::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) UBItem* UBGraphicsStrokesGroup::deepCopy() const { - UBGraphicsStrokesGroup* copy = new UBGraphicsStrokesGroup(); + UBGraphicsStrokesGroup* copy = new UBGraphicsStrokesGroup(); - QList chl = childItems(); + QTransform groupTransform = transform(); + const_cast(this)->resetTransform(); - foreach(QGraphicsItem *child, chl) - { - UBGraphicsPolygonItem *polygon = dynamic_cast(child); - if (polygon) - { - copy->addToGroup(dynamic_cast(polygon->deepCopy())); - polygon->setStrokesGroup(copy); - } - } - copyItemParameters(copy); + QList chl = childItems(); + + foreach(QGraphicsItem *child, chl) + { + UBGraphicsPolygonItem *polygon = dynamic_cast(child); + + if (polygon){ + QGraphicsItem* pItem = dynamic_cast(polygon->deepCopy()); + copy->addToGroup(pItem); + } + + } + const_cast(this)->setTransform(groupTransform); + copyItemParameters(copy); - return copy; + return copy; } void UBGraphicsStrokesGroup::copyItemParameters(UBItem *copy) const { - UBGraphicsStrokesGroup *cp = dynamic_cast(copy); + QGraphicsItem *cp = dynamic_cast(copy); + if(NULL != cp) { cp->setTransform(transform());