Re: resize and rotate handle
hi,
please send the source.
Re: resize and rotate handle
hi i solve it, but only partly
Code:
QColor color, HandleItem
::HandleRole role,
{
m_role = role;
m_color = color;
m_item = item;
m_handles = handles;
m_pressed = false;
setZValue( 100 );
setFlag( ItemIsMovable );
}
QRectF HandleItem
::boundingRect() const {
QPointF point
= m_item
->boundingRect
().
center();
switch( m_role ){
case CenterHandle:
case RightHandle:
point.setX( m_item->boundingRect().right() );
case TopHandle:
point.setY( m_item->boundingRect().top() );
}
}
{
paint->setPen( m_color );
paint->setBrush( m_color );
QVector<QPointF> points;
switch( m_role ){
case CenterHandle:
paint->drawEllipse( rect );
break;
case RightHandle:
paint
->drawConvexPolygon
( QPolygonF(points
) );
break;
case TopHandle:
paint
->drawConvexPolygon
( QPolygonF(points
) );
break;
}
}
{
m_pressed = true;
}
{
m_pressed = false;
}
QVariant HandleItem
::itemChange( GraphicsItemChange change,
const QVariant &data
) {
if( change == ItemPositionChange && m_pressed ){
QPointF movement
= data.
toPoint() - pos
();
QPointF center
= m_item
->boundingRect
().
center();
switch( m_role ){
case CenterHandle:
m_item->moveBy( movement.x(), movement.y() );
foreach( HandleItem *handle, m_handles )
handle->translate( movement.x(), movement.y() );
break;
case TopHandle:
if( -2*movement.y() + m_item->sceneBoundingRect().height() <= 5 )
movement.setX( 0 );
m_item->translate( center.x(), center.y() );
m_item->scale( 1, 1.0-2.0*movement.y() /(m_item->sceneBoundingRect().height()) );
m_item->translate( -center.x(), -center.y() );
break;
case RightHandle:
if( 2*movement.x() + m_item->sceneBoundingRect().width() <= 5 )
movement.setY( 0 );
m_item->translate( center.x(), center.y() );
m_item->scale( 1.0+2.0*movement.x()/(m_item->sceneBoundingRect().width()), 1 );
m_item->translate( -center.x(), -center.y() );
break;
}
}
}
class:
Code:
{
public:
enum HandleRole { CenterHandle, RightHandle, TopHandle };
QColor color, HandleRole role
= CenterHandle,
QList<HandleItem*> handles = QList<HandleItem*>() );
protected:
private:
HandleRole m_role;
QList<HandleItem*> m_handles;
bool m_pressed;
};
It is OK, but I dont know how translate coordition system to my item has CenterHandle, TopHandle and RightHandle at same pocition...
When I get mouseClick into my item CenterHandle, TopHandle and RightHandle are set well, I get mouse click next to my item CenterHandle, TopHandle and RightHandle are removed. It is OK. If I get mouseClick into my item CenterHandle, TopHandle and RightHandle are set and then I want to move my item. It is OK too. Then I click next to my item. It is OK. Then I want to move my item again, so I click into my item, but CenterHandle, TopHandle and RightHandle are set at first position(so I isnt in my item)
So I would like to ask, how I set translate or something else my item, when I change position of item.
Thanks a lot and sorry for my simple english
Re: resize and rotate handle
There is some Photo Wall application on Qt-apps.org
You can search for it and see the code. It had provided good means to rotate and resize graphics item.
Re: resize and rotate handle
wow it is great thanks :) I try it
Re: resize and rotate handle
I solved it only partly, but when I try to resize QGraphicsTextItem, i show handles in position 0,0 of all scene :(