Hi.
When we read a point from a QGraphicsItem, it refers to the (0,0) coordinate system of the same item.
How can i map that point , so it refers to an other (x,y) point{not (0,0)} of the same item????
In general:
How can i obtain a generic rappresentation on the mouse moving in degree, that is valid both for the case in which the item has the (0,0) local coordinate in its centre or in other parts(like the topleft corner)?? thanks
I found this code that is valid if and only if the item has the (0,0) local coordinate in its centre.
qreal rectItem
::angleForPos(const QPointF &pos
){ qreal angle = acos(pos.x() / distanceToPoint(pos));
if (pos.y() > 0)
angle = -angle;//pi * 2.0 - angle;
return angle;
}
qreal rectItem
::distanceToPoint(const QPointF &pos
){ return sqrt(pos.x() * pos.x() + pos.y() * pos.y());
}
void function_rotating(){
QPointF buttonDownPos
= mapFromScene
(event
->buttonDownScenePos
(Qt
::LeftButton));
qreal oldAngle = (180 * angleForPos(buttonDownPos)) / 3.14159265359;
qreal newAngle = (180 * angleForPos(event->pos())) / 3.14159265359;
newrotation = rotation + oldAngle - newAngle;
setMatrix
(QMatrix().
rotate(newrotation
));
}
qreal rectItem::angleForPos(const QPointF &pos){
qreal angle = acos(pos.x() / distanceToPoint(pos));
if (pos.y() > 0)
angle = -angle;//pi * 2.0 - angle;
return angle;
}
qreal rectItem::distanceToPoint(const QPointF &pos){
return sqrt(pos.x() * pos.x() + pos.y() * pos.y());
}
void function_rotating(){
QPointF buttonDownPos = mapFromScene(event->buttonDownScenePos(Qt::LeftButton));
qreal oldAngle = (180 * angleForPos(buttonDownPos)) / 3.14159265359;
qreal newAngle = (180 * angleForPos(event->pos())) / 3.14159265359;
newrotation = rotation + oldAngle - newAngle;
setMatrix(QMatrix().rotate(newrotation));
}
To copy to clipboard, switch view to plain text mode
Bookmarks