Backup of the mirroring implementation

preferencesAboutTextFull
shibakaneki 12 years ago
parent 29405d5375
commit 4d2990a905
  1. 70
      src/domain/UBGraphicsDelegateFrame.cpp
  2. 1
      src/domain/UBGraphicsDelegateFrame.h
  3. 2
      src/domain/UBGraphicsPixmapItem.cpp

@ -189,7 +189,7 @@ void UBGraphicsDelegateFrame::initializeTransform()
mAngle = topLine.angle(); mAngle = topLine.angle();
//the fact the the lenght is used we loose the horizontalFlip information // the fact the the length is used we loose the horizontalFlip information
// a better way to do this is using DeltaX that preserve the direction information. // a better way to do this is using DeltaX that preserve the direction information.
mTotalScaleX = (width / itemRect.width()) * horizontalFlip; mTotalScaleX = (width / itemRect.width()) * horizontalFlip;
mTotalScaleY = height / itemRect.height() * verticalFlip; mTotalScaleY = height / itemRect.height() * verticalFlip;
@ -227,6 +227,22 @@ void UBGraphicsDelegateFrame::mousePressEvent(QGraphicsSceneMouseEvent *event)
event->accept(); event->accept();
} }
bool UBGraphicsDelegateFrame::canResizeBottomRight(qreal width, qreal height, qreal scaleFactor)
{
bool res = false;
if(!mMirrorX && !mMirrorX && ((width * scaleFactor) > 2*mFrameWidth && (height * scaleFactor) > 2*mFrameWidth)){
res = true;
}else if(mMirrorX && !mMirrorY && (-width * scaleFactor) > 2*mFrameWidth && (height*scaleFactor) > 2*mFrameWidth){
res = true;
}else if(!mMirrorX && mMirrorY && (width * scaleFactor) > 2*mFrameWidth && (-height*scaleFactor) > 2*mFrameWidth){
res = true;
}else if(mMirrorX && mMirrorY && (-width * scaleFactor) > 2*mFrameWidth && (-height*scaleFactor) > 2*mFrameWidth){
res = true;
}
return res;
}
void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{ {
@ -237,27 +253,33 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
qreal height = delegated()->boundingRect().height() * mTotalScaleY; qreal height = delegated()->boundingRect().height() * mTotalScaleY;
mTranslateX = moveX; mTranslateX = moveX;
if(mOperationMode == Scaling) if(mOperationMode == Scaling)
{ {
// // Hide the buttons
// mDelegate->setButtonsVisible(false);
// mResizing = true;
// Perform the resize // Perform the resize
if (resizingBottomRight()) if (resizingBottomRight())
{ {
// ----------------------------------------------------- // -----------------------------------------------------
// ! We want to keep the aspect ratio with this resize ! // ! We want to keep the aspect ratio with this resize !
// ----------------------------------------------------- // -----------------------------------------------------
qreal scaleX = (width + moveX) / width; qreal scaleX;
qreal scaleY = (height + moveY) / height; qreal scaleY;
if(!mMirrorX){
scaleX = (width + moveX) / width;
}else{
scaleX = (width - moveX) / width;
}
if(!mMirrorY){
scaleY = (height + moveY) / height;
}else{
scaleY = (height - moveY) / height;
}
qreal scaleFactor = (scaleX + scaleY) / 2; qreal scaleFactor = (scaleX + scaleY) / 2;
// Do not allow resizing of image size under frame size // Do not allow resizing of image size under frame size
if (scaleFactor > 1 if (canResizeBottomRight(width, height, scaleFactor))
|| ((width * scaleFactor) > 2 * mFrameWidth
&& (height * scaleFactor) > 2 * mFrameWidth))
{ {
if (mRespectRatio) if (mRespectRatio)
{ {
@ -282,7 +304,6 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
if(mDelegate->isFlippable() && qAbs(scaleX) != 0){ if(mDelegate->isFlippable() && qAbs(scaleX) != 0){
if((qAbs(width * scaleX)) < 2*mFrameWidth){ if((qAbs(width * scaleX)) < 2*mFrameWidth){
bool negative = (scaleX < 0)?true:false; bool negative = (scaleX < 0)?true:false;
//mMirrorX = (negative?mMirrorX:!mMirrorX);
if(negative){ if(negative){
scaleX = -2*mFrameWidth/width; scaleX = -2*mFrameWidth/width;
}else{ }else{
@ -360,9 +381,6 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
QSizeF newSize = resizableItem->size() + incVector; QSizeF newSize = resizableItem->size() + incVector;
// if (newSize.width() < 50 /*0*/ || newSize.height() < /*0*/ 50)
// return;
resizableItem->resize(newSize); resizableItem->resize(newSize);
} }
} }
@ -395,10 +413,28 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
//TODO UB 4.x: Could find a better solution ? //TODO UB 4.x: Could find a better solution ?
if (resizingRight() || resizingBottom() || resizingBottomRight()) if (resizingRight() || resizingBottom() || resizingBottomRight())
{ {
QPointF topLeft = tr.map(delegated()->boundingRect().topLeft()); QPointF ref;
QPointF fixedPoint = mInitialTransform.map(delegated()->boundingRect().topLeft()); if(!mMirrorX && !mMirrorY){
ref = delegated()->boundingRect().topLeft();
}else if(mMirrorX && !mMirrorY){
ref = delegated()->boundingRect().topRight();
}else if(!mMirrorX && mMirrorY){
ref = delegated()->boundingRect().bottomLeft();
}else if(mMirrorX && mMirrorY){
ref = delegated()->boundingRect().bottomRight();
}
// 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);
// Update the translation coordinates
mTranslateX += fixedPoint.x() - topLeft.x(); mTranslateX += fixedPoint.x() - topLeft.x();
mTranslateY += fixedPoint.y() - topLeft.y(); mTranslateY += fixedPoint.y() - topLeft.y();
// Update the transform
tr = buildTransform(); tr = buildTransform();
} }
else if (resizingTop() || resizingLeft()) else if (resizingTop() || resizingLeft())

@ -64,6 +64,7 @@ class UBGraphicsDelegateFrame: public QGraphicsRectItem, public QObject
inline bool resizingTop () const { return mCurrentTool == ResizeTop; } inline bool resizingTop () const { return mCurrentTool == ResizeTop; }
inline bool rotating () const { return mCurrentTool == Rotate; } inline bool rotating () const { return mCurrentTool == Rotate; }
inline bool moving () const { return mCurrentTool == Move; } inline bool moving () const { return mCurrentTool == Move; }
bool canResizeBottomRight(qreal width, qreal height, qreal scaleFactor);
QTransform buildTransform (); QTransform buildTransform ();
void updateResizeCursors (); void updateResizeCursors ();

@ -32,7 +32,7 @@ UBGraphicsPixmapItem::UBGraphicsPixmapItem(QGraphicsItem* parent)
mDelegate->init(); mDelegate->init();
// NOTE: Do not remove this code, I'm just doing a backup of my changes! thx.. // NOTE: Do not remove this code, I'm just doing a backup of my changes! thx..
mDelegate->setFlippable(true); //mDelegate->setFlippable(true);
setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object);
setTransformationMode(Qt::SmoothTransformation); setTransformationMode(Qt::SmoothTransformation);

Loading…
Cancel
Save