From 37b0eafa61e67a6bb30fae0ca8e2fc094995e452 Mon Sep 17 00:00:00 2001 From: Ilia Ryabokon Date: Tue, 21 Aug 2012 15:23:49 +0300 Subject: [PATCH 01/12] Sankore-834 --- src/domain/UBAbstractUndoCommand.h | 3 +- src/domain/UBGraphicsItemGroupUndoCommand.cpp | 58 +++++++++++++++++++ src/domain/UBGraphicsItemGroupUndoCommand.h | 30 ++++++++++ .../UBGraphicsItemTransformUndoCommand.h | 2 +- src/domain/UBGraphicsItemUndoCommand.cpp | 9 +++ src/domain/UBGraphicsItemUndoCommand.h | 6 +- src/domain/UBGraphicsScene.cpp | 3 +- src/domain/domain.pri | 6 +- 8 files changed, 109 insertions(+), 8 deletions(-) create mode 100644 src/domain/UBGraphicsItemGroupUndoCommand.cpp create mode 100644 src/domain/UBGraphicsItemGroupUndoCommand.h diff --git a/src/domain/UBAbstractUndoCommand.h b/src/domain/UBAbstractUndoCommand.h index da451769..a0c3d187 100644 --- a/src/domain/UBAbstractUndoCommand.h +++ b/src/domain/UBAbstractUndoCommand.h @@ -32,7 +32,8 @@ class UBAbstractUndoCommand : public QUndoCommand undotype_GRAPHICITEMTRANSFORM = 2, undotype_GRAPHICITEM = 3, undotype_GRAPHICTEXTITEM = 4, - undotype_PAGESIZE = 5 + undotype_PAGESIZE = 5, + undotype_GRAPHICSGROUPITEM = 6 }; virtual UndoType getType() { return undotype_UNKNOWN; } diff --git a/src/domain/UBGraphicsItemGroupUndoCommand.cpp b/src/domain/UBGraphicsItemGroupUndoCommand.cpp new file mode 100644 index 00000000..9b58dc1d --- /dev/null +++ b/src/domain/UBGraphicsItemGroupUndoCommand.cpp @@ -0,0 +1,58 @@ +#include "UBGraphicsItemGroupUndoCommand.h" + +#include "UBGraphicsGroupContainerItem.h" +#include "UBGraphicsScene.h" +#include "core/memcheck.h" + + +UBGraphicsItemGroupUndoCommand::UBGraphicsItemGroupUndoCommand(UBGraphicsScene *pScene, UBGraphicsGroupContainerItem *pGroupCreated) : + mScene (pScene), mGroup(pGroupCreated), mFirstRedo(true) + +{ + if (pGroupCreated->childItems().count()) { + foreach (QGraphicsItem *item, pGroupCreated->childItems()) { + mItems << item; + } + } +} + +UBGraphicsItemGroupUndoCommand::~UBGraphicsItemGroupUndoCommand() +{ +} + +void UBGraphicsItemGroupUndoCommand::undo() +{ + mGroup->destroy(); + foreach(QGraphicsItem *item, mItems) { + item->setSelected(true); + } +} + +void UBGraphicsItemGroupUndoCommand::redo() +{ + if (mFirstRedo) { + //Work around. TODO determine why does Qt call the redo function on pushing to undo + mFirstRedo = false; + return; + } + + foreach (QGraphicsItem *item, mItems) { + if (item->type() == UBGraphicsGroupContainerItem::Type) { + QList childItems = item->childItems(); + UBGraphicsGroupContainerItem *currentGroup = dynamic_cast(item); + if (currentGroup) { + currentGroup->destroy(); + } + foreach (QGraphicsItem *chItem, childItems) { + mGroup->addToGroup(chItem); + } + } else { + mGroup->addToGroup(item); + } + } + + mScene->addItem(mGroup); + mGroup->setVisible(true); + mGroup->setFocus(); + mGroup->setSelected(true); +} diff --git a/src/domain/UBGraphicsItemGroupUndoCommand.h b/src/domain/UBGraphicsItemGroupUndoCommand.h new file mode 100644 index 00000000..bbc0a022 --- /dev/null +++ b/src/domain/UBGraphicsItemGroupUndoCommand.h @@ -0,0 +1,30 @@ +#ifndef UBGRAPHICSITEMGROUPUNDOCOMMAND_H +#define UBGRAPHICSITEMGROUPUNDOCOMMAND_H + +#include +#include "UBAbstractUndoCommand.h" + +class UBGraphicsScene; +class UBGraphicsGroupContainerItem; + +class UBGraphicsItemGroupUndoCommand : public UBAbstractUndoCommand +{ +public: + UBGraphicsItemGroupUndoCommand(UBGraphicsScene *pScene, UBGraphicsGroupContainerItem *pGroupCreated); + virtual ~UBGraphicsItemGroupUndoCommand(); + + virtual UndoType getType() { return undotype_GRAPHICSGROUPITEM; } + +protected: + virtual void undo(); + virtual void redo(); + +private: + UBGraphicsScene *mScene; + UBGraphicsGroupContainerItem *mGroup; + QList mItems; + + bool mFirstRedo; +}; + +#endif // UBGRAPHICSITEMGROUPUNDOCOMMAND_H diff --git a/src/domain/UBGraphicsItemTransformUndoCommand.h b/src/domain/UBGraphicsItemTransformUndoCommand.h index 0f6b405d..07d8e0c3 100644 --- a/src/domain/UBGraphicsItemTransformUndoCommand.h +++ b/src/domain/UBGraphicsItemTransformUndoCommand.h @@ -32,7 +32,7 @@ class UBGraphicsItemTransformUndoCommand : public UBAbstractUndoCommand const QSizeF& prevSize = QSizeF()); virtual ~UBGraphicsItemTransformUndoCommand(); - virtual UndoType getType() { return undotype_GRAPHICITEMTRANSFORM; }; + virtual UndoType getType() { return undotype_GRAPHICITEMTRANSFORM; } protected: virtual void undo(); diff --git a/src/domain/UBGraphicsItemUndoCommand.cpp b/src/domain/UBGraphicsItemUndoCommand.cpp index 8d4ebf52..d9961fa0 100644 --- a/src/domain/UBGraphicsItemUndoCommand.cpp +++ b/src/domain/UBGraphicsItemUndoCommand.cpp @@ -24,6 +24,7 @@ #include "board/UBBoardController.h" #include "core/memcheck.h" +#include "domain/UBGraphicsGroupContainerItem.h" UBGraphicsItemUndoCommand::UBGraphicsItemUndoCommand(UBGraphicsScene* pScene, const QSet& pRemovedItems, const QSet& pAddedItems) @@ -81,6 +82,14 @@ void UBGraphicsItemUndoCommand::undo() { QGraphicsItem* item = itAdded.next(); + //if removing group + if (item->type() == UBGraphicsGroupContainerItem::Type) { + UBGraphicsGroupContainerItem *curGroup = qgraphicsitem_cast(item); + if (curGroup) { + curGroup->destroy(); + } + } + UBApplication::boardController->freezeW3CWidget(item, true); item->setSelected(false); mScene->removeItem(item); diff --git a/src/domain/UBGraphicsItemUndoCommand.h b/src/domain/UBGraphicsItemUndoCommand.h index 113c421e..78e7ec9a 100644 --- a/src/domain/UBGraphicsItemUndoCommand.h +++ b/src/domain/UBGraphicsItemUndoCommand.h @@ -34,10 +34,10 @@ class UBGraphicsItemUndoCommand : public UBAbstractUndoCommand virtual ~UBGraphicsItemUndoCommand(); - QSet GetAddedList() { return mAddedItems; }; - QSet GetRemovedList() { return mRemovedItems; }; + QSet GetAddedList() { return mAddedItems; } + QSet GetRemovedList() { return mRemovedItems; } - virtual UndoType getType() { return undotype_GRAPHICITEM; }; + virtual UndoType getType() { return undotype_GRAPHICITEM; } protected: virtual void undo(); diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 19a7e851..6b573710 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -47,6 +47,7 @@ #include "board/UBBoardView.h" #include "UBGraphicsItemUndoCommand.h" +#include "UBGraphicsItemGroupUndoCommand.h" #include "UBGraphicsTextItemUndoCommand.h" #include "UBGraphicsProxyWidget.h" #include "UBGraphicsPixmapItem.h" @@ -1521,7 +1522,7 @@ UBGraphicsGroupContainerItem *UBGraphicsScene::createGroup(QListsetFocus(); if (enableUndoRedoStack) { //should be deleted after scene own undo stack implemented - UBGraphicsItemUndoCommand* uc = new UBGraphicsItemUndoCommand(this, 0, groupItem); + UBGraphicsItemGroupUndoCommand* uc = new UBGraphicsItemGroupUndoCommand(this, groupItem); UBApplication::undoStack->push(uc); } diff --git a/src/domain/domain.pri b/src/domain/domain.pri index d66c72ec..e8b46b4d 100644 --- a/src/domain/domain.pri +++ b/src/domain/domain.pri @@ -20,7 +20,8 @@ HEADERS += src/domain/UBGraphicsScene.h \ src/domain/UBAbstractUndoCommand.h\ src/domain/UBGraphicsGroupContainerItem.h \ src/domain/UBGraphicsGroupContainerItemDelegate.h \ - src/domain/UBGraphicsStrokesGroup.h + src/domain/UBGraphicsStrokesGroup.h \ + src/domain/UBGraphicsItemGroupUndoCommand.h HEADERS += src/domain/UBGraphicsItemDelegate.h \ src/domain/UBGraphicsTextItemDelegate.h \ @@ -51,7 +52,8 @@ SOURCES += src/domain/UBGraphicsScene.cpp \ src/domain/UBAbstractUndoCommand.cpp \ src/domain/ubgraphicsgroupcontaineritem.cpp \ src/domain/ubgraphicsgroupcontaineritemdelegate.cpp \ - src/domain/UBGraphicsStrokesGroup.cpp + src/domain/UBGraphicsStrokesGroup.cpp \ + src/domain/UBGraphicsItemGroupUndoCommand.cpp SOURCES += src/domain/UBGraphicsItemDelegate.cpp \ src/domain/UBGraphicsTextItemDelegate.cpp \ From 4e691d519728faf2d1de24a6f360ae5a479f0fd8 Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Tue, 21 Aug 2012 15:32:04 +0300 Subject: [PATCH 02/12] Enabled garbage cleaning. Selected items can be moved by any frame of any item. --- src/board/UBBoardController.cpp | 11 ++-- src/domain/UBGraphicsDelegateFrame.cpp | 69 ++++++++++++++++++++++++++ src/domain/UBGraphicsDelegateFrame.h | 6 +++ 3 files changed, 81 insertions(+), 5 deletions(-) diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index d5a383df..2410a74b 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -1466,12 +1466,13 @@ void UBBoardController::ClearUndoStack() while (itUniq.hasNext()) { QGraphicsItem* item = itUniq.next(); + UBGraphicsScene *scene = NULL; if (item->scene()) { - UBGraphicsScene *scene = dynamic_cast(item->scene()); - if(!scene) - { - mActiveScene->deleteItem(item); - } + scene = dynamic_cast(item->scene()); + } + if(!scene) + { + mActiveScene->deleteItem(item); } } diff --git a/src/domain/UBGraphicsDelegateFrame.cpp b/src/domain/UBGraphicsDelegateFrame.cpp index e2181020..f2e597c9 100644 --- a/src/domain/UBGraphicsDelegateFrame.cpp +++ b/src/domain/UBGraphicsDelegateFrame.cpp @@ -228,6 +228,9 @@ void UBGraphicsDelegateFrame::mousePressEvent(QGraphicsSceneMouseEvent *event) mCurrentTool = toolFromPos(event->pos()); setCursorFromAngle(QString("")); event->accept(); + + prepareFramesToMove(getLinkedFrames()); + } void UBGraphicsDelegateFrame::setCursorFromAngle(QString angle) @@ -469,6 +472,7 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { mTranslateX = move.dx(); mTranslateY = move.dy(); + moveLinkedItems(move); } QTransform tr = buildTransform(); @@ -534,6 +538,71 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) event->accept(); } +QList UBGraphicsDelegateFrame::getLinkedFrames() +{ + QList linkedFrames; + QList sItems = mDelegate->delegated()->scene()->selectedItems(); + if (sItems.count()) + { + sItems.removeAll(delegated()); + + foreach(QGraphicsItem *item, sItems) + { + UBGraphicsItem *gitem = dynamic_cast(item); + if (gitem) + linkedFrames << gitem->Delegate()->frame(); + } + } + return linkedFrames; +} + +void UBGraphicsDelegateFrame::prepareFramesToMove(QList framesToMove) +{ + mLinkedFrames = framesToMove; + foreach (UBGraphicsDelegateFrame *frame, mLinkedFrames) + { + frame->prepareLinkedFrameToMove(); + } +} + +void UBGraphicsDelegateFrame::prepareLinkedFrameToMove() +{ + mDelegate->startUndoStep(); + + mStartingPoint = QPointF(0,0); + + initializeTransform(); + + mScaleX = 1; + mScaleY = 1; + mTranslateX = 0; + mTranslateY = 0; + mAngleOffset = 0; + + mInitialTransform = buildTransform(); + + mCurrentTool = Move; +} + +void UBGraphicsDelegateFrame::moveLinkedItems(QLineF movingVector, bool bLinked) +{ + if (bLinked) + { + mCurrentTool = Move; + + mTranslateX = movingVector.dx(); + mTranslateY = movingVector.dy(); + + delegated()->setTransform(buildTransform(), false); + } + else + { + foreach(UBGraphicsDelegateFrame* frame, mLinkedFrames) + { + frame->moveLinkedItems(movingVector, true); + } + } +} QTransform UBGraphicsDelegateFrame::buildTransform() { diff --git a/src/domain/UBGraphicsDelegateFrame.h b/src/domain/UBGraphicsDelegateFrame.h index b08ae219..142766fe 100644 --- a/src/domain/UBGraphicsDelegateFrame.h +++ b/src/domain/UBGraphicsDelegateFrame.h @@ -48,6 +48,10 @@ class UBGraphicsDelegateFrame: public QGraphicsRectItem, public QObject enum OperationMode {Scaling, Resizing, ResizingHorizontally}; void setOperationMode(OperationMode pMode) {mOperationMode = pMode;} bool isResizing(){return mResizing;} + void moveLinkedItems(QLineF movingVector, bool bLinked = false); + void prepareFramesToMove(QList framesToMove); + void prepareLinkedFrameToMove(); + QList getLinkedFrames(); private: QRectF bottomRightResizeGripRect() const; @@ -120,5 +124,7 @@ class UBGraphicsDelegateFrame: public QGraphicsRectItem, public QObject bool mResizing; bool mMirroredXAtStart; bool mMirroredYAtStart; + + QList mLinkedFrames; }; #endif /* UBGRAPHICSDELEGATEFRAME_H_ */ From 7a4edf75d69191a74068ddb596681d5a048fdd29 Mon Sep 17 00:00:00 2001 From: Ilia Ryabokon Date: Tue, 21 Aug 2012 16:33:33 +0300 Subject: [PATCH 03/12] Features selfdrop resolved --- src/gui/UBFeaturesWidget.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/gui/UBFeaturesWidget.cpp b/src/gui/UBFeaturesWidget.cpp index 85a41cad..78b4725e 100644 --- a/src/gui/UBFeaturesWidget.cpp +++ b/src/gui/UBFeaturesWidget.cpp @@ -379,6 +379,12 @@ void UBFeaturesListView::dragMoveEvent( QDragMoveEvent *event ) event->ignore(); return; } + foreach (UBFeature curFeature, fMimeData->features()) { + if (curFeature == onFeature) { + event->ignore(); + return; + } + } } if ( event->mimeData()->hasUrls() || event->mimeData()->hasImage() ) { From 370e5b37d06dd98e7409313f8ee1ea44debf71ad Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Wed, 22 Aug 2012 10:07:04 +0300 Subject: [PATCH 04/12] Page 1 (not title) can be deleted. --- src/board/UBBoardController.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 2410a74b..34d94bf2 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -624,7 +624,7 @@ void UBBoardController::duplicateItem(UBItem *item) void UBBoardController::deleteScene(int nIndex) { - if (selectedDocument()->pageCount()>2) + if (selectedDocument()->pageCount()>=2) { QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); persistCurrentScene(); From a748e8a2990d9f7e95c3ce9c6061cfdc084374ae Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Wed, 22 Aug 2012 12:34:07 +0300 Subject: [PATCH 05/12] SANKORE-852 Draw lines and move --- src/board/UBBoardView.cpp | 12 +++++++++++- src/board/UBBoardView.h | 2 ++ src/domain/UBGraphicsStrokesGroup.cpp | 25 +++++++++++++++++++++++++ src/domain/UBGraphicsStrokesGroup.h | 3 +++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index 4786c9d0..26ea969d 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -596,7 +596,7 @@ void UBBoardView::handleItemMousePress(QMouseEvent *event) mLastPressedMousePos = mapToScene(event->pos()); - if (movingItem && QGraphicsSvgItem::Type != movingItem->type() + if (movingItem && !hasSelectedParents(movingItem) && QGraphicsSvgItem::Type != movingItem->type() && UBGraphicsDelegateFrame::Type != movingItem->type() && !mMultipleSelectionIsEnabled) { @@ -1405,3 +1405,13 @@ UBBoardView::setToolCursor (int tool) controlViewport->setCursor (UBResources::resources ()->penCursor); } } + + +bool UBBoardView::hasSelectedParents(QGraphicsItem * item) +{ + if (item->isSelected()) + return true; + if (item->parentItem()==NULL) + return false; + return hasSelectedParents(item->parentItem()); +} diff --git a/src/board/UBBoardView.h b/src/board/UBBoardView.h index 34cf7fc7..98907b11 100644 --- a/src/board/UBBoardView.h +++ b/src/board/UBBoardView.h @@ -148,6 +148,8 @@ class UBBoardView : public QGraphicsView bool mIsDragInProgress; bool mMultipleSelectionIsEnabled; + static bool hasSelectedParents(QGraphicsItem * item); + private slots: void settingChanged(QVariant newValue); diff --git a/src/domain/UBGraphicsStrokesGroup.cpp b/src/domain/UBGraphicsStrokesGroup.cpp index 4f1be91f..2f98bed3 100644 --- a/src/domain/UBGraphicsStrokesGroup.cpp +++ b/src/domain/UBGraphicsStrokesGroup.cpp @@ -112,6 +112,31 @@ void UBGraphicsStrokesGroup::paint(QPainter *painter, const QStyleOptionGraphics QVariant UBGraphicsStrokesGroup::itemChange(GraphicsItemChange change, const QVariant &value) { + if (change == QGraphicsItem::ItemSelectedChange) + { + int a = 13; + } + QVariant newValue = mDelegate->itemChange(change, value); return QGraphicsItemGroup::itemChange(change, newValue); } + + +QPainterPath UBGraphicsStrokesGroup::shape () const +{ + QPainterPath path; + + if (isSelected()) + { + path.addRect(boundingRect()); + } + else + { + foreach(QGraphicsItem* item, childItems()) + { + path.addPath(item->shape()); + } + } + + return path; +} diff --git a/src/domain/UBGraphicsStrokesGroup.h b/src/domain/UBGraphicsStrokesGroup.h index 8339e1c2..b2310773 100644 --- a/src/domain/UBGraphicsStrokesGroup.h +++ b/src/domain/UBGraphicsStrokesGroup.h @@ -25,6 +25,9 @@ public: virtual void setUuid(const QUuid &pUuid); protected: + + virtual QPainterPath shape () const; + virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); From 97c2f6f7cebc13a93206bfbe3a4810fe7dc7af49 Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Wed, 22 Aug 2012 13:49:30 +0300 Subject: [PATCH 06/12] Removed debug code --- src/domain/UBGraphicsStrokesGroup.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/domain/UBGraphicsStrokesGroup.cpp b/src/domain/UBGraphicsStrokesGroup.cpp index 2f98bed3..a5320924 100644 --- a/src/domain/UBGraphicsStrokesGroup.cpp +++ b/src/domain/UBGraphicsStrokesGroup.cpp @@ -112,11 +112,6 @@ void UBGraphicsStrokesGroup::paint(QPainter *painter, const QStyleOptionGraphics QVariant UBGraphicsStrokesGroup::itemChange(GraphicsItemChange change, const QVariant &value) { - if (change == QGraphicsItem::ItemSelectedChange) - { - int a = 13; - } - QVariant newValue = mDelegate->itemChange(change, value); return QGraphicsItemGroup::itemChange(change, newValue); } From c4f4343be868d63c1d2585934a4482352bf5e367 Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Wed, 22 Aug 2012 15:46:16 +0300 Subject: [PATCH 07/12] Fixed scaling of rotated and mirrored images. --- src/domain/UBGraphicsDelegateFrame.cpp | 27 +++++++++----------------- 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/src/domain/UBGraphicsDelegateFrame.cpp b/src/domain/UBGraphicsDelegateFrame.cpp index f2e597c9..a2da072a 100644 --- a/src/domain/UBGraphicsDelegateFrame.cpp +++ b/src/domain/UBGraphicsDelegateFrame.cpp @@ -477,29 +477,20 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) QTransform tr = buildTransform(); - //TODO UB 4.x: Could find a better solution ? if (resizingRight() || resizingBottom() || resizingBottomRight()) { QPointF ref; - if(!mMirrorX && !mMirrorY){ - ref = delegated()->boundingRect().topLeft(); - }else if(mMirrorX && !mMirrorY){ - ref = delegated()->boundingRect().topLeft(); - }else if(!mMirrorX && mMirrorY){ - ref = delegated()->boundingRect().topLeft(); - }else if(mMirrorX && mMirrorY){ - ref = delegated()->boundingRect().topRight(); - } - - // Map the item topleft point to the current mouse move transform - QPointF topLeft = tr.map(ref); - // Map the item topleft point to the mouse press transform - QPointF fixedPoint = mInitialTransform.map(ref); + // 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(); - // Update the translation coordinates - mTranslateX += fixedPoint.x() - topLeft.x(); - mTranslateY += fixedPoint.y() - topLeft.y(); + if (resizingBottomRight() && mMirrorY) + mTranslateY += mInitialTransform.map(delegated()->boundingRect().bottomRight()).y() - tr.map(delegated()->boundingRect().bottomRight()).y(); + else + mTranslateY += mInitialTransform.map(delegated()->boundingRect().topLeft()).y() - tr.map(delegated()->boundingRect().topLeft()).y(); // Update the transform tr = buildTransform(); From 474e71a031baabbfeee0109e8ca76420f96754f8 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Wed, 22 Aug 2012 15:24:56 +0200 Subject: [PATCH 08/12] fixed issue with licence. Is now stored as combo box index to avoid translations problems --- src/gui/UBTeacherGuideWidget.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/gui/UBTeacherGuideWidget.cpp b/src/gui/UBTeacherGuideWidget.cpp index 2bec3d15..5322919a 100644 --- a/src/gui/UBTeacherGuideWidget.cpp +++ b/src/gui/UBTeacherGuideWidget.cpp @@ -879,17 +879,21 @@ void UBTeacherGuidePageZeroWidget::fillComboBoxes() parametersFile.close(); QStringList licences; - licences << tr("Attribution CC BY") << tr("Attribution-NoDerivs CC BY-ND") + licences << tr("Attribution CC BY") + << tr("Attribution-NoDerivs CC BY-ND") << tr("Attribution-ShareAlike CC BY-SA") << tr("Attribution-NonCommercial CC BY-NC") << tr("Attribution-NonCommercial-NoDerivs CC BY-NC-ND") << tr("Attribution-NonCommercial-ShareAlike CC BY-NC-SA") - << tr("Public domain") << tr("Copyright"); + << tr("Public domain") + << tr("Copyright"); mpLicenceBox->addItems(licences); QStringList licenceIconList; licenceIconList << ":images/licenses/ccby.png" - << ":images/licenses/ccbynd.png" << ":images/licenses/ccbysa.png" - << ":images/licenses/ccbync.png" << ":images/licenses/ccbyncnd.png" + << ":images/licenses/ccbynd.png" + << ":images/licenses/ccbysa.png" + << ":images/licenses/ccbync.png" + << ":images/licenses/ccbyncnd.png" << ":images/licenses/ccbyncsa.png"; for (int i = 0; i < licenceIconList.count(); i += 1) mpLicenceBox->setItemData(i, licenceIconList.at(i)); @@ -945,7 +949,7 @@ void UBTeacherGuidePageZeroWidget::loadData() currentIndex = mpSchoolTypeBox->findText(documentProxy->metaData(UBSettings::sessionType).toString()); mpSchoolTypeBox->setCurrentIndex((currentIndex != -1) ? currentIndex : 0); - currentIndex = mpLicenceBox->findText(documentProxy->metaData(UBSettings::sessionLicence).toString()); + currentIndex = documentProxy->metaData(UBSettings::sessionLicence).toInt(); mpLicenceBox->setCurrentIndex((currentIndex != -1) ? currentIndex : 0); } @@ -962,7 +966,7 @@ void UBTeacherGuidePageZeroWidget::persistData() documentProxy->setMetaData(UBSettings::sessionGradeLevel, mpSchoolLevelBox->currentText()); documentProxy->setMetaData(UBSettings::sessionSubjects, mpSchoolSubjectsBox->currentText()); documentProxy->setMetaData(UBSettings::sessionType, mpSchoolTypeBox->currentText()); - documentProxy->setMetaData(UBSettings::sessionLicence, mpLicenceBox->currentText()); + documentProxy->setMetaData(UBSettings::sessionLicence, mpLicenceBox->currentIndex()); } } @@ -1087,7 +1091,7 @@ QVector UBTeacherGuidePageZeroWidget::getData() elementNode = new tUBGEElementNode(); elementNode->name = "licence"; - elementNode->attributes.insert("value", mpLicenceBox->currentText()); + elementNode->attributes.insert("value", QString("%1").arg(mpLicenceBox->currentIndex())); result << elementNode; return result; } From 68a1b88a79996a81aa27dab1560b12694aad0304 Mon Sep 17 00:00:00 2001 From: Ilia Ryabokon Date: Wed, 22 Aug 2012 17:31:45 +0300 Subject: [PATCH 09/12] Sankore-1027 fixed extended view behaviour --- src/board/UBBoardController.cpp | 2 +- src/board/UBBoardView.cpp | 13 +++++++++++-- src/board/UBBoardView.h | 5 +++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 34d94bf2..a1fbd435 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -158,7 +158,7 @@ void UBBoardController::setupViews() mControlLayout = new QHBoxLayout(mControlContainer); mControlLayout->setContentsMargins(0, 0, 0, 0); - mControlView = new UBBoardView(this, mControlContainer); + mControlView = new UBBoardView(this, mControlContainer, true); mControlView->setInteractive(true); mControlView->setMouseTracking(true); diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index 4786c9d0..0c9b6dbe 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -62,7 +62,7 @@ #include "core/memcheck.h" -UBBoardView::UBBoardView (UBBoardController* pController, QWidget* pParent) +UBBoardView::UBBoardView (UBBoardController* pController, QWidget* pParent, bool pIsControl) : QGraphicsView (pParent) , mController (pController) , mIsCreatingTextZone (false) @@ -72,6 +72,7 @@ UBBoardView::UBBoardView (UBBoardController* pController, QWidget* pParent) , mLongPressInterval(1000) , mIsDragInProgress(false) , mMultipleSelectionIsEnabled(false) +, isControl(pIsControl) { init (); @@ -81,13 +82,14 @@ UBBoardView::UBBoardView (UBBoardController* pController, QWidget* pParent) mLongPressTimer.setSingleShot(true); } -UBBoardView::UBBoardView (UBBoardController* pController, int pStartLayer, int pEndLayer, QWidget* pParent) +UBBoardView::UBBoardView (UBBoardController* pController, int pStartLayer, int pEndLayer, QWidget* pParent, bool pIscontrol) : QGraphicsView (pParent) , mController (pController) , suspendedMousePressEvent(NULL) , mLongPressInterval(1000) , mIsDragInProgress(false) , mMultipleSelectionIsEnabled(false) +, isControl(pIscontrol) { init (); @@ -124,6 +126,8 @@ void UBBoardView::init () setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff); setAcceptDrops (true); + setOptimizationFlag (QGraphicsView::IndirectPainting); // enable UBBoardView::drawItems filter + mTabletStylusIsPressed = false; mMouseButtonIsPressed = false; mPendingStylusReleaseEvent = false; @@ -729,6 +733,11 @@ void UBBoardView::longPressEvent() void UBBoardView::mousePressEvent (QMouseEvent *event) { + if (!isControl) { + event->ignore(); + return; + } + mIsDragInProgress = false; if (isAbsurdPoint (event->pos ())) diff --git a/src/board/UBBoardView.h b/src/board/UBBoardView.h index 34cf7fc7..bcbf4723 100644 --- a/src/board/UBBoardView.h +++ b/src/board/UBBoardView.h @@ -31,8 +31,8 @@ class UBBoardView : public QGraphicsView public: - UBBoardView(UBBoardController* pController, QWidget* pParent = 0); - UBBoardView(UBBoardController* pController, int pStartLayer, int pEndLayer, QWidget* pParent = 0); + UBBoardView(UBBoardController* pController, QWidget* pParent = 0, bool pIsControl = false); + UBBoardView(UBBoardController* pController, int pStartLayer, int pEndLayer, QWidget* pParent = 0, bool pIscontrol = false); virtual ~UBBoardView(); UBGraphicsScene* scene(); @@ -147,6 +147,7 @@ class UBBoardView : public QGraphicsView bool mIsDragInProgress; bool mMultipleSelectionIsEnabled; + bool isControl; private slots: From 56cbf532944dbd6b678409ed8730c18e5194fa2f Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Wed, 22 Aug 2012 17:37:46 +0300 Subject: [PATCH 10/12] Fixed behavior of mouse press events for strokes groups and found and fixed a bug - grouped w3c widgets was doesn't accepted mouse press events. --- src/board/UBBoardView.cpp | 47 ++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index 26ea969d..38674eaf 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -532,11 +532,11 @@ bool UBBoardView::itemShouldBeMoved(QGraphicsItem *item) if (movingItem->data(UBGraphicsItemData::ItemLocked).toBool()) return false; + if (movingItem->parentItem() && UBGraphicsGroupContainerItem::Type == movingItem->parentItem()->type() && !movingItem->isSelected() && movingItem->parentItem()->isSelected()) + return false; + UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController()->stylusTool(); - if (movingItem->parentItem() && !movingItem->isSelected() && movingItem->parentItem()->isSelected()) - return false; - switch(item->type()) { case UBGraphicsGroupContainerItem::Type: @@ -557,6 +557,7 @@ bool UBBoardView::itemShouldBeMoved(QGraphicsItem *item) case UBGraphicsTextItem::Type: return !item->isSelected(); } + return false; } @@ -566,24 +567,33 @@ QGraphicsItem* UBBoardView::determineItemToMove(QGraphicsItem *item) if(item) { UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController()->stylusTool(); + + //W3C widgets should take mouse move events from play tool. if ((UBStylusTool::Play == currentTool) && (UBGraphicsW3CWidgetItem::Type == item->type())) return item; + // if item is in group if(item->parentItem() && UBGraphicsGroupContainerItem::Type == item->parentItem()->type()) { + // play tool should move groups by any element if (UBStylusTool::Play == currentTool && item->parentItem()->isSelected()) return item->parentItem(); - + + // groups should should be moved instead of strokes groups + if (UBGraphicsStrokesGroup::Type == item->type()) + return item->parentItem(); + + // selected groups should be moved by moving any element if (item->parentItem()->isSelected()) return item; - - + if (item->isSelected()) return NULL; return item->parentItem(); } + // items like polygons placed in two groups nested, so we need to recursive call. if(item->parentItem() && UBGraphicsStrokesGroup::Type == item->parentItem()->type()) return determineItemToMove(item->parentItem()); } @@ -595,14 +605,21 @@ void UBBoardView::handleItemMousePress(QMouseEvent *event) { mLastPressedMousePos = mapToScene(event->pos()); - - if (movingItem && !hasSelectedParents(movingItem) && QGraphicsSvgItem::Type != movingItem->type() - && UBGraphicsDelegateFrame::Type != movingItem->type() + // Determining item who will take mouse press event + //all other items will be deselected and if all item will be deselected, then + // wrong item can catch mouse press. because selected items placed on the top + QGraphicsItem *pressedItem = determineItemToMove(movingItem); + + if (movingItem + && !(movingItem->parentItem() && UBGraphicsGroupContainerItem::Type == movingItem->parentItem()->type()) + && QGraphicsSvgItem::Type != movingItem->type() + && UBGraphicsDelegateFrame::Type != movingItem->type() + && UBGraphicsStrokesGroup::Type != movingItem->type() && !mMultipleSelectionIsEnabled) { foreach(QGraphicsItem *item, scene()->selectedItems()) { - if (item != movingItem) + if (item != pressedItem) { item->setSelected(false); } @@ -634,9 +651,10 @@ void UBBoardView::handleItemMousePress(QMouseEvent *event) void UBBoardView::handleItemMouseMove(QMouseEvent *event) { - if (movingItem) - movingItem = determineItemToMove(movingItem); + // determine item to move (maybee we need to move group of item or his parent. + movingItem = determineItemToMove(movingItem); + // items should be moved not every mouse move. if (movingItem && itemShouldBeMoved(movingItem) && (mMouseButtonIsPressed || mTabletStylusIsPressed)) { QPointF scenePos = mapToScene(event->pos()); @@ -662,6 +680,8 @@ void UBBoardView::handleItemMouseMove(QMouseEvent *event) mWidgetMoved = ((posAfterMove-posBeforeMove).manhattanLength() != 0); // a cludge for terminate moving of w3c widgets. + // in some cases w3c widgets catches mouse move and doesn't sends that events to web page, + // at simple - in google map widget - mouse move events doesn't comes to web page from rectangle of wearch bar on bottom right corner of widget. if (mWidgetMoved && UBGraphicsW3CWidgetItem::Type == movingItem->type()) movingItem->setPos(posBeforeMove); @@ -990,7 +1010,8 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event) if (QGraphicsSvgItem::Type != movingItem->type() && UBGraphicsDelegateFrame::Type != movingItem->type() && UBToolWidget::Type != movingItem->type() && - QGraphicsWidget::Type != movingItem->type()) + QGraphicsWidget::Type != movingItem->type() && + !(movingItem->parentItem() && UBGraphicsW3CWidgetItem::Type == movingItem->type() && UBGraphicsGroupContainerItem::Type == movingItem->parentItem()->type())) { bReleaseIsNeed = false; if (movingItem->isSelected() && mMultipleSelectionIsEnabled) From 3eb0bdda70e90eaa0005aeb758fc0064f803e646 Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Wed, 22 Aug 2012 17:58:34 +0300 Subject: [PATCH 11/12] Removed permanent multiple selection for strokes groups. --- src/board/UBBoardView.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index 36299048..4fcca179 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -618,7 +618,6 @@ void UBBoardView::handleItemMousePress(QMouseEvent *event) && !(movingItem->parentItem() && UBGraphicsGroupContainerItem::Type == movingItem->parentItem()->type()) && QGraphicsSvgItem::Type != movingItem->type() && UBGraphicsDelegateFrame::Type != movingItem->type() - && UBGraphicsStrokesGroup::Type != movingItem->type() && !mMultipleSelectionIsEnabled) { foreach(QGraphicsItem *item, scene()->selectedItems()) From fcb9845cb1e5120f3c1237acb13a1424c2887273 Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Wed, 22 Aug 2012 18:58:48 +0300 Subject: [PATCH 12/12] Fixed sankore crashes at deletion groups at deletion a scene. --- src/domain/UBGraphicsGroupContainerItem.cpp | 10 ++++++++++ src/domain/UBGraphicsGroupContainerItem.h | 1 + 2 files changed, 11 insertions(+) diff --git a/src/domain/UBGraphicsGroupContainerItem.cpp b/src/domain/UBGraphicsGroupContainerItem.cpp index 75e57711..bed3b219 100644 --- a/src/domain/UBGraphicsGroupContainerItem.cpp +++ b/src/domain/UBGraphicsGroupContainerItem.cpp @@ -32,6 +32,16 @@ UBGraphicsGroupContainerItem::UBGraphicsGroupContainerItem(QGraphicsItem *parent } +UBGraphicsGroupContainerItem::~UBGraphicsGroupContainerItem() +{ + foreach (QGraphicsItem *item, childItems()) + { + removeFromGroup(item); + if (item && item->scene()) + item->scene()->removeItem(item); + } +} + void UBGraphicsGroupContainerItem::addToGroup(QGraphicsItem *item) { if (!item) { diff --git a/src/domain/UBGraphicsGroupContainerItem.h b/src/domain/UBGraphicsGroupContainerItem.h index 1eca384a..535627eb 100644 --- a/src/domain/UBGraphicsGroupContainerItem.h +++ b/src/domain/UBGraphicsGroupContainerItem.h @@ -10,6 +10,7 @@ class UBGraphicsGroupContainerItem : public QGraphicsItem, public UBItem, public public: UBGraphicsGroupContainerItem (QGraphicsItem *parent = 0); + virtual ~UBGraphicsGroupContainerItem(); void addToGroup(QGraphicsItem *item); void removeFromGroup(QGraphicsItem *item);