From 8b0e41ea9136b8f091740ac7d9e526d47d7ba963 Mon Sep 17 00:00:00 2001 From: Ilia Ryabokon Date: Tue, 4 Sep 2012 17:10:45 +0300 Subject: [PATCH 01/10] Sankore 1107 Crashes fixed Undo command left --- src/api/UBWidgetUniboardAPI.cpp | 2 +- src/board/UBBoardController.cpp | 8 +- src/desktop/UBDesktopAnnotationController.cpp | 2 +- src/domain/UBGraphicsGroupContainerItem.cpp | 5 +- src/domain/UBGraphicsItemDelegate.cpp | 19 ++- src/domain/UBGraphicsItemDelegate.h | 1 + src/domain/UBGraphicsScene.cpp | 132 +++++++----------- src/domain/UBGraphicsScene.h | 12 +- src/domain/UBGraphicsTextItemDelegate.cpp | 9 +- src/domain/UBGraphicsTextItemDelegate.h | 1 + src/domain/UBItem.cpp | 43 ++++++ src/domain/UBItem.h | 1 + src/gui/UBKeyboardPalette.cpp | 5 +- 13 files changed, 140 insertions(+), 100 deletions(-) diff --git a/src/api/UBWidgetUniboardAPI.cpp b/src/api/UBWidgetUniboardAPI.cpp index 0e2a54f1..b86e7aa1 100644 --- a/src/api/UBWidgetUniboardAPI.cpp +++ b/src/api/UBWidgetUniboardAPI.cpp @@ -250,7 +250,7 @@ void UBWidgetUniboardAPI::eraseLineTo(const qreal x, const qreal y, const qreal void UBWidgetUniboardAPI::clear() { if (mScene) - mScene->clearItemsAndAnnotations(); + mScene->clearContent(UBGraphicsScene::clearItemsAndAnnotations); } diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index b7a5ad6b..3fd87fe3 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -683,7 +683,7 @@ void UBBoardController::clearScene() if (mActiveScene) { freezeW3CWidgets(true); - mActiveScene->clearItemsAndAnnotations(); + mActiveScene->clearContent(UBGraphicsScene::clearItemsAndAnnotations); updateActionStates(); } } @@ -694,7 +694,7 @@ void UBBoardController::clearSceneItems() if (mActiveScene) { freezeW3CWidgets(true); - mActiveScene->clearItems(); + mActiveScene->clearContent(UBGraphicsScene::clearItems); updateActionStates(); } } @@ -704,7 +704,7 @@ void UBBoardController::clearSceneAnnotation() { if (mActiveScene) { - mActiveScene->clearAnnotations(); + mActiveScene->clearContent(UBGraphicsScene::clearAnnotations); updateActionStates(); } } @@ -713,7 +713,7 @@ void UBBoardController::clearSceneBackground() { if (mActiveScene) { - mActiveScene->clearBackground(); + mActiveScene->clearContent(UBGraphicsScene::clearBackground); updateActionStates(); } } diff --git a/src/desktop/UBDesktopAnnotationController.cpp b/src/desktop/UBDesktopAnnotationController.cpp index e86dca46..b95b433d 100644 --- a/src/desktop/UBDesktopAnnotationController.cpp +++ b/src/desktop/UBDesktopAnnotationController.cpp @@ -274,7 +274,7 @@ void UBDesktopAnnotationController::eraseDesktopAnnotations() { if (mTransparentDrawingScene) { - mTransparentDrawingScene->clearAnnotations(); + mTransparentDrawingScene->clearContent(UBGraphicsScene::clearAnnotations); } } diff --git a/src/domain/UBGraphicsGroupContainerItem.cpp b/src/domain/UBGraphicsGroupContainerItem.cpp index 95b95af3..818eb88e 100644 --- a/src/domain/UBGraphicsGroupContainerItem.cpp +++ b/src/domain/UBGraphicsGroupContainerItem.cpp @@ -78,7 +78,10 @@ void UBGraphicsGroupContainerItem::addToGroup(QGraphicsItem *item) QTransform newItemTransform(itemTransform); item->setPos(mapFromItem(item, 0, 0)); - item->scene()->removeItem(item); + if (item->scene()) { + item->scene()->removeItem(item); + } + if (corescene()) corescene()->removeItemFromDeletion(item); item->setParentItem(this); diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index 6c0349e4..d5620d12 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -387,12 +387,25 @@ void UBGraphicsItemDelegate::remove(bool canUndo) UBGraphicsScene* scene = dynamic_cast(mDelegated->scene()); if (scene) { - foreach(DelegateButton* button, mButtons) - scene->removeItem(button); +// bool shownOnDisplay = mDelegated->data(UBGraphicsItemData::ItemLayerType).toInt() != UBItemLayerType::Control; +// showHide(shownOnDisplay); +// updateFrame(); +// updateButtons(); + + if (mFrame && !mFrame->scene() && mDelegated->scene()) + { + mDelegated->scene()->addItem(mFrame); + } + mFrame->setAntiScale(mAntiScaleRatio); + mFrame->positionHandles(); + updateButtons(true); + foreach(DelegateButton* button, mButtons) { + scene->removeItem(button); + } scene->removeItem(mFrame); - /* this is performed because when removing delegated from scene while it contains flash content, segfault happens because of QGraphicsScene::removeItem() */ + /* this is performed because when removing delegated from scene while it contains flash content, segfault happens because of QGraphicsScene::removeItem() */ UBGraphicsWebView *mDelegated_casted = dynamic_cast(mDelegated); if (mDelegated_casted) mDelegated_casted->setHtml(QString()); diff --git a/src/domain/UBGraphicsItemDelegate.h b/src/domain/UBGraphicsItemDelegate.h index c782c94b..01ef854b 100644 --- a/src/domain/UBGraphicsItemDelegate.h +++ b/src/domain/UBGraphicsItemDelegate.h @@ -244,6 +244,7 @@ class UBGraphicsItemDelegate : public QObject UBGraphicsToolBarItem* getToolBarItem() const { return mToolBarItem; } qreal antiScaleRatio() const { return mAntiScaleRatio; } + virtual void update() {positionHandles();} signals: void showOnDisplayChanged(bool shown); diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index ea3666df..0cdb2ae6 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -1064,106 +1064,72 @@ UBItem* UBGraphicsScene::deepCopy() const return sceneDeepCopy(); } -void UBGraphicsScene::clearItemsAndAnnotations() +void UBGraphicsScene::clearContent(clearCase pCase) { - deselectAllItems(); - - QSet emptyList; - QSet removedItems; - - QList sceneItems = items(); - foreach(QGraphicsItem* item, sceneItems) - { - if(!mTools.contains(item) && !isBackgroundObject(item)) - { - removeItem(item); - removedItems << item; - } - } - - // force refresh, QT is a bit lazy and take a lot of time (nb item ^2 ?) to trigger repaint - update(sceneRect()); - - if (enableUndoRedoStack) { //should be deleted after scene own undo stack implemented - UBGraphicsItemUndoCommand* uc = new UBGraphicsItemUndoCommand(this, removedItems, emptyList); - UBApplication::undoStack->push(uc); - } - - setDocumentUpdated(); -} - -void UBGraphicsScene::clearItems() -{ - deselectAllItems(); - - QSet emptyList; QSet removedItems; - QList sceneItems = items(); - foreach(QGraphicsItem* item, sceneItems) - { - bool isGroup = qgraphicsitem_cast(item) != NULL; - bool isPolygon = qgraphicsitem_cast(item) != NULL; - bool isStrokesGroup = qgraphicsitem_cast(item) != NULL; - - if(!isGroup && !isPolygon && !isStrokesGroup && !mTools.contains(item) && !isBackgroundObject(item)) - { - removeItem(item); - removedItems << item; - } - } - - // force refresh, QT is a bit lazy and take a lot of time (nb item ^2 ?) to trigger repaint - update(sceneRect()); - - - if (enableUndoRedoStack) { //should be deleted after scene own undo stack implemented - UBGraphicsItemUndoCommand* uc = new UBGraphicsItemUndoCommand(this, removedItems, emptyList); - UBApplication::undoStack->push(uc); - } + switch (pCase) { + case clearBackground : + removeItem(mBackgroundObject); + removedItems << mBackgroundObject; + break; + + case clearItemsAndAnnotations : + case clearItems : + case clearAnnotations : + foreach(QGraphicsItem* item, items()) { + + bool isGroup = item->type() == UBGraphicsGroupContainerItem::Type; + bool isStrokesGroup = item->type() == UBGraphicsStrokesGroup::Type; + + UBGraphicsGroupContainerItem *itemGroup = item->parentItem() + ? qgraphicsitem_cast(item->parentItem()) + : 0; + UBGraphicsItemDelegate *curDelegate = UBGraphicsItem::Delegate(item); + if (!curDelegate) { + continue; + } - setDocumentUpdated(); -} + bool shouldDelete = false; + switch (static_cast(pCase)) { + case clearAnnotations : + shouldDelete = isStrokesGroup; + break; + case clearItems : + shouldDelete = !isGroup && !isBackgroundObject(item) && !isStrokesGroup; + break; + case clearItemsAndAnnotations: + shouldDelete = !isGroup && !isBackgroundObject(item); + break; + } -void UBGraphicsScene::clearAnnotations() -{ - QSet emptyList; - QSet removedItems; + if(shouldDelete) { + if (itemGroup) { + itemGroup->removeFromGroup(item); + if (itemGroup->childItems().count() == 1) { + itemGroup->destroy(); + } + itemGroup->Delegate()->update(); + } - QList sceneItems = items(); - foreach(QGraphicsItem* item, sceneItems) - { - UBGraphicsStrokesGroup* pi = qgraphicsitem_cast(item); - if (pi) - { - removeItem(item); - removedItems << item; + curDelegate->remove(false); + removedItems << item; + } } + break; } // force refresh, QT is a bit lazy and take a lot of time (nb item ^2 ?) to trigger repaint update(sceneRect()); if (enableUndoRedoStack) { //should be deleted after scene own undo stack implemented - UBGraphicsItemUndoCommand* uc = new UBGraphicsItemUndoCommand(this, removedItems, emptyList); + UBGraphicsItemUndoCommand* uc = new UBGraphicsItemUndoCommand(this, removedItems, QSet()); UBApplication::undoStack->push(uc); } - setDocumentUpdated(); -} - -void UBGraphicsScene::clearBackground() -{ - if(mBackgroundObject){ - removeItem(mBackgroundObject); - - if (enableUndoRedoStack) { //should be deleted after scene own undo stack implemented - UBGraphicsItemUndoCommand* uc = new UBGraphicsItemUndoCommand(this, mBackgroundObject, NULL); - UBApplication::undoStack->push(uc); - } + if (pCase == clearBackground) { mBackgroundObject = 0; } - update(sceneRect()); setDocumentUpdated(); } @@ -1357,8 +1323,8 @@ UBGraphicsW3CWidgetItem* UBGraphicsScene::addOEmbed(const QUrl& pContentUrl, con UBGraphicsGroupContainerItem *UBGraphicsScene::createGroup(QList items) { UBGraphicsGroupContainerItem *groupItem = new UBGraphicsGroupContainerItem(); - addItem(groupItem); + addItem(groupItem); foreach (QGraphicsItem *item, items) { if (item->type() == UBGraphicsGroupContainerItem::Type) { QList childItems = item->childItems(); diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index 6f8c8def..0dedb9c1 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -101,6 +101,13 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem public: + enum clearCase { + clearItemsAndAnnotations = 0 + , clearAnnotations + , clearItems + , clearBackground + }; + // tmp stub for divide addings scene objects from undo mechanism implementation void setURStackEnable(bool set = true) {enableUndoRedoStack = set;} bool isURStackIsEnabled(){ return enableUndoRedoStack;} @@ -114,10 +121,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem UBGraphicsScene* sceneDeepCopy() const; - void clearItemsAndAnnotations(); - void clearItems(); - void clearAnnotations(); - void clearBackground(); + void clearContent(clearCase pCase = clearItemsAndAnnotations); bool inputDevicePress(const QPointF& scenePos, const qreal& pressure = 1.0); bool inputDeviceMove(const QPointF& scenePos, const qreal& pressure = 1.0); diff --git a/src/domain/UBGraphicsTextItemDelegate.cpp b/src/domain/UBGraphicsTextItemDelegate.cpp index 6e7e730e..9f7b5fdb 100644 --- a/src/domain/UBGraphicsTextItemDelegate.cpp +++ b/src/domain/UBGraphicsTextItemDelegate.cpp @@ -263,6 +263,11 @@ void UBGraphicsTextItemDelegate::setEditable(bool editable) mDelegated->setData(UBGraphicsItemData::ItemEditable, QVariant(false)); } } +void UBGraphicsTextItemDelegate::remove(bool canUndo) +{ + UBGraphicsItemDelegate::remove(canUndo); +} + bool UBGraphicsTextItemDelegate::isEditable() { return mDelegated->data(UBGraphicsItemData::ItemEditable).toBool(); @@ -419,8 +424,8 @@ QVariant UBGraphicsTextItemDelegate::itemChange(QGraphicsItem::GraphicsItemChang QTextCursor c = delegated()->textCursor(); if (c.hasSelection()) { - c.clearSelection(); - delegated()->setTextCursor(c); + c.clearSelection(); + delegated()->setTextCursor(c); } } } diff --git a/src/domain/UBGraphicsTextItemDelegate.h b/src/domain/UBGraphicsTextItemDelegate.h index 26b3ba9b..2cf6f447 100644 --- a/src/domain/UBGraphicsTextItemDelegate.h +++ b/src/domain/UBGraphicsTextItemDelegate.h @@ -46,6 +46,7 @@ class UBGraphicsTextItemDelegate : public UBGraphicsItemDelegate public slots: void contentsChanged(); virtual void setEditable(bool); + virtual void remove(bool canUndo); protected: virtual void buildButtons(); diff --git a/src/domain/UBItem.cpp b/src/domain/UBItem.cpp index 9d999a94..10d3d6ce 100644 --- a/src/domain/UBItem.cpp +++ b/src/domain/UBItem.cpp @@ -17,6 +17,15 @@ #include "core/memcheck.h" +#include "domain/UBGraphicsPixmapItem.h" +#include "domain/UBGraphicsTextItem.h" +#include "domain/UBGraphicsSvgItem.h" +#include "domain/UBGraphicsMediaItem.h" +#include "domain/UBGraphicsStrokesGroup.h" +#include "domain/UBGraphicsGroupContainerItem.h" +#include "domain/UBGraphicsWidgetItem.h" +#include "tools/UBGraphicsCurtainItem.h" + UBItem::UBItem() : mUuid(QUuid()) , mRenderingQuality(UBItem::RenderingQualityNormal) @@ -44,3 +53,37 @@ bool UBGraphicsItem::isRotatable(QGraphicsItem *item) { return item->data(UBGraphicsItemData::ItemRotatable).toBool(); } + +UBGraphicsItemDelegate *UBGraphicsItem::Delegate(QGraphicsItem *pItem) +{ + UBGraphicsItemDelegate *result = 0; + + switch (static_cast(pItem->type())) { + case UBGraphicsPixmapItem::Type : + result = (static_cast(pItem))->Delegate(); + break; + case UBGraphicsTextItem::Type : + result = (static_cast(pItem))->Delegate(); + break; + case UBGraphicsSvgItem::Type : + result = (static_cast(pItem))->Delegate(); + break; + case UBGraphicsMediaItem::Type: + result = (static_cast(pItem))->Delegate(); + break; + case UBGraphicsStrokesGroup::Type : + result = (static_cast(pItem))->Delegate(); + break; + case UBGraphicsGroupContainerItem::Type : + result = (static_cast(pItem))->Delegate(); + break; + case UBGraphicsWidgetItem::Type : + result = (static_cast(pItem))->Delegate(); + break; + case UBGraphicsCurtainItem::Type : + result = (static_cast(pItem))->Delegate(); + break; + } + + return result; +} diff --git a/src/domain/UBItem.h b/src/domain/UBItem.h index 99c3e6a6..ca8a0f3b 100644 --- a/src/domain/UBItem.h +++ b/src/domain/UBItem.h @@ -108,6 +108,7 @@ public: static bool isRotatable(QGraphicsItem *item); static bool isFlippable(QGraphicsItem *item); + static UBGraphicsItemDelegate *Delegate(QGraphicsItem *pItem); virtual UBGraphicsItemDelegate *Delegate() const = 0; virtual void remove() = 0; diff --git a/src/gui/UBKeyboardPalette.cpp b/src/gui/UBKeyboardPalette.cpp index 3f1fe242..2a496526 100644 --- a/src/gui/UBKeyboardPalette.cpp +++ b/src/gui/UBKeyboardPalette.cpp @@ -60,7 +60,10 @@ UBKeyboardPalette::UBKeyboardPalette(QWidget *parent) createCtrlButtons(); nCurrentLocale = UBSettings::settings()->KeyboardLocale->get().toInt(); - setInput(locales[nCurrentLocale]); + if (nCurrentLocale < 0 || nCurrentLocale >= nLocalesCount) + nCurrentLocale = 0; + if (locales!=NULL) + setInput(locales[nCurrentLocale]); setContentsMargins( 22, 22, 22, 22 ); From 2519df805b2fa581318558e161a6d1e068e859bf Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Fri, 7 Sep 2012 11:26:12 +0200 Subject: [PATCH 02/10] fixed issue 880 --- src/domain/UBGraphicsScene.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index f244bae8..6137033d 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -1442,6 +1442,7 @@ UBGraphicsTextItem* UBGraphicsScene::textForObjectName(const QString& pString, c textItem->setObjectName(objectName); QSizeF size = textItem->size(); textItem->setPos(QPointF(-size.width()/2.0,-size.height()/2.0)); + textItem->setData(UBGraphicsItemData::ItemEditable,QVariant(false)); } textItem->setPlainText(pString); From 571109e386a5a2018274d2abe0dd9cfce9a68893 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Fri, 7 Sep 2012 13:19:48 +0200 Subject: [PATCH 03/10] fixed issue 1083 --- src/gui/UBTeacherGuideWidget.cpp | 6 ++++-- src/web/UBWebController.cpp | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/gui/UBTeacherGuideWidget.cpp b/src/gui/UBTeacherGuideWidget.cpp index 679da6a8..09031a0c 100644 --- a/src/gui/UBTeacherGuideWidget.cpp +++ b/src/gui/UBTeacherGuideWidget.cpp @@ -163,7 +163,8 @@ UBTeacherGuideEditionWidget::~UBTeacherGuideEditionWidget() void UBTeacherGuideEditionWidget::onSliderMoved(int size) { Q_UNUSED(size); - mpAddAMediaItem->setExpanded(true); + if(mpAddAMediaItem) + mpAddAMediaItem->setExpanded(true); } #endif void UBTeacherGuideEditionWidget::showEvent(QShowEvent* event) @@ -491,7 +492,8 @@ UBTeacherGuidePresentationWidget::~UBTeacherGuidePresentationWidget() void UBTeacherGuidePresentationWidget::onSliderMoved(int size) { Q_UNUSED(size); - mpMediaSwitchItem->setExpanded(true); + if(mpMediaSwitchItem) + mpMediaSwitchItem->setExpanded(true); } #endif diff --git a/src/web/UBWebController.cpp b/src/web/UBWebController.cpp index 9ad0861e..e9d55be2 100644 --- a/src/web/UBWebController.cpp +++ b/src/web/UBWebController.cpp @@ -733,8 +733,8 @@ bool UBWebController::isEduMedia(const QUrl& pUrl) void UBWebController::loadUrl(const QUrl& url) { - bool webBrowserAlreadyInstanciated = dynamic_cast(mStackedWidget->widget(WebBrowser)) != NULL; - UBApplication::applicationController->showInternet(); + bool webBrowserAlreadyInstanciated = dynamic_cast(mStackedWidget->widget(WebBrowser)) != NULL; + UBApplication::applicationController->showInternet(); if (UBSettings::settings()->webUseExternalBrowser->get().toBool()) { QDesktopServices::openUrl(url); From cd010590edd98ed6c2bcab950558a6df312d6897 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Fri, 7 Sep 2012 14:40:19 +0200 Subject: [PATCH 04/10] fixed issue 1115 --- src/board/UBBoardController.cpp | 6 +++--- src/core/UBPersistenceManager.cpp | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index e83414f7..3a6a2394 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -645,7 +645,7 @@ void UBBoardController::duplicateItem(UBItem *item) { mActiveScene->addItem(gitem); gitem->setPos(itemPos); - mLastCreatedItem = gitem; + mLastCreatedItem = gitem; gitem->setSelected(true); } return; @@ -1132,7 +1132,7 @@ UBItem *UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QStri QString destFile; bool b = UBPersistenceManager::persistenceManager()->addFileToDocument(selectedDocument(), - "", + sourceUrl.toString(), UBPersistenceManager::videoDirectory, uuid, destFile, @@ -1175,7 +1175,7 @@ UBItem *UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QStri QString destFile; bool b = UBPersistenceManager::persistenceManager()->addFileToDocument(selectedDocument(), - "", + sourceUrl.toString(), UBPersistenceManager::audioDirectory, uuid, destFile, diff --git a/src/core/UBPersistenceManager.cpp b/src/core/UBPersistenceManager.cpp index 2c025a7c..62c1aca0 100644 --- a/src/core/UBPersistenceManager.cpp +++ b/src/core/UBPersistenceManager.cpp @@ -913,6 +913,7 @@ bool UBPersistenceManager::addFileToDocument(UBDocumentProxy* pDocumentProxy, QString& destinationPath, QByteArray* data) { + QAssert(path.length()); QFileInfo fi(path); if (!pDocumentProxy || objectUuid.isNull()) @@ -920,6 +921,8 @@ bool UBPersistenceManager::addFileToDocument(UBDocumentProxy* pDocumentProxy, if (data == NULL && !fi.exists()) return false; + qDebug() << fi.suffix(); + QString fileName = subdir + "/" + objectUuid.toString() + "." + fi.suffix(); destinationPath = pDocumentProxy->persistencePath() + "/" + fileName; From 9d21875c079efd09c6fb2d6608cd26eca5a0f6d5 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Fri, 7 Sep 2012 14:41:34 +0200 Subject: [PATCH 05/10] fixed issue 1115 --- src/core/UBPersistenceManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/UBPersistenceManager.cpp b/src/core/UBPersistenceManager.cpp index 62c1aca0..44c534aa 100644 --- a/src/core/UBPersistenceManager.cpp +++ b/src/core/UBPersistenceManager.cpp @@ -913,7 +913,7 @@ bool UBPersistenceManager::addFileToDocument(UBDocumentProxy* pDocumentProxy, QString& destinationPath, QByteArray* data) { - QAssert(path.length()); + Q_ASSERT(path.length()); QFileInfo fi(path); if (!pDocumentProxy || objectUuid.isNull()) From e0c2fdc3e2ad26443a82b2459de6dd48b544ac34 Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Fri, 7 Sep 2012 15:42:42 +0300 Subject: [PATCH 06/10] Fixed some cases for resizing items. --- src/domain/UBGraphicsDelegateFrame.cpp | 143 +++++++++++++------------ src/domain/UBGraphicsItemDelegate.cpp | 3 +- 2 files changed, 79 insertions(+), 67 deletions(-) diff --git a/src/domain/UBGraphicsDelegateFrame.cpp b/src/domain/UBGraphicsDelegateFrame.cpp index de40ab43..5c6284be 100644 --- a/src/domain/UBGraphicsDelegateFrame.cpp +++ b/src/domain/UBGraphicsDelegateFrame.cpp @@ -291,13 +291,18 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) if (None == mCurrentTool) return; - QLineF move(mStartingPoint, event->scenePos()); + QLineF move; + if(rotating() || moving() || mOperationMode == Scaling) + move = QLineF(mStartingPoint, event->scenePos()); + else + move = QLineF(event->lastScenePos(), event->scenePos()); + qreal moveX = move.length() * cos((move.angle() - mAngle) * PI / 180); qreal moveY = -move.length() * sin((move.angle() - mAngle) * PI / 180); qreal width = delegated()->boundingRect().width() * mTotalScaleX; qreal height = delegated()->boundingRect().height() * mTotalScaleY; - if(mOperationMode == Scaling) + if(!rotating()) { mTranslateX = moveX; // Perform the resize @@ -398,44 +403,7 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) } } } - else if (mOperationMode == Resizing || mOperationMode == ResizingHorizontally) - { - mTranslateX = moveX; - UBResizableGraphicsItem* resizableItem = dynamic_cast(delegated()); - - if (resizableItem) - { - QLineF mousePosDelta(delegated()->mapFromScene(event->lastScenePos()) - , delegated()->mapFromScene(event->scenePos())); - QSizeF incVector(0, 0); - - if (resizingBottomRight()) - { - incVector = QSizeF(mousePosDelta.dx(), mousePosDelta.dy()); - } - else if (resizingRight()) - { - incVector = QSizeF(mousePosDelta.dx(), 0); - } - else if (resizingBottom()) - { - incVector = QSizeF(0, mousePosDelta.dy()); - } - else if (resizingLeft()) - { - incVector = QSizeF(- mousePosDelta.dx(), 0); - } - else if (resizingTop()) - { - incVector = QSizeF(0, - mousePosDelta.dy()); - } - - QSizeF newSize = resizableItem->size() + incVector; - - resizableItem->resize(newSize); - } - } - + if (rotating()) { mTranslateX = 0; @@ -483,49 +451,92 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) // we just detects coordinates of corner before and after scaling and then moves object at diff between them. if (resizingBottomRight() && mMirrorX) + { mTranslateX += mInitialTransform.map(delegated()->boundingRect().bottomRight()).x() - tr.map(delegated()->boundingRect().bottomRight()).x(); - else - mTranslateX += mInitialTransform.map(delegated()->boundingRect().topLeft()).x() - tr.map(delegated()->boundingRect().topLeft()).x(); - - if (resizingBottomRight() && mMirrorY) mTranslateY += mInitialTransform.map(delegated()->boundingRect().bottomRight()).y() - tr.map(delegated()->boundingRect().bottomRight()).y(); + } else + { + mTranslateX += mInitialTransform.map(delegated()->boundingRect().topLeft()).x() - tr.map(delegated()->boundingRect().topLeft()).x(); mTranslateY += mInitialTransform.map(delegated()->boundingRect().topLeft()).y() - tr.map(delegated()->boundingRect().topLeft()).y(); + } + } + else if (mOperationMode == Scaling && (resizingTop() || resizingLeft())) + { + QPointF bottomRight = tr.map(delegated()->boundingRect().bottomRight()); + QPointF fixedPoint = mInitialTransform.map(delegated()->boundingRect().bottomRight()); + mTranslateX += fixedPoint.x() - bottomRight.x(); + mTranslateY += fixedPoint.y() - bottomRight.y(); + } - // Update the transform + + if (mOperationMode == Scaling || moving() || rotating()) + { tr = buildTransform(); + delegated()->setTransform(tr); } - else if (resizingTop() || resizingLeft()) + else if (mOperationMode == Resizing) { - if (mOperationMode == Scaling) - { - QPointF bottomRight = tr.map(delegated()->boundingRect().bottomRight()); - QPointF fixedPoint = mInitialTransform.map(delegated()->boundingRect().bottomRight()); - mTranslateX += fixedPoint.x() - bottomRight.x(); - mTranslateY += fixedPoint.y() - bottomRight.y(); - } - else + QSizeF originalSize = delegated()->boundingRect().size(); + // QSizeF originalSize = delegated()->sceneBoundingRect().size(); // + + mScaleX = 1; + mScaleY = 1; + + tr = buildTransform().translate(moveX, moveY); + if (resizingRight() || resizingBottom() || resizingBottomRight() || resizingTop() || resizingLeft()) { - QLineF vector; - if (resizingLeft()) + + + qreal dPosX; + qreal dPosY; + + if (resizingTop() || resizingLeft()) + { + dPosX = mMirrorX ? moveX : -moveX; + dPosY = mMirrorY ? moveY : -moveY; + } + else if (resizingBottomRight()) { - QPointF topRight1 = mInitialTransform.map(QPointF(delegated()->boundingRect().width() - moveX, 0)); - QPointF topRight2 = mInitialTransform.map(QPointF(delegated()->boundingRect().width(), 0)); - vector.setPoints(topRight1, topRight2); + dPosX = moveX; + dPosY = moveY; } else { - QPointF bottomLeft1 = mInitialTransform.map(QPointF(0, delegated()->boundingRect().height() - moveY)); - QPointF bottomLeft2 = mInitialTransform.map(QPointF(0, delegated()->boundingRect().height())); - vector.setPoints(bottomLeft1, bottomLeft2); + dPosX = mMirrorX ? -moveX :moveX; + dPosY = mMirrorY ? -moveY : moveY; + } + + + QPointF oldPos; + if (mMirrorX) + oldPos = delegated()->sceneBoundingRect().topLeft(); + else + oldPos = delegated()->sceneBoundingRect().bottomRight(); + + delegated()->setTransform(tr); + + UBResizableGraphicsItem* resizableItem = dynamic_cast(delegated()); + if (resizableItem) + { + + resizableItem->resize(originalSize.width() + dPosX, originalSize.height() + dPosY); + if (resizingTop() || resizingLeft() || (mMirrorX && resizingBottomRight())) + { + QPointF newPos; + + if (mMirrorX) + newPos = delegated()->sceneBoundingRect().topLeft(); + else + newPos = delegated()->sceneBoundingRect().bottomRight(); + + delegated()->setPos(delegated()->pos()-newPos+oldPos); + + } } - mTranslateX = vector.dx(); - mTranslateY = vector.dy(); } - tr = buildTransform(); } - delegated()->setTransform(tr); event->accept(); } diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index d5620d12..9419774e 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -166,7 +166,8 @@ void UBGraphicsItemDelegate::init() UBGraphicsItemDelegate::~UBGraphicsItemDelegate() { - disconnect(UBApplication::boardController, SIGNAL(zoomChanged(qreal)), this, SLOT(onZoomChanged())); + if (UBApplication::boardController) + disconnect(UBApplication::boardController, SIGNAL(zoomChanged(qreal)), this, SLOT(onZoomChanged())); // do not release mMimeData. // the mMimeData is owned by QDrag since the setMimeData call as specified in the documentation } From f6693f4e854d52637388d1e89511afef184d9e6f Mon Sep 17 00:00:00 2001 From: Ilia Ryabokon Date: Fri, 7 Sep 2012 19:36:50 +0300 Subject: [PATCH 07/10] Undo-redo stack for eraising operations and Sankore 834 --- src/adaptors/UBSvgSubsetAdaptor.cpp | 2 +- src/domain/UBGraphicsGroupContainerItem.cpp | 6 +- src/domain/UBGraphicsGroupContainerItem.h | 2 +- src/domain/UBGraphicsItemGroupUndoCommand.cpp | 4 +- src/domain/UBGraphicsItemUndoCommand.cpp | 66 ++++++++++++++++++- src/domain/UBGraphicsItemUndoCommand.h | 4 +- src/domain/UBGraphicsScene.cpp | 15 +++-- src/domain/UBGraphicsScene.h | 2 +- src/domain/UBItem.cpp | 6 ++ src/domain/UBItem.h | 1 + 10 files changed, 93 insertions(+), 15 deletions(-) diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index f557ff8a..80f91e9d 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -1084,7 +1084,7 @@ QGraphicsItem *UBSvgSubsetAdaptor::UBSvgSubsetReader::readElementFromGroup() { QGraphicsItem *result = 0; - result = mScene->itemByUuid(QUuid(mXmlReader.attributes().value(aId).toString())); + result = mScene->itemForUuid(QUuid(mXmlReader.attributes().value(aId).toString())); mXmlReader.skipCurrentElement(); mXmlReader.readNext(); diff --git a/src/domain/UBGraphicsGroupContainerItem.cpp b/src/domain/UBGraphicsGroupContainerItem.cpp index 818eb88e..07b71ab3 100644 --- a/src/domain/UBGraphicsGroupContainerItem.cpp +++ b/src/domain/UBGraphicsGroupContainerItem.cpp @@ -125,6 +125,8 @@ void UBGraphicsGroupContainerItem::removeFromGroup(QGraphicsItem *item) pRemoveFromGroup(item); + item->setFlags(ItemIsSelectable | ItemIsFocusable); + } void UBGraphicsGroupContainerItem::deselectCurrentItem() @@ -219,7 +221,7 @@ void UBGraphicsGroupContainerItem::setUuid(const QUuid &pUuid) setData(UBGraphicsItemData::ItemUuid, QVariant(pUuid)); //store item uuid inside the QGraphicsItem to fast operations with Items on the scene } -void UBGraphicsGroupContainerItem::destroy() { +void UBGraphicsGroupContainerItem::destroy(bool canUndo) { foreach (QGraphicsItem *item, childItems()) { pRemoveFromGroup(item); @@ -227,7 +229,7 @@ void UBGraphicsGroupContainerItem::destroy() { item->setFlag(QGraphicsItem::ItemIsFocusable, true); } - remove(); + mDelegate->remove(canUndo); } void UBGraphicsGroupContainerItem::clearSource() diff --git a/src/domain/UBGraphicsGroupContainerItem.h b/src/domain/UBGraphicsGroupContainerItem.h index e8fa77eb..7207315d 100644 --- a/src/domain/UBGraphicsGroupContainerItem.h +++ b/src/domain/UBGraphicsGroupContainerItem.h @@ -37,7 +37,7 @@ public: } virtual void setUuid(const QUuid &pUuid); - void destroy(); + void destroy(bool canUndo = true); virtual void clearSource(); diff --git a/src/domain/UBGraphicsItemGroupUndoCommand.cpp b/src/domain/UBGraphicsItemGroupUndoCommand.cpp index 9b58dc1d..d087216f 100644 --- a/src/domain/UBGraphicsItemGroupUndoCommand.cpp +++ b/src/domain/UBGraphicsItemGroupUndoCommand.cpp @@ -22,7 +22,7 @@ UBGraphicsItemGroupUndoCommand::~UBGraphicsItemGroupUndoCommand() void UBGraphicsItemGroupUndoCommand::undo() { - mGroup->destroy(); + mGroup->destroy(false); foreach(QGraphicsItem *item, mItems) { item->setSelected(true); } @@ -41,7 +41,7 @@ void UBGraphicsItemGroupUndoCommand::redo() QList childItems = item->childItems(); UBGraphicsGroupContainerItem *currentGroup = dynamic_cast(item); if (currentGroup) { - currentGroup->destroy(); + currentGroup->destroy(false); } foreach (QGraphicsItem *chItem, childItems) { mGroup->addToGroup(chItem); diff --git a/src/domain/UBGraphicsItemUndoCommand.cpp b/src/domain/UBGraphicsItemUndoCommand.cpp index d9961fa0..64ea6091 100644 --- a/src/domain/UBGraphicsItemUndoCommand.cpp +++ b/src/domain/UBGraphicsItemUndoCommand.cpp @@ -27,10 +27,11 @@ #include "domain/UBGraphicsGroupContainerItem.h" UBGraphicsItemUndoCommand::UBGraphicsItemUndoCommand(UBGraphicsScene* pScene, const QSet& pRemovedItems, - const QSet& pAddedItems) + const QSet& pAddedItems, const QMultiMap &groupsMap) : mScene(pScene) - , mRemovedItems(pRemovedItems - pAddedItems) - , mAddedItems(pAddedItems - pRemovedItems) + , mRemovedItems(pRemovedItems - pAddedItems) + , mAddedItems(pAddedItems - pRemovedItems) + , mExcludedFromGroup(groupsMap) { mFirstRedo = true; @@ -110,6 +111,36 @@ void UBGraphicsItemUndoCommand::undo() } } + QMapIterator curMapElement(mExcludedFromGroup); + UBGraphicsGroupContainerItem *nextGroup = 0; + UBGraphicsGroupContainerItem *previousGroupItem; + bool groupChanged = false; + + while (curMapElement.hasNext()) { + curMapElement.next(); + + groupChanged = previousGroupItem != curMapElement.key(); + //trying to find the group on the scene; + if (!nextGroup || groupChanged) { + UBGraphicsGroupContainerItem *groupCandidate = curMapElement.key(); + if (groupCandidate) { + nextGroup = groupCandidate; + if(!mScene->items().contains(nextGroup)) { + mScene->addItem(nextGroup); + } + nextGroup->setVisible(true); + } + } + + QGraphicsItem *groupedItem = mScene->itemForUuid(curMapElement.value()); + if (groupedItem) { + nextGroup->addToGroup(groupedItem); + } + + previousGroupItem = curMapElement.key(); + UBGraphicsItem::Delegate(nextGroup)->update(); + } + // force refresh, QT is a bit lazy and take a lot of time (nb item ^2 ?) to trigger repaint mScene->update(mScene->sceneRect()); @@ -125,6 +156,35 @@ void UBGraphicsItemUndoCommand::redo() return; } + QMapIterator curMapElement(mExcludedFromGroup); + UBGraphicsGroupContainerItem *nextGroup = 0; + UBGraphicsGroupContainerItem *previousGroupItem; + bool groupChanged = false; + + while (curMapElement.hasNext()) { + curMapElement.next(); + + groupChanged = previousGroupItem != curMapElement.key(); + //trying to find the group on the scene; + if (!nextGroup || groupChanged) { + UBGraphicsGroupContainerItem *groupCandidate = curMapElement.key(); + if (groupCandidate) { + nextGroup = groupCandidate; + } + } + QGraphicsItem *groupedItem = mScene->itemForUuid(curMapElement.value()); + if (groupedItem) { + if (nextGroup->childItems().count() == 1) { + nextGroup->destroy(false); + break; + } + nextGroup->removeFromGroup(groupedItem); + } + + previousGroupItem = curMapElement.key(); + UBGraphicsItem::Delegate(nextGroup)->update(); + } + QSetIterator itRemoved(mRemovedItems); while (itRemoved.hasNext()) { diff --git a/src/domain/UBGraphicsItemUndoCommand.h b/src/domain/UBGraphicsItemUndoCommand.h index 78e7ec9a..be8fa9d4 100644 --- a/src/domain/UBGraphicsItemUndoCommand.h +++ b/src/domain/UBGraphicsItemUndoCommand.h @@ -18,6 +18,7 @@ #include #include "UBAbstractUndoCommand.h" +#include "UBGraphicsGroupContainerItem.h" class UBGraphicsScene; @@ -27,7 +28,7 @@ class UBGraphicsItemUndoCommand : public UBAbstractUndoCommand { public: UBGraphicsItemUndoCommand(UBGraphicsScene* pScene, const QSet& pRemovedItems, - const QSet& pAddedItems); + const QSet& pAddedItems, const QMultiMap &groupsMap = QMultiMap()); UBGraphicsItemUndoCommand(UBGraphicsScene* pScene, QGraphicsItem* pRemovedItem, QGraphicsItem* pAddedItem); @@ -47,6 +48,7 @@ class UBGraphicsItemUndoCommand : public UBAbstractUndoCommand UBGraphicsScene* mScene; QSet mRemovedItems; QSet mAddedItems; + QMultiMap mExcludedFromGroup; bool mFirstRedo; }; diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 0cdb2ae6..ecbcc424 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -1067,6 +1067,7 @@ UBItem* UBGraphicsScene::deepCopy() const void UBGraphicsScene::clearContent(clearCase pCase) { QSet removedItems; + QMultiMap groupsMap; switch (pCase) { case clearBackground : @@ -1106,8 +1107,13 @@ void UBGraphicsScene::clearContent(clearCase pCase) if(shouldDelete) { if (itemGroup) { itemGroup->removeFromGroup(item); + groupsMap.insert(itemGroup, UBGraphicsItem::getOwnUuid(item)); if (itemGroup->childItems().count() == 1) { - itemGroup->destroy(); + groupsMap.insert(itemGroup, UBGraphicsItem::getOwnUuid(itemGroup->childItems().first())); + QGraphicsItem *lastItem = itemGroup->childItems().first(); + bool isSelected = itemGroup->isSelected(); + itemGroup->destroy(false); + lastItem->setSelected(isSelected); } itemGroup->Delegate()->update(); } @@ -1123,7 +1129,7 @@ void UBGraphicsScene::clearContent(clearCase pCase) update(sceneRect()); if (enableUndoRedoStack) { //should be deleted after scene own undo stack implemented - UBGraphicsItemUndoCommand* uc = new UBGraphicsItemUndoCommand(this, removedItems, QSet()); + UBGraphicsItemUndoCommand* uc = new UBGraphicsItemUndoCommand(this, removedItems, QSet(), groupsMap); UBApplication::undoStack->push(uc); } @@ -1571,8 +1577,9 @@ void UBGraphicsScene::removeItem(QGraphicsItem* item) void UBGraphicsScene::removeItems(const QSet& items) { - foreach(QGraphicsItem* item, items) + foreach(QGraphicsItem* item, items) { UBCoreGraphicsScene::removeItem(item); + } mItemCount -= items.size(); @@ -1665,7 +1672,7 @@ QRectF UBGraphicsScene::normalizedSceneRect(qreal ratio) return normalizedRect; } -QGraphicsItem *UBGraphicsScene::itemByUuid(QUuid uuid) +QGraphicsItem *UBGraphicsScene::itemForUuid(QUuid uuid) { QGraphicsItem *result = 0; diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index 0dedb9c1..3722d8be 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -174,7 +174,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem QRectF normalizedSceneRect(qreal ratio = -1.0); - QGraphicsItem *itemByUuid(QUuid uuid); + QGraphicsItem *itemForUuid(QUuid uuid); void moveTo(const QPointF& pPoint); void drawLineTo(const QPointF& pEndPoint, const qreal& pWidth, bool bLineStyle); diff --git a/src/domain/UBItem.cpp b/src/domain/UBItem.cpp index 10d3d6ce..e7083338 100644 --- a/src/domain/UBItem.cpp +++ b/src/domain/UBItem.cpp @@ -54,6 +54,12 @@ bool UBGraphicsItem::isRotatable(QGraphicsItem *item) return item->data(UBGraphicsItemData::ItemRotatable).toBool(); } +QUuid UBGraphicsItem::getOwnUuid(QGraphicsItem *item) +{ + QString idCandidate = item->data(UBGraphicsItemData::ItemUuid).toString(); + return idCandidate == QUuid().toString() ? QUuid() : QUuid(idCandidate); +} + UBGraphicsItemDelegate *UBGraphicsItem::Delegate(QGraphicsItem *pItem) { UBGraphicsItemDelegate *result = 0; diff --git a/src/domain/UBItem.h b/src/domain/UBItem.h index ca8a0f3b..2fe22ae8 100644 --- a/src/domain/UBItem.h +++ b/src/domain/UBItem.h @@ -107,6 +107,7 @@ public: static void assignZValue(QGraphicsItem*, qreal value); static bool isRotatable(QGraphicsItem *item); static bool isFlippable(QGraphicsItem *item); + static QUuid getOwnUuid(QGraphicsItem *item); static UBGraphicsItemDelegate *Delegate(QGraphicsItem *pItem); virtual UBGraphicsItemDelegate *Delegate() const = 0; From 46b81abe15d84ed116544102998421be779e75d5 Mon Sep 17 00:00:00 2001 From: Ilia Ryabokon Date: Mon, 10 Sep 2012 11:41:34 +0300 Subject: [PATCH 08/10] typedef for QMultiMap specified --- src/domain/UBGraphicsItemUndoCommand.cpp | 2 +- src/domain/UBGraphicsItemUndoCommand.h | 6 ++++-- src/domain/UBGraphicsScene.cpp | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/domain/UBGraphicsItemUndoCommand.cpp b/src/domain/UBGraphicsItemUndoCommand.cpp index 64ea6091..c8637242 100644 --- a/src/domain/UBGraphicsItemUndoCommand.cpp +++ b/src/domain/UBGraphicsItemUndoCommand.cpp @@ -27,7 +27,7 @@ #include "domain/UBGraphicsGroupContainerItem.h" UBGraphicsItemUndoCommand::UBGraphicsItemUndoCommand(UBGraphicsScene* pScene, const QSet& pRemovedItems, - const QSet& pAddedItems, const QMultiMap &groupsMap) + const QSet& pAddedItems, const GroupDataTable &groupsMap) : mScene(pScene) , mRemovedItems(pRemovedItems - pAddedItems) , mAddedItems(pAddedItems - pRemovedItems) diff --git a/src/domain/UBGraphicsItemUndoCommand.h b/src/domain/UBGraphicsItemUndoCommand.h index be8fa9d4..fec45d4f 100644 --- a/src/domain/UBGraphicsItemUndoCommand.h +++ b/src/domain/UBGraphicsItemUndoCommand.h @@ -27,8 +27,10 @@ class UBGraphicsScene; class UBGraphicsItemUndoCommand : public UBAbstractUndoCommand { public: + typedef QMultiMap GroupDataTable; + UBGraphicsItemUndoCommand(UBGraphicsScene* pScene, const QSet& pRemovedItems, - const QSet& pAddedItems, const QMultiMap &groupsMap = QMultiMap()); + const QSet& pAddedItems, const GroupDataTable &groupsMap = GroupDataTable()); UBGraphicsItemUndoCommand(UBGraphicsScene* pScene, QGraphicsItem* pRemovedItem, QGraphicsItem* pAddedItem); @@ -48,7 +50,7 @@ class UBGraphicsItemUndoCommand : public UBAbstractUndoCommand UBGraphicsScene* mScene; QSet mRemovedItems; QSet mAddedItems; - QMultiMap mExcludedFromGroup; + GroupDataTable mExcludedFromGroup; bool mFirstRedo; }; diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 0e476dea..352d0f2a 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -1067,7 +1067,7 @@ UBItem* UBGraphicsScene::deepCopy() const void UBGraphicsScene::clearContent(clearCase pCase) { QSet removedItems; - QMultiMap groupsMap; + UBGraphicsItemUndoCommand::GroupDataTable groupsMap; switch (pCase) { case clearBackground : From e68336e1e30e16da026f7673a88ca905ca93e79f Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Mon, 10 Sep 2012 15:30:04 +0300 Subject: [PATCH 09/10] Resizing of items fixed for all resizers instead of bottom right resizer. --- src/domain/UBGraphicsDelegateFrame.cpp | 103 +++++++++++++++++-------- src/domain/UBGraphicsDelegateFrame.h | 1 + 2 files changed, 71 insertions(+), 33 deletions(-) diff --git a/src/domain/UBGraphicsDelegateFrame.cpp b/src/domain/UBGraphicsDelegateFrame.cpp index 5c6284be..8c8e5dcb 100644 --- a/src/domain/UBGraphicsDelegateFrame.cpp +++ b/src/domain/UBGraphicsDelegateFrame.cpp @@ -286,6 +286,52 @@ bool UBGraphicsDelegateFrame::canResizeBottomRight(qreal width, qreal height, qr return res; } +QPointF UBGraphicsDelegateFrame::getFixedPointFromPos() +{ + QPointF fixedPoint; + if (!moving() && !rotating()) + { + if (resizingTop()) + { + if (mMirrorX && mMirrorY) + { + if ((0 < mAngle) && (mAngle < 90)) + fixedPoint = delegated()->sceneBoundingRect().topLeft(); + else + fixedPoint = delegated()->sceneBoundingRect().topRight(); + } + else + { + if ((0 < mAngle) && (mAngle <= 90)) + fixedPoint = delegated()->sceneBoundingRect().bottomRight(); + else + fixedPoint = delegated()->sceneBoundingRect().bottomLeft(); + } + } + else if (resizingLeft()) + { + if (mMirrorX && mMirrorY) + { + if ((0 < mAngle) && (mAngle < 90)) + fixedPoint = delegated()->sceneBoundingRect().bottomLeft(); + else + fixedPoint = delegated()->sceneBoundingRect().topLeft(); + } + else + { + if ((0 < mAngle) && (mAngle <= 90)) + fixedPoint = delegated()->sceneBoundingRect().topRight(); + else + fixedPoint = delegated()->sceneBoundingRect().bottomRight(); + } + } + else if (resizingBottomRight()) + { + } + } + return fixedPoint; +} + void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { if (None == mCurrentTool) @@ -461,7 +507,7 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) mTranslateY += mInitialTransform.map(delegated()->boundingRect().topLeft()).y() - tr.map(delegated()->boundingRect().topLeft()).y(); } } - else if (mOperationMode == Scaling && (resizingTop() || resizingLeft())) + else if (resizingTop() || resizingLeft()) { QPointF bottomRight = tr.map(delegated()->boundingRect().bottomRight()); QPointF fixedPoint = mInitialTransform.map(delegated()->boundingRect().bottomRight()); @@ -478,61 +524,52 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) else if (mOperationMode == Resizing) { QSizeF originalSize = delegated()->boundingRect().size(); - // QSizeF originalSize = delegated()->sceneBoundingRect().size(); // mScaleX = 1; mScaleY = 1; - tr = buildTransform().translate(moveX, moveY); - if (resizingRight() || resizingBottom() || resizingBottomRight() || resizingTop() || resizingLeft()) + if (!moving() && !rotating()) { + qreal dPosX = 0; + qreal dPosY = 0; + QPointF fixedPoint = getFixedPointFromPos(); - qreal dPosX; - qreal dPosY; - - if (resizingTop() || resizingLeft()) + if (resizingTop()) { - dPosX = mMirrorX ? moveX : -moveX; - dPosY = mMirrorY ? moveY : -moveY; + if (mMirrorX && mMirrorY) + dPosY = moveY; + else + dPosY = -moveY; + } + else if (resizingLeft()) + { + if (mMirrorX && mMirrorY) + dPosX = moveX; + else + dPosX = -moveX; } else if (resizingBottomRight()) { dPosX = moveX; dPosY = moveY; } - else - { - dPosX = mMirrorX ? -moveX :moveX; + else if (resizingRight()) + dPosX = (mMirrorX) ? -moveX : moveX; + else if (resizingBottom()) dPosY = mMirrorY ? -moveY : moveY; - } - - - QPointF oldPos; - if (mMirrorX) - oldPos = delegated()->sceneBoundingRect().topLeft(); - else - oldPos = delegated()->sceneBoundingRect().bottomRight(); - - delegated()->setTransform(tr); UBResizableGraphicsItem* resizableItem = dynamic_cast(delegated()); if (resizableItem) { - resizableItem->resize(originalSize.width() + dPosX, originalSize.height() + dPosY); - if (resizingTop() || resizingLeft() || (mMirrorX && resizingBottomRight())) + if (resizingTop() || resizingLeft() || ((mMirrorX || mMirrorY) && resizingBottomRight())) { - QPointF newPos; - - if (mMirrorX) - newPos = delegated()->sceneBoundingRect().topLeft(); - else - newPos = delegated()->sceneBoundingRect().bottomRight(); - - delegated()->setPos(delegated()->pos()-newPos+oldPos); + QPointF newFixedPoint = getFixedPointFromPos();; + delegated()->setPos(delegated()->pos()-newFixedPoint+fixedPoint); } + } } } diff --git a/src/domain/UBGraphicsDelegateFrame.h b/src/domain/UBGraphicsDelegateFrame.h index 142766fe..34aacda3 100644 --- a/src/domain/UBGraphicsDelegateFrame.h +++ b/src/domain/UBGraphicsDelegateFrame.h @@ -37,6 +37,7 @@ class UBGraphicsDelegateFrame: public QGraphicsRectItem, public QObject QPainterPath shape() const; virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); + QPointF getFixedPointFromPos(); virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); From 304591d1d8a5ac7c87a85fb43137d2418eeb96f5 Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Mon, 10 Sep 2012 16:04:19 +0300 Subject: [PATCH 10/10] Resizing of items works fine in all cases. --- src/domain/UBGraphicsDelegateFrame.cpp | 97 +++++++++++++++----------- src/domain/UBGraphicsDelegateFrame.h | 2 + 2 files changed, 58 insertions(+), 41 deletions(-) diff --git a/src/domain/UBGraphicsDelegateFrame.cpp b/src/domain/UBGraphicsDelegateFrame.cpp index 8c8e5dcb..b41e0376 100644 --- a/src/domain/UBGraphicsDelegateFrame.cpp +++ b/src/domain/UBGraphicsDelegateFrame.cpp @@ -325,11 +325,53 @@ QPointF UBGraphicsDelegateFrame::getFixedPointFromPos() fixedPoint = delegated()->sceneBoundingRect().bottomRight(); } } - else if (resizingBottomRight()) + } + return fixedPoint; +} + + +QSizeF UBGraphicsDelegateFrame::getResizeVector(qreal moveX, qreal moveY) +{ + qreal dPosX = 0; + qreal dPosY = 0; + + if (resizingTop()) + { + if (mMirrorX && mMirrorY) + dPosY = moveY; + else + dPosY = -moveY; + } + else if (resizingLeft()) + { + if (mMirrorX && mMirrorY) + dPosX = moveX; + else + dPosX = -moveX; + } + + else if (resizingRight()) + dPosX = (mMirrorX) ? -moveX : moveX; + else if (resizingBottom()) + dPosY = mMirrorY ? -moveY : moveY; + + return QSizeF(dPosX, dPosY); +} + +void UBGraphicsDelegateFrame::resizeDelegate(qreal moveX, qreal moveY) +{ + QPointF fixedPoint = getFixedPointFromPos(); + UBResizableGraphicsItem* resizableItem = dynamic_cast(delegated()); + if (resizableItem) + { + QSizeF originalSize = delegated()->boundingRect().size(); + resizableItem->resize(originalSize + getResizeVector(moveX, moveY)); + + if (resizingTop() || resizingLeft() || ((mMirrorX || mMirrorY) && resizingBottomRight())) { + delegated()->setPos(delegated()->pos()-getFixedPointFromPos()+fixedPoint); } } - return fixedPoint; } void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) @@ -523,54 +565,27 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) } else if (mOperationMode == Resizing) { - QSizeF originalSize = delegated()->boundingRect().size(); - - mScaleX = 1; - mScaleY = 1; - if (!moving() && !rotating()) { - qreal dPosX = 0; - qreal dPosY = 0; - - QPointF fixedPoint = getFixedPointFromPos(); - - if (resizingTop()) - { - if (mMirrorX && mMirrorY) - dPosY = moveY; - else - dPosY = -moveY; - } - else if (resizingLeft()) + if (resizingBottomRight()) { if (mMirrorX && mMirrorY) - dPosX = moveX; + mCurrentTool = ResizeTop; else - dPosX = -moveX; - } - else if (resizingBottomRight()) - { - dPosX = moveX; - dPosY = moveY; - } - else if (resizingRight()) - dPosX = (mMirrorX) ? -moveX : moveX; - else if (resizingBottom()) - dPosY = mMirrorY ? -moveY : moveY; + mCurrentTool = ResizeBottom; - UBResizableGraphicsItem* resizableItem = dynamic_cast(delegated()); - if (resizableItem) - { - resizableItem->resize(originalSize.width() + dPosX, originalSize.height() + dPosY); - if (resizingTop() || resizingLeft() || ((mMirrorX || mMirrorY) && resizingBottomRight())) - { - QPointF newFixedPoint = getFixedPointFromPos();; + resizeDelegate(moveX, moveY); - delegated()->setPos(delegated()->pos()-newFixedPoint+fixedPoint); - } + if (mMirrorX && mMirrorY) + mCurrentTool = ResizeLeft; + else + mCurrentTool = ResizeRight; + resizeDelegate(moveX, moveY); + mCurrentTool = ResizeBottomRight; } + else + resizeDelegate(moveX, moveY); } } diff --git a/src/domain/UBGraphicsDelegateFrame.h b/src/domain/UBGraphicsDelegateFrame.h index 34aacda3..07166adf 100644 --- a/src/domain/UBGraphicsDelegateFrame.h +++ b/src/domain/UBGraphicsDelegateFrame.h @@ -38,6 +38,8 @@ class UBGraphicsDelegateFrame: public QGraphicsRectItem, public QObject virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); QPointF getFixedPointFromPos(); + QSizeF getResizeVector(qreal moveX, qreal moveY); + void resizeDelegate(qreal moveX, qreal moveY); virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);