From 71e8585b742a67ab2d1a8e24d9700b721e219583 Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Thu, 12 Apr 2012 17:09:19 +0300 Subject: [PATCH 1/2] SANKORE-429 Document explorer(navigator): Imported ubz files are always imported into "Untitled Documents" folder --- src/adaptors/UBImportDocument.cpp | 2 +- src/core/UBPersistenceManager.cpp | 14 ++++++++++++-- src/core/UBPersistenceManager.h | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/adaptors/UBImportDocument.cpp b/src/adaptors/UBImportDocument.cpp index 7d43feee..27ba6673 100644 --- a/src/adaptors/UBImportDocument.cpp +++ b/src/adaptors/UBImportDocument.cpp @@ -191,7 +191,7 @@ UBDocumentProxy* UBImportDocument::importFile(const QFile& pFile, const QString& return 0; } else{ - UBDocumentProxy* newDocument = UBPersistenceManager::persistenceManager()->createDocumentFromDir(documentRootFolder); + UBDocumentProxy* newDocument = UBPersistenceManager::persistenceManager()->createDocumentFromDir(documentRootFolder, pGroup); UBApplication::showMessage(tr("Import successful.")); return newDocument; } diff --git a/src/core/UBPersistenceManager.cpp b/src/core/UBPersistenceManager.cpp index 23b5e3c3..8d0e1952 100644 --- a/src/core/UBPersistenceManager.cpp +++ b/src/core/UBPersistenceManager.cpp @@ -254,13 +254,23 @@ UBDocumentProxy* UBPersistenceManager::createDocument(const QString& pGroupName, return doc; } - -UBDocumentProxy* UBPersistenceManager::createDocumentFromDir(const QString& pDocumentDirectory) +UBDocumentProxy* UBPersistenceManager::createDocumentFromDir(const QString& pDocumentDirectory, const QString& pGroupName, const QString& pName, bool withEmptyPage) { checkIfDocumentRepositoryExists(); UBDocumentProxy* doc = new UBDocumentProxy(pDocumentDirectory); // deleted in UBPersistenceManager::destructor + if (pGroupName.length() > 0) + { + doc->setMetaData(UBSettings::documentGroupName, pGroupName); + } + + if (pName.length() > 0) + { + doc->setMetaData(UBSettings::documentName, pName); + } + if (withEmptyPage) createDocumentSceneAt(doc, 0); + QMap metadatas = UBMetadataDcSubsetAdaptor::load(pDocumentDirectory); foreach(QString key, metadatas.keys()) diff --git a/src/core/UBPersistenceManager.h b/src/core/UBPersistenceManager.h index 7a7bdd87..b9c53579 100644 --- a/src/core/UBPersistenceManager.h +++ b/src/core/UBPersistenceManager.h @@ -46,7 +46,7 @@ class UBPersistenceManager : public QObject static void destroy(); virtual UBDocumentProxy* createDocument(const QString& pGroupName = "", const QString& pName = "", bool withEmptyPage = true); - virtual UBDocumentProxy* createDocumentFromDir(const QString& pDocumentDirectory); + virtual UBDocumentProxy* createDocumentFromDir(const QString& pDocumentDirectory, const QString& pGroupName = "", const QString& pName = "", bool withEmptyPage = false); virtual UBDocumentProxy* persistDocumentMetadata(UBDocumentProxy* pDocumentProxy); From 368a4dc5a63d082e139ec9b8ef10c3ce6c6ef893 Mon Sep 17 00:00:00 2001 From: shibakaneki Date: Thu, 12 Apr 2012 16:33:36 +0200 Subject: [PATCH 2/2] Fixed the rotation issue --- src/domain/UBGraphicsDelegateFrame.cpp | 58 ++++++++++++++++++++------ 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/src/domain/UBGraphicsDelegateFrame.cpp b/src/domain/UBGraphicsDelegateFrame.cpp index c0e22a16..d6df2c62 100644 --- a/src/domain/UBGraphicsDelegateFrame.cpp +++ b/src/domain/UBGraphicsDelegateFrame.cpp @@ -254,10 +254,10 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) qreal moveY = -move.length() * sin((move.angle() - mAngle) * PI / 180); qreal width = delegated()->boundingRect().width() * mTotalScaleX; qreal height = delegated()->boundingRect().height() * mTotalScaleY; - mTranslateX = moveX; if(mOperationMode == Scaling) { + mTranslateX = moveX; // Perform the resize if (resizingBottomRight()) { @@ -353,6 +353,7 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) } else if (mOperationMode == Resizing) { + mTranslateX = moveX; UBResizableGraphicsItem* resizableItem = dynamic_cast(delegated()); if (resizableItem) @@ -390,12 +391,14 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) if (rotating()) { + mTranslateX = 0; + mTranslateY = 0; + QLineF startLine(sceneBoundingRect().center(), event->lastScenePos()); - QLineF currentLine(sceneBoundingRect().center(), event->scenePos()); + QLineF currentLine(sceneBoundingRect().center(), event->scenePos()); mAngle += startLine.angleTo(currentLine); - if ((int)mAngle % 45 >= 45 - mAngleTolerance - || (int)mAngle % 45 <= mAngleTolerance) + if ((int)mAngle % 45 >= 45 - mAngleTolerance || (int)mAngle % 45 <= mAngleTolerance) { mAngle = qRound(mAngle / 45) * 45; mAngleOffset += startLine.angleTo(currentLine); @@ -405,8 +408,7 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) mAngleOffset = 0; } } - else if ((int)mAngle % 30 >= 30 - mAngleTolerance - || (int)mAngle % 30 <= mAngleTolerance) + else if ((int)mAngle % 30 >= 30 - mAngleTolerance || (int)mAngle % 30 <= mAngleTolerance) { mAngle = qRound(mAngle / 30) * 30; mAngleOffset += startLine.angleTo(currentLine); @@ -498,10 +500,16 @@ QTransform UBGraphicsDelegateFrame::buildTransform() { QTransform tr; QPointF center = delegated()->boundingRect().center(); + + // Translate tr.translate(mTotalTranslateX + mTranslateX, mTotalTranslateY + mTranslateY); + + // Set angle tr.translate(center.x() * mTotalScaleX * mScaleX, center.y() * mTotalScaleY * mScaleY); tr.rotate(-mAngle); tr.translate(-center.x() * mTotalScaleX * mScaleX, -center.y() * mTotalScaleY * mScaleY); + + // Scale tr.scale(mTotalScaleX * mScaleX, mTotalScaleY * mScaleY); return tr; } @@ -565,35 +573,53 @@ void UBGraphicsDelegateFrame::setVisible(bool visible) void UBGraphicsDelegateFrame::positionHandles() { + // TODO: Check why the height is modified if the user rotates the item more than 90° + QRectF itemRect = delegated()->boundingRect(); QTransform itemTransform = delegated()->sceneTransform(); QPointF topLeft = itemTransform.map(itemRect.topLeft()); QPointF topRight = itemTransform.map(itemRect.topRight()); QPointF bottomLeft = itemTransform.map(itemRect.bottomLeft()); + QPointF bottomRight = itemTransform.map(itemRect.bottomRight()); QPointF center = itemTransform.map(itemRect.center()); + int rotateHeight = QLineF(topLeft, bottomLeft).length(); // Handle the mirroring if(topLeft.x() > topRight.x()){ - QPointF tmp = topRight; + QPointF topTmp = topRight; + QPointF bottomTmp = bottomRight; topRight = topLeft; - topLeft = tmp; - bottomLeft.setX(topLeft.x()); + topLeft = topTmp; + bottomRight = bottomLeft; + bottomLeft = bottomTmp; + } + + if(bottomLeft.y() > topLeft.y()){ + QPointF leftTmp = bottomLeft; + QPointF rightTmp = bottomRight; + bottomLeft = topLeft; + topLeft = leftTmp; + bottomRight = topRight; + topRight = rightTmp; } QLineF topLine(topLeft, topRight); qreal angle = topLine.angle(); qreal width = topLine.length(); + QLineF leftLine(topLeft, bottomLeft); qreal height = leftLine.length(); + int h = rotating()?rotateHeight:height; + if (mVisible) { - setRect(center.x() - mFrameWidth - width / 2, center.y() - mFrameWidth - height / 2, - width + 2 * mFrameWidth, height + 2 * mFrameWidth); + qDebug() << center.y(); + setRect(center.x() - mFrameWidth - width / 2, center.y() - mFrameWidth - h / 2, width + 2 * mFrameWidth, h + 2 * mFrameWidth); } else { - setRect(center.x() - width / 2, center.y() - height / 2, width, height); + setRect(center.x() - width / 2, center.y() - h / 2, width, h); } resetTransform(); @@ -680,30 +706,38 @@ UBGraphicsDelegateFrame::FrameTool UBGraphicsDelegateFrame::toolFromPos(QPointF return ResizeBottomRight; else if (bottomResizeGripRect().contains(pos)){ if(mMirrorY){ + qDebug() << "Top"; return ResizeTop; }else{ + qDebug() << "Bottom"; return ResizeBottom; } } else if (leftResizeGripRect().contains(pos)){ if(mMirrorX){ + qDebug() << "Right"; return ResizeRight; }else{ + qDebug() << "Left"; return ResizeLeft; } return ResizeLeft; } else if (rightResizeGripRect().contains(pos)){ if(mMirrorX){ + qDebug() << "Left"; return ResizeLeft; }else{ + qDebug() << "Right"; return ResizeRight; } } else if (topResizeGripRect().contains(pos)){ if(mMirrorY){ + qDebug() << "Bottom"; return ResizeBottom; }else{ + qDebug() << "Top"; return ResizeTop; } }