21 #include <QGraphicsScene>
22 #include <QGraphicsRectItem>
43 const double dx = position.x() -
start.x();
44 const double dy = position.y() -
start.y();
46 if ( constrainSquare )
48 if ( std::fabs( dx ) > std::fabs( dy ) )
50 width = std::fabs( dx );
55 height = std::fabs( dy );
59 x =
start.x() - ( ( dx < 0 ) ? width : 0 );
60 y =
start.y() - ( ( dy < 0 ) ? height : 0 );
90 x =
start.x() - width;
91 y =
start.y() - height;
96 return QRectF( x, y, width, height );
128 if ( mRubberBandItem )
130 canvas()->scene()->removeItem( mRubberBandItem );
131 delete mRubberBandItem;
138 mRubberBandItem =
new QGraphicsRectItem( 0, 0, 0, 0 );
139 mRubberBandItem->setBrush(
brush() );
140 mRubberBandItem->setPen(
pen() );
141 mRubberBandStartPos = position;
142 t.translate( position.x(), position.y() );
143 mRubberBandItem->setTransform( t );
144 mRubberBandItem->setZValue( 1000 );
145 canvas()->scene()->addItem( mRubberBandItem );
146 canvas()->scene()->update();
151 if ( !mRubberBandItem )
156 const bool constrainSquare = modifiers & Qt::ShiftModifier;
157 const bool fromCenter = modifiers & Qt::AltModifier;
159 const QRectF newRect =
updateRect( mRubberBandStartPos, position, constrainSquare, fromCenter );
160 mRubberBandItem->setRect( 0, 0, newRect.width(), newRect.height() );
162 t.translate( newRect.x(), newRect.y() );
163 mRubberBandItem->setTransform( t );
168 const bool constrainSquare = modifiers & Qt::ShiftModifier;
169 const bool fromCenter = modifiers & Qt::AltModifier;
171 if ( mRubberBandItem )
173 canvas()->scene()->removeItem( mRubberBandItem );
174 delete mRubberBandItem;
175 mRubberBandItem =
nullptr;
177 return updateRect( mRubberBandStartPos, position, constrainSquare, fromCenter );