Added startUserTransformation() and handleUserTransformation() methods to the CustomElementPart class and all of its subclasses.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2026 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
xavier
2013-02-08 22:05:12 +00:00
parent c2b69dd6da
commit 73fa01c7b9
20 changed files with 269 additions and 0 deletions

View File

@@ -43,3 +43,33 @@ ElementScene *CustomElementPart::elementScene() const {
QUndoStack &CustomElementPart::undoStack() const {
return(elementScene() -> undoStack());
}
/**
Helper method to map points in CustomElementPart::handleUserTransformation()
@param initial_selection_rect Selection rectangle when the movement started, in scene coordinates
@param new_selection_rect New selection rectangle, in scene coordinates
@param points List of points when the movement started, in scene coordinates.
@return The list of points mapped from initial_selection_rect to new_selection_rect
*/
QList<QPointF> CustomElementPart::mapPoints(const QRectF &initial_selection_rect, const QRectF &new_selection_rect, const QList<QPointF> &points) {
QList<QPointF> new_points;
if (!points.count()) return(new_points);
// compare the new selection rectangle with the stored one to get the scaling ratio
qreal sx = new_selection_rect.width() / initial_selection_rect.width();
qreal sy = new_selection_rect.height() / initial_selection_rect.height();
QPointF initial_top_left = initial_selection_rect.topLeft();
qreal new_top_left_x = new_selection_rect.x();
qreal new_top_left_y = new_selection_rect.y();
foreach (QPointF point, points) {
QPointF point_offset = point - initial_top_left;
new_points << QPointF(
new_top_left_x + (point_offset.rx() * sx),
new_top_left_y + (point_offset.y() * sy)
);
}
return(new_points);
}