20 #include <QGraphicsRectItem>
40 double dx = position.x() -
start.x();
41 double dy = position.y() -
start.y();
43 if ( constrainSquare )
45 if ( std::fabs( dx ) > std::fabs( dy ) )
47 width = std::fabs( dx );
52 height = std::fabs( dy );
56 x =
start.x() - ( ( dx < 0 ) ? width : 0 );
57 y =
start.y() - ( ( dy < 0 ) ? height : 0 );
87 x =
start.x() - width;
88 y =
start.y() - height;
93 return QRectF( x, y, width, height );
129 if ( mRubberBandItem )
131 view()->scene()->removeItem( mRubberBandItem );
132 delete mRubberBandItem;
139 mRubberBandItem =
new QGraphicsRectItem( 0, 0, 0, 0 );
140 mRubberBandItem->setBrush(
brush() );
141 mRubberBandItem->setPen(
pen() );
142 mRubberBandStartPos = position;
143 t.translate( position.x(), position.y() );
144 mRubberBandItem->setTransform( t );
145 mRubberBandItem->setZValue( QgsModelGraphicsScene::RubberBand );
146 view()->scene()->addItem( mRubberBandItem );
147 view()->scene()->update();
152 if ( !mRubberBandItem )
157 bool constrainSquare = modifiers & Qt::ShiftModifier;
158 bool fromCenter = modifiers & Qt::AltModifier;
160 QRectF newRect =
updateRect( mRubberBandStartPos, position, constrainSquare, fromCenter );
161 mRubberBandItem->setRect( 0, 0, newRect.width(), newRect.height() );
163 t.translate( newRect.x(), newRect.y() );
164 mRubberBandItem->setTransform( t );
169 bool constrainSquare = modifiers & Qt::ShiftModifier;
170 bool fromCenter = modifiers & Qt::AltModifier;
172 if ( mRubberBandItem )
174 view()->scene()->removeItem( mRubberBandItem );
175 delete mRubberBandItem;
176 mRubberBandItem =
nullptr;
178 return updateRect( mRubberBandStartPos, position, constrainSquare, fromCenter );