17#include "moc_qgslayoutviewtoolselect.cpp"
26const double QgsLayoutViewToolSelect::sSearchToleranceInMillimeters = 2.0;
35 mRubberBand->setBrush( QBrush( QColor( 224, 178, 76, 63 ) ) );
36 mRubberBand->setPen( QPen( QBrush( QColor( 254, 58, 29, 100 ) ), 0, Qt::DotLine ) );
44 if ( mMouseHandles->scene() )
45 mMouseHandles->scene()->removeItem( mMouseHandles );
46 mMouseHandles->deleteLater();
52 if ( mMouseHandles->shouldBlockEvent( event ) )
57 if ( mMouseHandles->isVisible() )
72 if ( event->button() != Qt::LeftButton )
77 mRubberBand->finish();
88 if ( event->modifiers() & Qt::ControlModifier )
92 if ( !selectedItems.isEmpty() )
94 previousSelectedItem = selectedItems.at( 0 );
98 if ( previousSelectedItem )
123 selectedItem = group;
129 mMousePressStartPos =
event->pos();
130 mRubberBand->start( event->
layoutPoint(), Qt::KeyboardModifiers() );
134 if ( ( event->modifiers() & Qt::ShiftModifier ) && ( selectedItem->isSelected() ) )
141 if ( !selectedItems.isEmpty() )
152 if ( ( !selectedItem->isSelected() ) &&
153 !( event->modifiers() & Qt::ShiftModifier ) )
165 mMouseHandles->startMove(
view()->mapToScene( event->pos() ) );
175 mRubberBand->update( event->
layoutPoint(), Qt::KeyboardModifiers() );
179 if ( !mMouseHandles->isDragging() && !mMouseHandles->isResizing() )
183 view()->viewport()->setCursor( Qt::SizeAllCursor );
187 view()->viewport()->setCursor( Qt::ArrowCursor );
196 if ( event->button() != Qt::LeftButton && mMouseHandles->shouldBlockEvent( event ) )
202 if ( !mIsSelecting || event->button() != Qt::LeftButton )
208 mIsSelecting =
false;
209 bool wasClick = !
isClickAndDrag( mMousePressStartPos, event->pos() );
213 QRectF rect = mRubberBand->finish( event->
layoutPoint() );
215 bool subtractingSelection =
false;
216 if ( event->modifiers() & Qt::ShiftModifier )
220 else if ( event->modifiers() & Qt::ControlModifier )
223 subtractingSelection =
true;
232 Qt::ItemSelectionMode selectionMode = Qt::IntersectsItemShape;
233 if ( event->modifiers() & Qt::AltModifier )
236 selectionMode = Qt::ContainsItemShape;
240 QList<QGraphicsItem *> itemList;
244 itemList =
layout()->items( QRectF( rect.center().x() - tolerance, rect.center().y() - tolerance, 2 * tolerance, 2 * tolerance ), selectionMode );
247 itemList =
layout()->items( rect, selectionMode );
250 for ( QGraphicsItem *item : std::as_const( itemList ) )
255 focusedPaperItem = paperItem;
257 if ( layoutItem && !paperItem )
261 if ( subtractingSelection )
281 if ( !selectedItemList.isEmpty() )
285 else if ( focusedPaperItem )
293 mMouseHandles->selectionChanged();
298 if ( mMouseHandles->shouldBlockEvent( event ) )
311 if ( mMouseHandles->isDragging() || mMouseHandles->isResizing() )
325 mRubberBand->finish();
326 mIsSelecting =
false;
332QgsLayoutMouseHandles *QgsLayoutViewToolSelect::mouseHandles()
334 return mMouseHandles;
341 mMouseHandles->deleteLater();
344 mMouseHandles =
new QgsLayoutMouseHandles(
layout,
view() );
345 mMouseHandles->hide();
347 layout->addItem( mMouseHandles );
351 const double pixelsPerMm =
view()->physicalDpiX() / 25.4;
352 return sSearchToleranceInMillimeters * pixelsPerMm /
view()->transform().m11();
MouseHandlesAction
Action to be performed by the mouse handles.
A container for grouping several QgsLayoutItems.
Item representing the paper in a layout.
Base class for graphical items within a QgsLayout.
QgsLayoutItemGroup * parentGroup() const
Returns the item's parent group, if the item is part of a QgsLayoutItemGroup group.
virtual void setSelected(bool selected)
Sets whether the item should be selected.
bool isLocked() const
Returns true if the item is locked, and cannot be interacted with using the mouse.
A QgsLayoutViewMouseEvent is the result of a user interaction with the mouse on a QgsLayoutView.
QPointF layoutPoint() const
Returns the event point location in layout coordinates.
QgsLayoutViewRectangularRubberBand is rectangular rubber band for use within QgsLayoutView widgets.
A graphical widget to display and interact with QgsLayouts.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
QgsLayoutItem * layoutItemAt(QPointF position, bool ignoreLocked=false, double searchTolerance=0) const
Returns the topmost layout item at a specified position.
QList< QgsLayoutItem * > selectedLayoutItems(bool includeLockedItems=true)
Returns list of selected layout items.
void setSelectedItem(QgsLayoutItem *item)
Clears any selected items and sets item as the current selection.
@ ZMouseHandles
Z-value for mouse handles.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.