PDA

View Full Version : QPointF transformation



dreamer
12th May 2008, 17:56
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));
}

adonel
13th May 2008, 10:40
Take a look at the :
int QPoint::manhattanLength ()

dreamer
13th May 2008, 11:02
I'm working with QPointF Object and not with QPoint............
Isn't there any "map" function that give me this behaviour?

aamer4yu
13th May 2008, 11:11
What do u want to do ???

I guess u take a look at scenePos() . Hope it will help u