From 81a49e952561272d73bbb874c59725c541409b3d Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Wed, 8 Aug 2012 20:02:03 +0300 Subject: [PATCH] Reworked items copying mechanism. Now coping creates a full copy of already created item. Copy has it's own content (like video, audio or folder) and stores original item properties (like locked, pos, size, freezed e.t.c.). --- src/board/UBBoardController.cpp | 127 ++++++++++++++++++-- src/board/UBBoardController.h | 4 +- src/domain/UBGraphicsGroupContainerItem.cpp | 23 +++- src/domain/UBGraphicsGroupContainerItem.h | 2 + src/domain/UBGraphicsItemDelegate.cpp | 5 +- src/domain/UBGraphicsMediaItem.cpp | 36 +++--- src/domain/UBGraphicsMediaItem.h | 2 + src/domain/UBGraphicsPDFItem.cpp | 23 ++-- src/domain/UBGraphicsPDFItem.h | 2 + src/domain/UBGraphicsPixmapItem.cpp | 26 ++-- src/domain/UBGraphicsPixmapItem.h | 2 + src/domain/UBGraphicsPolygonItem.cpp | 36 +++--- src/domain/UBGraphicsPolygonItem.h | 1 + src/domain/UBGraphicsScene.cpp | 8 +- src/domain/UBGraphicsScene.h | 4 +- src/domain/UBGraphicsStrokesGroup.cpp | 21 +++- src/domain/UBGraphicsStrokesGroup.h | 1 + src/domain/UBGraphicsSvgItem.cpp | 25 ++-- src/domain/UBGraphicsSvgItem.h | 2 + src/domain/UBGraphicsTextItem.cpp | 40 +++--- src/domain/UBGraphicsTextItem.h | 3 + src/domain/UBGraphicsWidgetItem.cpp | 72 ++++++----- src/domain/UBGraphicsWidgetItem.h | 5 + src/domain/UBItem.h | 3 + src/tools/UBGraphicsCache.cpp | 15 ++- src/tools/UBGraphicsCache.h | 2 + src/tools/UBGraphicsCompass.cpp | 15 ++- src/tools/UBGraphicsCompass.h | 2 + src/tools/UBGraphicsCurtainItem.cpp | 24 ++-- src/tools/UBGraphicsCurtainItem.h | 1 + src/tools/UBGraphicsProtractor.cpp | 25 ++-- src/tools/UBGraphicsProtractor.h | 1 + src/tools/UBGraphicsRuler.cpp | 15 ++- src/tools/UBGraphicsRuler.h | 1 + src/tools/UBGraphicsTriangle.cpp | 15 ++- src/tools/UBGraphicsTriangle.h | 1 + 36 files changed, 434 insertions(+), 156 deletions(-) diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 0d23d9f9..88f98768 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -53,6 +53,7 @@ #include "domain/UBGraphicsTextItem.h" #include "domain/UBPageSizeUndoCommand.h" #include "domain/UBGraphicsGroupContainerItem.h" +#include "domain/UBItem.h" #include "tools/UBToolsManager.h" @@ -529,6 +530,92 @@ void UBBoardController::duplicateScene() duplicateScene(mActiveSceneIndex); } +void UBBoardController::duplicateItem(UBItem *item) +{ + if (!item) + return; + + QUrl sourceUrl; + QByteArray pData; + + //common parameters for any item + QPointF itemPos; + QSizeF itemSize; + + QGraphicsItem *commonItem = dynamic_cast(item); + if (commonItem) + { + itemPos = commonItem->pos(); + itemSize = commonItem->boundingRect().size(); + } + + QString contentTypeHeader = UBFileSystemUtils::mimeTypeFromFileName(item->sourceUrl().toLocalFile()); + + UBMimeType::Enum itemMimeType = UBFileSystemUtils::mimeTypeFromString(contentTypeHeader); + + switch(static_cast(itemMimeType)) + { + case UBMimeType::AppleWidget: + case UBMimeType::W3CWidget: + { + UBGraphicsWidgetItem *witem = dynamic_cast(item); + if (witem) + { + sourceUrl = witem->getOwnFolder(); + } + }break; + + case UBMimeType::Video: + case UBMimeType::Audio: + { + UBGraphicsMediaItem *mitem = dynamic_cast(item); + if (mitem) + { + sourceUrl = mitem->mediaFileUrl(); + } + }break; + + case UBMimeType::VectorImage: + { + UBGraphicsSvgItem *viitem = dynamic_cast(item); + if (viitem) + { + pData = viitem->fileData(); + sourceUrl = item->sourceUrl(); + } + }break; + + case UBMimeType::RasterImage: + { + UBGraphicsPixmapItem *pixitem = dynamic_cast(item); + if (pixitem) + { + QBuffer buffer(&pData); + buffer.open(QIODevice::WriteOnly); + QString format = UBFileSystemUtils::extension(item->sourceUrl().toLocalFile()); + pixitem->pixmap().save(&buffer, format.toLatin1()); + } + }break; + case UBMimeType::UNKNOWN: + { + QGraphicsItem *gitem = dynamic_cast(item->deepCopy()); + if (gitem) + { + mActiveScene->addItem(gitem); + gitem->setPos(itemPos); + } + return; + }break; + } + + UBItem *createdItem = downloadFinished(true, sourceUrl, contentTypeHeader, pData, itemPos, QSize(itemSize.width(), itemSize.height()), false); + if (createdItem) + { + createdItem->setSourceUrl(item->sourceUrl()); + item->copyItemParameters(createdItem); + } +} + void UBBoardController::deleteScene(int nIndex) { if (selectedDocument()->pageCount()>2) @@ -854,7 +941,7 @@ void UBBoardController::downloadURL(const QUrl& url, const QPointF& pPos, const } -void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground) +UBItem *UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground) { QString mimeType = pContentTypeHeader; @@ -869,7 +956,7 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString if (!pSuccess) { UBApplication::showMessage(tr("Downloading content %1 failed").arg(sourceUrl.toString())); - return; + return NULL; } if (!sourceUrl.toString().startsWith("file://") && !sourceUrl.toString().startsWith("uniboardTool://")) @@ -897,12 +984,14 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString pixItem->setSelected(true); UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector); } + + return pixItem; } else if (UBMimeType::VectorImage == itemMimeType) { qDebug() << "accepting mime type" << mimeType << "as vecto image"; - UBGraphicsSvgItem* svgItem = mActiveScene->addSvg(sourceUrl, pPos); + UBGraphicsSvgItem* svgItem = mActiveScene->addSvg(sourceUrl, pPos, pData); svgItem->setSourceUrl(sourceUrl); if (isBackground) @@ -915,6 +1004,8 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString svgItem->setSelected(true); UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector); } + + return svgItem; } else if (UBMimeType::AppleWidget == itemMimeType) //mime type invented by us :-( { @@ -939,6 +1030,8 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString { UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector); } + + return appleWidgetItem; } else if (UBMimeType::W3CWidget == itemMimeType) { @@ -960,6 +1053,8 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString { UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector); } + + return w3cWidgetItem; } else if (UBMimeType::Video == itemMimeType) { @@ -989,6 +1084,8 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString } UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector); + + return mediaVideoItem; } else if (UBMimeType::Audio == itemMimeType) { @@ -1018,6 +1115,8 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString } UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector); + + return audioMediaItem; } else if (UBMimeType::Flash == itemMimeType) @@ -1061,6 +1160,8 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString widgetItem->setSourceUrl(sourceUrl); UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector); + + return widgetItem; } if (eduMediaFile) @@ -1182,6 +1283,8 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString widgetItem->setSourceUrl(sourceUrl); UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector); + + return widgetItem; } } } @@ -1193,6 +1296,8 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString UBApplication::showMessage(tr("Unknown content type %1").arg(pContentTypeHeader)); qWarning() << "ignoring mime type" << pContentTypeHeader ; } + + return NULL; } void UBBoardController::setActiveDocumentScene(int pSceneIndex) @@ -1902,7 +2007,7 @@ UBGraphicsWidgetItem *UBBoardController::addW3cWidget(const QUrl &pUrl, const QP } - return 0; + return w3cWidgetItem; } void UBBoardController::cut() @@ -1957,7 +2062,11 @@ void UBBoardController::copy() UBItem* ubItem = dynamic_cast(gi); if (ubItem && !mActiveScene->tools().contains(gi)) - selected << ubItem->deepCopy(); + { + UBItem *itemCopy = ubItem->deepCopy(); + if (itemCopy) + selected << itemCopy; + } } if (selected.size() > 0) @@ -2014,13 +2123,7 @@ void UBBoardController::processMimeData(const QMimeData* pMimeData, const QPoint { foreach(UBItem* item, mimeData->items()) { - QGraphicsItem* gi = dynamic_cast(item->deepCopy()); - - if (gi) - { - mActiveScene->addItem(gi); - gi->setPos(gi->pos() + QPointF(50, 50)); - } + duplicateItem(item); } return; diff --git a/src/board/UBBoardController.h b/src/board/UBBoardController.h index d5f2b0f6..e2fd4dfe 100644 --- a/src/board/UBBoardController.h +++ b/src/board/UBBoardController.h @@ -39,6 +39,7 @@ class UBGraphicsVideoItem; class UBGraphicsAudioItem; class UBGraphicsWidgetItem; class UBBoardPaletteManager; +class UBItem; class UBBoardController : public UBDocumentContainer @@ -157,6 +158,7 @@ class UBBoardController : public UBDocumentContainer void moveSceneToIndex(int source, int target); void duplicateScene(int index); + void duplicateItem(UBItem *item); void deleteScene(int index); bool cacheIsVisible() {return mCacheWidgetIsEnabled;} @@ -188,7 +190,7 @@ class UBBoardController : public UBDocumentContainer void lastScene(); void groupButtonClicked(); void downloadURL(const QUrl& url, const QPointF& pPos = QPointF(0.0, 0.0), const QSize& pSize = QSize(), bool isBackground = false); - void downloadFinished(bool pSuccess, QUrl sourceUrl, QString pHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground = false); + UBItem *downloadFinished(bool pSuccess, QUrl sourceUrl, QString pHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground = false); void changeBackground(bool isDark, bool isCrossed); void setToolCursor(int tool); void showMessage(const QString& message, bool showSpinningWheel); diff --git a/src/domain/UBGraphicsGroupContainerItem.cpp b/src/domain/UBGraphicsGroupContainerItem.cpp index 09461236..b35cbdbf 100644 --- a/src/domain/UBGraphicsGroupContainerItem.cpp +++ b/src/domain/UBGraphicsGroupContainerItem.cpp @@ -157,18 +157,29 @@ UBGraphicsGroupContainerItem *UBGraphicsGroupContainerItem::deepCopy() const UBGraphicsGroupContainerItem *copy = new UBGraphicsGroupContainerItem(parentItem()); - copy->setPos(this->pos()); - copy->setTransform(this->transform()); - copy->setFlag(QGraphicsItem::ItemIsMovable, true); - copy->setFlag(QGraphicsItem::ItemIsSelectable, true); - copy->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); - copy->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); copy->setUuid(this->uuid()); // this is OK for now as long as Widgets are imutable + copyItemParameters(copy); + // copy->resize(this->size()); return copy; } + +void UBGraphicsGroupContainerItem::copyItemParameters(UBItem *copy) const +{ + UBGraphicsGroupContainerItem *cp = dynamic_cast(copy); + if (cp) + { + cp->setPos(this->pos()); + cp->setTransform(this->transform()); + cp->setFlag(QGraphicsItem::ItemIsMovable, true); + cp->setFlag(QGraphicsItem::ItemIsSelectable, true); + cp->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); + cp->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); + } +} + void UBGraphicsGroupContainerItem::remove() { if (mDelegate) diff --git a/src/domain/UBGraphicsGroupContainerItem.h b/src/domain/UBGraphicsGroupContainerItem.h index 6c08f05f..1eca384a 100644 --- a/src/domain/UBGraphicsGroupContainerItem.h +++ b/src/domain/UBGraphicsGroupContainerItem.h @@ -24,6 +24,8 @@ public: virtual UBGraphicsScene* scene(); virtual UBGraphicsGroupContainerItem *deepCopy() const; + virtual void copyItemParameters(UBItem *copy) const; + virtual void remove(); enum { Type = UBGraphicsItemType::groupContainerType }; diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index 0781bfc5..816636c1 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -406,10 +406,7 @@ bool UBGraphicsItemDelegate::isLocked() void UBGraphicsItemDelegate::duplicate() { - // TODO UB 4.x .. rewrite .. .this is absurde ... we know what we are duplicating - - UBApplication::boardController->copy(); - UBApplication::boardController->paste(); + UBApplication::boardController->duplicateItem(dynamic_cast(delegated())); } void UBGraphicsItemDelegate::increaseZLevelUp() diff --git a/src/domain/UBGraphicsMediaItem.cpp b/src/domain/UBGraphicsMediaItem.cpp index 4b3dbc7c..e14aac6f 100644 --- a/src/domain/UBGraphicsMediaItem.cpp +++ b/src/domain/UBGraphicsMediaItem.cpp @@ -241,26 +241,34 @@ void UBGraphicsMediaItem::showOnDisplayChanged(bool shown) UBItem* UBGraphicsMediaItem::deepCopy() const { QUrl url = this->mediaFileUrl(); - UBGraphicsMediaItem *copy; - - copy = new UBGraphicsMediaItem(url, parentItem()); + UBGraphicsMediaItem *copy = new UBGraphicsMediaItem(url, parentItem()); - copy->setPos(this->pos()); - copy->setTransform(this->transform()); - copy->setFlag(QGraphicsItem::ItemIsMovable, true); - copy->setFlag(QGraphicsItem::ItemIsSelectable, true); - copy->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); - copy->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); - copy->setUuid(this->uuid()); // this is OK as long as Videos are imutable - copy->setSourceUrl(this->sourceUrl()); - copy->resize(this->size()); + copy->setUuid(this->uuid()); // this is OK for now as long as Widgets are imutable - connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), copy, SLOT(activeSceneChanged())); - // TODO UB 4.7 complete all members + copyItemParameters(copy); return copy; } +void UBGraphicsMediaItem::copyItemParameters(UBItem *copy) const +{ + UBGraphicsMediaItem *cp = dynamic_cast(copy); + if (cp) + { + cp->setPos(this->pos()); + cp->setTransform(this->transform()); + cp->setFlag(QGraphicsItem::ItemIsMovable, true); + cp->setFlag(QGraphicsItem::ItemIsSelectable, true); + cp->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); + cp->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); + cp->setSourceUrl(this->sourceUrl()); + cp->resize(this->size()); + + connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), cp, SLOT(activeSceneChanged())); + // TODO UB 4.7 complete all members + } +} + void UBGraphicsMediaItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { if (mDelegate) diff --git a/src/domain/UBGraphicsMediaItem.h b/src/domain/UBGraphicsMediaItem.h index 8a226795..e646129d 100644 --- a/src/domain/UBGraphicsMediaItem.h +++ b/src/domain/UBGraphicsMediaItem.h @@ -95,6 +95,8 @@ public: virtual UBItem* deepCopy() const; + virtual void copyItemParameters(UBItem *copy) const; + virtual void setSourceUrl(const QUrl &pSourceUrl) { UBAudioPresentationWidget* pAudioWidget = dynamic_cast(mAudioWidget); diff --git a/src/domain/UBGraphicsPDFItem.cpp b/src/domain/UBGraphicsPDFItem.cpp index 2383c82c..f918b3d2 100644 --- a/src/domain/UBGraphicsPDFItem.cpp +++ b/src/domain/UBGraphicsPDFItem.cpp @@ -89,17 +89,26 @@ UBItem* UBGraphicsPDFItem::deepCopy() const { UBGraphicsPDFItem *copy = new UBGraphicsPDFItem(mRenderer, mPageNumber, parentItem()); - copy->setPos(this->pos()); - copy->setTransform(this->transform()); - copy->setFlag(QGraphicsItem::ItemIsMovable, true); - copy->setFlag(QGraphicsItem::ItemIsSelectable, true); - copy->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); - copy->setUuid(this->uuid()); // this is OK for now as long as PDF are imutable - copy->setSourceUrl(this->sourceUrl()); + copy->setUuid(this->uuid()); // this is OK for now as long as Widgets are imutable + + copyItemParameters(copy); return copy; } +void UBGraphicsPDFItem::copyItemParameters(UBItem *copy) const +{ + UBGraphicsPDFItem *cp = dynamic_cast(copy); + if (cp) + { + cp->setPos(this->pos()); + cp->setTransform(this->transform()); + cp->setFlag(QGraphicsItem::ItemIsMovable, true); + cp->setFlag(QGraphicsItem::ItemIsSelectable, true); + cp->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); + cp->setSourceUrl(this->sourceUrl()); + } +} void UBGraphicsPDFItem::setRenderingQuality(RenderingQuality pRenderingQuality) { diff --git a/src/domain/UBGraphicsPDFItem.h b/src/domain/UBGraphicsPDFItem.h index 85778865..ac55190e 100644 --- a/src/domain/UBGraphicsPDFItem.h +++ b/src/domain/UBGraphicsPDFItem.h @@ -41,6 +41,8 @@ class UBGraphicsPDFItem: public GraphicsPDFItem, public UBItem, public UBGraphic virtual UBItem* deepCopy() const; + virtual void copyItemParameters(UBItem *copy) const; + virtual void setRenderingQuality(RenderingQuality pRenderingQuality); virtual UBGraphicsScene* scene(); diff --git a/src/domain/UBGraphicsPixmapItem.cpp b/src/domain/UBGraphicsPixmapItem.cpp index 634a150f..936b9195 100644 --- a/src/domain/UBGraphicsPixmapItem.cpp +++ b/src/domain/UBGraphicsPixmapItem.cpp @@ -114,22 +114,30 @@ UBItem* UBGraphicsPixmapItem::deepCopy() const { UBGraphicsPixmapItem* copy = new UBGraphicsPixmapItem(); - copy->setPixmap(this->pixmap()); - copy->setPos(this->pos()); - copy->setTransform(this->transform()); - copy->setFlag(QGraphicsItem::ItemIsMovable, true); - copy->setFlag(QGraphicsItem::ItemIsSelectable, true); - copy->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); - copy->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); + copy->setUuid(this->uuid()); // this is OK for now as long as Widgets are imutable - copy->setUuid(this->uuid()); // This is OK for now, as long as pixmaps are immutable - - copy->setSourceUrl(this->sourceUrl()); + copyItemParameters(copy); // TODO UB 4.7 ... complete all members ? return copy; } +void UBGraphicsPixmapItem::copyItemParameters(UBItem *copy) const +{ + UBGraphicsPixmapItem *cp = dynamic_cast(copy); + if (cp) + { + cp->setPixmap(this->pixmap()); + cp->setPos(this->pos()); + cp->setTransform(this->transform()); + cp->setFlag(QGraphicsItem::ItemIsMovable, true); + cp->setFlag(QGraphicsItem::ItemIsSelectable, true); + cp->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); + cp->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); + cp->setSourceUrl(this->sourceUrl()); + } +} UBGraphicsScene* UBGraphicsPixmapItem::scene() { diff --git a/src/domain/UBGraphicsPixmapItem.h b/src/domain/UBGraphicsPixmapItem.h index 9e9bb05c..787f28eb 100644 --- a/src/domain/UBGraphicsPixmapItem.h +++ b/src/domain/UBGraphicsPixmapItem.h @@ -40,6 +40,8 @@ class UBGraphicsPixmapItem : public QObject, public QGraphicsPixmapItem, public } virtual UBItem* deepCopy() const; + virtual void copyItemParameters(UBItem *copy) const; + virtual UBGraphicsScene* scene(); virtual void remove(); diff --git a/src/domain/UBGraphicsPolygonItem.cpp b/src/domain/UBGraphicsPolygonItem.cpp index 0fd59189..256f8143 100644 --- a/src/domain/UBGraphicsPolygonItem.cpp +++ b/src/domain/UBGraphicsPolygonItem.cpp @@ -156,29 +156,37 @@ UBGraphicsPolygonItem* UBGraphicsPolygonItem::deepCopy(const QPolygonF& pol) con { UBGraphicsPolygonItem* copy = new UBGraphicsPolygonItem(pol); - copy->mOriginalLine = QLineF(); - copy->mOriginalWidth = -1; - copy->mIsNominalLine = false; + copyItemParameters(copy); - copy->setStroke(this->stroke()); - copy->setStrokesGroup(this->strokesGroup()); - copy->setBrush(this->brush()); - copy->setPen(this->pen()); - copy->mHasAlpha = this->mHasAlpha; + // TODO UB 4.7 ... complete all members ? + return copy; - copy->setColorOnDarkBackground(this->colorOnDarkBackground()); - copy->setColorOnLightBackground(this->colorOnLightBackground()); +} + +void UBGraphicsPolygonItem::copyItemParameters(UBItem *copy) const +{ + UBGraphicsPolygonItem *cp = dynamic_cast(copy); + if (cp) + { + cp->mOriginalLine = QLineF(); + cp->mOriginalWidth = -1; + cp->mIsNominalLine = false; - copy->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); + cp->setStroke(this->stroke()); + cp->setStrokesGroup(this->strokesGroup()); + cp->setBrush(this->brush()); + cp->setPen(this->pen()); + cp->mHasAlpha = this->mHasAlpha; - // TODO UB 4.7 ... complete all members ? - return copy; + cp->setColorOnDarkBackground(this->colorOnDarkBackground()); + cp->setColorOnLightBackground(this->colorOnLightBackground()); + cp->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); + } } - void UBGraphicsPolygonItem::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { if(mHasAlpha && scene() && scene()->isLightBackground()) diff --git a/src/domain/UBGraphicsPolygonItem.h b/src/domain/UBGraphicsPolygonItem.h index 6aa189ac..6ee1cc7e 100644 --- a/src/domain/UBGraphicsPolygonItem.h +++ b/src/domain/UBGraphicsPolygonItem.h @@ -88,6 +88,7 @@ class UBGraphicsPolygonItem : public QGraphicsPolygonItem, public UBItem // optimisation (eraser) UBGraphicsPolygonItem* deepCopy(const QPolygonF& pol) const; + virtual void copyItemParameters(UBItem *copy) const; QLineF originalLine() { return mOriginalLine;} qreal originalWidth() { return mOriginalWidth;} diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 25f94c03..1c45145f 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -1539,11 +1539,15 @@ void UBGraphicsScene::addGroup(UBGraphicsGroupContainerItem *groupItem) setDocumentUpdated(); } -UBGraphicsSvgItem* UBGraphicsScene::addSvg(const QUrl& pSvgFileUrl, const QPointF& pPos) +UBGraphicsSvgItem* UBGraphicsScene::addSvg(const QUrl& pSvgFileUrl, const QPointF& pPos, const QByteArray pData) { QString path = pSvgFileUrl.toLocalFile(); - UBGraphicsSvgItem *svgItem = new UBGraphicsSvgItem(path); + UBGraphicsSvgItem *svgItem; + if (pData.isNull()) + svgItem = new UBGraphicsSvgItem(path); + else + svgItem = new UBGraphicsSvgItem(pData); svgItem->setFlag(QGraphicsItem::ItemIsMovable, true); svgItem->setFlag(QGraphicsItem::ItemIsSelectable, true); diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index b8cdb7b7..7433cde9 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -109,6 +109,8 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem virtual UBItem* deepCopy() const; + virtual void copyItemParameters(UBItem *copy) const {Q_UNUSED(copy);} + UBGraphicsScene* sceneDeepCopy() const; void clearItemsAndAnnotations(); @@ -136,7 +138,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem UBGraphicsMediaItem* addMedia(const QUrl& pMediaFileUrl, bool shouldPlayAsap, const QPointF& pPos = QPointF(0, 0)); UBGraphicsMediaItem* addVideo(const QUrl& pVideoFileUrl, bool shouldPlayAsap, const QPointF& pPos = QPointF(0, 0)); UBGraphicsMediaItem* addAudio(const QUrl& pAudioFileUrl, bool shouldPlayAsap, const QPointF& pPos = QPointF(0, 0)); - UBGraphicsSvgItem* addSvg(const QUrl& pSvgFileUrl, const QPointF& pPos = QPointF(0, 0)); + UBGraphicsSvgItem* addSvg(const QUrl& pSvgFileUrl, const QPointF& pPos = QPointF(0, 0), const QByteArray pData = QByteArray()); UBGraphicsTextItem* addText(const QString& pString, const QPointF& pTopLeft = QPointF(0, 0)); UBGraphicsTextItem* textForObjectName(const QString& pString, const QString &objectName = "UBTGZeroPageSessionTitle"); diff --git a/src/domain/UBGraphicsStrokesGroup.cpp b/src/domain/UBGraphicsStrokesGroup.cpp index 7fdbd1a7..bff2dd5e 100644 --- a/src/domain/UBGraphicsStrokesGroup.cpp +++ b/src/domain/UBGraphicsStrokesGroup.cpp @@ -63,16 +63,25 @@ UBItem* UBGraphicsStrokesGroup::deepCopy() const { UBGraphicsStrokesGroup* copy = new UBGraphicsStrokesGroup(); - copy->setPos(this->pos()); - copy->setTransform(this->transform()); - copy->setFlag(QGraphicsItem::ItemIsMovable, true); - copy->setFlag(QGraphicsItem::ItemIsSelectable, true); - copy->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); - copy->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); + copyItemParameters(copy); return copy; } +void UBGraphicsStrokesGroup::copyItemParameters(UBItem *copy) const +{ + UBGraphicsStrokesGroup *cp = dynamic_cast(copy); + { + cp->setPos(this->pos()); + + cp->setTransform(this->transform()); + cp->setFlag(QGraphicsItem::ItemIsMovable, true); + cp->setFlag(QGraphicsItem::ItemIsSelectable, true); + cp->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); + cp->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); + } +} + void UBGraphicsStrokesGroup::remove() { if (mDelegate) diff --git a/src/domain/UBGraphicsStrokesGroup.h b/src/domain/UBGraphicsStrokesGroup.h index 55b33653..8339e1c2 100644 --- a/src/domain/UBGraphicsStrokesGroup.h +++ b/src/domain/UBGraphicsStrokesGroup.h @@ -14,6 +14,7 @@ public: UBGraphicsStrokesGroup(QGraphicsItem* parent = 0); ~UBGraphicsStrokesGroup(); virtual UBItem* deepCopy() const; + virtual void copyItemParameters(UBItem *copy) const; virtual void remove(); virtual UBGraphicsItemDelegate* Delegate() const {return mDelegate;} enum { Type = UBGraphicsItemType::StrokeItemType }; diff --git a/src/domain/UBGraphicsSvgItem.cpp b/src/domain/UBGraphicsSvgItem.cpp index 31386bcb..b9976ae9 100644 --- a/src/domain/UBGraphicsSvgItem.cpp +++ b/src/domain/UBGraphicsSvgItem.cpp @@ -135,14 +135,9 @@ UBItem* UBGraphicsSvgItem::deepCopy() const { UBGraphicsSvgItem* copy = new UBGraphicsSvgItem(this->fileData()); - copy->setPos(this->pos()); - copy->setTransform(this->transform()); - copy->setFlag(QGraphicsItem::ItemIsMovable, true); - copy->setFlag(QGraphicsItem::ItemIsSelectable, true); - copy->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); - copy->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); - copy->setUuid(this->uuid()); // this is OK for now as long as SVG are imutable - copy->setSourceUrl(this->sourceUrl()); + copy->setUuid(this->uuid()); // this is OK for now as long as Widgets are imutable + + copyItemParameters(copy); // TODO UB 4.7... complete all members ? @@ -150,6 +145,20 @@ UBItem* UBGraphicsSvgItem::deepCopy() const } +void UBGraphicsSvgItem::copyItemParameters(UBItem *copy) const +{ + UBGraphicsSvgItem *cp = dynamic_cast(copy); + if (cp) + { + cp->setPos(this->pos()); + cp->setTransform(this->transform()); + cp->setFlag(QGraphicsItem::ItemIsMovable, true); + cp->setFlag(QGraphicsItem::ItemIsSelectable, true); + cp->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); + cp->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); + cp->setSourceUrl(this->sourceUrl()); + } +} void UBGraphicsSvgItem::setRenderingQuality(RenderingQuality pRenderingQuality) { diff --git a/src/domain/UBGraphicsSvgItem.h b/src/domain/UBGraphicsSvgItem.h index f02025af..95b9d536 100644 --- a/src/domain/UBGraphicsSvgItem.h +++ b/src/domain/UBGraphicsSvgItem.h @@ -52,6 +52,8 @@ class UBGraphicsSvgItem: public QGraphicsSvgItem, public UBItem, public UBGraphi virtual UBItem* deepCopy() const; + virtual void copyItemParameters(UBItem *copy) const; + virtual void setRenderingQuality(RenderingQuality pRenderingQuality); virtual UBGraphicsScene* scene(); diff --git a/src/domain/UBGraphicsTextItem.cpp b/src/domain/UBGraphicsTextItem.cpp index 80625045..eb93f975 100644 --- a/src/domain/UBGraphicsTextItem.cpp +++ b/src/domain/UBGraphicsTextItem.cpp @@ -201,28 +201,36 @@ UBItem* UBGraphicsTextItem::deepCopy() const { UBGraphicsTextItem* copy = new UBGraphicsTextItem(); - copy->setHtml(toHtml()); - copy->setPos(this->pos()); - copy->setTransform(this->transform()); - copy->setFlag(QGraphicsItem::ItemIsMovable, true); - copy->setFlag(QGraphicsItem::ItemIsSelectable, true); - copy->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); - copy->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); - copy->setData(UBGraphicsItemData::ItemEditable, data(UBGraphicsItemData::ItemEditable).toBool()); -// copy->setDefaultTextColor(this->defaultTextColor()); -// copy->setFont(this->font()); -// copy->setColorOnDarkBackground(this->colorOnDarkBackground()); -// copy->setColorOnLightBackground(this->colorOnLightBackground()); - copy->setTextWidth(this->textWidth()); - copy->setTextHeight(this->textHeight()); - - copy->setSourceUrl(this->sourceUrl()); + copyItemParameters(copy); // TODO UB 4.7 ... complete all members ? return copy; } +void UBGraphicsTextItem::copyItemParameters(UBItem *copy) const +{ + UBGraphicsTextItem *cp = dynamic_cast(copy); + if (cp) + { + cp->setHtml(toHtml()); + cp->setPos(this->pos()); + cp->setTransform(this->transform()); + cp->setFlag(QGraphicsItem::ItemIsMovable, true); + cp->setFlag(QGraphicsItem::ItemIsSelectable, true); + cp->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); + cp->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); + cp->setData(UBGraphicsItemData::ItemEditable, data(UBGraphicsItemData::ItemEditable).toBool()); + // cp->setDefaultTextColor(this->defaultTextColor()); + // cp->setFont(this->font()); + // cp->setColorOnDarkBackground(this->colorOnDarkBackground()); + // cp->setColorOnLightBackground(this->colorOnLightBackground()); + cp->setTextWidth(this->textWidth()); + cp->setTextHeight(this->textHeight()); + + cp->setSourceUrl(this->sourceUrl()); + } +} QRectF UBGraphicsTextItem::boundingRect() const { diff --git a/src/domain/UBGraphicsTextItem.h b/src/domain/UBGraphicsTextItem.h index 8bbe3df5..c7dc5c95 100644 --- a/src/domain/UBGraphicsTextItem.h +++ b/src/domain/UBGraphicsTextItem.h @@ -40,6 +40,9 @@ class UBGraphicsTextItem : public QGraphicsTextItem, public UBItem, public UBRes } virtual UBItem* deepCopy() const; + + virtual void copyItemParameters(UBItem *copy) const; + virtual UBGraphicsScene* scene(); virtual QRectF boundingRect() const; diff --git a/src/domain/UBGraphicsWidgetItem.cpp b/src/domain/UBGraphicsWidgetItem.cpp index 835a7e0e..8ef47b33 100644 --- a/src/domain/UBGraphicsWidgetItem.cpp +++ b/src/domain/UBGraphicsWidgetItem.cpp @@ -330,19 +330,29 @@ UBItem* UBGraphicsAppleWidgetItem::deepCopy() const { UBGraphicsAppleWidgetItem *appleWidget = new UBGraphicsAppleWidgetItem(mWebKitWidget->widgetUrl(), parentItem()); - foreach(QString key, mPreferences.keys()) - { - appleWidget->setPreference(key, mPreferences.value(key)); - } + copyItemParameters(appleWidget); + + return appleWidget; - foreach(QString key, mDatastore.keys()) +} + +void UBGraphicsAppleWidgetItem::copyItemParameters(UBItem *copy) const +{ + UBGraphicsAppleWidgetItem *cp = dynamic_cast(copy); + if (cp) { - appleWidget->setDatastoreEntry(key, mDatastore.value(key)); - } + foreach(QString key, mPreferences.keys()) + { + cp->setPreference(key, mPreferences.value(key)); + } - appleWidget->setSourceUrl(this->sourceUrl()); + foreach(QString key, mDatastore.keys()) + { + cp->setDatastoreEntry(key, mDatastore.value(key)); + } - return appleWidget; + cp->setSourceUrl(this->sourceUrl()); + } } void UBGraphicsAppleWidgetItem::setUuid(const QUuid &pUuid) @@ -431,27 +441,35 @@ UBW3CWidget* UBGraphicsW3CWidgetItem::w3cWidget() const UBItem* UBGraphicsW3CWidgetItem::deepCopy() const { UBGraphicsW3CWidgetItem *copy = new UBGraphicsW3CWidgetItem(mWebKitWidget->widgetUrl(), parentItem()); - - copy->setPos(this->pos()); - copy->setTransform(this->transform()); - copy->setFlag(QGraphicsItem::ItemIsMovable, true); - copy->setFlag(QGraphicsItem::ItemIsSelectable, true); - copy->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); - copy->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); copy->setUuid(this->uuid()); // this is OK for now as long as Widgets are imutable - copy->setSourceUrl(this->sourceUrl()); + copyItemParameters(copy); - copy->resize(this->size()); + return copy; +} - foreach(QString key, mPreferences.keys()) +void UBGraphicsW3CWidgetItem::copyItemParameters(UBItem *copy) const +{ + UBGraphicsW3CWidgetItem *cp = dynamic_cast(copy); + if (cp) { - copy->setPreference(key, mPreferences.value(key)); - } + cp->setPos(this->pos()); + cp->setTransform(this->transform()); + cp->setFlag(QGraphicsItem::ItemIsMovable, true); + cp->setFlag(QGraphicsItem::ItemIsSelectable, true); + cp->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); + cp->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); + cp->setSourceUrl(this->sourceUrl()); - foreach(QString key, mDatastore.keys()) - { - copy->setDatastoreEntry(key, mDatastore.value(key)); - } + cp->resize(this->size()); - return copy; -} + foreach(QString key, mPreferences.keys()) + { + cp->setPreference(key, mPreferences.value(key)); + } + + foreach(QString key, mDatastore.keys()) + { + cp->setDatastoreEntry(key, mDatastore.value(key)); + } + } +} \ No newline at end of file diff --git a/src/domain/UBGraphicsWidgetItem.h b/src/domain/UBGraphicsWidgetItem.h index ae71955d..d3728b00 100644 --- a/src/domain/UBGraphicsWidgetItem.h +++ b/src/domain/UBGraphicsWidgetItem.h @@ -130,6 +130,9 @@ class UBGraphicsAppleWidgetItem : public UBGraphicsWidgetItem } virtual UBItem* deepCopy() const; + + virtual void copyItemParameters(UBItem *copy) const; + virtual void setUuid(const QUuid &pUuid); }; @@ -152,6 +155,8 @@ class UBGraphicsW3CWidgetItem : public UBGraphicsWidgetItem virtual UBItem* deepCopy() const; + virtual void copyItemParameters(UBItem *copy) const; + UBW3CWidget::Metadata metadatas() const; UBW3CWidget* w3cWidget() const; diff --git a/src/domain/UBItem.h b/src/domain/UBItem.h index e9bd5df2..21519a1b 100644 --- a/src/domain/UBItem.h +++ b/src/domain/UBItem.h @@ -20,6 +20,7 @@ #include "core/UB.h" class UBGraphicsScene; +class UBGraphicsItem; class UBItem { @@ -58,6 +59,8 @@ class UBItem virtual UBItem* deepCopy() const = 0; + virtual void copyItemParameters(UBItem *copy) const = 0; + virtual UBGraphicsScene* scene() // TODO UB 4.x should be pure virtual ... { return 0; diff --git a/src/tools/UBGraphicsCache.cpp b/src/tools/UBGraphicsCache.cpp index eff63b59..7a89c534 100644 --- a/src/tools/UBGraphicsCache.cpp +++ b/src/tools/UBGraphicsCache.cpp @@ -45,15 +45,24 @@ UBItem* UBGraphicsCache::deepCopy() const { UBGraphicsCache* copy = new UBGraphicsCache(); - copy->setPos(this->pos()); - copy->setRect(this->rect()); - copy->setTransform(this->transform()); + copyItemParameters(copy); // TODO UB 4.7 ... complete all members ? return copy; } +void UBGraphicsCache::copyItemParameters(UBItem *copy) const +{ + UBGraphicsCache *cp = dynamic_cast(copy); + if (cp) + { + cp->setPos(this->pos()); + cp->setRect(this->rect()); + cp->setTransform(this->transform()); + } +} + QColor UBGraphicsCache::maskColor() { return mMaskColor; diff --git a/src/tools/UBGraphicsCache.h b/src/tools/UBGraphicsCache.h index d1ad25ae..9ca07d0d 100644 --- a/src/tools/UBGraphicsCache.h +++ b/src/tools/UBGraphicsCache.h @@ -39,6 +39,8 @@ public: virtual UBItem* deepCopy() const; + virtual void copyItemParameters(UBItem *copy) const; + QColor maskColor(); void setMaskColor(QColor color); eMaskShape maskshape(); diff --git a/src/tools/UBGraphicsCompass.cpp b/src/tools/UBGraphicsCompass.cpp index 08e44d48..183d9ea3 100644 --- a/src/tools/UBGraphicsCompass.cpp +++ b/src/tools/UBGraphicsCompass.cpp @@ -86,15 +86,24 @@ UBItem* UBGraphicsCompass::deepCopy() const { UBGraphicsCompass* copy = new UBGraphicsCompass(); - copy->setPos(this->pos()); - copy->setRect(this->rect()); - copy->setTransform(this->transform()); + copyItemParameters(copy); // TODO UB 4.7 ... complete all members ? return copy; } +void UBGraphicsCompass::copyItemParameters(UBItem *copy) const +{ + UBGraphicsCompass *cp = dynamic_cast(copy); + if (cp) + { + cp->setPos(this->pos()); + cp->setRect(this->rect()); + cp->setTransform(this->transform()); + } +} + void UBGraphicsCompass::paint(QPainter *painter, const QStyleOptionGraphicsItem *styleOption, QWidget *widget) { Q_UNUSED(styleOption); diff --git a/src/tools/UBGraphicsCompass.h b/src/tools/UBGraphicsCompass.h index d7b6fea2..6ed90429 100644 --- a/src/tools/UBGraphicsCompass.h +++ b/src/tools/UBGraphicsCompass.h @@ -41,6 +41,8 @@ class UBGraphicsCompass: public QObject, public QGraphicsRectItem, public UBItem virtual UBItem* deepCopy() const; + virtual void copyItemParameters(UBItem *copy) const; + signals: void hidden(); diff --git a/src/tools/UBGraphicsCurtainItem.cpp b/src/tools/UBGraphicsCurtainItem.cpp index 390b2f7e..746ed5c6 100644 --- a/src/tools/UBGraphicsCurtainItem.cpp +++ b/src/tools/UBGraphicsCurtainItem.cpp @@ -133,20 +133,28 @@ UBItem* UBGraphicsCurtainItem::deepCopy() const { UBGraphicsCurtainItem* copy = new UBGraphicsCurtainItem(); - copy->setRect(this->rect()); - copy->setPos(this->pos()); - copy->setBrush(this->brush()); - copy->setPen(this->pen()); - copy->setTransform(this->transform()); - copy->setFlag(QGraphicsItem::ItemIsMovable, true); - copy->setFlag(QGraphicsItem::ItemIsSelectable, true); - copy->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); + copyItemParameters(copy); // TODO UB 4.7 ... complete all members ? return copy; } +void UBGraphicsCurtainItem::copyItemParameters(UBItem *copy) const +{ + UBGraphicsCurtainItem *cp = dynamic_cast(copy); + if (cp) + { + cp->setRect(this->rect()); + cp->setPos(this->pos()); + cp->setBrush(this->brush()); + cp->setPen(this->pen()); + cp->setTransform(this->transform()); + cp->setFlag(QGraphicsItem::ItemIsMovable, true); + cp->setFlag(QGraphicsItem::ItemIsSelectable, true); + cp->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); + } +} QColor UBGraphicsCurtainItem::drawColor() const { diff --git a/src/tools/UBGraphicsCurtainItem.h b/src/tools/UBGraphicsCurtainItem.h index 516e8bd1..afef3960 100644 --- a/src/tools/UBGraphicsCurtainItem.h +++ b/src/tools/UBGraphicsCurtainItem.h @@ -42,6 +42,7 @@ class UBGraphicsCurtainItem : public QObject, public QGraphicsRectItem, public U } virtual UBItem* deepCopy() const; + virtual void copyItemParameters(UBItem *copy) const; virtual void remove(); diff --git a/src/tools/UBGraphicsProtractor.cpp b/src/tools/UBGraphicsProtractor.cpp index 23505e80..c46a678f 100644 --- a/src/tools/UBGraphicsProtractor.cpp +++ b/src/tools/UBGraphicsProtractor.cpp @@ -579,20 +579,27 @@ UBItem* UBGraphicsProtractor::deepCopy() const { UBGraphicsProtractor* copy = new UBGraphicsProtractor(); - copy->setPos(this->pos()); - copy->setRect(this->rect()); - copy->setTransform(this->transform()); - - copy->mCurrentAngle = this->mCurrentAngle; - copy->mSpan = this->mSpan; - copy->mStartAngle = this->mStartAngle; - copy->mScaleFactor = this->mScaleFactor; + copyItemParameters(copy); // TODO UB 4.7 ... complete all members ? return copy; } - +void UBGraphicsProtractor::copyItemParameters(UBItem *copy) const +{ + UBGraphicsProtractor *cp = dynamic_cast(copy); + if (cp) + { + cp->setPos(this->pos()); + cp->setRect(this->rect()); + cp->setTransform(this->transform()); + + cp->mCurrentAngle = this->mCurrentAngle; + cp->mSpan = this->mSpan; + cp->mStartAngle = this->mStartAngle; + cp->mScaleFactor = this->mScaleFactor; + } +} void UBGraphicsProtractor::rotateAroundCenter(qreal angle) { diff --git a/src/tools/UBGraphicsProtractor.h b/src/tools/UBGraphicsProtractor.h index e6a7ecac..0af790de 100644 --- a/src/tools/UBGraphicsProtractor.h +++ b/src/tools/UBGraphicsProtractor.h @@ -40,6 +40,7 @@ class UBGraphicsProtractor : public UBAbstractDrawRuler, public QGraphicsEllipse void setMarkerAngle (qreal angle) { mCurrentAngle = angle; } virtual UBItem* deepCopy() const; + virtual void copyItemParameters(UBItem *copy) const; enum { Type = UBGraphicsItemType::ProtractorItemType }; diff --git a/src/tools/UBGraphicsRuler.cpp b/src/tools/UBGraphicsRuler.cpp index 4a1a74d6..2542bdec 100644 --- a/src/tools/UBGraphicsRuler.cpp +++ b/src/tools/UBGraphicsRuler.cpp @@ -75,15 +75,24 @@ UBItem* UBGraphicsRuler::deepCopy() const { UBGraphicsRuler* copy = new UBGraphicsRuler(); - copy->setPos(this->pos()); - copy->setRect(this->rect()); - copy->setTransform(this->transform()); + copyItemParameters(copy); // TODO UB 4.7 ... complete all members ? return copy; } +void UBGraphicsRuler::copyItemParameters(UBItem *copy) const +{ + UBGraphicsRuler *cp = dynamic_cast(copy); + if (cp) + { + cp->setPos(this->pos()); + cp->setRect(this->rect()); + cp->setTransform(this->transform()); + } +} + void UBGraphicsRuler::paint(QPainter *painter, const QStyleOptionGraphicsItem *styleOption, QWidget *widget) { Q_UNUSED(styleOption); diff --git a/src/tools/UBGraphicsRuler.h b/src/tools/UBGraphicsRuler.h index 89584b70..f58e6348 100644 --- a/src/tools/UBGraphicsRuler.h +++ b/src/tools/UBGraphicsRuler.h @@ -41,6 +41,7 @@ class UBGraphicsRuler : public UBAbstractDrawRuler, public QGraphicsRectItem, pu } virtual UBItem* deepCopy() const; + virtual void copyItemParameters(UBItem *copy) const; virtual void StartLine(const QPointF& position, qreal width); virtual void DrawLine(const QPointF& position, qreal width); diff --git a/src/tools/UBGraphicsTriangle.cpp b/src/tools/UBGraphicsTriangle.cpp index f62413fe..49880a01 100644 --- a/src/tools/UBGraphicsTriangle.cpp +++ b/src/tools/UBGraphicsTriangle.cpp @@ -94,9 +94,7 @@ UBItem* UBGraphicsTriangle::deepCopy(void) const { UBGraphicsTriangle* copy = new UBGraphicsTriangle(); - copy->setPos(this->pos()); - copy->setPolygon(this->polygon()); - copy->setTransform(this->transform()); + copyItemParameters(copy); // TODO UB 4.7 ... complete all members ? @@ -104,6 +102,17 @@ UBItem* UBGraphicsTriangle::deepCopy(void) const } +void UBGraphicsTriangle::copyItemParameters(UBItem *copy) const +{ + UBGraphicsTriangle* cp = dynamic_cast(copy); + if (cp) + { + cp->setPos(this->pos()); + cp->setPolygon(this->polygon()); + cp->setTransform(this->transform()); + } +} + void UBGraphicsTriangle::setRect(qreal x, qreal y, qreal w, qreal h, UBGraphicsTriangleOrientation orientation) { QPolygonF polygon; diff --git a/src/tools/UBGraphicsTriangle.h b/src/tools/UBGraphicsTriangle.h index 60f8d145..b945b6b6 100644 --- a/src/tools/UBGraphicsTriangle.h +++ b/src/tools/UBGraphicsTriangle.h @@ -45,6 +45,7 @@ class UBGraphicsTriangle : public UBAbstractDrawRuler, public QGraphicsPolygonIt virtual UBItem* deepCopy(void) const; + virtual void copyItemParameters(UBItem *copy) const; virtual void StartLine(const QPointF& scenePos, qreal width); virtual void DrawLine(const QPointF& position, qreal width);