20 #include <QGraphicsRectItem> 
   21 #include <QGraphicsEllipseItem> 
   22 #include <QGraphicsPolygonItem> 
   47   const double dx = position.x() - 
start.x();
 
   48   const double dy = position.y() - 
start.y();
 
   50   if ( constrainSquare )
 
   52     if ( std::fabs( dx ) > std::fabs( dy ) )
 
   54       width = std::fabs( dx );
 
   59       height = std::fabs( dy );
 
   63     x = 
start.x() - ( ( dx < 0 ) ? width : 0 );
 
   64     y = 
start.y() - ( ( dy < 0 ) ? height : 0 );
 
   94     x = 
start.x() - width;
 
   95     y = 
start.y() - height;
 
  100   return QRectF( x, y, width, height );
 
  136   if ( mRubberBandItem )
 
  138     layout()->removeItem( mRubberBandItem );
 
  139     delete mRubberBandItem;
 
  146   mRubberBandItem = 
new QGraphicsRectItem( 0, 0, 0, 0 );
 
  147   mRubberBandItem->setBrush( 
brush() );
 
  148   mRubberBandItem->setPen( 
pen() );
 
  149   mRubberBandStartPos = position;
 
  150   t.translate( position.x(), position.y() );
 
  151   mRubberBandItem->setTransform( t );
 
  153   layout()->addItem( mRubberBandItem );
 
  159   if ( !mRubberBandItem )
 
  164   const bool constrainSquare = modifiers & Qt::ShiftModifier;
 
  165   const bool fromCenter = modifiers & Qt::AltModifier;
 
  167   const QRectF newRect = 
updateRect( mRubberBandStartPos, position, constrainSquare, fromCenter );
 
  168   mRubberBandItem->setRect( 0, 0, newRect.width(), newRect.height() );
 
  170   t.translate( newRect.x(), newRect.y() );
 
  171   mRubberBandItem->setTransform( t );
 
  178   const bool constrainSquare = modifiers & Qt::ShiftModifier;
 
  179   const bool fromCenter = modifiers & Qt::AltModifier;
 
  181   if ( mRubberBandItem )
 
  183     layout()->removeItem( mRubberBandItem );
 
  184     delete mRubberBandItem;
 
  185     mRubberBandItem = 
nullptr;
 
  187   return updateRect( mRubberBandStartPos, position, constrainSquare, fromCenter );
 
  203   if ( mRubberBandItem )
 
  205     layout()->removeItem( mRubberBandItem );
 
  206     delete mRubberBandItem;
 
  213   mRubberBandItem = 
new QGraphicsEllipseItem( 0, 0, 0, 0 );
 
  214   mRubberBandItem->setBrush( 
brush() );
 
  215   mRubberBandItem->setPen( 
pen() );
 
  216   mRubberBandStartPos = position;
 
  217   t.translate( position.x(), position.y() );
 
  218   mRubberBandItem->setTransform( t );
 
  220   layout()->addItem( mRubberBandItem );
 
  226   if ( !mRubberBandItem )
 
  231   const bool constrainSquare = modifiers & Qt::ShiftModifier;
 
  232   const bool fromCenter = modifiers & Qt::AltModifier;
 
  234   const QRectF newRect = 
updateRect( mRubberBandStartPos, position, constrainSquare, fromCenter );
 
  235   mRubberBandItem->setRect( 0, 0, newRect.width(), newRect.height() );
 
  237   t.translate( newRect.x(), newRect.y() );
 
  238   mRubberBandItem->setTransform( t );
 
  245   const bool constrainSquare = modifiers & Qt::ShiftModifier;
 
  246   const bool fromCenter = modifiers & Qt::AltModifier;
 
  248   if ( mRubberBandItem )
 
  250     layout()->removeItem( mRubberBandItem );
 
  251     delete mRubberBandItem;
 
  252     mRubberBandItem = 
nullptr;
 
  254   return updateRect( mRubberBandStartPos, position, constrainSquare, fromCenter );
 
  274   if ( mRubberBandItem )
 
  276     layout()->removeItem( mRubberBandItem );
 
  277     delete mRubberBandItem;
 
  284   mRubberBandItem = 
new QGraphicsPolygonItem();
 
  285   mRubberBandItem->setBrush( 
brush() );
 
  286   mRubberBandItem->setPen( 
pen() );
 
  287   mRubberBandStartPos = position;
 
  288   t.translate( position.x(), position.y() );
 
  289   mRubberBandItem->setTransform( t );
 
  291   layout()->addItem( mRubberBandItem );
 
  297   if ( !mRubberBandItem )
 
  302   const bool constrainSquare = modifiers & Qt::ShiftModifier;
 
  303   const bool fromCenter = modifiers & Qt::AltModifier;
 
  305   const QRectF newRect = 
updateRect( mRubberBandStartPos, position, constrainSquare, fromCenter );
 
  307   const QPolygonF shapePolygon = QPolygonF() << QPointF( 0, newRect.height() )
 
  308                                  << QPointF( newRect.width(), newRect.height() )
 
  309                                  << QPointF( newRect.width() / 2.0, 0 )
 
  310                                  << QPointF( 0, newRect.height() );
 
  312   mRubberBandItem->setPolygon( shapePolygon );
 
  314   t.translate( newRect.x(), newRect.y() );
 
  315   mRubberBandItem->setTransform( t );
 
  322   const bool constrainSquare = modifiers & Qt::ShiftModifier;
 
  323   const bool fromCenter = modifiers & Qt::AltModifier;
 
  325   if ( mRubberBandItem )
 
  327     layout()->removeItem( mRubberBandItem );
 
  328     delete mRubberBandItem;
 
  329     mRubberBandItem = 
nullptr;
 
  331   return updateRect( mRubberBandStartPos, position, constrainSquare, fromCenter );