18#include "moc_qgslayoutviewrubberband.cpp" 
   22#include <QGraphicsRectItem> 
   23#include <QGraphicsEllipseItem> 
   24#include <QGraphicsPolygonItem> 
   48  const double dx = position.x() - 
start.x();
 
   49  const double dy = position.y() - 
start.y();
 
   51  if ( constrainSquare )
 
   53    if ( std::fabs( dx ) > std::fabs( dy ) )
 
   55      width = std::fabs( dx );
 
   60      height = std::fabs( dy );
 
   64    x = 
start.x() - ( ( dx < 0 ) ? width : 0 );
 
   65    y = 
start.y() - ( ( dy < 0 ) ? height : 0 );
 
   95    x = 
start.x() - width;
 
   96    y = 
start.y() - height;
 
  101  return QRectF( x, y, width, height );
 
 
  137  if ( mRubberBandItem )
 
  139    layout()->removeItem( mRubberBandItem );
 
  140    delete mRubberBandItem;
 
 
  147  mRubberBandItem = 
new QGraphicsRectItem( 0, 0, 0, 0 );
 
  148  mRubberBandItem->setBrush( 
brush() );
 
  149  mRubberBandItem->setPen( 
pen() );
 
  150  mRubberBandStartPos = position;
 
  151  t.translate( position.x(), position.y() );
 
  152  mRubberBandItem->setTransform( t );
 
  154  layout()->addItem( mRubberBandItem );
 
 
  160  if ( !mRubberBandItem )
 
  165  const bool constrainSquare = modifiers & Qt::ShiftModifier;
 
  166  const bool fromCenter = modifiers & Qt::AltModifier;
 
  168  const QRectF newRect = 
updateRect( mRubberBandStartPos, position, constrainSquare, fromCenter );
 
  169  mRubberBandItem->setRect( 0, 0, newRect.width(), newRect.height() );
 
  171  t.translate( newRect.x(), newRect.y() );
 
  172  mRubberBandItem->setTransform( t );
 
 
  179  const bool constrainSquare = modifiers & Qt::ShiftModifier;
 
  180  const bool fromCenter = modifiers & Qt::AltModifier;
 
  182  if ( mRubberBandItem )
 
  184    layout()->removeItem( mRubberBandItem );
 
  185    delete mRubberBandItem;
 
  186    mRubberBandItem = 
nullptr;
 
  188  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 );
 
 
  273  if ( mRubberBandItem )
 
  275    layout()->removeItem( mRubberBandItem );
 
  276    delete mRubberBandItem;
 
 
  283  mRubberBandItem = 
new QGraphicsPolygonItem();
 
  284  mRubberBandItem->setBrush( 
brush() );
 
  285  mRubberBandItem->setPen( 
pen() );
 
  286  mRubberBandStartPos = position;
 
  287  t.translate( position.x(), position.y() );
 
  288  mRubberBandItem->setTransform( t );
 
  290  layout()->addItem( mRubberBandItem );
 
 
  296  if ( !mRubberBandItem )
 
  301  const bool constrainSquare = modifiers & Qt::ShiftModifier;
 
  302  const bool fromCenter = modifiers & Qt::AltModifier;
 
  304  const QRectF newRect = 
updateRect( mRubberBandStartPos, position, constrainSquare, fromCenter );
 
  306  const QPolygonF shapePolygon = QPolygonF() << QPointF( 0, newRect.height() )
 
  307                                             << QPointF( newRect.width(), newRect.height() )
 
  308                                             << QPointF( newRect.width() / 2.0, 0 )
 
  309                                             << QPointF( 0, newRect.height() );
 
  311  mRubberBandItem->setPolygon( shapePolygon );
 
  313  t.translate( newRect.x(), newRect.y() );
 
  314  mRubberBandItem->setTransform( t );
 
 
  321  const bool constrainSquare = modifiers & Qt::ShiftModifier;
 
  322  const bool fromCenter = modifiers & Qt::AltModifier;
 
  324  if ( mRubberBandItem )
 
  326    layout()->removeItem( mRubberBandItem );
 
  327    delete mRubberBandItem;
 
  328    mRubberBandItem = 
nullptr;
 
  330  return updateRect( mRubberBandStartPos, position, constrainSquare, fromCenter );
 
 
