33 , mAnnotation( annotation )
35 setFlag( QGraphicsItem::ItemIsSelectable,
true );
41 connect( mAnnotation, &
QgsAnnotation::moved,
this, &QgsMapCanvasAnnotationItem::setFeatureForMapPosition );
50 connect( mAnnotation, &QgsAnnotation::destroyed,
this, &QgsMapCanvasAnnotationItem::annotationDeleted );
53 setFeatureForMapPosition();
89 void QgsMapCanvasAnnotationItem::updateBoundingRect()
91 prepareGeometryChange();
94 double fillSymbolBleed = mAnnotation && mAnnotation->
fillSymbol() ?
97 const double mmToPixelScale =
mMapCanvas->logicalDpiX() / 25.4;
101 mBoundingRect = QRectF( - fillSymbolBleed, -fillSymbolBleed,
102 mmToPixelScale * mAnnotation->
frameSizeMm().width() + fillSymbolBleed * 2,
103 mmToPixelScale * mAnnotation->
frameSizeMm().height() + fillSymbolBleed * 2 );
107 double halfSymbolSize = 0.0;
110 halfSymbolSize = scaledSymbolSize() / 2.0;
116 QSizeF frameSize = mAnnotation ? QSizeF( mAnnotation->
frameSizeMm().width() * mmToPixelScale,
117 mAnnotation->
frameSizeMm().height() * mmToPixelScale ) : QSizeF( 0.0, 0.0 );
119 double xMinPos = std::min( -halfSymbolSize, offset.x() - fillSymbolBleed );
120 double xMaxPos = std::max( halfSymbolSize, offset.x() + frameSize.width() + fillSymbolBleed );
121 double yMinPos = std::min( -halfSymbolSize, offset.y() - fillSymbolBleed );
122 double yMaxPos = std::max( halfSymbolSize, offset.y() + frameSize.height() + fillSymbolBleed );
123 mBoundingRect = QRectF( xMinPos, yMinPos, xMaxPos - xMinPos, yMaxPos - yMinPos );
127 void QgsMapCanvasAnnotationItem::onCanvasLayersChanged()
135 else if ( !mAnnotation->
mapLayer() )
145 void QgsMapCanvasAnnotationItem::setFeatureForMapPosition()
161 mapPosition = ct.transform( mapPosition );
167 QgsRectangle searchRect( mapPosition.
x() - halfIdentifyWidth, mapPosition.
y() - halfIdentifyWidth,
168 mapPosition.
x() + halfIdentifyWidth, mapPosition.
y() + halfIdentifyWidth );
179 void QgsMapCanvasAnnotationItem::annotationDeleted()
181 mAnnotation =
nullptr;
185 void QgsMapCanvasAnnotationItem::drawSelectionBoxes( QPainter *p )
const
192 double handlerSize = 10;
193 p->setPen( Qt::NoPen );
194 p->setBrush( QColor( 200, 200, 210, 120 ) );
195 p->drawRect( QRectF( mBoundingRect.left(), mBoundingRect.top(), handlerSize, handlerSize ) );
196 p->drawRect( QRectF( mBoundingRect.right() - handlerSize, mBoundingRect.top(), handlerSize, handlerSize ) );
197 p->drawRect( QRectF( mBoundingRect.right() - handlerSize, mBoundingRect.bottom() - handlerSize, handlerSize, handlerSize ) );
198 p->drawRect( QRectF( mBoundingRect.left(), mBoundingRect.bottom() - handlerSize, handlerSize, handlerSize ) );
203 QPointF itemPos = mapFromScene( pos );
205 int cursorSensitivity = 7;
208 std::fabs( itemPos.x() ) < cursorSensitivity && std::fabs( itemPos.y() ) < cursorSensitivity )
213 const double mmToPixelScale =
mMapCanvas->logicalDpiX() / 25.4;
216 QSizeF frameSize = mAnnotation ? mAnnotation->
frameSizeMm() * mmToPixelScale : QSizeF( 0, 0 );
218 bool left, right, up, down;
219 left = std::fabs( itemPos.x() - offset.x() ) < cursorSensitivity;
220 right = std::fabs( itemPos.x() - ( offset.x() + frameSize.width() ) ) < cursorSensitivity;
221 up = std::fabs( itemPos.y() - offset.y() ) < cursorSensitivity;
222 down = std::fabs( itemPos.y() - ( offset.y() + frameSize.height() ) ) < cursorSensitivity;
228 else if ( right && up )
232 else if ( left && down )
236 else if ( right && down )
258 if ( itemPos.x() >= offset.x() && itemPos.x() <= ( offset.x() + frameSize.width() )
259 && itemPos.y() >= offset.y() && itemPos.y() <= ( offset.y() + frameSize.height() ) )
268 switch ( moveAction )
271 return Qt::ArrowCursor;
274 return Qt::SizeAllCursor;
277 return Qt::SizeVerCursor;
280 return Qt::SizeHorCursor;
283 return Qt::SizeFDiagCursor;
286 return Qt::SizeBDiagCursor;
288 return Qt::ArrowCursor;
292 double QgsMapCanvasAnnotationItem::scaledSymbolSize()
const
304 double dpmm =
mMapCanvas->logicalDpiX() / 25.4;
310 if ( !mAnnotation || !mAnnotation->
isVisible() )
317 mAnnotation->
render( rc );
321 drawSelectionBoxes( painter );