From a5aa8996da95d44709b80226ce812e9e26b3a7f6 Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Thu, 5 Apr 2012 17:19:42 +0300 Subject: [PATCH] SANKORE-80 Objects rotation --- src/core/UBSettings.cpp | 3 +++ src/core/UBSettings.h | 5 +++-- src/domain/UBGraphicsDelegateFrame.cpp | 31 +++++++++++++++++++++++--- src/domain/UBGraphicsDelegateFrame.h | 7 +++++- src/domain/domain.pri | 6 +++-- 5 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/core/UBSettings.cpp b/src/core/UBSettings.cpp index afd08aa9..8e689a61 100644 --- a/src/core/UBSettings.cpp +++ b/src/core/UBSettings.cpp @@ -377,6 +377,8 @@ void UBSettings::init() KeyboardLocale = new UBSetting(this, "Board", "StartupKeyboardLocale", 0); swapControlAndDisplayScreens = new UBSetting(this, "App", "SwapControlAndDisplayScreens", false); + + angleTolerance = new UBSetting(this, "App", "AngleTolerance", 4); } @@ -1139,3 +1141,4 @@ QString UBSettings::replaceWildcard(QString& path) return result; } + diff --git a/src/core/UBSettings.h b/src/core/UBSettings.h index 4e8c9666..d9d4d80d 100644 --- a/src/core/UBSettings.h +++ b/src/core/UBSettings.h @@ -97,8 +97,7 @@ class UBSettings : public QObject void setCommunityPassword(const QString& password); void init(); - - + //user directories static QString userDataDirectory(); static QString userDocumentDirectory(); @@ -326,6 +325,8 @@ class UBSettings : public QObject UBSetting* KeyboardLocale; UBSetting* swapControlAndDisplayScreens; + UBSetting* angleTolerance; + public slots: void setPenWidthIndex(int index); diff --git a/src/domain/UBGraphicsDelegateFrame.cpp b/src/domain/UBGraphicsDelegateFrame.cpp index ea90a676..8968d498 100644 --- a/src/domain/UBGraphicsDelegateFrame.cpp +++ b/src/domain/UBGraphicsDelegateFrame.cpp @@ -29,8 +29,6 @@ #include "core/memcheck.h" -qreal const UBGraphicsDelegateFrame::mAngleTolerance = 6; - UBGraphicsDelegateFrame::UBGraphicsDelegateFrame(UBGraphicsItemDelegate* pDelegate, QRectF pRect, qreal pFrameWidth, bool respectRatio) : QGraphicsRectItem(), QObject(pDelegate) , mCurrentTool(None) @@ -51,6 +49,8 @@ UBGraphicsDelegateFrame::UBGraphicsDelegateFrame(UBGraphicsItemDelegate* pDelega , mMirrorX(false) , mMirrorY(false) { + mAngleTolerance = UBSettings::settings()->angleTolerance->get().toReal(); + setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); setAcceptedMouseButtons(Qt::LeftButton); @@ -90,11 +90,14 @@ UBGraphicsDelegateFrame::UBGraphicsDelegateFrame(UBGraphicsItemDelegate* pDelega positionHandles(); this->setAcceptHoverEvents(true); + + angleWidget = new UBAngleWidget(); } UBGraphicsDelegateFrame::~UBGraphicsDelegateFrame() { +delete angleWidget; // NOOP } @@ -372,7 +375,9 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) QLineF startLine(sceneBoundingRect().center(), event->lastScenePos()); 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); @@ -382,6 +387,23 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) mAngleOffset = 0; } } + else if ((int)mAngle % 30 >= 30 - mAngleTolerance + || (int)mAngle % 30 <= mAngleTolerance) + { + mAngle = qRound(mAngle / 30) * 30; + mAngleOffset += startLine.angleTo(currentLine); + if ((int)mAngleOffset % 360 > mAngleTolerance && (int)mAngleOffset % 360 < 360 - mAngleTolerance) + { + mAngle += mAngleOffset; + mAngleOffset = 0; + } + } + + if (!angleWidget->isVisible()) + angleWidget->show(); + + angleWidget->setText(QString::number((int)mAngle % 360)); + angleWidget->update(); } else if (moving()) @@ -451,6 +473,9 @@ QTransform UBGraphicsDelegateFrame::buildTransform() void UBGraphicsDelegateFrame::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { + if (angleWidget->isVisible()) + angleWidget->hide(); + updateResizeCursors(); mDelegate->commitUndoStep(); diff --git a/src/domain/UBGraphicsDelegateFrame.h b/src/domain/UBGraphicsDelegateFrame.h index 2cd1e0d1..11d451f1 100644 --- a/src/domain/UBGraphicsDelegateFrame.h +++ b/src/domain/UBGraphicsDelegateFrame.h @@ -18,6 +18,7 @@ #include #include "core/UB.h" +#include "domain/UBAngleWidget.h" class QGraphicsSceneMouseEvent; class UBGraphicsItemDelegate; @@ -91,7 +92,8 @@ class UBGraphicsDelegateFrame: public QGraphicsRectItem, public QObject qreal mTranslateY; qreal mTotalTranslateX; qreal mTotalTranslateY; - static const qreal mAngleTolerance; + qreal mAngleTolerance; + QRect mAngleRect; QPointF mStartingPoint; QTransform mInitialTransform; @@ -117,5 +119,8 @@ class UBGraphicsDelegateFrame: public QGraphicsRectItem, public QObject bool mResizing; bool mMirroredXAtStart; bool mMirroredYAtStart; + + UBAngleWidget *angleWidget; + }; #endif /* UBGRAPHICSDELEGATEFRAME_H_ */ diff --git a/src/domain/domain.pri b/src/domain/domain.pri index e3653576..a2d126ac 100644 --- a/src/domain/domain.pri +++ b/src/domain/domain.pri @@ -22,7 +22,8 @@ HEADERS += src/domain/UBGraphicsScene.h \ src/domain/UBGraphicsMediaItem.h \ src/domain/UBGraphicsAudioItem.h \ src/domain/UBGraphicsAudioItemDelegate.h \ - src/domain/UBAbstractUndoCommand.h + src/domain/UBAbstractUndoCommand.h\ + src/domain/UBAngleWidget.h HEADERS += src/domain/UBGraphicsItemDelegate.h \ src/domain/UBGraphicsVideoItemDelegate.h \ @@ -54,7 +55,8 @@ SOURCES += src/domain/UBGraphicsScene.cpp \ src/domain/UBGraphicsMediaItem.cpp \ src/domain/UBGraphicsAudioItem.cpp \ src/domain/UBGraphicsAudioItemDelegate.cpp \ - src/domain/UBAbstractUndoCommand.cpp + src/domain/UBAbstractUndoCommand.cpp \ + src/domain/UBAngleWidget.cpp SOURCES += src/domain/UBGraphicsItemDelegate.cpp \ src/domain/UBGraphicsVideoItemDelegate.cpp \