Corrected stroke movement

- When clicking a stroke, they aren't moved immediately anymore; a
certain drag distance is necessary, which makes it easy (again) to
select a stroke with a stylus (which tends to move a little as it is
clicked, hence the problem).

- Removed duplicate code; the movement is now managed by
QGraphicsItemGroup::mouseMoveEvent. This prevents use of the transform()
method to get the stroke's transformation matrix; so sceneTransform() is
used instead when copying a strokes group.

- Also fixed an oversight in UBBoardView: Media items couldn't be moved
directly anymore.
preferencesAboutTextFull
Craig Watson 8 years ago
parent 6cc9394f0d
commit 2c5793b54e
  1. 1
      src/board/UBBoardView.cpp
  2. 106
      src/domain/UBGraphicsStrokesGroup.cpp
  3. 28
      src/domain/UBGraphicsStrokesGroup.h

@ -663,6 +663,7 @@ bool UBBoardView::itemShouldBeMoved(QGraphicsItem *item)
if (item->isSelected())
return false;
case UBGraphicsMediaItem::Type:
return true;
case UBGraphicsStrokesGroup::Type:
return false;
case UBGraphicsTextItem::Type:

@ -113,40 +113,23 @@ void UBGraphicsStrokesGroup::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
Delegate()->startUndoStep();
mStartingPoint = event->scenePos();
initializeTransform();
mTranslateX = 0;
mTranslateY = 0;
mAngleOffset = 0;
mInitialTransform = buildTransform();
QGraphicsItemGroup::mousePressEvent(event);
event->accept();
setSelected(false);
}
void UBGraphicsStrokesGroup::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
QLineF move = QLineF(mStartingPoint, event->scenePos());
mTranslateX = move.dx();
mTranslateY = move.dy();
//Delegate()->frame()->moveLinkedItems(move);
QGraphicsItemGroup::mouseMoveEvent(event);
setTransform(buildTransform());
event->accept();
setSelected(false);
}
void UBGraphicsStrokesGroup::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
Delegate()->commitUndoStep();
mTotalTranslateX += mTranslateX;
mTotalTranslateY += mTranslateY;
event->accept();
Delegate()->mouseReleaseEvent(event);
@ -183,7 +166,7 @@ UBItem* UBGraphicsStrokesGroup::deepCopy() const
}
}
const_cast<UBGraphicsStrokesGroup*>(this)->setTransform(groupTransform);
copy->setTransform(groupTransform);
copy->setTransform(sceneTransform());
return copy;
}
@ -240,80 +223,3 @@ QPainterPath UBGraphicsStrokesGroup::shape() const
return path;
}
void UBGraphicsStrokesGroup::initializeTransform()
{
QTransform itemTransform = sceneTransform();
QRectF itemRect = boundingRect();
QPointF topLeft = itemTransform.map(itemRect.topLeft());
QPointF topRight = itemTransform.map(itemRect.topRight());
QPointF bottomLeft = itemTransform.map(itemRect.bottomLeft());
qreal horizontalFlip = (topLeft.x() > topRight.x()) ? -1 : 1;
mMirrorX = horizontalFlip < 0 ;
if(horizontalFlip < 0){
// why this is because of the way of calculating the translations that checks which side is the most is the
// nearest instead of checking which one is the left side.
QPointF tmp = topLeft;
topLeft = topRight;
topRight = tmp;
// because of the calculation of the height is done by lenght and not deltaY
bottomLeft = itemTransform.map(itemRect.bottomRight());
}
qreal verticalFlip = (bottomLeft.y() < topLeft.y()) ? -1 : 1;
// not sure that is usefull
mMirrorY = verticalFlip < 0;
if(verticalFlip < 0 && !mMirrorX){
topLeft = itemTransform.map(itemRect.bottomLeft());
topRight = itemTransform.map(itemRect.bottomRight());
bottomLeft = itemTransform.map(itemRect.topLeft());
}
QLineF topLine(topLeft, topRight);
QLineF leftLine(topLeft, bottomLeft);
qreal width = topLine.length();
qreal height = leftLine.length();
mAngle = topLine.angle();
// 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.
mTotalScaleX = (width / itemRect.width()) * horizontalFlip;
mTotalScaleY = height / itemRect.height() * verticalFlip;
QTransform tr;
QPointF center = boundingRect().center();
tr.translate(center.x() * mTotalScaleX, center.y() * mTotalScaleY);
tr.rotate(-mAngle);
tr.translate(-center.x() * mTotalScaleX, -center.y() * mTotalScaleY);
tr.scale(mTotalScaleX, mTotalScaleY);
mTotalTranslateX = transform().dx() - tr.dx();
mTotalTranslateY = transform().dy() - tr.dy();
}
QTransform UBGraphicsStrokesGroup::buildTransform()
{
QTransform tr;
QPointF center = boundingRect().center();
// Translate
tr.translate(mTotalTranslateX + mTranslateX, mTotalTranslateY + mTranslateY);
// Set angle
tr.translate(center.x() * mTotalScaleX, center.y() * mTotalScaleY);
tr.rotate(-mAngle);
tr.translate(-center.x() * mTotalScaleX, -center.y() * mTotalScaleY);
// Scale
tr.scale(mTotalScaleX, mTotalScaleY );
return tr;
}

@ -66,34 +66,6 @@ protected:
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
private:
qreal mTranslateX;
qreal mTranslateY;
qreal mTotalTranslateX;
qreal mTotalTranslateY;
qreal mAngle;
qreal mAngleOffset;
qreal mTotalScaleX;
qreal mTotalScaleY;
qreal mScaleX;
qreal mScaleY;
bool mFlippedX;
bool mFlippedY;
bool mMirrorX;
bool mMirrorY;
bool mResizing;
bool mMirroredXAtStart;
bool mMirroredYAtStart;
QPointF mStartingPoint;
QTransform mInitialTransform;
QTransform buildTransform ();
void initializeTransform ();
};
#endif // UBGRAPHICSSTROKESGROUP_H

Loading…
Cancel
Save