23#include <QGraphicsEllipseItem>
24#include <QGraphicsPolygonItem>
25#include <QGraphicsRectItem>
27#include "moc_qgslayoutviewrubberband.cpp"
40 return mView->currentLayout();
50 const double dx = position.x() -
start.x();
51 const double dy = position.y() -
start.y();
53 if ( constrainSquare )
55 if ( std::fabs( dx ) > std::fabs( dy ) )
57 width = std::fabs( dx );
62 height = std::fabs( dy );
66 x =
start.x() - ( ( dx < 0 ) ? width : 0 );
67 y =
start.y() - ( ( dy < 0 ) ? height : 0 );
97 x =
start.x() - width;
98 y =
start.y() - height;
103 return QRectF( x, y, width, height );
138 if ( mRubberBandItem )
140 layout()->removeItem( mRubberBandItem );
141 delete mRubberBandItem;
148 mRubberBandItem =
new QGraphicsRectItem( 0, 0, 0, 0 );
149 mRubberBandItem->setBrush(
brush() );
150 mRubberBandItem->setPen(
pen() );
151 mRubberBandStartPos = position;
152 t.translate( position.x(), position.y() );
153 mRubberBandItem->setTransform( t );
155 layout()->addItem( mRubberBandItem );
161 if ( !mRubberBandItem )
166 const bool constrainSquare = modifiers & Qt::ShiftModifier;
167 const bool fromCenter = modifiers & Qt::AltModifier;
169 const QRectF newRect =
updateRect( mRubberBandStartPos, position, constrainSquare, fromCenter );
170 mRubberBandItem->setRect( 0, 0, newRect.width(), newRect.height() );
172 t.translate( newRect.x(), newRect.y() );
173 mRubberBandItem->setTransform( t );
180 const bool constrainSquare = modifiers & Qt::ShiftModifier;
181 const bool fromCenter = modifiers & Qt::AltModifier;
183 if ( mRubberBandItem )
185 layout()->removeItem( mRubberBandItem );
186 delete mRubberBandItem;
187 mRubberBandItem =
nullptr;
189 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 );
272 if ( mRubberBandItem )
274 layout()->removeItem( mRubberBandItem );
275 delete mRubberBandItem;
282 mRubberBandItem =
new QGraphicsPolygonItem();
283 mRubberBandItem->setBrush(
brush() );
284 mRubberBandItem->setPen(
pen() );
285 mRubberBandStartPos = position;
286 t.translate( position.x(), position.y() );
287 mRubberBandItem->setTransform( t );
289 layout()->addItem( mRubberBandItem );
295 if ( !mRubberBandItem )
300 const bool constrainSquare = modifiers & Qt::ShiftModifier;
301 const bool fromCenter = modifiers & Qt::AltModifier;
303 const QRectF newRect =
updateRect( mRubberBandStartPos, position, constrainSquare, fromCenter );
305 const QPolygonF shapePolygon = QPolygonF() << QPointF( 0, newRect.height() ) << QPointF( newRect.width(), newRect.height() ) << QPointF( newRect.width() / 2.0, 0 ) << QPointF( 0, newRect.height() );
307 mRubberBandItem->setPolygon( shapePolygon );
309 t.translate( newRect.x(), newRect.y() );
310 mRubberBandItem->setTransform( t );
317 const bool constrainSquare = modifiers & Qt::ShiftModifier;
318 const bool fromCenter = modifiers & Qt::AltModifier;
320 if ( mRubberBandItem )
322 layout()->removeItem( mRubberBandItem );
323 delete mRubberBandItem;
324 mRubberBandItem =
nullptr;
326 return updateRect( mRubberBandStartPos, position, constrainSquare, fromCenter );
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.
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.
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.
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.
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.