30 #include <QGraphicsView> 31 #include <QGraphicsSceneHoverEvent> 40 , QGraphicsRectItem( nullptr )
45 connect( mLayout, &QGraphicsScene::selectionChanged,
this, &QgsLayoutMouseHandles::selectionChanged );
48 setAcceptHoverEvents(
true );
50 mHorizontalSnapLine = mView->createSnapLine();
51 mHorizontalSnapLine->hide();
52 layout->addItem( mHorizontalSnapLine );
53 mVerticalSnapLine = mView->createSnapLine();
54 mVerticalSnapLine->hide();
55 layout->addItem( mVerticalSnapLine );
58 void QgsLayoutMouseHandles::paint( QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget )
63 if ( !mLayout->renderContext().isPreviewRender() )
69 if ( mLayout->renderContext().boundingBoxesVisible() )
72 double rectHandlerSize = rectHandlerBorderTolerance();
73 drawHandles( painter, rectHandlerSize );
76 if ( mIsResizing || mIsDragging || mLayout->renderContext().boundingBoxesVisible() )
79 drawSelectedItemBounds( painter );
83 void QgsLayoutMouseHandles::drawHandles( QPainter *painter,
double rectHandlerSize )
86 QPen handlePen = QPen( QColor( 55, 140, 195, 255 ) );
87 handlePen.setWidth( 0 );
88 painter->setPen( handlePen );
91 painter->setBrush( Qt::NoBrush );
92 painter->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
95 painter->setBrush( QColor( 255, 255, 255, 255 ) );
97 painter->drawRect( QRectF( 0, 0, rectHandlerSize, rectHandlerSize ) );
99 painter->drawRect( QRectF( ( rect().width() - rectHandlerSize ) / 2, 0, rectHandlerSize, rectHandlerSize ) );
101 painter->drawRect( QRectF( rect().width() - rectHandlerSize, 0, rectHandlerSize, rectHandlerSize ) );
103 painter->drawRect( QRectF( 0, ( rect().height() - rectHandlerSize ) / 2, rectHandlerSize, rectHandlerSize ) );
105 painter->drawRect( QRectF( rect().width() - rectHandlerSize, ( rect().height() - rectHandlerSize ) / 2, rectHandlerSize, rectHandlerSize ) );
107 painter->drawRect( QRectF( 0, rect().height() - rectHandlerSize, rectHandlerSize, rectHandlerSize ) );
109 painter->drawRect( QRectF( ( rect().width() - rectHandlerSize ) / 2, rect().height() - rectHandlerSize, rectHandlerSize, rectHandlerSize ) );
111 painter->drawRect( QRectF( rect().width() - rectHandlerSize, rect().height() - rectHandlerSize, rectHandlerSize, rectHandlerSize ) );
114 void QgsLayoutMouseHandles::drawSelectedItemBounds( QPainter *painter )
117 const QList<QgsLayoutItem *> selectedItems = mLayout->selectedLayoutItems(
false );
118 if ( selectedItems.isEmpty() )
125 painter->setCompositionMode( QPainter::CompositionMode_Difference );
128 QPen selectedItemPen = QPen( QColor( 144, 144, 144, 255 ) );
129 selectedItemPen.setStyle( Qt::DashLine );
130 selectedItemPen.setWidth( 0 );
131 painter->setPen( selectedItemPen );
132 painter->setBrush( Qt::NoBrush );
134 QList< QgsLayoutItem * > itemsToDraw;
135 collectItems( selectedItems, itemsToDraw );
140 QPolygonF itemBounds;
141 if ( mIsDragging && !item->isLocked() )
145 QPolygonF itemSceneBounds = item->mapToScene( item->rectWithFrame() );
148 itemSceneBounds.translate( transform().dx(), transform().dy() );
150 itemBounds = mapFromScene( itemSceneBounds );
152 else if ( mIsResizing && !item->isLocked() )
155 if ( selectedItems.size() > 1 )
158 QRectF itemRect = mapRectFromItem( item, item->rectWithFrame() );
161 itemBounds = QPolygonF( itemRect );
172 itemBounds = mapRectFromItem( item, item->rectWithFrame() );
178 path.addPolygon( itemBounds );
179 painter->drawPath( path );
184 void QgsLayoutMouseHandles::selectionChanged()
187 const QList<QGraphicsItem *> itemList = layout()->items();
188 for ( QGraphicsItem *graphicsItem : itemList )
194 if ( item->isSelected() )
214 void QgsLayoutMouseHandles::selectedItemSizeChanged()
216 if ( !mIsDragging && !mIsResizing )
223 void QgsLayoutMouseHandles::selectedItemRotationChanged()
225 if ( !mIsDragging && !mIsResizing )
232 void QgsLayoutMouseHandles::updateHandles()
237 QList<QgsLayoutItem *> selectedItems = mLayout->selectedLayoutItems(
false );
238 if ( !selectedItems.isEmpty() )
244 if ( selectionRotation( rotation ) )
247 setRotation( rotation );
256 QRectF newHandleBounds = selectionBounds();
259 setRect( 0, 0, newHandleBounds.width(), newHandleBounds.height() );
260 setPos( mapToScene( newHandleBounds.topLeft() ) );
273 QRectF QgsLayoutMouseHandles::selectionBounds()
const 276 const QList<QgsLayoutItem *> selectedItems = mLayout->selectedLayoutItems(
false );
277 auto itemIter = selectedItems.constBegin();
280 QRectF bounds = mapFromItem( ( *itemIter ), ( *itemIter )->rectWithFrame() ).boundingRect();
283 for ( ++itemIter; itemIter != selectedItems.constEnd(); ++itemIter )
285 bounds = bounds.united( mapFromItem( ( *itemIter ), ( *itemIter )->rectWithFrame() ).boundingRect() );
291 bool QgsLayoutMouseHandles::selectionRotation(
double &rotation )
const 294 QList<QgsLayoutItem *> selectedItems = mLayout->selectedLayoutItems(
false );
295 auto itemIter = selectedItems.constBegin();
298 double firstItemRotation = ( *itemIter )->rotation();
301 for ( ++itemIter; itemIter != selectedItems.constEnd(); ++itemIter )
303 if ( !
qgsDoubleNear( ( *itemIter )->rotation(), firstItemRotation ) )
311 rotation = firstItemRotation;
315 double QgsLayoutMouseHandles::rectHandlerBorderTolerance()
322 double viewScaleFactor = mView->transform().m11();
325 double rectHandlerSize = 10.0 / viewScaleFactor;
328 if ( rectHandlerSize > ( rect().width() / 3 ) )
330 rectHandlerSize = rect().width() / 3;
332 if ( rectHandlerSize > ( rect().height() / 3 ) )
334 rectHandlerSize = rect().height() / 3;
336 return rectHandlerSize;
339 Qt::CursorShape QgsLayoutMouseHandles::cursorForPosition( QPointF itemCoordPos )
341 QgsLayoutMouseHandles::MouseAction mouseAction = mouseActionForPosition( itemCoordPos );
342 switch ( mouseAction )
345 return Qt::ForbiddenCursor;
347 return Qt::SizeAllCursor;
351 if ( ( rotation() <= 22.5 || rotation() >= 337.5 ) || ( rotation() >= 157.5 && rotation() <= 202.5 ) )
353 return Qt::SizeVerCursor;
355 else if ( ( rotation() >= 22.5 && rotation() <= 67.5 ) || ( rotation() >= 202.5 && rotation() <= 247.5 ) )
357 return Qt::SizeBDiagCursor;
359 else if ( ( rotation() >= 67.5 && rotation() <= 112.5 ) || ( rotation() >= 247.5 && rotation() <= 292.5 ) )
361 return Qt::SizeHorCursor;
365 return Qt::SizeFDiagCursor;
370 if ( ( rotation() <= 22.5 || rotation() >= 337.5 ) || ( rotation() >= 157.5 && rotation() <= 202.5 ) )
372 return Qt::SizeHorCursor;
374 else if ( ( rotation() >= 22.5 && rotation() <= 67.5 ) || ( rotation() >= 202.5 && rotation() <= 247.5 ) )
376 return Qt::SizeFDiagCursor;
378 else if ( ( rotation() >= 67.5 && rotation() <= 112.5 ) || ( rotation() >= 247.5 && rotation() <= 292.5 ) )
380 return Qt::SizeVerCursor;
384 return Qt::SizeBDiagCursor;
388 case ResizeRightDown:
390 if ( ( rotation() <= 22.5 || rotation() >= 337.5 ) || ( rotation() >= 157.5 && rotation() <= 202.5 ) )
392 return Qt::SizeFDiagCursor;
394 else if ( ( rotation() >= 22.5 && rotation() <= 67.5 ) || ( rotation() >= 202.5 && rotation() <= 247.5 ) )
396 return Qt::SizeVerCursor;
398 else if ( ( rotation() >= 67.5 && rotation() <= 112.5 ) || ( rotation() >= 247.5 && rotation() <= 292.5 ) )
400 return Qt::SizeBDiagCursor;
404 return Qt::SizeHorCursor;
409 if ( ( rotation() <= 22.5 || rotation() >= 337.5 ) || ( rotation() >= 157.5 && rotation() <= 202.5 ) )
411 return Qt::SizeBDiagCursor;
413 else if ( ( rotation() >= 22.5 && rotation() <= 67.5 ) || ( rotation() >= 202.5 && rotation() <= 247.5 ) )
415 return Qt::SizeHorCursor;
417 else if ( ( rotation() >= 67.5 && rotation() <= 112.5 ) || ( rotation() >= 247.5 && rotation() <= 292.5 ) )
419 return Qt::SizeFDiagCursor;
423 return Qt::SizeVerCursor;
426 return Qt::ArrowCursor;
429 return Qt::ArrowCursor;
432 QgsLayoutMouseHandles::MouseAction QgsLayoutMouseHandles::mouseActionForPosition( QPointF itemCoordPos )
434 bool nearLeftBorder =
false;
435 bool nearRightBorder =
false;
436 bool nearLowerBorder =
false;
437 bool nearUpperBorder =
false;
439 bool withinWidth =
false;
440 bool withinHeight =
false;
441 if ( itemCoordPos.x() >= 0 && itemCoordPos.x() <= rect().width() )
445 if ( itemCoordPos.y() >= 0 && itemCoordPos.y() <= rect().height() )
450 double borderTolerance = rectHandlerBorderTolerance();
452 if ( itemCoordPos.x() >= 0 && itemCoordPos.x() < borderTolerance )
454 nearLeftBorder =
true;
456 if ( itemCoordPos.y() >= 0 && itemCoordPos.y() < borderTolerance )
458 nearUpperBorder =
true;
460 if ( itemCoordPos.x() <= rect().width() && itemCoordPos.x() > ( rect().width() - borderTolerance ) )
462 nearRightBorder =
true;
464 if ( itemCoordPos.y() <= rect().height() && itemCoordPos.y() > ( rect().height() - borderTolerance ) )
466 nearLowerBorder =
true;
469 if ( nearLeftBorder && nearUpperBorder )
471 return QgsLayoutMouseHandles::ResizeLeftUp;
473 else if ( nearLeftBorder && nearLowerBorder )
475 return QgsLayoutMouseHandles::ResizeLeftDown;
477 else if ( nearRightBorder && nearUpperBorder )
479 return QgsLayoutMouseHandles::ResizeRightUp;
481 else if ( nearRightBorder && nearLowerBorder )
483 return QgsLayoutMouseHandles::ResizeRightDown;
485 else if ( nearLeftBorder && withinHeight )
487 return QgsLayoutMouseHandles::ResizeLeft;
489 else if ( nearRightBorder && withinHeight )
491 return QgsLayoutMouseHandles::ResizeRight;
493 else if ( nearUpperBorder && withinWidth )
495 return QgsLayoutMouseHandles::ResizeUp;
497 else if ( nearLowerBorder && withinWidth )
499 return QgsLayoutMouseHandles::ResizeDown;
503 QPointF scenePoint = mapToScene( itemCoordPos );
504 const QList<QGraphicsItem *> itemsAtCursorPos = mLayout->items( scenePoint );
505 if ( itemsAtCursorPos.isEmpty() )
508 return QgsLayoutMouseHandles::SelectItem;
510 for ( QGraphicsItem *graphicsItem : itemsAtCursorPos )
513 if ( item && item->isSelected() )
516 return QgsLayoutMouseHandles::MoveItem;
521 return QgsLayoutMouseHandles::SelectItem;
524 QgsLayoutMouseHandles::MouseAction QgsLayoutMouseHandles::mouseActionForScenePos( QPointF sceneCoordPos )
527 QPointF itemPos = mapFromScene( sceneCoordPos );
528 return mouseActionForPosition( itemPos );
531 bool QgsLayoutMouseHandles::shouldBlockEvent( QInputEvent * )
const 533 return mIsDragging || mIsResizing;
536 void QgsLayoutMouseHandles::hoverMoveEvent( QGraphicsSceneHoverEvent *event )
538 setViewportCursor( cursorForPosition( event->pos() ) );
541 void QgsLayoutMouseHandles::hoverLeaveEvent( QGraphicsSceneHoverEvent *event )
544 setViewportCursor( Qt::ArrowCursor );
547 void QgsLayoutMouseHandles::setViewportCursor( Qt::CursorShape cursor )
552 if ( dynamic_cast< QgsLayoutViewToolSelect *>( mView->tool() ) )
554 mView->viewport()->setCursor( cursor );
558 void QgsLayoutMouseHandles::mouseMoveEvent( QGraphicsSceneMouseEvent *event )
565 dragMouseMove( event->lastScenePos(),
event->modifiers() & Qt::ShiftModifier,
event->modifiers() & Qt::ControlModifier );
567 else if ( mIsResizing )
572 resizeMouseMove( event->lastScenePos(),
event->modifiers() & Qt::ShiftModifier,
event->modifiers() & Qt::AltModifier );
575 mLastMouseEventPos =
event->lastScenePos();
578 void QgsLayoutMouseHandles::mouseReleaseEvent( QGraphicsSceneMouseEvent *event )
580 QPointF mouseMoveStopPoint =
event->lastScenePos();
581 double diffX = mouseMoveStopPoint.x() - mMouseMoveStartPos.x();
582 double diffY = mouseMoveStopPoint.y() - mMouseMoveStartPos.y();
585 if ( std::fabs( diffX ) < std::numeric_limits<double>::min() && std::fabs( diffY ) < std::numeric_limits<double>::min() )
594 if ( mCurrentMouseMoveAction == QgsLayoutMouseHandles::MoveItem )
597 mLayout->undoStack()->beginMacro( tr(
"Move Items" ) );
599 QPointF mEndHandleMovePos = scenePos();
601 double deltaX = mEndHandleMovePos.x() - mBeginHandlePos.x();
602 double deltaY = mEndHandleMovePos.y() - mBeginHandlePos.y();
605 const QList<QgsLayoutItem *> selectedItems = mLayout->selectedLayoutItems(
false );
608 if ( item->
isLocked() || ( item->flags() & QGraphicsItem::ItemIsSelectable ) == 0 || item->
isGroupMember() )
614 std::unique_ptr< QgsAbstractLayoutUndoCommand > command( item->
createCommand( QString(), 0 ) );
615 command->saveBeforeState();
619 command->saveAfterState();
620 mLayout->undoStack()->push( command.release() );
622 mLayout->undoStack()->endMacro();
624 else if ( mCurrentMouseMoveAction != QgsLayoutMouseHandles::NoAction )
627 mLayout->undoStack()->beginMacro( tr(
"Resize Items" ) );
630 const QList<QgsLayoutItem *> selectedItems = mLayout->selectedLayoutItems(
false );
633 if ( item->
isLocked() || ( item->flags() & QGraphicsItem::ItemIsSelectable ) == 0 )
639 std::unique_ptr< QgsAbstractLayoutUndoCommand > command( item->
createCommand( QString(), 0 ) );
640 command->saveBeforeState();
643 if ( selectedItems.size() == 1 )
646 itemRect = mResizeRect;
655 itemRect = itemRect.normalized();
656 QPointF newPos = mapToScene( itemRect.topLeft() );
665 command->saveAfterState();
666 mLayout->undoStack()->push( command.release() );
668 mLayout->undoStack()->endMacro();
682 mCurrentMouseMoveAction = QgsLayoutMouseHandles::MoveItem;
683 setViewportCursor( Qt::ArrowCursor );
691 void QgsLayoutMouseHandles::resetStatusBar()
696 const QList<QgsLayoutItem *> selectedItems = mLayout->selectedLayoutItems(
false );
697 int selectedCount = selectedItems.size();
698 if ( selectedCount > 1 )
701 mView->pushStatusMessage( tr(
"%1 items selected" ).arg( selectedCount ) );
703 else if ( selectedCount == 1 )
706 mView->pushStatusMessage( tr(
"1 item selected" ) );
711 mView->pushStatusMessage( QString() );
715 QPointF QgsLayoutMouseHandles::snapPoint( QPointF originalPoint, QgsLayoutMouseHandles::SnapGuideMode mode,
bool snapHorizontal,
bool snapVertical )
717 bool snapped =
false;
719 const QList< QgsLayoutItem * > selectedItems = mLayout->selectedLayoutItems();
720 QList< QgsLayoutItem * > itemsToExclude;
721 collectItems( selectedItems, itemsToExclude );
724 QPointF snappedPoint;
728 snappedPoint = mLayout->snapper().snapRect( rect().translated( originalPoint ), mView->transform().m11(), snapped, snapHorizontal ? mHorizontalSnapLine :
nullptr,
729 snapVertical ? mVerticalSnapLine :
nullptr, &itemsToExclude ).topLeft();
732 snappedPoint = mLayout->snapper().snapPoint( originalPoint, mView->transform().m11(), snapped, snapHorizontal ? mHorizontalSnapLine :
nullptr,
733 snapVertical ? mVerticalSnapLine :
nullptr, &itemsToExclude );
737 return snapped ? snappedPoint : originalPoint;
740 void QgsLayoutMouseHandles::hideAlignItems()
742 mHorizontalSnapLine->hide();
743 mVerticalSnapLine->hide();
746 void QgsLayoutMouseHandles::collectItems(
const QList<QgsLayoutItem *> items, QList<QgsLayoutItem *> &collected )
753 collectItems( static_cast< QgsLayoutItemGroup * >( item )->items(), collected );
762 void QgsLayoutMouseHandles::mousePressEvent( QGraphicsSceneMouseEvent *event )
765 mMouseMoveStartPos =
event->lastScenePos();
766 mLastMouseEventPos =
event->lastScenePos();
768 mBeginMouseEventPos =
event->lastScenePos();
769 mBeginHandlePos = scenePos();
770 mBeginHandleWidth = rect().width();
771 mBeginHandleHeight = rect().height();
773 mCurrentMouseMoveAction = mouseActionForPosition( event->pos() );
777 if ( mCurrentMouseMoveAction == QgsLayoutMouseHandles::MoveItem )
782 else if ( mCurrentMouseMoveAction != QgsLayoutMouseHandles::SelectItem &&
783 mCurrentMouseMoveAction != QgsLayoutMouseHandles::NoAction )
787 mResizeRect = QRectF( 0, 0, mBeginHandleWidth, mBeginHandleHeight );
790 mCursorOffset = calcCursorEdgeOffset( mMouseMoveStartPos );
796 void QgsLayoutMouseHandles::mouseDoubleClickEvent( QGraphicsSceneMouseEvent *event )
801 QSizeF QgsLayoutMouseHandles::calcCursorEdgeOffset( QPointF cursorPos )
804 QPointF sceneMousePos = mapFromScene( cursorPos );
806 switch ( mCurrentMouseMoveAction )
809 case QgsLayoutMouseHandles::ResizeUp:
810 return QSizeF( 0, sceneMousePos.y() );
812 case QgsLayoutMouseHandles::ResizeDown:
813 return QSizeF( 0, sceneMousePos.y() - rect().height() );
816 case QgsLayoutMouseHandles::ResizeLeft:
817 return QSizeF( sceneMousePos.x(), 0 );
819 case QgsLayoutMouseHandles::ResizeRight:
820 return QSizeF( sceneMousePos.x() - rect().width(), 0 );
823 case QgsLayoutMouseHandles::ResizeLeftUp:
824 return QSizeF( sceneMousePos.x(), sceneMousePos.y() );
826 case QgsLayoutMouseHandles::ResizeRightDown:
827 return QSizeF( sceneMousePos.x() - rect().width(), sceneMousePos.y() - rect().height() );
829 case QgsLayoutMouseHandles::ResizeRightUp:
830 return QSizeF( sceneMousePos.x() - rect().width(), sceneMousePos.y() );
832 case QgsLayoutMouseHandles::ResizeLeftDown:
833 return QSizeF( sceneMousePos.x(), sceneMousePos.y() - rect().height() );
844 void QgsLayoutMouseHandles::dragMouseMove( QPointF currentPosition,
bool lockMovement,
bool preventSnap )
852 double moveX = currentPosition.x() - mBeginMouseEventPos.x();
853 double moveY = currentPosition.y() - mBeginMouseEventPos.y();
856 QPointF upperLeftPoint( mBeginHandlePos.x() + moveX, mBeginHandlePos.y() + moveY );
858 QPointF snappedLeftPoint;
864 snappedLeftPoint = snapPoint( upperLeftPoint, QgsLayoutMouseHandles::Item );
870 snappedLeftPoint = upperLeftPoint;
875 double moveRectX = snappedLeftPoint.x() - mBeginHandlePos.x();
876 double moveRectY = snappedLeftPoint.y() - mBeginHandlePos.y();
882 if ( std::fabs( moveRectX ) <= std::fabs( moveRectY ) )
893 QTransform moveTransform;
894 moveTransform.translate( moveRectX, moveRectY );
895 setTransform( moveTransform );
898 mView->pushStatusMessage( tr(
"dx: %1 mm dy: %2 mm" ).arg( moveRectX ).arg( moveRectY ) );
901 void QgsLayoutMouseHandles::resizeMouseMove( QPointF currentPosition,
bool lockRatio,
bool fromCenter )
909 double mx = 0.0, my = 0.0, rx = 0.0, ry = 0.0;
911 QPointF beginMousePos;
912 QPointF finalPosition;
917 bool snapVertical = mCurrentMouseMoveAction == ResizeLeft ||
918 mCurrentMouseMoveAction == ResizeRight ||
919 mCurrentMouseMoveAction == ResizeLeftUp ||
920 mCurrentMouseMoveAction == ResizeRightUp ||
921 mCurrentMouseMoveAction == ResizeLeftDown ||
922 mCurrentMouseMoveAction == ResizeRightDown;
924 bool snapHorizontal = mCurrentMouseMoveAction == ResizeUp ||
925 mCurrentMouseMoveAction == ResizeDown ||
926 mCurrentMouseMoveAction == ResizeLeftUp ||
927 mCurrentMouseMoveAction == ResizeRightUp ||
928 mCurrentMouseMoveAction == ResizeLeftDown ||
929 mCurrentMouseMoveAction == ResizeRightDown;
933 beginMousePos = mapFromScene( QPointF( mBeginMouseEventPos.x() - mCursorOffset.width(), mBeginMouseEventPos.y() - mCursorOffset.height() ) );
934 QPointF snappedPosition = snapPoint( QPointF( currentPosition.x() - mCursorOffset.width(), currentPosition.y() - mCursorOffset.height() ), QgsLayoutMouseHandles::Point, snapHorizontal, snapVertical );
935 finalPosition = mapFromScene( snappedPosition );
940 beginMousePos = mapFromScene( mBeginMouseEventPos );
941 finalPosition = mapFromScene( currentPosition );
944 double diffX = finalPosition.x() - beginMousePos.x();
945 double diffY = finalPosition.y() - beginMousePos.y();
948 if ( lockRatio && !
qgsDoubleNear( mBeginHandleHeight, 0.0 ) )
950 ratio = mBeginHandleWidth / mBeginHandleHeight;
953 switch ( mCurrentMouseMoveAction )
956 case QgsLayoutMouseHandles::ResizeUp:
960 diffX = ( ( mBeginHandleHeight - diffY ) * ratio ) - mBeginHandleWidth;
976 case QgsLayoutMouseHandles::ResizeDown:
980 diffX = ( ( mBeginHandleHeight + diffY ) * ratio ) - mBeginHandleWidth;
997 case QgsLayoutMouseHandles::ResizeLeft:
1001 diffY = ( ( mBeginHandleWidth - diffX ) / ratio ) - mBeginHandleHeight;
1016 case QgsLayoutMouseHandles::ResizeRight:
1020 diffY = ( ( mBeginHandleWidth + diffX ) / ratio ) - mBeginHandleHeight;
1036 case QgsLayoutMouseHandles::ResizeLeftUp:
1041 if ( ( mBeginHandleWidth - diffX ) / ( mBeginHandleHeight - diffY ) > ratio )
1043 diffX = mBeginHandleWidth - ( ( mBeginHandleHeight - diffY ) * ratio );
1047 diffY = mBeginHandleHeight - ( ( mBeginHandleWidth - diffX ) / ratio );
1050 mx = diffX, my = diffY;
1056 case QgsLayoutMouseHandles::ResizeRightDown:
1061 if ( ( mBeginHandleWidth + diffX ) / ( mBeginHandleHeight + diffY ) > ratio )
1063 diffX = ( ( mBeginHandleHeight + diffY ) * ratio ) - mBeginHandleWidth;
1067 diffY = ( ( mBeginHandleWidth + diffX ) / ratio ) - mBeginHandleHeight;
1072 rx = diffX, ry = diffY;
1076 case QgsLayoutMouseHandles::ResizeRightUp:
1081 if ( ( mBeginHandleWidth + diffX ) / ( mBeginHandleHeight - diffY ) > ratio )
1083 diffX = ( ( mBeginHandleHeight - diffY ) * ratio ) - mBeginHandleWidth;
1087 diffY = mBeginHandleHeight - ( ( mBeginHandleWidth + diffX ) / ratio );
1091 my = diffY, rx = diffX, ry = -diffY;
1095 case QgsLayoutMouseHandles::ResizeLeftDown:
1100 if ( ( mBeginHandleWidth - diffX ) / ( mBeginHandleHeight + diffY ) > ratio )
1102 diffX = mBeginHandleWidth - ( ( mBeginHandleHeight + diffY ) * ratio );
1106 diffY = ( ( mBeginHandleWidth - diffX ) / ratio ) - mBeginHandleHeight;
1115 case QgsLayoutMouseHandles::MoveItem:
1116 case QgsLayoutMouseHandles::SelectItem:
1117 case QgsLayoutMouseHandles::NoAction:
1133 mResizeMoveX = mBeginHandleWidth + rx > 0 ? mx : mx + mBeginHandleWidth + rx;
1134 mResizeMoveY = mBeginHandleHeight + ry > 0 ? my : my + mBeginHandleHeight + ry;
1137 QLineF translateLine = QLineF( 0, 0, mResizeMoveX, mResizeMoveY );
1138 translateLine.setAngle( translateLine.angle() - rotation() );
1139 QPointF sceneTranslate = translateLine.p2();
1142 QTransform itemTransform;
1143 itemTransform.translate( sceneTranslate.x(), sceneTranslate.y() );
1144 setTransform( itemTransform );
1147 if ( mBeginHandleWidth + rx >= 0 && mBeginHandleHeight + ry >= 0 )
1149 mResizeRect = QRectF( 0, 0, mBeginHandleWidth + rx, mBeginHandleHeight + ry );
1151 else if ( mBeginHandleHeight + ry >= 0 )
1153 mResizeRect = QRectF( QPointF( -( mBeginHandleWidth + rx ), 0 ), QPointF( 0, mBeginHandleHeight + ry ) );
1155 else if ( mBeginHandleWidth + rx >= 0 )
1157 mResizeRect = QRectF( QPointF( 0, -( mBeginHandleHeight + ry ) ), QPointF( mBeginHandleWidth + rx, 0 ) );
1161 mResizeRect = QRectF( QPointF( -( mBeginHandleWidth + rx ), -( mBeginHandleHeight + ry ) ), QPointF( 0, 0 ) );
1164 setRect( 0, 0, std::fabs( mBeginHandleWidth + rx ), std::fabs( mBeginHandleHeight + ry ) );
1167 mView->pushStatusMessage( tr(
"width: %1 mm height: %2 mm" ).arg( rect().width() ).arg( rect().height() ) );
Base class for graphical items within a QgsLayout.
int type() const override
Returns a unique graphics item type identifier.
A graphical widget to display and interact with QgsLayouts.
bool isGroupMember() const
Returns true if the item is part of a QgsLayoutItemGroup group.
QgsUnitTypes::LayoutUnit units() const
Returns the units for the size.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
void attemptMoveBy(double deltaX, double deltaY)
Attempts to shift the item's position by a specified deltaX and deltaY, in layout units...
QgsLayoutSize sizeWithUnits() const
Returns the item's current size, including units.
QgsLayoutPoint positionWithUnits() const
Returns the item's current position, including units.
This class provides a method of storing points, consisting of an x and y coordinate, for use in QGIS layouts.
void frameChanged()
Emitted if the item's frame style changes.
void sizePositionChanged()
Emitted when the item's size or position changes.
virtual void attemptResize(const QgsLayoutSize &size, bool includesFrame=false)
Attempts to resize the item to a specified target size.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
virtual QRectF rectWithFrame() const
Returns the item's rectangular bounds, including any bleed caused by the item's frame.
void lockChanged()
Emitted if the item's lock status changes.
virtual void attemptMove(const QgsLayoutPoint &point, bool useReferencePoint=true, bool includesFrame=false, int page=-1)
Attempts to move the item to a specified point.
static void relativeResizeRect(QRectF &rectToResize, const QRectF &boundsBefore, const QRectF &boundsAfter)
Resizes a QRectF relative to a resized bounding rectangle.
bool isLocked() const
Returns true if the item is locked, and cannot be interacted with using the mouse.
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
void rotationChanged(double newRotation)
Emitted on item rotation change.
QgsUnitTypes::LayoutUnit units() const
Returns the units for the point.
QgsAbstractLayoutUndoCommand * createCommand(const QString &text, int id, QUndoCommand *parent=nullptr) override
Creates a new layout undo command with the specified text and parent.