25const double QgsLayoutViewToolSelect::sSearchToleranceInMillimeters = 2.0;
34 mRubberBand->setBrush( QBrush( QColor( 224, 178, 76, 63 ) ) );
35 mRubberBand->setPen( QPen( QBrush( QColor( 254, 58, 29, 100 ) ), 0, Qt::DotLine ) );
43 if ( mMouseHandles->scene() )
44 mMouseHandles->scene()->removeItem( mMouseHandles );
45 mMouseHandles->deleteLater();
51 if ( mMouseHandles->shouldBlockEvent( event ) )
56 if ( mMouseHandles->isVisible() )
59 QgsLayoutMouseHandles::MouseAction mouseAction = mMouseHandles->mouseActionForScenePos( event->
layoutPoint() );
61 if ( mouseAction != QgsLayoutMouseHandles::MoveItem
62 && mouseAction != QgsLayoutMouseHandles::NoAction
63 && mouseAction != QgsLayoutMouseHandles::SelectItem )
71 if ( event->button() != Qt::LeftButton )
76 mRubberBand->finish();
87 if ( event->modifiers() & Qt::ControlModifier )
91 if ( !selectedItems.isEmpty() )
93 previousSelectedItem = selectedItems.at( 0 );
97 if ( previousSelectedItem )
122 selectedItem = group;
128 mMousePressStartPos =
event->pos();
129 mRubberBand->start( event->
layoutPoint(), Qt::KeyboardModifiers() );
133 if ( ( event->modifiers() & Qt::ShiftModifier ) && ( selectedItem->isSelected() ) )
140 if ( !selectedItems.isEmpty() )
151 if ( ( !selectedItem->isSelected() ) &&
152 !( event->modifiers() & Qt::ShiftModifier ) )
164 mMouseHandles->startMove(
view()->mapToScene( event->pos() ) );
174 mRubberBand->update( event->
layoutPoint(), Qt::KeyboardModifiers() );
178 if ( !mMouseHandles->isDragging() && !mMouseHandles->isResizing() )
182 view()->viewport()->setCursor( Qt::SizeAllCursor );
186 view()->viewport()->setCursor( Qt::ArrowCursor );
195 if ( event->button() != Qt::LeftButton && mMouseHandles->shouldBlockEvent( event ) )
201 if ( !mIsSelecting || event->button() != Qt::LeftButton )
207 mIsSelecting =
false;
208 bool wasClick = !
isClickAndDrag( mMousePressStartPos, event->pos() );
212 QRectF rect = mRubberBand->finish( event->
layoutPoint() );
214 bool subtractingSelection =
false;
215 if ( event->modifiers() & Qt::ShiftModifier )
219 else if ( event->modifiers() & Qt::ControlModifier )
222 subtractingSelection =
true;
231 Qt::ItemSelectionMode selectionMode = Qt::IntersectsItemShape;
232 if ( event->modifiers() & Qt::AltModifier )
235 selectionMode = Qt::ContainsItemShape;
239 QList<QGraphicsItem *> itemList;
243 itemList =
layout()->items( QRectF( rect.center().x() - tolerance, rect.center().y() - tolerance, 2 * tolerance, 2 * tolerance ), selectionMode );
246 itemList =
layout()->items( rect, selectionMode );
249 for ( QGraphicsItem *item : std::as_const( itemList ) )
254 focusedPaperItem = paperItem;
256 if ( layoutItem && !paperItem )
260 if ( subtractingSelection )
280 if ( !selectedItemList.isEmpty() )
284 else if ( focusedPaperItem )
292 mMouseHandles->selectionChanged();
297 if ( mMouseHandles->shouldBlockEvent( event ) )
310 if ( mMouseHandles->isDragging() || mMouseHandles->isResizing() )
324 mRubberBand->finish();
325 mIsSelecting =
false;
331QgsLayoutMouseHandles *QgsLayoutViewToolSelect::mouseHandles()
333 return mMouseHandles;
340 mMouseHandles->deleteLater();
343 mMouseHandles =
new QgsLayoutMouseHandles(
layout,
view() );
344 mMouseHandles->hide();
346 layout->addItem( mMouseHandles );
350 const double pixelsPerMm =
view()->physicalDpiX() / 25.4;
351 return sSearchToleranceInMillimeters * pixelsPerMm /
view()->transform().m11();
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.