An elliptical rubber band for use within QgsLayoutView widgets.
 
QgsLayoutViewEllipticalRubberBand(QgsLayoutView *view=nullptr)
Constructor for QgsLayoutViewEllipticalRubberBand.
 
void update(QPointF position, Qt::KeyboardModifiers modifiers) override
Called when a rubber band should be updated to reflect a temporary ending position (in layout coordin...
 
QgsLayoutViewEllipticalRubberBand * create(QgsLayoutView *view) const override
Creates a new instance of the QgsLayoutViewRubberBand subclass.
 
~QgsLayoutViewEllipticalRubberBand() override
 
void start(QPointF position, Qt::KeyboardModifiers modifiers) override
Called when a rubber band should be created at the specified starting position (in layout coordinate ...
 
QRectF finish(QPointF position=QPointF(), Qt::KeyboardModifiers modifiers=Qt::KeyboardModifiers()) override
Called when a rubber band use has finished and the rubber band is no longer required.
 
A rectangular rubber band for use within QgsLayoutView widgets.
 
QgsLayoutViewRectangularRubberBand * create(QgsLayoutView *view) const override
Creates a new instance of the QgsLayoutViewRubberBand subclass.
 
void update(QPointF position, Qt::KeyboardModifiers modifiers) override
Called when a rubber band should be updated to reflect a temporary ending position (in layout coordin...
 
QgsLayoutViewRectangularRubberBand(QgsLayoutView *view=nullptr)
Constructor for QgsLayoutViewRectangularRubberBand.
 
void start(QPointF position, Qt::KeyboardModifiers modifiers) override
Called when a rubber band should be created at the specified starting position (in layout coordinate ...
 
~QgsLayoutViewRectangularRubberBand() override
 
QRectF finish(QPointF position=QPointF(), Qt::KeyboardModifiers modifiers=Qt::KeyboardModifiers()) override
Called when a rubber band use has finished and the rubber band is no longer required.
 
An abstract base class for temporary rubber band items in various shapes, for use within QgsLayoutVie...
 
QgsLayoutViewRubberBand(QgsLayoutView *view=nullptr)
Constructor for QgsLayoutViewRubberBand.
 
QgsLayoutView * view() const
Returns the view associated with the rubber band.
 
void sizeChanged(const QString &size)
Emitted when the size of the rubber band is changed.
 
QBrush brush() const
Returns the brush used for drawing the rubber band.
 
virtual void start(QPointF position, Qt::KeyboardModifiers modifiers)=0
Called when a rubber band should be created at the specified starting position (in layout coordinate ...
 
void setPen(const QPen &pen)
Sets the pen used for drawing the rubber band.
 
void setBrush(const QBrush &brush)
Sets the brush used for drawing the rubber band.
 
QgsLayout * layout() const
Returns the layout associated with the rubber band.
 
QPen pen() const
Returns the pen used for drawing the rubber band.
 
QRectF updateRect(QPointF start, QPointF position, bool constrainSquare, bool fromCenter)
Calculates an updated bounding box rectangle from a original start position and new position.
 
A triangular rubber band for use within QgsLayoutView widgets.
 
QRectF finish(QPointF position=QPointF(), Qt::KeyboardModifiers modifiers=Qt::KeyboardModifiers()) override
Called when a rubber band use has finished and the rubber band is no longer required.
 
QgsLayoutViewTriangleRubberBand(QgsLayoutView *view=nullptr)
Constructor for QgsLayoutViewTriangleRubberBand.
 
QgsLayoutViewTriangleRubberBand * create(QgsLayoutView *view) const override
Creates a new instance of the QgsLayoutViewRubberBand subclass.
 
void update(QPointF position, Qt::KeyboardModifiers modifiers) override
Called when a rubber band should be updated to reflect a temporary ending position (in layout coordin...
 
~QgsLayoutViewTriangleRubberBand() override
 
void start(QPointF position, Qt::KeyboardModifiers modifiers) override
Called when a rubber band should be created at the specified starting position (in layout coordinate ...
 
A graphical widget to display and interact with QgsLayouts.
 
QgsLayout * currentLayout
 
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
 
@ ZViewTool
Z-value for temporary view tool items.
 
static Q_INVOKABLE QString toAbbreviatedString(Qgis::DistanceUnit unit)
Returns a translated abbreviation representing a distance unit.