19#include "moc_qgsgraphicsviewmousehandles.cpp"
22#include <QGraphicsView>
23#include <QGraphicsSceneHoverEvent>
30QgsGraphicsViewMouseHandles::QgsGraphicsViewMouseHandles( QGraphicsView *view )
32 , QGraphicsRectItem( nullptr )
36 setAcceptHoverEvents(
true );
39void QgsGraphicsViewMouseHandles::paintInternal( QPainter *painter,
bool showHandles,
bool showStaticBoundingBoxes,
bool showTemporaryBoundingBoxes,
const QStyleOptionGraphicsItem *, QWidget * )
46 if ( showStaticBoundingBoxes )
49 double rectHandlerSize = rectHandlerBorderTolerance();
50 drawHandles( painter, rectHandlerSize );
53 if ( showTemporaryBoundingBoxes && ( mIsResizing || mIsDragging || showStaticBoundingBoxes ) )
56 drawSelectedItemBounds( painter );
60QRectF QgsGraphicsViewMouseHandles::storedItemRect( QGraphicsItem *item )
const
62 return itemRect( item );
65void QgsGraphicsViewMouseHandles::previewItemMove( QGraphicsItem *,
double,
double )
69QRectF QgsGraphicsViewMouseHandles::previewSetItemRect( QGraphicsItem *, QRectF )
74void QgsGraphicsViewMouseHandles::startMacroCommand(
const QString & )
78void QgsGraphicsViewMouseHandles::endMacroCommand()
82void QgsGraphicsViewMouseHandles::endItemCommand( QGraphicsItem * )
86void QgsGraphicsViewMouseHandles::createItemCommand( QGraphicsItem * )
90QPointF QgsGraphicsViewMouseHandles::snapPoint( QPointF originalPoint, QgsGraphicsViewMouseHandles::SnapGuideMode,
bool,
bool )
95void QgsGraphicsViewMouseHandles::expandItemList(
const QList<QGraphicsItem *> &items, QList<QGraphicsItem *> &collected )
const
100void QgsGraphicsViewMouseHandles::drawHandles( QPainter *painter,
double rectHandlerSize )
103 QPen handlePen = QPen( QColor( 55, 140, 195, 255 ) );
104 handlePen.setWidth( 0 );
105 painter->setPen( handlePen );
108 painter->setBrush( Qt::NoBrush );
109 painter->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
112 painter->setBrush( QColor( 255, 255, 255, 255 ) );
114 painter->drawRect( QRectF( 0, 0, rectHandlerSize, rectHandlerSize ) );
116 painter->drawRect( QRectF( ( rect().width() - rectHandlerSize ) / 2, 0, rectHandlerSize, rectHandlerSize ) );
118 painter->drawRect( QRectF( rect().width() - rectHandlerSize, 0, rectHandlerSize, rectHandlerSize ) );
120 painter->drawRect( QRectF( 0, ( rect().height() - rectHandlerSize ) / 2, rectHandlerSize, rectHandlerSize ) );
122 painter->drawRect( QRectF( rect().width() - rectHandlerSize, ( rect().height() - rectHandlerSize ) / 2, rectHandlerSize, rectHandlerSize ) );
124 painter->drawRect( QRectF( 0, rect().height() - rectHandlerSize, rectHandlerSize, rectHandlerSize ) );
126 painter->drawRect( QRectF( ( rect().width() - rectHandlerSize ) / 2, rect().height() - rectHandlerSize, rectHandlerSize, rectHandlerSize ) );
128 painter->drawRect( QRectF( rect().width() - rectHandlerSize, rect().height() - rectHandlerSize, rectHandlerSize, rectHandlerSize ) );
131void QgsGraphicsViewMouseHandles::drawSelectedItemBounds( QPainter *painter )
134 const QList<QGraphicsItem *> selectedItems = selectedSceneItems(
false );
135 if ( selectedItems.isEmpty() )
140 QList<QGraphicsItem *> itemsToDraw;
141 expandItemList( selectedItems, itemsToDraw );
143 if ( itemsToDraw.size() <= 1 )
151 painter->setCompositionMode( QPainter::CompositionMode_Difference );
154 QPen selectedItemPen = QPen( QColor( 144, 144, 144, 255 ) );
155 selectedItemPen.setStyle( Qt::DashLine );
156 selectedItemPen.setWidth( 0 );
157 painter->setPen( selectedItemPen );
158 painter->setBrush( Qt::NoBrush );
160 for ( QGraphicsItem *item : std::as_const( itemsToDraw ) )
163 QPolygonF itemBounds;
164 if ( isDragging() && !itemIsLocked( item ) )
168 QPolygonF itemSceneBounds = item->mapToScene( itemRect( item ) );
171 itemSceneBounds.translate( transform().dx(), transform().dy() );
173 itemBounds = mapFromScene( itemSceneBounds );
175 else if ( isResizing() && !itemIsLocked( item ) )
179 QRectF thisItemRect = mapRectFromItem( item, itemRect( item ) );
181 relativeResizeRect( thisItemRect, QRectF( -mResizeMoveX, -mResizeMoveY, mBeginHandleWidth, mBeginHandleHeight ), mResizeRect );
182 itemBounds = QPolygonF( thisItemRect );
187 itemBounds = item->mapToItem(
this, itemRect( item ) );
193 path.addPolygon( itemBounds );
194 painter->drawPath( path );
198double QgsGraphicsViewMouseHandles::rectHandlerBorderTolerance()
205 double viewScaleFactor = mView->transform().m11();
208 double rectHandlerSize = mHandleSize / viewScaleFactor;
211 if ( rectHandlerSize > ( rect().width() / 3 ) )
213 rectHandlerSize = rect().width() / 3;
215 if ( rectHandlerSize > ( rect().height() / 3 ) )
217 rectHandlerSize = rect().height() / 3;
219 return rectHandlerSize;
222Qt::CursorShape QgsGraphicsViewMouseHandles::cursorForPosition( QPointF itemCoordPos )
225 double normalizedRotation = std::fmod( rotation(), 360 );
226 if ( normalizedRotation < 0 )
228 normalizedRotation += 360;
230 switch ( mouseAction )
233 return Qt::ForbiddenCursor;
235 return Qt::SizeAllCursor;
239 if ( ( normalizedRotation <= 22.5 || normalizedRotation >= 337.5 ) || ( normalizedRotation >= 157.5 && normalizedRotation <= 202.5 ) )
241 return Qt::SizeVerCursor;
243 else if ( ( normalizedRotation >= 22.5 && normalizedRotation <= 67.5 ) || ( normalizedRotation >= 202.5 && normalizedRotation <= 247.5 ) )
245 return Qt::SizeBDiagCursor;
247 else if ( ( normalizedRotation >= 67.5 && normalizedRotation <= 112.5 ) || ( normalizedRotation >= 247.5 && normalizedRotation <= 292.5 ) )
249 return Qt::SizeHorCursor;
253 return Qt::SizeFDiagCursor;
258 if ( ( normalizedRotation <= 22.5 || normalizedRotation >= 337.5 ) || ( normalizedRotation >= 157.5 && normalizedRotation <= 202.5 ) )
260 return Qt::SizeHorCursor;
262 else if ( ( normalizedRotation >= 22.5 && normalizedRotation <= 67.5 ) || ( normalizedRotation >= 202.5 && normalizedRotation <= 247.5 ) )
264 return Qt::SizeFDiagCursor;
266 else if ( ( normalizedRotation >= 67.5 && normalizedRotation <= 112.5 ) || ( normalizedRotation >= 247.5 && normalizedRotation <= 292.5 ) )
268 return Qt::SizeVerCursor;
272 return Qt::SizeBDiagCursor;
278 if ( ( normalizedRotation <= 22.5 || normalizedRotation >= 337.5 ) || ( normalizedRotation >= 157.5 && normalizedRotation <= 202.5 ) )
280 return Qt::SizeFDiagCursor;
282 else if ( ( normalizedRotation >= 22.5 && normalizedRotation <= 67.5 ) || ( normalizedRotation >= 202.5 && normalizedRotation <= 247.5 ) )
284 return Qt::SizeVerCursor;
286 else if ( ( normalizedRotation >= 67.5 && normalizedRotation <= 112.5 ) || ( normalizedRotation >= 247.5 && normalizedRotation <= 292.5 ) )
288 return Qt::SizeBDiagCursor;
292 return Qt::SizeHorCursor;
297 if ( ( normalizedRotation <= 22.5 || normalizedRotation >= 337.5 ) || ( normalizedRotation >= 157.5 && normalizedRotation <= 202.5 ) )
299 return Qt::SizeBDiagCursor;
301 else if ( ( normalizedRotation >= 22.5 && normalizedRotation <= 67.5 ) || ( normalizedRotation >= 202.5 && normalizedRotation <= 247.5 ) )
303 return Qt::SizeHorCursor;
305 else if ( ( normalizedRotation >= 67.5 && normalizedRotation <= 112.5 ) || ( normalizedRotation >= 247.5 && normalizedRotation <= 292.5 ) )
307 return Qt::SizeFDiagCursor;
311 return Qt::SizeVerCursor;
314 return Qt::ArrowCursor;
317 return Qt::ArrowCursor;
322 bool nearLeftBorder =
false;
323 bool nearRightBorder =
false;
324 bool nearLowerBorder =
false;
325 bool nearUpperBorder =
false;
327 bool withinWidth =
false;
328 bool withinHeight =
false;
329 if ( itemCoordPos.x() >= 0 && itemCoordPos.x() <= rect().width() )
333 if ( itemCoordPos.y() >= 0 && itemCoordPos.y() <= rect().height() )
338 double borderTolerance = rectHandlerBorderTolerance();
340 if ( itemCoordPos.x() >= 0 && itemCoordPos.x() < borderTolerance )
342 nearLeftBorder =
true;
344 if ( itemCoordPos.y() >= 0 && itemCoordPos.y() < borderTolerance )
346 nearUpperBorder =
true;
348 if ( itemCoordPos.x() <= rect().width() && itemCoordPos.x() > ( rect().width() - borderTolerance ) )
350 nearRightBorder =
true;
352 if ( itemCoordPos.y() <= rect().height() && itemCoordPos.y() > ( rect().height() - borderTolerance ) )
354 nearLowerBorder =
true;
357 if ( nearLeftBorder && nearUpperBorder )
361 else if ( nearLeftBorder && nearLowerBorder )
365 else if ( nearRightBorder && nearUpperBorder )
369 else if ( nearRightBorder && nearLowerBorder )
373 else if ( nearLeftBorder && withinHeight )
377 else if ( nearRightBorder && withinHeight )
381 else if ( nearUpperBorder && withinWidth )
385 else if ( nearLowerBorder && withinWidth )
391 QPointF scenePoint = mapToScene( itemCoordPos );
392 const QList<QGraphicsItem *> itemsAtCursorPos = sceneItemsAtPoint( scenePoint );
393 if ( itemsAtCursorPos.isEmpty() )
398 for ( QGraphicsItem *graphicsItem : itemsAtCursorPos )
400 if ( graphicsItem && graphicsItem->isSelected() )
414 QPointF itemPos = mapFromScene( sceneCoordPos );
415 return mouseActionForPosition( itemPos );
418bool QgsGraphicsViewMouseHandles::shouldBlockEvent( QInputEvent * )
const
420 return mIsDragging || mIsResizing;
423void QgsGraphicsViewMouseHandles::startMove( QPointF sceneCoordPos )
426 mMouseMoveStartPos = sceneCoordPos;
428 mBeginMouseEventPos = sceneCoordPos;
429 mBeginHandlePos = scenePos();
430 mBeginHandleWidth = rect().width();
431 mBeginHandleHeight = rect().height();
437 if ( mView->scene()->mouseGrabberItem() !=
this )
443void QgsGraphicsViewMouseHandles::selectedItemSizeChanged()
445 if ( !isDragging() && !isResizing() )
452void QgsGraphicsViewMouseHandles::selectedItemRotationChanged()
454 if ( !isDragging() && !isResizing() )
461void QgsGraphicsViewMouseHandles::hoverMoveEvent( QGraphicsSceneHoverEvent *event )
463 setViewportCursor( cursorForPosition( event->pos() ) );
466void QgsGraphicsViewMouseHandles::hoverLeaveEvent( QGraphicsSceneHoverEvent *event )
469 setViewportCursor( Qt::ArrowCursor );
472void QgsGraphicsViewMouseHandles::mousePressEvent( QGraphicsSceneMouseEvent *event )
474 if ( event->button() != Qt::LeftButton )
481 mMouseMoveStartPos =
event->lastScenePos();
483 mBeginMouseEventPos =
event->lastScenePos();
484 mBeginHandlePos = scenePos();
485 mBeginHandleWidth = rect().width();
486 mBeginHandleHeight = rect().height();
488 mCurrentMouseMoveAction = mouseActionForPosition( event->pos() );
501 mResizeRect = QRectF( 0, 0, mBeginHandleWidth, mBeginHandleHeight );
504 mCursorOffset = calcCursorEdgeOffset( mMouseMoveStartPos );
508void QgsGraphicsViewMouseHandles::resetStatusBar()
510 const QList<QGraphicsItem *> selectedItems = selectedSceneItems(
false );
511 int selectedCount = selectedItems.size();
515 showStatusMessage( tr(
"%n item(s) selected",
nullptr, selectedCount ) );
520 showStatusMessage( QString() );
524void QgsGraphicsViewMouseHandles::mouseMoveEvent( QGraphicsSceneMouseEvent *event )
531 dragMouseMove( event->lastScenePos(), event->modifiers() & Qt::ShiftModifier, event->modifiers() & Qt::ControlModifier );
533 else if ( isResizing() )
538 resizeMouseMove( event->lastScenePos(), event->modifiers() & Qt::ShiftModifier, event->modifiers() & Qt::AltModifier );
542void QgsGraphicsViewMouseHandles::mouseReleaseEvent( QGraphicsSceneMouseEvent *event )
544 if ( event->button() != Qt::LeftButton )
550 if ( mDoubleClickInProgress )
552 mDoubleClickInProgress =
false;
561 QPointF mouseMoveStopPoint =
event->lastScenePos();
562 double diffX = mouseMoveStopPoint.x() - mMouseMoveStartPos.x();
563 double diffY = mouseMoveStopPoint.y() - mMouseMoveStartPos.y();
566 if ( std::fabs( diffX ) < std::numeric_limits<double>::min() && std::fabs( diffY ) < std::numeric_limits<double>::min() )
578 startMacroCommand( tr(
"Move Items" ) );
580 QPointF mEndHandleMovePos = scenePos();
582 double deltaX = mEndHandleMovePos.x() - mBeginHandlePos.x();
583 double deltaY = mEndHandleMovePos.y() - mBeginHandlePos.y();
586 const QList<QGraphicsItem *> selectedItems = selectedSceneItems(
false );
587 for ( QGraphicsItem *item : selectedItems )
589 if ( itemIsLocked( item ) || ( item->flags() & QGraphicsItem::ItemIsSelectable ) == 0 || itemIsGroupMember( item ) )
595 createItemCommand( item );
596 moveItem( item, deltaX, deltaY );
597 endItemCommand( item );
604 startMacroCommand( tr(
"Resize Items" ) );
607 const QList<QGraphicsItem *> selectedItems = selectedSceneItems(
false );
608 for ( QGraphicsItem *item : selectedItems )
610 if ( itemIsLocked( item ) || ( item->flags() & QGraphicsItem::ItemIsSelectable ) == 0 )
615 createItemCommand( item );
618 if ( selectedItems.size() == 1 )
621 thisItemRect = mResizeRect;
626 thisItemRect = mapRectFromItem( item, itemRect( item ) );
627 relativeResizeRect( thisItemRect, QRectF( -mResizeMoveX, -mResizeMoveY, mBeginHandleWidth, mBeginHandleHeight ), mResizeRect );
630 thisItemRect = thisItemRect.normalized();
631 QPointF newPos = mapToScene( thisItemRect.topLeft() );
632 thisItemRect.moveTopLeft( newPos );
633 setItemRect( item, thisItemRect );
635 endItemCommand( item );
659bool QgsGraphicsViewMouseHandles::selectionRotation(
double &rotation )
const
662 QList<QGraphicsItem *> selectedItems = selectedSceneItems(
false );
663 auto itemIter = selectedItems.constBegin();
666 double firstItemRotation = ( *itemIter )->rotation();
669 for ( ++itemIter; itemIter != selectedItems.constEnd(); ++itemIter )
671 if ( !
qgsDoubleNear( ( *itemIter )->rotation(), firstItemRotation ) )
679 rotation = firstItemRotation;
683void QgsGraphicsViewMouseHandles::updateHandles()
688 QList<QGraphicsItem *> selectedItems = selectedSceneItems(
false );
689 if ( !selectedItems.isEmpty() )
695 if ( selectionRotation( rotation ) )
698 setRotation( rotation );
707 QRectF newHandleBounds = selectionBounds();
710 setRect( 0, 0, newHandleBounds.width(), newHandleBounds.height() );
711 setPos( mapToScene( newHandleBounds.topLeft() ) );
724void QgsGraphicsViewMouseHandles::dragMouseMove( QPointF currentPosition,
bool lockMovement,
bool preventSnap )
732 double moveX = currentPosition.x() - mBeginMouseEventPos.x();
733 double moveY = currentPosition.y() - mBeginMouseEventPos.y();
736 QPointF upperLeftPoint( mBeginHandlePos.x() + moveX, mBeginHandlePos.y() + moveY );
738 QPointF snappedLeftPoint;
744 snappedLeftPoint = snapPoint( upperLeftPoint, Item );
749 snappedLeftPoint = upperLeftPoint;
754 double moveRectX = snappedLeftPoint.x() - mBeginHandlePos.x();
755 double moveRectY = snappedLeftPoint.y() - mBeginHandlePos.y();
761 if ( std::fabs( moveRectX ) <= std::fabs( moveRectY ) )
772 QTransform moveTransform;
773 moveTransform.translate( moveRectX, moveRectY );
774 setTransform( moveTransform );
776 const QList<QGraphicsItem *> selectedItems = selectedSceneItems(
false );
777 for ( QGraphicsItem *item : selectedItems )
779 previewItemMove( item, moveRectX, moveRectY );
782 showStatusMessage( tr(
"dx: %1 mm dy: %2 mm" ).arg( moveRectX ).arg( moveRectY ) );
785void QgsGraphicsViewMouseHandles::resizeMouseMove( QPointF currentPosition,
bool lockRatio,
bool fromCenter )
792 double mx = 0.0, my = 0.0, rx = 0.0, ry = 0.0;
794 QPointF beginMousePos;
795 QPointF finalPosition;
806 beginMousePos = mapFromScene( QPointF( mBeginMouseEventPos.x() - mCursorOffset.width(), mBeginMouseEventPos.y() - mCursorOffset.height() ) );
807 QPointF snappedPosition = snapPoint( QPointF( currentPosition.x() - mCursorOffset.width(), currentPosition.y() - mCursorOffset.height() ), Point, snapHorizontal, snapVertical );
808 finalPosition = mapFromScene( snappedPosition );
813 beginMousePos = mapFromScene( mBeginMouseEventPos );
814 finalPosition = mapFromScene( currentPosition );
817 double diffX = finalPosition.x() - beginMousePos.x();
818 double diffY = finalPosition.y() - beginMousePos.y();
821 if ( lockRatio && !
qgsDoubleNear( mBeginHandleHeight, 0.0 ) )
823 ratio = mBeginHandleWidth / mBeginHandleHeight;
826 switch ( mCurrentMouseMoveAction )
833 diffX = ( ( mBeginHandleHeight - diffY ) * ratio ) - mBeginHandleWidth;
853 diffX = ( ( mBeginHandleHeight + diffY ) * ratio ) - mBeginHandleWidth;
874 diffY = ( ( mBeginHandleWidth - diffX ) / ratio ) - mBeginHandleHeight;
893 diffY = ( ( mBeginHandleWidth + diffX ) / ratio ) - mBeginHandleHeight;
914 if ( ( mBeginHandleWidth - diffX ) / ( mBeginHandleHeight - diffY ) > ratio )
916 diffX = mBeginHandleWidth - ( ( mBeginHandleHeight - diffY ) * ratio );
920 diffY = mBeginHandleHeight - ( ( mBeginHandleWidth - diffX ) / ratio );
923 mx = diffX, my = diffY;
934 if ( ( mBeginHandleWidth + diffX ) / ( mBeginHandleHeight + diffY ) > ratio )
936 diffX = ( ( mBeginHandleHeight + diffY ) * ratio ) - mBeginHandleWidth;
940 diffY = ( ( mBeginHandleWidth + diffX ) / ratio ) - mBeginHandleHeight;
945 rx = diffX, ry = diffY;
954 if ( ( mBeginHandleWidth + diffX ) / ( mBeginHandleHeight - diffY ) > ratio )
956 diffX = ( ( mBeginHandleHeight - diffY ) * ratio ) - mBeginHandleWidth;
960 diffY = mBeginHandleHeight - ( ( mBeginHandleWidth + diffX ) / ratio );
964 my = diffY, rx = diffX, ry = -diffY;
973 if ( ( mBeginHandleWidth - diffX ) / ( mBeginHandleHeight + diffY ) > ratio )
975 diffX = mBeginHandleWidth - ( ( mBeginHandleHeight + diffY ) * ratio );
979 diffY = ( ( mBeginHandleWidth - diffX ) / ratio ) - mBeginHandleHeight;
1006 mResizeMoveX = mBeginHandleWidth + rx > 0 ? mx : mx + mBeginHandleWidth + rx;
1007 mResizeMoveY = mBeginHandleHeight + ry > 0 ? my : my + mBeginHandleHeight + ry;
1010 QLineF translateLine = QLineF( 0, 0, mResizeMoveX, mResizeMoveY );
1011 translateLine.setAngle( translateLine.angle() - rotation() );
1012 QPointF sceneTranslate = translateLine.p2();
1015 QTransform itemTransform;
1016 itemTransform.translate( sceneTranslate.x(), sceneTranslate.y() );
1017 setTransform( itemTransform );
1020 if ( mBeginHandleWidth + rx >= 0 && mBeginHandleHeight + ry >= 0 )
1022 mResizeRect = QRectF( 0, 0, mBeginHandleWidth + rx, mBeginHandleHeight + ry );
1024 else if ( mBeginHandleHeight + ry >= 0 )
1026 mResizeRect = QRectF( QPointF( -( mBeginHandleWidth + rx ), 0 ), QPointF( 0, mBeginHandleHeight + ry ) );
1028 else if ( mBeginHandleWidth + rx >= 0 )
1030 mResizeRect = QRectF( QPointF( 0, -( mBeginHandleHeight + ry ) ), QPointF( mBeginHandleWidth + rx, 0 ) );
1034 mResizeRect = QRectF( QPointF( -( mBeginHandleWidth + rx ), -( mBeginHandleHeight + ry ) ), QPointF( 0, 0 ) );
1037 const QList<QGraphicsItem *> selectedItems = selectedSceneItems(
false );
1038 QRectF newHandleBounds;
1039 for ( QGraphicsItem *item : selectedItems )
1042 QRectF thisItemRect = mapRectFromScene( storedItemRect( item ) );
1044 relativeResizeRect( thisItemRect, QRectF( -mResizeMoveX, -mResizeMoveY, mBeginHandleWidth, mBeginHandleHeight ), mResizeRect );
1046 thisItemRect = mapRectFromScene( previewSetItemRect( item, mapRectToScene( thisItemRect ) ) );
1047 newHandleBounds = newHandleBounds.isValid() ? newHandleBounds.united( thisItemRect ) : thisItemRect;
1050 setRect( newHandleBounds.isValid() ? newHandleBounds : QRectF( 0, 0, std::fabs( mBeginHandleWidth + rx ), std::fabs( mBeginHandleHeight + ry ) ) );
1053 showStatusMessage( tr(
"width: %1 mm height: %2 mm" ).arg( rect().width() ).arg( rect().height() ) );
1056void QgsGraphicsViewMouseHandles::setHandleSize(
double size )
1061void QgsGraphicsViewMouseHandles::mouseDoubleClickEvent( QGraphicsSceneMouseEvent *event )
1065 mDoubleClickInProgress =
true;
1068QSizeF QgsGraphicsViewMouseHandles::calcCursorEdgeOffset( QPointF cursorPos )
1071 QPointF sceneMousePos = mapFromScene( cursorPos );
1073 switch ( mCurrentMouseMoveAction )
1077 return QSizeF( 0, sceneMousePos.y() );
1080 return QSizeF( 0, sceneMousePos.y() - rect().height() );
1084 return QSizeF( sceneMousePos.x(), 0 );
1087 return QSizeF( sceneMousePos.x() - rect().width(), 0 );
1091 return QSizeF( sceneMousePos.x(), sceneMousePos.y() );
1094 return QSizeF( sceneMousePos.x() - rect().width(), sceneMousePos.y() - rect().height() );
1097 return QSizeF( sceneMousePos.x() - rect().width(), sceneMousePos.y() );
1100 return QSizeF( sceneMousePos.x(), sceneMousePos.y() - rect().height() );
1111QRectF QgsGraphicsViewMouseHandles::selectionBounds()
const
1114 const QList<QGraphicsItem *> selectedItems = selectedSceneItems(
false );
1115 auto itemIter = selectedItems.constBegin();
1118 QRectF bounds = mapFromItem( ( *itemIter ), itemRect( *itemIter ) ).boundingRect();
1121 for ( ++itemIter; itemIter != selectedItems.constEnd(); ++itemIter )
1123 bounds = bounds.united( mapFromItem( ( *itemIter ), itemRect( *itemIter ) ).boundingRect() );
1129void QgsGraphicsViewMouseHandles::relativeResizeRect( QRectF &rectToResize,
const QRectF &boundsBefore,
const QRectF &boundsAfter )
1132 double left = relativePosition( rectToResize.left(), boundsBefore.left(), boundsBefore.right(), boundsAfter.left(), boundsAfter.right() );
1133 double right = relativePosition( rectToResize.right(), boundsBefore.left(), boundsBefore.right(), boundsAfter.left(), boundsAfter.right() );
1134 double top = relativePosition( rectToResize.top(), boundsBefore.top(), boundsBefore.bottom(), boundsAfter.top(), boundsAfter.bottom() );
1135 double bottom = relativePosition( rectToResize.bottom(), boundsBefore.top(), boundsBefore.bottom(), boundsAfter.top(), boundsAfter.bottom() );
1137 rectToResize.setRect( left, top, right - left, bottom - top );
1140double QgsGraphicsViewMouseHandles::relativePosition(
double position,
double beforeMin,
double beforeMax,
double afterMin,
double afterMax )
1143 double m = ( afterMax - afterMin ) / ( beforeMax - beforeMin );
1144 double c = afterMin - ( beforeMin * m );
1147 return m * position +
c;
MouseHandlesAction
Action to be performed by the mouse handles.
@ ResizeRightDown
Resize right down (Bottom right handle)
@ ResizeLeftUp
Resize left up (Top left handle)
@ ResizeLeftDown
Resize left down (Bottom left handle)
@ ResizeRight
Resize right (Right handle)
@ ResizeDown
Resize down (Bottom handle)
@ ResizeRightUp
Resize right up (Top right handle)
@ ResizeLeft
Resize left (Left handle)
@ ResizeUp
Resize up (Top handle)
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)