28 , mMapPositionFixed( true )
29 , mOffsetFromReferencePoint( QPointF( 50, -50 ) )
30 , mBalloonSegment( -1 )
32 setFlag( QGraphicsItem::ItemIsSelectable,
true );
37 setData( 0,
"AnnotationItem" );
103 return QSizeF( 0, 0 );
108 prepareGeometryChange();
109 double halfSymbolSize = 0.0;
119 mBoundingRect = QRectF( xMinPos, yMinPos, xMaxPos - xMinPos, yMaxPos - yMinPos );
134 QList<QLineF> segmentList;
138 double minEdgeDist = DBL_MAX;
139 int minEdgeIndex = -1;
144 for (
int i = 0; i < 4; ++i )
146 QLineF currentSegment = segmentList.at( i );
148 double currentMinDist = origin.
sqrDistToSegment( currentSegment.x1(), currentSegment.y1(), currentSegment.x2(), currentSegment.y2(), currentMinDistPoint );
149 if ( currentMinDist < minEdgeDist )
152 minEdgePoint = currentMinDistPoint;
153 minEdgeDist = currentMinDist;
154 minEdge = currentSegment;
158 if ( minEdgeIndex < 0 )
164 double segmentPointWidth = 10;
167 QPointF minEdgeEnd = minEdge.p2();
169 if ( sqrt( minEdgePoint.
sqrDist( minEdgeEnd.x(), minEdgeEnd.y() ) ) < segmentPointWidth )
182 p->setPen( framePen );
184 p->setBrush( frameBrush );
185 p->setRenderHint( QPainter::Antialiasing,
true );
188 for (
int i = 0; i < 4; ++i )
190 QLineF currentSegment =
segment( i );
191 poly << currentSegment.p1();
195 poly << QPointF( 0, 0 );
198 poly << currentSegment.p2();
200 p->drawPolygon( poly );
240 if ( data( 1 ).toString() ==
"composer" )
245 double handlerSize = 10;
246 p->setPen( Qt::NoPen );
247 p->setBrush( QColor( 200, 200, 210, 120 ) );
277 double dx = directionPoint.x() - startPoint.x();
278 double dy = directionPoint.y() - startPoint.y();
279 double length = sqrt( dx * dx + dy * dy );
280 double scaleFactor = distance / length;
281 return QPointF( startPoint.x() + dx * scaleFactor, startPoint.y() + dy * scaleFactor );
286 QPointF itemPos = mapFromScene( pos );
288 int cursorSensitivity = 7;
290 if ( qAbs( itemPos.x() ) < cursorSensitivity && qAbs( itemPos.y() ) < cursorSensitivity )
295 bool left, right, up, down;
305 else if ( right && up )
309 else if ( left && down )
313 else if ( right && down )
345 switch ( moveAction )
348 return Qt::ArrowCursor;
351 return Qt::SizeAllCursor;
354 return Qt::SizeVerCursor;
357 return Qt::SizeHorCursor;
360 return Qt::SizeFDiagCursor;
363 return Qt::SizeBDiagCursor;
365 return Qt::ArrowCursor;
381 double dpmm =
mMapCanvas->logicalDpiX() / 25.4;
387 if ( itemElem.isNull() )
391 QDomElement annotationElem = doc.createElement(
"AnnotationItem" );
397 annotationElem.setAttribute(
"frameWidth", QString::number(
mFrameSize.width() ) );
398 annotationElem.setAttribute(
"frameHeight", QString::number(
mFrameSize.height() ) );
399 QPointF canvasPos = pos();
402 annotationElem.setAttribute(
"frameBorderWidth", QString::number(
mFrameBorderWidth ) );
403 annotationElem.setAttribute(
"frameColor",
mFrameColor.name() );
404 annotationElem.setAttribute(
"frameColorAlpha",
mFrameColor.alpha() );
407 annotationElem.setAttribute(
"visible", isVisible() );
411 if ( !symbolElem.isNull() )
413 annotationElem.appendChild( symbolElem );
416 itemElem.appendChild( annotationElem );
422 if ( annotationElem.isNull() )
427 pos.setX( annotationElem.attribute(
"canvasPosX",
"0" ).toDouble() );
428 pos.setY( annotationElem.attribute(
"canvasPosY",
"0" ).toDouble() );
431 mapPos.
setX( annotationElem.attribute(
"mapPosX",
"0" ).toDouble() );
432 mapPos.
setY( annotationElem.attribute(
"mapPosY",
"0" ).toDouble() );
434 mFrameBorderWidth = annotationElem.attribute(
"frameBorderWidth",
"0.5" ).toDouble();
435 mFrameColor.setNamedColor( annotationElem.attribute(
"frameColor",
"#000000" ) );
436 mFrameColor.setAlpha( annotationElem.attribute(
"frameColorAlpha",
"255" ).toInt() );
438 mFrameBackgroundColor.setAlpha( annotationElem.attribute(
"frameBackgroundColorAlpha",
"255" ).toInt() );
439 mFrameSize.setWidth( annotationElem.attribute(
"frameWidth",
"50" ).toDouble() );
440 mFrameSize.setHeight( annotationElem.attribute(
"frameHeight",
"50" ).toDouble() );
444 setVisible( annotationElem.attribute(
"visible",
"1" ).toInt() );
447 QDomElement symbolElem = annotationElem.firstChildElement(
"symbol" );
448 if ( !symbolElem.isNull() )
450 QgsMarkerSymbolV2* symbol = QgsSymbolLayerV2Utils::loadSymbol<QgsMarkerSymbolV2>( symbolElem );