From 8ee8b59ba8f0b5ff8618d8ca4454e66090441c5b Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Tue, 2 Oct 2012 11:41:22 +0300 Subject: [PATCH 1/2] Fixed duplication of groups. --- src/board/UBBoardController.cpp | 65 ++++++++++++++++----------------- src/board/UBBoardController.h | 2 +- 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index b269b8fa..a929434f 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -537,7 +537,7 @@ void UBBoardController::duplicateScene() duplicateScene(mActiveSceneIndex); } -UBGraphicsItem *UBBoardController::duplicateItem(UBItem *item) +UBGraphicsItem *UBBoardController::duplicateItem(UBItem *item, bool bAsync) { if (!item) return NULL; @@ -593,9 +593,13 @@ UBGraphicsItem *UBBoardController::duplicateItem(UBItem *item) if (mitem) { sourceUrl = mitem->mediaFileUrl(); - downloadURL(sourceUrl, srcFile, itemPos, QSize(itemSize.width(), itemSize.height()), false, false); + if (bAsync) + { + downloadURL(sourceUrl, srcFile, itemPos, QSize(itemSize.width(), itemSize.height()), false, false); + return NULL; // async operation + } } - }return NULL; // async operation + }break; case UBMimeType::VectorImage: { @@ -621,35 +625,22 @@ UBGraphicsItem *UBBoardController::duplicateItem(UBItem *item) case UBMimeType::Group: { - UBGraphicsGroupContainerItem* groupItem = dynamic_cast(item); - UBGraphicsGroupContainerItem* duplicatedGroup = NULL; - 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); - } - } - 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 - duplicatedGroup = dynamic_cast(selItems.at(0)); - if(NULL != duplicatedGroup){ - duplicatedGroup->setTransform(groupTransform); - } - } - } - retItem = dynamic_cast(duplicatedGroup); - break; - } + UBGraphicsGroupContainerItem* groupItem = dynamic_cast(item); + UBGraphicsGroupContainerItem* duplicatedGroup = new UBGraphicsGroupContainerItem(); + + QList children = groupItem->childItems(); + foreach(QGraphicsItem* pIt, children){ + UBItem* pItem = dynamic_cast(pIt); + if(pItem) // we diong sync duplication of all childs. + duplicatedGroup->addToGroup(dynamic_cast(duplicateItem(pItem, false))); + } + + duplicatedGroup->setTransform(groupItem->transform()); + groupItem->setSelected(false); + + retItem = dynamic_cast(duplicatedGroup); + + }break; case UBMimeType::UNKNOWN: { @@ -666,9 +657,17 @@ UBGraphicsItem *UBBoardController::duplicateItem(UBItem *item) } if (retItem) + { + QGraphicsItem * itemToAdd = dynamic_cast(retItem); + if (itemToAdd) + { + mActiveScene->addItem(itemToAdd); + itemToAdd->setSelected(true); + } return retItem; + } - UBItem *createdItem = downloadFinished(true, sourceUrl, sourceUrl, contentTypeHeader, pData, itemPos, QSize(itemSize.width(), itemSize.height()), false); + UBItem *createdItem = downloadFinished(true, sourceUrl, srcFile, contentTypeHeader, pData, itemPos, QSize(itemSize.width(), itemSize.height()), false); if (createdItem) { createdItem->setSourceUrl(item->sourceUrl()); diff --git a/src/board/UBBoardController.h b/src/board/UBBoardController.h index d7f44e37..aa27b788 100644 --- a/src/board/UBBoardController.h +++ b/src/board/UBBoardController.h @@ -159,7 +159,7 @@ class UBBoardController : public UBDocumentContainer void moveSceneToIndex(int source, int target); void duplicateScene(int index); - UBGraphicsItem *duplicateItem(UBItem *item); + UBGraphicsItem *duplicateItem(UBItem *item, bool bAsync = true); void deleteScene(int index); bool cacheIsVisible() {return mCacheWidgetIsEnabled;} From 0ed0540d3e52125ec145b5965ea91d42d3661bb4 Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Tue, 2 Oct 2012 12:42:09 +0300 Subject: [PATCH 2/2] Fixed creation duplicated groups - used scene mechanism. Excluded case of trying to determine mime type for empty string. --- src/board/UBBoardController.cpp | 31 ++++++++++++++++------------ src/frameworks/UBFileSystemUtils.cpp | 2 +- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index a929434f..be837e6a 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -568,7 +568,10 @@ UBGraphicsItem *UBBoardController::duplicateItem(UBItem *item, bool bAsync) if (srcFile.isEmpty()) srcFile = item->sourceUrl().toString(); - QString contentTypeHeader = UBFileSystemUtils::mimeTypeFromFileName(srcFile); + QString contentTypeHeader; + if (!srcFile.isEmpty()) + contentTypeHeader = UBFileSystemUtils::mimeTypeFromFileName(srcFile); + if(NULL != qgraphicsitem_cast(commonItem)) itemMimeType = UBMimeType::Group; else @@ -626,20 +629,30 @@ UBGraphicsItem *UBBoardController::duplicateItem(UBItem *item, bool bAsync) case UBMimeType::Group: { UBGraphicsGroupContainerItem* groupItem = dynamic_cast(item); - UBGraphicsGroupContainerItem* duplicatedGroup = new UBGraphicsGroupContainerItem(); + UBGraphicsGroupContainerItem* duplicatedGroup = NULL; + QList duplicatedItems; QList children = groupItem->childItems(); foreach(QGraphicsItem* pIt, children){ UBItem* pItem = dynamic_cast(pIt); - if(pItem) // we diong sync duplication of all childs. - duplicatedGroup->addToGroup(dynamic_cast(duplicateItem(pItem, false))); + if(pItem){ // we diong sync duplication of all childs. + QGraphicsItem * itemToGroup = dynamic_cast(duplicateItem(pItem, false)); + if (itemToGroup) + duplicatedItems.append(itemToGroup); + } } - + duplicatedGroup = mActiveScene->createGroup(duplicatedItems); duplicatedGroup->setTransform(groupItem->transform()); groupItem->setSelected(false); retItem = dynamic_cast(duplicatedGroup); + QGraphicsItem * itemToAdd = dynamic_cast(retItem); + if (itemToAdd) + { + mActiveScene->addItem(itemToAdd); + itemToAdd->setSelected(true); + } }break; case UBMimeType::UNKNOWN: @@ -657,15 +670,7 @@ UBGraphicsItem *UBBoardController::duplicateItem(UBItem *item, bool bAsync) } if (retItem) - { - QGraphicsItem * itemToAdd = dynamic_cast(retItem); - if (itemToAdd) - { - mActiveScene->addItem(itemToAdd); - itemToAdd->setSelected(true); - } return retItem; - } UBItem *createdItem = downloadFinished(true, sourceUrl, srcFile, contentTypeHeader, pData, itemPos, QSize(itemSize.width(), itemSize.height()), false); if (createdItem) diff --git a/src/frameworks/UBFileSystemUtils.cpp b/src/frameworks/UBFileSystemUtils.cpp index 2bde7364..101dbb2d 100644 --- a/src/frameworks/UBFileSystemUtils.cpp +++ b/src/frameworks/UBFileSystemUtils.cpp @@ -853,4 +853,4 @@ QString UBFileSystemUtils::readTextFile(QString path) } return ""; -} \ No newline at end of file +}