@stampede - I haven't implemented resizing the line item yet. I'll work on it today and see how it goes.
Btw I implemented the rotation algorithm first hand today and it works brilliant!!!. Now I want to handle the corner cases too, for instance if the line item is dropped very close to the bounding rect of the graphicssceen. Now if we intend to rotate the line item, how should it behave?
Should the line stop rotating if it touches the screen boundary? or should the rotating anchor shift such that the rotation is possible? I guess the second thought is too complicated to implement.
I have a vague idea how to proceed in this regard. my understanding is that, in the QGrpahicsLineItem::mouseMoveEvent() after we calculated the rotated point,
we need to check if the rotated point lies with in the boundary rect of the graphics screen(convert rotated to screen coordinates by using mapToScreen() ), if yes then proceed to call setLine() on the line item other wise do not proceed to set the line.
if( _dragIndex != -1 ){
const QPointF anchor
= _dragIndex
== 0 ? this
->line
().
p1() : this
->line
().
p2();
ma.setLength( line().length() );
//Check if the QPointF rotated falls with the bounding rect of the screen, if yes proceed else do not setLine with new coordinates.
this
->setLine
( _dragIndex
== 0 ?
QLineF(anchor,rotated
) : QLineF(rotated,anchor
) );
}
}
void Line::mouseMoveEvent( QGraphicsSceneMouseEvent * event ){
if( _dragIndex != -1 ){
const QPointF anchor = _dragIndex == 0 ? this->line().p1() : this->line().p2();
QLineF ma = QLineF(anchor,event->pos());
ma.setLength( line().length() );
const QPointF rotated = anchor + QPointF( ma.dx(), ma.dy() );
//Check if the QPointF rotated falls with the bounding rect of the screen, if yes proceed else do not setLine with new coordinates.
this->setLine( _dragIndex == 0 ? QLineF(anchor,rotated) : QLineF(rotated,anchor) );
}
}
To copy to clipboard, switch view to plain text mode
Am I thinking on correct lines? I'm not sure if there is a way to check if the QPointF rotated falls with in the bound rect of screen.
Bookmarks