21#include <QGraphicsView>
22#include <QGraphicsSceneHoverEvent>
29QgsGraphicsViewMouseHandles::QgsGraphicsViewMouseHandles( QGraphicsView *view )
31 , QGraphicsRectItem( nullptr )
35 setAcceptHoverEvents(
true );
38void QgsGraphicsViewMouseHandles::paintInternal( QPainter *painter,
bool showHandles,
bool showStaticBoundingBoxes,
bool showTemporaryBoundingBoxes,
const QStyleOptionGraphicsItem *, QWidget * )
45 if ( showStaticBoundingBoxes )
48 double rectHandlerSize = rectHandlerBorderTolerance();
49 drawHandles( painter, rectHandlerSize );
52 if ( showTemporaryBoundingBoxes && ( mIsResizing || mIsDragging || showStaticBoundingBoxes ) )
55 drawSelectedItemBounds( painter );
59QRectF QgsGraphicsViewMouseHandles::storedItemRect( QGraphicsItem *item )
const
61 return itemRect( item );
64void QgsGraphicsViewMouseHandles::previewItemMove( QGraphicsItem *,
double,
double )
69QRectF QgsGraphicsViewMouseHandles::previewSetItemRect( QGraphicsItem *, QRectF )
74void QgsGraphicsViewMouseHandles::startMacroCommand(
const QString & )
79void QgsGraphicsViewMouseHandles::endMacroCommand()
84void QgsGraphicsViewMouseHandles::endItemCommand( QGraphicsItem * )
89void QgsGraphicsViewMouseHandles::createItemCommand( QGraphicsItem * )
94QPointF QgsGraphicsViewMouseHandles::snapPoint( QPointF originalPoint, QgsGraphicsViewMouseHandles::SnapGuideMode,
bool,
bool )
99void QgsGraphicsViewMouseHandles::expandItemList(
const QList<QGraphicsItem *> &items, QList<QGraphicsItem *> &collected )
const
104void QgsGraphicsViewMouseHandles::drawHandles( QPainter *painter,
double rectHandlerSize )
107 QPen handlePen = QPen( QColor( 55, 140, 195, 255 ) );
108 handlePen.setWidth( 0 );
109 painter->setPen( handlePen );
112 painter->setBrush( Qt::NoBrush );
113 painter->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
116 painter->setBrush( QColor( 255, 255, 255, 255 ) );
118 painter->drawRect( QRectF( 0, 0, rectHandlerSize, rectHandlerSize ) );
120 painter->drawRect( QRectF( ( rect().width() - rectHandlerSize ) / 2, 0, rectHandlerSize, rectHandlerSize ) );
122 painter->drawRect( QRectF( rect().width() - rectHandlerSize, 0, rectHandlerSize, rectHandlerSize ) );
124 painter->drawRect( QRectF( 0, ( rect().height() - rectHandlerSize ) / 2, rectHandlerSize, rectHandlerSize ) );
126 painter->drawRect( QRectF( rect().width() - rectHandlerSize, ( rect().height() - rectHandlerSize ) / 2, rectHandlerSize, rectHandlerSize ) );
128 painter->drawRect( QRectF( 0, rect().height() - rectHandlerSize, rectHandlerSize, rectHandlerSize ) );
130 painter->drawRect( QRectF( ( rect().width() - rectHandlerSize ) / 2, rect().height() - rectHandlerSize, rectHandlerSize, rectHandlerSize ) );
132 painter->drawRect( QRectF( rect().width() - rectHandlerSize, rect().height() - rectHandlerSize, rectHandlerSize, rectHandlerSize ) );
135void QgsGraphicsViewMouseHandles::drawSelectedItemBounds( QPainter *painter )
138 const QList<QGraphicsItem *> selectedItems = selectedSceneItems(
false );
139 if ( selectedItems.isEmpty() )
146 painter->setCompositionMode( QPainter::CompositionMode_Difference );
149 QPen selectedItemPen = QPen( QColor( 144, 144, 144, 255 ) );
150 selectedItemPen.setStyle( Qt::DashLine );
151 selectedItemPen.setWidth( 0 );
152 painter->setPen( selectedItemPen );
153 painter->setBrush( Qt::NoBrush );
155 QList< QGraphicsItem * > itemsToDraw;
156 expandItemList( selectedItems, itemsToDraw );
158 for ( QGraphicsItem *item : std::as_const( itemsToDraw ) )
161 QPolygonF itemBounds;
162 if ( isDragging() && !itemIsLocked( item ) )
166 QPolygonF itemSceneBounds = item->mapToScene( itemRect( item ) );
169 itemSceneBounds.translate( transform().dx(), transform().dy() );
171 itemBounds = mapFromScene( itemSceneBounds );
173 else if ( isResizing() && !itemIsLocked( item ) )
176 if ( selectedItems.size() > 1 )
179 QRectF thisItemRect = mapRectFromItem( item, itemRect( item ) );
181 relativeResizeRect( thisItemRect, QRectF( -mResizeMoveX, -mResizeMoveY, mBeginHandleWidth, mBeginHandleHeight ), mResizeRect );
182 itemBounds = QPolygonF( thisItemRect );
193 itemBounds = mapRectFromItem( item, itemRect( item ) );
199 path.addPolygon( itemBounds );
200 painter->drawPath( path );
204double QgsGraphicsViewMouseHandles::rectHandlerBorderTolerance()
211 double viewScaleFactor = mView->transform().m11();
214 double rectHandlerSize = mHandleSize / viewScaleFactor;
217 if ( rectHandlerSize > ( rect().width() / 3 ) )
219 rectHandlerSize = rect().width() / 3;
221 if ( rectHandlerSize > ( rect().height() / 3 ) )
223 rectHandlerSize = rect().height() / 3;
225 return rectHandlerSize;
228Qt::CursorShape QgsGraphicsViewMouseHandles::cursorForPosition( QPointF itemCoordPos )
230 QgsGraphicsViewMouseHandles::MouseAction mouseAction = mouseActionForPosition( itemCoordPos );
231 switch ( mouseAction )
234 return Qt::ForbiddenCursor;
236 return Qt::SizeAllCursor;
240 if ( ( rotation() <= 22.5 || rotation() >= 337.5 ) || ( rotation() >= 157.5 && rotation() <= 202.5 ) )
242 return Qt::SizeVerCursor;
244 else if ( ( rotation() >= 22.5 && rotation() <= 67.5 ) || ( rotation() >= 202.5 && rotation() <= 247.5 ) )
246 return Qt::SizeBDiagCursor;
248 else if ( ( rotation() >= 67.5 && rotation() <= 112.5 ) || ( rotation() >= 247.5 && rotation() <= 292.5 ) )
250 return Qt::SizeHorCursor;
254 return Qt::SizeFDiagCursor;
259 if ( ( rotation() <= 22.5 || rotation() >= 337.5 ) || ( rotation() >= 157.5 && rotation() <= 202.5 ) )
261 return Qt::SizeHorCursor;
263 else if ( ( rotation() >= 22.5 && rotation() <= 67.5 ) || ( rotation() >= 202.5 && rotation() <= 247.5 ) )
265 return Qt::SizeFDiagCursor;
267 else if ( ( rotation() >= 67.5 && rotation() <= 112.5 ) || ( rotation() >= 247.5 && rotation() <= 292.5 ) )
269 return Qt::SizeVerCursor;
273 return Qt::SizeBDiagCursor;
277 case ResizeRightDown:
279 if ( ( rotation() <= 22.5 || rotation() >= 337.5 ) || ( rotation() >= 157.5 && rotation() <= 202.5 ) )
281 return Qt::SizeFDiagCursor;
283 else if ( ( rotation() >= 22.5 && rotation() <= 67.5 ) || ( rotation() >= 202.5 && rotation() <= 247.5 ) )
285 return Qt::SizeVerCursor;
287 else if ( ( rotation() >= 67.5 && rotation() <= 112.5 ) || ( rotation() >= 247.5 && rotation() <= 292.5 ) )
289 return Qt::SizeBDiagCursor;
293 return Qt::SizeHorCursor;
298 if ( ( rotation() <= 22.5 || rotation() >= 337.5 ) || ( rotation() >= 157.5 && rotation() <= 202.5 ) )
300 return Qt::SizeBDiagCursor;
302 else if ( ( rotation() >= 22.5 && rotation() <= 67.5 ) || ( rotation() >= 202.5 && rotation() <= 247.5 ) )
304 return Qt::SizeHorCursor;
306 else if ( ( rotation() >= 67.5 && rotation() <= 112.5 ) || ( rotation() >= 247.5 && rotation() <= 292.5 ) )
308 return Qt::SizeFDiagCursor;
312 return Qt::SizeVerCursor;
315 return Qt::ArrowCursor;
318 return Qt::ArrowCursor;
321QgsGraphicsViewMouseHandles::MouseAction QgsGraphicsViewMouseHandles::mouseActionForPosition( QPointF itemCoordPos )
323 bool nearLeftBorder =
false;
324 bool nearRightBorder =
false;
325 bool nearLowerBorder =
false;
326 bool nearUpperBorder =
false;
328 bool withinWidth =
false;
329 bool withinHeight =
false;
330 if ( itemCoordPos.x() >= 0 && itemCoordPos.x() <= rect().width() )
334 if ( itemCoordPos.y() >= 0 && itemCoordPos.y() <= rect().height() )
339 double borderTolerance = rectHandlerBorderTolerance();
341 if ( itemCoordPos.x() >= 0 && itemCoordPos.x() < borderTolerance )
343 nearLeftBorder =
true;
345 if ( itemCoordPos.y() >= 0 && itemCoordPos.y() < borderTolerance )
347 nearUpperBorder =
true;
349 if ( itemCoordPos.x() <= rect().width() && itemCoordPos.x() > ( rect().width() - borderTolerance ) )
351 nearRightBorder =
true;
353 if ( itemCoordPos.y() <= rect().height() && itemCoordPos.y() > ( rect().height() - borderTolerance ) )
355 nearLowerBorder =
true;
358 if ( nearLeftBorder && nearUpperBorder )
360 return QgsGraphicsViewMouseHandles::ResizeLeftUp;
362 else if ( nearLeftBorder && nearLowerBorder )
364 return QgsGraphicsViewMouseHandles::ResizeLeftDown;
366 else if ( nearRightBorder && nearUpperBorder )
368 return QgsGraphicsViewMouseHandles::ResizeRightUp;
370 else if ( nearRightBorder && nearLowerBorder )
372 return QgsGraphicsViewMouseHandles::ResizeRightDown;
374 else if ( nearLeftBorder && withinHeight )
376 return QgsGraphicsViewMouseHandles::ResizeLeft;
378 else if ( nearRightBorder && withinHeight )
380 return QgsGraphicsViewMouseHandles::ResizeRight;
382 else if ( nearUpperBorder && withinWidth )
384 return QgsGraphicsViewMouseHandles::ResizeUp;
386 else if ( nearLowerBorder && withinWidth )
388 return QgsGraphicsViewMouseHandles::ResizeDown;
392 QPointF scenePoint = mapToScene( itemCoordPos );
393 const QList<QGraphicsItem *> itemsAtCursorPos = sceneItemsAtPoint( scenePoint );
394 if ( itemsAtCursorPos.isEmpty() )
397 return QgsGraphicsViewMouseHandles::SelectItem;
399 for ( QGraphicsItem *graphicsItem : itemsAtCursorPos )
401 if ( graphicsItem && graphicsItem->isSelected() )
404 return QgsGraphicsViewMouseHandles::MoveItem;
409 return QgsGraphicsViewMouseHandles::SelectItem;
412QgsGraphicsViewMouseHandles::MouseAction QgsGraphicsViewMouseHandles::mouseActionForScenePos( QPointF sceneCoordPos )
415 QPointF itemPos = mapFromScene( sceneCoordPos );
416 return mouseActionForPosition( itemPos );
419bool QgsGraphicsViewMouseHandles::shouldBlockEvent( QInputEvent * )
const
421 return mIsDragging || mIsResizing;
424void QgsGraphicsViewMouseHandles::selectedItemSizeChanged()
426 if ( !isDragging() && !isResizing() )
433void QgsGraphicsViewMouseHandles::selectedItemRotationChanged()
435 if ( !isDragging() && !isResizing() )
442void QgsGraphicsViewMouseHandles::hoverMoveEvent( QGraphicsSceneHoverEvent *event )
444 setViewportCursor( cursorForPosition( event->pos() ) );
447void QgsGraphicsViewMouseHandles::hoverLeaveEvent( QGraphicsSceneHoverEvent *event )
450 setViewportCursor( Qt::ArrowCursor );
453void QgsGraphicsViewMouseHandles::mousePressEvent( QGraphicsSceneMouseEvent *event )
455 if ( event->button() != Qt::LeftButton )
462 mMouseMoveStartPos =
event->lastScenePos();
463 mLastMouseEventPos =
event->lastScenePos();
465 mBeginMouseEventPos =
event->lastScenePos();
466 mBeginHandlePos = scenePos();
467 mBeginHandleWidth = rect().width();
468 mBeginHandleHeight = rect().height();
470 mCurrentMouseMoveAction = mouseActionForPosition( event->pos() );
474 if ( mCurrentMouseMoveAction == MoveItem )
479 else if ( mCurrentMouseMoveAction != SelectItem &&
480 mCurrentMouseMoveAction != NoAction )
484 mResizeRect = QRectF( 0, 0, mBeginHandleWidth, mBeginHandleHeight );
487 mCursorOffset = calcCursorEdgeOffset( mMouseMoveStartPos );
492void QgsGraphicsViewMouseHandles::resetStatusBar()
494 const QList<QGraphicsItem *> selectedItems = selectedSceneItems(
false );
495 int selectedCount = selectedItems.size();
499 showStatusMessage( tr(
"%n item(s) selected",
nullptr, selectedCount ) );
504 showStatusMessage( QString() );
508void QgsGraphicsViewMouseHandles::mouseMoveEvent( QGraphicsSceneMouseEvent *event )
515 dragMouseMove( event->lastScenePos(), event->modifiers() & Qt::ShiftModifier, event->modifiers() & Qt::ControlModifier );
517 else if ( isResizing() )
522 resizeMouseMove( event->lastScenePos(), event->modifiers() & Qt::ShiftModifier, event->modifiers() & Qt::AltModifier );
525 mLastMouseEventPos =
event->lastScenePos();
528void QgsGraphicsViewMouseHandles::mouseReleaseEvent( QGraphicsSceneMouseEvent *event )
530 if ( event->button() != Qt::LeftButton )
536 QPointF mouseMoveStopPoint =
event->lastScenePos();
537 double diffX = mouseMoveStopPoint.x() - mMouseMoveStartPos.x();
538 double diffY = mouseMoveStopPoint.y() - mMouseMoveStartPos.y();
541 if ( std::fabs( diffX ) < std::numeric_limits<double>::min() && std::fabs( diffY ) < std::numeric_limits<double>::min() )
550 if ( mCurrentMouseMoveAction == MoveItem )
553 startMacroCommand( tr(
"Move Items" ) );
555 QPointF mEndHandleMovePos = scenePos();
557 double deltaX = mEndHandleMovePos.x() - mBeginHandlePos.x();
558 double deltaY = mEndHandleMovePos.y() - mBeginHandlePos.y();
561 const QList<QGraphicsItem *> selectedItems = selectedSceneItems(
false );
562 for ( QGraphicsItem *item : selectedItems )
564 if ( itemIsLocked( item ) || ( item->flags() & QGraphicsItem::ItemIsSelectable ) == 0 || itemIsGroupMember( item ) )
570 createItemCommand( item );
571 moveItem( item, deltaX, deltaY );
572 endItemCommand( item );
576 else if ( mCurrentMouseMoveAction != NoAction )
579 startMacroCommand( tr(
"Resize Items" ) );
582 const QList<QGraphicsItem *> selectedItems = selectedSceneItems(
false );
583 for ( QGraphicsItem *item : selectedItems )
585 if ( itemIsLocked( item ) || ( item->flags() & QGraphicsItem::ItemIsSelectable ) == 0 )
590 createItemCommand( item );
593 if ( selectedItems.size() == 1 )
596 thisItemRect = mResizeRect;
601 thisItemRect = mapRectFromItem( item, itemRect( item ) );
602 relativeResizeRect( thisItemRect, QRectF( -mResizeMoveX, -mResizeMoveY, mBeginHandleWidth, mBeginHandleHeight ), mResizeRect );
605 thisItemRect = thisItemRect.normalized();
606 QPointF newPos = mapToScene( thisItemRect.topLeft() );
607 thisItemRect.moveTopLeft( newPos );
608 setItemRect( item, thisItemRect );
610 endItemCommand( item );
626 mCurrentMouseMoveAction = MoveItem;
627 setViewportCursor( Qt::ArrowCursor );
635bool QgsGraphicsViewMouseHandles::selectionRotation(
double &rotation )
const
638 QList<QGraphicsItem *> selectedItems = selectedSceneItems(
false );
639 auto itemIter = selectedItems.constBegin();
642 double firstItemRotation = ( *itemIter )->rotation();
645 for ( ++itemIter; itemIter != selectedItems.constEnd(); ++itemIter )
647 if ( !
qgsDoubleNear( ( *itemIter )->rotation(), firstItemRotation ) )
655 rotation = firstItemRotation;
659void QgsGraphicsViewMouseHandles::updateHandles()
664 QList<QGraphicsItem *> selectedItems = selectedSceneItems(
false );
665 if ( !selectedItems.isEmpty() )
671 if ( selectionRotation( rotation ) )
674 setRotation( rotation );
683 QRectF newHandleBounds = selectionBounds();
686 setRect( 0, 0, newHandleBounds.width(), newHandleBounds.height() );
687 setPos( mapToScene( newHandleBounds.topLeft() ) );
700void QgsGraphicsViewMouseHandles::dragMouseMove( QPointF currentPosition,
bool lockMovement,
bool preventSnap )
708 double moveX = currentPosition.x() - mBeginMouseEventPos.x();
709 double moveY = currentPosition.y() - mBeginMouseEventPos.y();
712 QPointF upperLeftPoint( mBeginHandlePos.x() + moveX, mBeginHandlePos.y() + moveY );
714 QPointF snappedLeftPoint;
720 snappedLeftPoint = snapPoint( upperLeftPoint, Item );
725 snappedLeftPoint = upperLeftPoint;
730 double moveRectX = snappedLeftPoint.x() - mBeginHandlePos.x();
731 double moveRectY = snappedLeftPoint.y() - mBeginHandlePos.y();
737 if ( std::fabs( moveRectX ) <= std::fabs( moveRectY ) )
748 QTransform moveTransform;
749 moveTransform.translate( moveRectX, moveRectY );
750 setTransform( moveTransform );
752 const QList<QGraphicsItem *> selectedItems = selectedSceneItems(
false );
753 for ( QGraphicsItem *item : selectedItems )
755 previewItemMove( item, moveRectX, moveRectY );
758 showStatusMessage( tr(
"dx: %1 mm dy: %2 mm" ).arg( moveRectX ).arg( moveRectY ) );
761void QgsGraphicsViewMouseHandles::resizeMouseMove( QPointF currentPosition,
bool lockRatio,
bool fromCenter )
768 double mx = 0.0, my = 0.0, rx = 0.0, ry = 0.0;
770 QPointF beginMousePos;
771 QPointF finalPosition;
776 bool snapVertical = mCurrentMouseMoveAction == ResizeLeft ||
777 mCurrentMouseMoveAction == ResizeRight ||
778 mCurrentMouseMoveAction == ResizeLeftUp ||
779 mCurrentMouseMoveAction == ResizeRightUp ||
780 mCurrentMouseMoveAction == ResizeLeftDown ||
781 mCurrentMouseMoveAction == ResizeRightDown;
783 bool snapHorizontal = mCurrentMouseMoveAction == ResizeUp ||
784 mCurrentMouseMoveAction == ResizeDown ||
785 mCurrentMouseMoveAction == ResizeLeftUp ||
786 mCurrentMouseMoveAction == ResizeRightUp ||
787 mCurrentMouseMoveAction == ResizeLeftDown ||
788 mCurrentMouseMoveAction == ResizeRightDown;
792 beginMousePos = mapFromScene( QPointF( mBeginMouseEventPos.x() - mCursorOffset.width(), mBeginMouseEventPos.y() - mCursorOffset.height() ) );
793 QPointF snappedPosition = snapPoint( QPointF( currentPosition.x() - mCursorOffset.width(), currentPosition.y() - mCursorOffset.height() ), Point, snapHorizontal, snapVertical );
794 finalPosition = mapFromScene( snappedPosition );
799 beginMousePos = mapFromScene( mBeginMouseEventPos );
800 finalPosition = mapFromScene( currentPosition );
803 double diffX = finalPosition.x() - beginMousePos.x();
804 double diffY = finalPosition.y() - beginMousePos.y();
807 if ( lockRatio && !
qgsDoubleNear( mBeginHandleHeight, 0.0 ) )
809 ratio = mBeginHandleWidth / mBeginHandleHeight;
812 switch ( mCurrentMouseMoveAction )
819 diffX = ( ( mBeginHandleHeight - diffY ) * ratio ) - mBeginHandleWidth;
839 diffX = ( ( mBeginHandleHeight + diffY ) * ratio ) - mBeginHandleWidth;
860 diffY = ( ( mBeginHandleWidth - diffX ) / ratio ) - mBeginHandleHeight;
879 diffY = ( ( mBeginHandleWidth + diffX ) / ratio ) - mBeginHandleHeight;
900 if ( ( mBeginHandleWidth - diffX ) / ( mBeginHandleHeight - diffY ) > ratio )
902 diffX = mBeginHandleWidth - ( ( mBeginHandleHeight - diffY ) * ratio );
906 diffY = mBeginHandleHeight - ( ( mBeginHandleWidth - diffX ) / ratio );
909 mx = diffX, my = diffY;
915 case ResizeRightDown:
920 if ( ( mBeginHandleWidth + diffX ) / ( mBeginHandleHeight + diffY ) > ratio )
922 diffX = ( ( mBeginHandleHeight + diffY ) * ratio ) - mBeginHandleWidth;
926 diffY = ( ( mBeginHandleWidth + diffX ) / ratio ) - mBeginHandleHeight;
931 rx = diffX, ry = diffY;
940 if ( ( mBeginHandleWidth + diffX ) / ( mBeginHandleHeight - diffY ) > ratio )
942 diffX = ( ( mBeginHandleHeight - diffY ) * ratio ) - mBeginHandleWidth;
946 diffY = mBeginHandleHeight - ( ( mBeginHandleWidth + diffX ) / ratio );
950 my = diffY, rx = diffX, ry = -diffY;
959 if ( ( mBeginHandleWidth - diffX ) / ( mBeginHandleHeight + diffY ) > ratio )
961 diffX = mBeginHandleWidth - ( ( mBeginHandleHeight + diffY ) * ratio );
965 diffY = ( ( mBeginHandleWidth - diffX ) / ratio ) - mBeginHandleHeight;
992 mResizeMoveX = mBeginHandleWidth + rx > 0 ? mx : mx + mBeginHandleWidth + rx;
993 mResizeMoveY = mBeginHandleHeight + ry > 0 ? my : my + mBeginHandleHeight + ry;
996 QLineF translateLine = QLineF( 0, 0, mResizeMoveX, mResizeMoveY );
997 translateLine.setAngle( translateLine.angle() - rotation() );
998 QPointF sceneTranslate = translateLine.p2();
1001 QTransform itemTransform;
1002 itemTransform.translate( sceneTranslate.x(), sceneTranslate.y() );
1003 setTransform( itemTransform );
1006 if ( mBeginHandleWidth + rx >= 0 && mBeginHandleHeight + ry >= 0 )
1008 mResizeRect = QRectF( 0, 0, mBeginHandleWidth + rx, mBeginHandleHeight + ry );
1010 else if ( mBeginHandleHeight + ry >= 0 )
1012 mResizeRect = QRectF( QPointF( -( mBeginHandleWidth + rx ), 0 ), QPointF( 0, mBeginHandleHeight + ry ) );
1014 else if ( mBeginHandleWidth + rx >= 0 )
1016 mResizeRect = QRectF( QPointF( 0, -( mBeginHandleHeight + ry ) ), QPointF( mBeginHandleWidth + rx, 0 ) );
1020 mResizeRect = QRectF( QPointF( -( mBeginHandleWidth + rx ), -( mBeginHandleHeight + ry ) ), QPointF( 0, 0 ) );
1023 const QList<QGraphicsItem *> selectedItems = selectedSceneItems(
false );
1024 QRectF newHandleBounds;
1025 for ( QGraphicsItem *item : selectedItems )
1028 QRectF thisItemRect = mapRectFromScene( storedItemRect( item ) );
1030 relativeResizeRect( thisItemRect, QRectF( -mResizeMoveX, -mResizeMoveY, mBeginHandleWidth, mBeginHandleHeight ), mResizeRect );
1032 thisItemRect = mapRectFromScene( previewSetItemRect( item, mapRectToScene( thisItemRect ) ) );
1033 newHandleBounds = newHandleBounds.isValid() ? newHandleBounds.united( thisItemRect ) : thisItemRect;
1036 setRect( newHandleBounds.isValid() ? newHandleBounds : QRectF( 0, 0, std::fabs( mBeginHandleWidth + rx ), std::fabs( mBeginHandleHeight + ry ) ) );
1039 showStatusMessage( tr(
"width: %1 mm height: %2 mm" ).arg( rect().width() ).arg( rect().height() ) );
1043void QgsGraphicsViewMouseHandles::setHandleSize(
double size )
1048void QgsGraphicsViewMouseHandles::mouseDoubleClickEvent( QGraphicsSceneMouseEvent *event )
1053QSizeF QgsGraphicsViewMouseHandles::calcCursorEdgeOffset( QPointF cursorPos )
1056 QPointF sceneMousePos = mapFromScene( cursorPos );
1058 switch ( mCurrentMouseMoveAction )
1061 case QgsGraphicsViewMouseHandles::ResizeUp:
1062 return QSizeF( 0, sceneMousePos.y() );
1064 case QgsGraphicsViewMouseHandles::ResizeDown:
1065 return QSizeF( 0, sceneMousePos.y() - rect().height() );
1068 case QgsGraphicsViewMouseHandles::ResizeLeft:
1069 return QSizeF( sceneMousePos.x(), 0 );
1071 case QgsGraphicsViewMouseHandles::ResizeRight:
1072 return QSizeF( sceneMousePos.x() - rect().width(), 0 );
1075 case QgsGraphicsViewMouseHandles::ResizeLeftUp:
1076 return QSizeF( sceneMousePos.x(), sceneMousePos.y() );
1078 case QgsGraphicsViewMouseHandles::ResizeRightDown:
1079 return QSizeF( sceneMousePos.x() - rect().width(), sceneMousePos.y() - rect().height() );
1081 case QgsGraphicsViewMouseHandles::ResizeRightUp:
1082 return QSizeF( sceneMousePos.x() - rect().width(), sceneMousePos.y() );
1084 case QgsGraphicsViewMouseHandles::ResizeLeftDown:
1085 return QSizeF( sceneMousePos.x(), sceneMousePos.y() - rect().height() );
1096QRectF QgsGraphicsViewMouseHandles::selectionBounds()
const
1099 const QList<QGraphicsItem *> selectedItems = selectedSceneItems(
false );
1100 auto itemIter = selectedItems.constBegin();
1103 QRectF bounds = mapFromItem( ( *itemIter ), itemRect( *itemIter ) ).boundingRect();
1106 for ( ++itemIter; itemIter != selectedItems.constEnd(); ++itemIter )
1108 bounds = bounds.united( mapFromItem( ( *itemIter ), itemRect( *itemIter ) ).boundingRect() );
1114void QgsGraphicsViewMouseHandles::relativeResizeRect( QRectF &rectToResize,
const QRectF &boundsBefore,
const QRectF &boundsAfter )
1117 double left = relativePosition( rectToResize.left(), boundsBefore.left(), boundsBefore.right(), boundsAfter.left(), boundsAfter.right() );
1118 double right = relativePosition( rectToResize.right(), boundsBefore.left(), boundsBefore.right(), boundsAfter.left(), boundsAfter.right() );
1119 double top = relativePosition( rectToResize.top(), boundsBefore.top(), boundsBefore.bottom(), boundsAfter.top(), boundsAfter.bottom() );
1120 double bottom = relativePosition( rectToResize.bottom(), boundsBefore.top(), boundsBefore.bottom(), boundsAfter.top(), boundsAfter.bottom() );
1122 rectToResize.setRect( left, top, right - left, bottom - top );
1125double QgsGraphicsViewMouseHandles::relativePosition(
double position,
double beforeMin,
double beforeMax,
double afterMin,
double afterMax )
1128 double m = ( afterMax - afterMin ) / ( beforeMax - beforeMin );
1129 double c = afterMin - ( beforeMin * m );
1132 return m * position +
c;
Scoped object for saving and restoring a QPainter object's state.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)