Commit 535c731a authored by Ivan Ilin's avatar Ivan Ilin

Merge branch 'master' of github.com:Sankore/Sankore-3.1

parents cd7bfd39 b45c784e
...@@ -210,6 +210,9 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) ...@@ -210,6 +210,9 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{ {
if (resizingBottomRight()) if (resizingBottomRight())
{ {
// -----------------------------------------------------
// ! We want to keep the aspect ratio with this resize !
// -----------------------------------------------------
qreal scaleX = (width + moveX) / width; qreal scaleX = (width + moveX) / width;
qreal scaleY = (height + moveY) / height; qreal scaleY = (height + moveY) / height;
qreal scaleFactor = (scaleX + scaleY) / 2; qreal scaleFactor = (scaleX + scaleY) / 2;
...@@ -230,39 +233,56 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) ...@@ -230,39 +233,56 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
mScaleY = scaleY; mScaleY = scaleY;
} }
} }
} }else if (resizingLeft() || resizingRight())
else if (resizingLeft())
{
qreal scaleX = (width - moveX) / width;
if (scaleX > 1 || (width * scaleX) > 2 * mFrameWidth)
{ {
if(width != 0){
qreal scaleX = 0.0;
if(resizingLeft()){
scaleX = (width - moveX) / width;
}else if(resizingRight()){
scaleX = (width + moveX) / width;
}
if(mDelegate->isFlippable() && qAbs(scaleX) != 0){
if((width * qAbs(scaleX)) < 2*mFrameWidth){
bool negative = (scaleX < 0)?true:false;
if(negative){
scaleX = -2*mFrameWidth/width;
}else{
scaleX = 2*mFrameWidth/width;
}
}
mScaleX = scaleX; mScaleX = scaleX;
}else if (scaleX > 1 || (width * scaleX) > 2 * mFrameWidth){
mScaleX = scaleX;
if(resizingLeft()){
mTranslateX = moveX; mTranslateX = moveX;
} }
} }
else if (resizingRight())
{
qreal scaleX = (width + moveX) / width;
if (scaleX > 1 || (width * scaleX) > 2 * mFrameWidth)
{
mScaleX = scaleX;
} }
}else if(resizingTop() || resizingBottom()){
if(height != 0){
qreal scaleY = 0.0;
if(resizingTop()){
scaleY = (height - moveY) / height;
}else if(resizingBottom()){
scaleY = (height + moveY) / height;
} }
else if (resizingTop())
{ if(mDelegate->isFlippable() && qAbs(scaleY) != 0){
qreal scaleY = (height - moveY) / height; if((height * qAbs(scaleY)) < 2*mFrameWidth){
if (scaleY > 1 || (height * scaleY) > 2 * mFrameWidth) bool negative = (scaleY < 0)?true:false;
{ if(negative){
mScaleY = scaleY; scaleY = -2*mFrameWidth/width;
mTranslateY = moveY; }else{
scaleY = 2*mFrameWidth/width;
} }
} }
else if (resizingBottom()) mScaleY = scaleY;
{ }else if (scaleY > 1 || (height * scaleY) > 2 * mFrameWidth)
qreal scaleY = (height + moveY) / height;
if (scaleY > 1 || (height * scaleY) > 2 * mFrameWidth)
{ {
mScaleY = scaleY; mScaleY = scaleY;
mTranslateY = moveY;
}
} }
} }
} }
......
...@@ -64,6 +64,7 @@ UBGraphicsItemDelegate::UBGraphicsItemDelegate(QGraphicsItem* pDelegated, QObjec ...@@ -64,6 +64,7 @@ UBGraphicsItemDelegate::UBGraphicsItemDelegate(QGraphicsItem* pDelegated, QObjec
, mCanDuplicate(true) , mCanDuplicate(true)
, mRespectRatio(respectRatio) , mRespectRatio(respectRatio)
, mMimeData(NULL) , mMimeData(NULL)
, mFlippable(false)
{ {
// NOOP // NOOP
} }
...@@ -486,4 +487,12 @@ void UBGraphicsItemDelegate::showMenu() ...@@ -486,4 +487,12 @@ void UBGraphicsItemDelegate::showMenu()
mMenu->exec(cv->mapToGlobal(pinPos.bottomRight())); mMenu->exec(cv->mapToGlobal(pinPos.bottomRight()));
} }
void UBGraphicsItemDelegate::setFlippable(bool flippable)
{
mFlippable = flippable;
}
bool UBGraphicsItemDelegate::isFlippable()
{
return mFlippable;
}
...@@ -136,6 +136,9 @@ class UBGraphicsItemDelegate : public QObject ...@@ -136,6 +136,9 @@ class UBGraphicsItemDelegate : public QObject
QMimeData* mimeData(){ return mMimeData; } QMimeData* mimeData(){ return mMimeData; }
void setMimeData(QMimeData* mimeData); void setMimeData(QMimeData* mimeData);
void setFlippable(bool flippable);
bool isFlippable();
signals: signals:
void showOnDisplayChanged(bool shown); void showOnDisplayChanged(bool shown);
void lockChanged(bool locked); void lockChanged(bool locked);
...@@ -196,6 +199,9 @@ private: ...@@ -196,6 +199,9 @@ private:
bool mCanDuplicate; bool mCanDuplicate;
bool mRespectRatio; bool mRespectRatio;
QMimeData* mMimeData; QMimeData* mMimeData;
/** A boolean saying that this object can be flippable (mirror effect) */
bool mFlippable;
}; };
......
...@@ -30,6 +30,10 @@ UBGraphicsPixmapItem::UBGraphicsPixmapItem(QGraphicsItem* parent) ...@@ -30,6 +30,10 @@ UBGraphicsPixmapItem::UBGraphicsPixmapItem(QGraphicsItem* parent)
{ {
mDelegate = new UBGraphicsItemDelegate(this, 0, true, true); mDelegate = new UBGraphicsItemDelegate(this, 0, true, true);
mDelegate->init(); mDelegate->init();
// NOTE: Do not remove this code, I'm just doing a backup of my changes! thx..
//mDelegate->setFlippable(true);
setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object);
setTransformationMode(Qt::SmoothTransformation); setTransformationMode(Qt::SmoothTransformation);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment