From 667be75e61862a870ff2fe79e69a3211917be804 Mon Sep 17 00:00:00 2001 From: shibakaneki Date: Thu, 6 Sep 2012 09:24:30 +0200 Subject: [PATCH] Fixed issue 862 --- src/board/UBBoardController.cpp | 30 ++++++++++++++++++++------- src/board/UBBoardController.h | 2 +- src/domain/UBGraphicsItemDelegate.cpp | 2 +- src/domain/UBGraphicsPolygonItem.cpp | 1 + src/domain/UBGraphicsStrokesGroup.cpp | 30 +++++++++++++++++---------- 5 files changed, 45 insertions(+), 20 deletions(-) diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index bcfc1ddd..bd8b3a95 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -533,7 +533,7 @@ void UBBoardController::duplicateScene() duplicateScene(mActiveSceneIndex); } -void UBBoardController::duplicateItem(UBItem *item) +void UBBoardController::duplicateItem(UBItem *item, QTransform trf) { if (!item) return; @@ -553,6 +553,7 @@ void UBBoardController::duplicateItem(UBItem *item) qreal shifting = UBSettings::settings()->objectFrameWidth; itemPos = commonItem->pos() + QPointF(shifting,shifting); itemSize = commonItem->boundingRect().size(); + commonItem->setSelected(false); } UBMimeType::Enum itemMimeType; @@ -611,18 +612,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->transform()); // The duplication already copies the item parameters } } + 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; @@ -633,10 +644,11 @@ void UBBoardController::duplicateItem(UBItem *item) QGraphicsItem *gitem = dynamic_cast(item->deepCopy()); if (gitem) { - qDebug() << "Adding a stroke: " << gitem; mActiveScene->addItem(gitem); gitem->setPos(itemPos); mLastCreatedItem = gitem; + + gitem->setSelected(true); } return; }break; @@ -652,6 +664,7 @@ void UBBoardController::duplicateItem(UBItem *item) if (createdGitem) createdGitem->setPos(itemPos); mLastCreatedItem = dynamic_cast(createdItem); + mLastCreatedItem->setSelected(true); } } @@ -2175,7 +2188,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, pItem->transform()); + } } return; diff --git a/src/board/UBBoardController.h b/src/board/UBBoardController.h index 042ba24a..fb42565a 100644 --- a/src/board/UBBoardController.h +++ b/src/board/UBBoardController.h @@ -158,7 +158,7 @@ class UBBoardController : public UBDocumentContainer void moveSceneToIndex(int source, int target); void duplicateScene(int index); - void duplicateItem(UBItem *item); + void duplicateItem(UBItem *item, QTransform trf); void deleteScene(int index); bool cacheIsVisible() {return mCacheWidgetIsEnabled;} diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index 4abeb1a2..b86ac541 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -417,7 +417,7 @@ bool UBGraphicsItemDelegate::isLocked() const void UBGraphicsItemDelegate::duplicate() { - UBApplication::boardController->duplicateItem(dynamic_cast(delegated())); + UBApplication::boardController->duplicateItem(dynamic_cast(delegated()), delegated()->transform()); } void UBGraphicsItemDelegate::increaseZLevelUp() diff --git a/src/domain/UBGraphicsPolygonItem.cpp b/src/domain/UBGraphicsPolygonItem.cpp index b21f2760..d5b545de 100644 --- a/src/domain/UBGraphicsPolygonItem.cpp +++ b/src/domain/UBGraphicsPolygonItem.cpp @@ -173,6 +173,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 a5320924..a2360bd9 100644 --- a/src/domain/UBGraphicsStrokesGroup.cpp +++ b/src/domain/UBGraphicsStrokesGroup.cpp @@ -65,25 +65,33 @@ void UBGraphicsStrokesGroup::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) UBItem* UBGraphicsStrokesGroup::deepCopy() const { - UBGraphicsStrokesGroup* copy = new UBGraphicsStrokesGroup(); + UBGraphicsStrokesGroup* copy = new UBGraphicsStrokesGroup(); + QTransform groupTransform = transform(); + const_cast(this)->resetTransform(); - QList chl = childItems(); + QList chl = childItems(); - foreach(QGraphicsItem *child, chl) - { - UBGraphicsPolygonItem *polygon = dynamic_cast(child); - if (polygon) - copy->addToGroup(dynamic_cast(polygon->deepCopy())); - } - copyItemParameters(copy); + 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->setPos(this->pos());