Objects rotation
preferencesAboutTextFull
Anatoly Mihalchenko 13 years ago
parent ab1b28e0b8
commit a5aa8996da
  1. 3
      src/core/UBSettings.cpp
  2. 5
      src/core/UBSettings.h
  3. 31
      src/domain/UBGraphicsDelegateFrame.cpp
  4. 7
      src/domain/UBGraphicsDelegateFrame.h
  5. 6
      src/domain/domain.pri

@ -377,6 +377,8 @@ void UBSettings::init()
KeyboardLocale = new UBSetting(this, "Board", "StartupKeyboardLocale", 0); KeyboardLocale = new UBSetting(this, "Board", "StartupKeyboardLocale", 0);
swapControlAndDisplayScreens = new UBSetting(this, "App", "SwapControlAndDisplayScreens", false); 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; return result;
} }

@ -97,8 +97,7 @@ class UBSettings : public QObject
void setCommunityPassword(const QString& password); void setCommunityPassword(const QString& password);
void init(); void init();
//user directories //user directories
static QString userDataDirectory(); static QString userDataDirectory();
static QString userDocumentDirectory(); static QString userDocumentDirectory();
@ -326,6 +325,8 @@ class UBSettings : public QObject
UBSetting* KeyboardLocale; UBSetting* KeyboardLocale;
UBSetting* swapControlAndDisplayScreens; UBSetting* swapControlAndDisplayScreens;
UBSetting* angleTolerance;
public slots: public slots:
void setPenWidthIndex(int index); void setPenWidthIndex(int index);

@ -29,8 +29,6 @@
#include "core/memcheck.h" #include "core/memcheck.h"
qreal const UBGraphicsDelegateFrame::mAngleTolerance = 6;
UBGraphicsDelegateFrame::UBGraphicsDelegateFrame(UBGraphicsItemDelegate* pDelegate, QRectF pRect, qreal pFrameWidth, bool respectRatio) UBGraphicsDelegateFrame::UBGraphicsDelegateFrame(UBGraphicsItemDelegate* pDelegate, QRectF pRect, qreal pFrameWidth, bool respectRatio)
: QGraphicsRectItem(), QObject(pDelegate) : QGraphicsRectItem(), QObject(pDelegate)
, mCurrentTool(None) , mCurrentTool(None)
@ -51,6 +49,8 @@ UBGraphicsDelegateFrame::UBGraphicsDelegateFrame(UBGraphicsItemDelegate* pDelega
, mMirrorX(false) , mMirrorX(false)
, mMirrorY(false) , mMirrorY(false)
{ {
mAngleTolerance = UBSettings::settings()->angleTolerance->get().toReal();
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
setAcceptedMouseButtons(Qt::LeftButton); setAcceptedMouseButtons(Qt::LeftButton);
@ -90,11 +90,14 @@ UBGraphicsDelegateFrame::UBGraphicsDelegateFrame(UBGraphicsItemDelegate* pDelega
positionHandles(); positionHandles();
this->setAcceptHoverEvents(true); this->setAcceptHoverEvents(true);
angleWidget = new UBAngleWidget();
} }
UBGraphicsDelegateFrame::~UBGraphicsDelegateFrame() UBGraphicsDelegateFrame::~UBGraphicsDelegateFrame()
{ {
delete angleWidget;
// NOOP // NOOP
} }
@ -372,7 +375,9 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
QLineF startLine(sceneBoundingRect().center(), event->lastScenePos()); QLineF startLine(sceneBoundingRect().center(), event->lastScenePos());
QLineF currentLine(sceneBoundingRect().center(), event->scenePos()); QLineF currentLine(sceneBoundingRect().center(), event->scenePos());
mAngle += startLine.angleTo(currentLine); 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; mAngle = qRound(mAngle / 45) * 45;
mAngleOffset += startLine.angleTo(currentLine); mAngleOffset += startLine.angleTo(currentLine);
@ -382,6 +387,23 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
mAngleOffset = 0; 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()) else if (moving())
@ -451,6 +473,9 @@ QTransform UBGraphicsDelegateFrame::buildTransform()
void UBGraphicsDelegateFrame::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void UBGraphicsDelegateFrame::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{ {
if (angleWidget->isVisible())
angleWidget->hide();
updateResizeCursors(); updateResizeCursors();
mDelegate->commitUndoStep(); mDelegate->commitUndoStep();

@ -18,6 +18,7 @@
#include <QtGui> #include <QtGui>
#include "core/UB.h" #include "core/UB.h"
#include "domain/UBAngleWidget.h"
class QGraphicsSceneMouseEvent; class QGraphicsSceneMouseEvent;
class UBGraphicsItemDelegate; class UBGraphicsItemDelegate;
@ -91,7 +92,8 @@ class UBGraphicsDelegateFrame: public QGraphicsRectItem, public QObject
qreal mTranslateY; qreal mTranslateY;
qreal mTotalTranslateX; qreal mTotalTranslateX;
qreal mTotalTranslateY; qreal mTotalTranslateY;
static const qreal mAngleTolerance; qreal mAngleTolerance;
QRect mAngleRect;
QPointF mStartingPoint; QPointF mStartingPoint;
QTransform mInitialTransform; QTransform mInitialTransform;
@ -117,5 +119,8 @@ class UBGraphicsDelegateFrame: public QGraphicsRectItem, public QObject
bool mResizing; bool mResizing;
bool mMirroredXAtStart; bool mMirroredXAtStart;
bool mMirroredYAtStart; bool mMirroredYAtStart;
UBAngleWidget *angleWidget;
}; };
#endif /* UBGRAPHICSDELEGATEFRAME_H_ */ #endif /* UBGRAPHICSDELEGATEFRAME_H_ */

@ -22,7 +22,8 @@ HEADERS += src/domain/UBGraphicsScene.h \
src/domain/UBGraphicsMediaItem.h \ src/domain/UBGraphicsMediaItem.h \
src/domain/UBGraphicsAudioItem.h \ src/domain/UBGraphicsAudioItem.h \
src/domain/UBGraphicsAudioItemDelegate.h \ src/domain/UBGraphicsAudioItemDelegate.h \
src/domain/UBAbstractUndoCommand.h src/domain/UBAbstractUndoCommand.h\
src/domain/UBAngleWidget.h
HEADERS += src/domain/UBGraphicsItemDelegate.h \ HEADERS += src/domain/UBGraphicsItemDelegate.h \
src/domain/UBGraphicsVideoItemDelegate.h \ src/domain/UBGraphicsVideoItemDelegate.h \
@ -54,7 +55,8 @@ SOURCES += src/domain/UBGraphicsScene.cpp \
src/domain/UBGraphicsMediaItem.cpp \ src/domain/UBGraphicsMediaItem.cpp \
src/domain/UBGraphicsAudioItem.cpp \ src/domain/UBGraphicsAudioItem.cpp \
src/domain/UBGraphicsAudioItemDelegate.cpp \ src/domain/UBGraphicsAudioItemDelegate.cpp \
src/domain/UBAbstractUndoCommand.cpp src/domain/UBAbstractUndoCommand.cpp \
src/domain/UBAngleWidget.cpp
SOURCES += src/domain/UBGraphicsItemDelegate.cpp \ SOURCES += src/domain/UBGraphicsItemDelegate.cpp \
src/domain/UBGraphicsVideoItemDelegate.cpp \ src/domain/UBGraphicsVideoItemDelegate.cpp \

Loading…
Cancel
Save