@Valderman
I did something like that in a project of mine, but with a difference that the rectangle does not rotate in his center but rotates relative to a center defined in a first click position called commandInitialPos, then you do a second click to start rotating, then you move the mouse to rotate.
I am posting the relevant code I used may it can be helpfull for you to adapt
the relevant pseudo code and link to the project:
https://bitbucket.org/joaodeusmorgado/techdrawstudio/src/142960ab5c809ddcbd20fb40f294e01d85c850d5/qml/qmlEntities/EntityTemplate.qml#lines-117
//first click - define the center of rotation
onCommandCprStart: function(pos) {
commandInitialPos = pos //assume that pos is the mouse click position
}
https://bitbucket.org/joaodeusmorgado/techdrawstudio/src/142960ab5c809ddcbd20fb40f294e01d85c850d5/qml/qmlEntities/RectangleThick.qml#lines-39
//second click - start rotation position
onCommandCprUpdate: function(pos, ....){
rotateStartPoint = pos //save the start rotation position
//calculates and saves the start angle
rotateStartAngle = mathLib.angleFromPoints(commandInitialPos, rotateStartPoint)
rectP0aux = re.p0 // here I just saving the rectangle initiall position vertexs
rectP1aux = re.p1
rectP2aux = re.p2
rectP3aux = re.p3
}
https://bitbucket.org/joaodeusmorgado/techdrawstudio/src/142960ab5c809ddcbd20fb40f294e01d85c850d5/qml/qmlEntities/RectangleThick.qml#lines-75
onCommandMtm: function(pos, ....){//this is equivalent to mouse move
rotateUpdateAngle = mathLib.angleFromPoints(commandInitialPos, pos)
var angle = rotateUpdateAngle - rotateStartAngle
// lets do it baby, lets rotate it, yeahhhh, updates the rectangles vertices, which is the rotation
re.p0 = mathLib.rotate2DFromPoint(commandInitialPos, angle, rectP0aux)
re.p1 = mathLib.rotate2DFromPoint(commandInitialPos, angle, rectP1aux)
re.p2 = mathLib.rotate2DFromPoint(commandInitialPos, angle, rectP2aux)
re.p3 = mathLib.rotate2DFromPoint(commandInitialPos, angle, rectP3aux)
}
https://bitbucket.org/joaodeusmorgado/techdrawstudio/src/142960ab5c809ddcbd20fb40f294e01d85c850d5/mathlib.cpp#lines-103
QVector3D MathLib::rotate2DFromPoint(const QVector3D ¢er, const float &angle, const QVector3D &p) const
{
float cosAngle = qCos(angle);
float sinAngle = qSin(angle);
float x = cosAngle*p.x() - sinAngle*p.y() + center.x() - cosAngle*center.x() + sinAngle*center.y();
float y = sinAngle*p.x() + cosAngle*p.y() + center.y() - sinAngle*center.x() - cosAngle*center.y();
return QVector3D(x, y, p.z());
}
This is the rectangle rotating:
[image: x7eha2y]