28 setFlag( QGraphicsItem::ItemIsSelectable,
true );
33 setData( 0,
"AnnotationItem" );
99 return QSizeF( 0, 0 );
104 prepareGeometryChange();
105 double halfSymbolSize = 0.0;
115 mBoundingRect = QRectF( xMinPos, yMinPos, xMaxPos - xMinPos, yMaxPos - yMinPos );
130 QList<QLineF> segmentList;
134 double minEdgeDist = DBL_MAX;
135 int minEdgeIndex = -1;
140 for (
int i = 0; i < 4; ++i )
142 QLineF currentSegment = segmentList.at( i );
144 double currentMinDist = origin.
sqrDistToSegment( currentSegment.x1(), currentSegment.y1(), currentSegment.x2(), currentSegment.y2(), currentMinDistPoint );
145 if ( currentMinDist < minEdgeDist )
148 minEdgePoint = currentMinDistPoint;
149 minEdgeDist = currentMinDist;
150 minEdge = currentSegment;
154 if ( minEdgeIndex < 0 )
160 double segmentPointWidth = 10;
163 QPointF minEdgeEnd = minEdge.p2();
165 if ( sqrt( minEdgePoint.
sqrDist( minEdgeEnd.x(), minEdgeEnd.y() ) ) < segmentPointWidth )
178 p->setPen( framePen );
180 p->setBrush( frameBrush );
181 p->setRenderHint( QPainter::Antialiasing,
true );
184 for (
int i = 0; i < 4; ++i )
186 QLineF currentSegment =
segment( i );
187 poly << currentSegment.p1();
191 poly << QPointF( 0, 0 );
194 poly << currentSegment.p2();
196 p->drawPolygon( poly );
236 if ( data( 1 ).toString() ==
"composer" )
241 double handlerSize = 10;
242 p->setPen( Qt::NoPen );
243 p->setBrush( QColor( 200, 200, 210, 120 ) );
273 double dx = directionPoint.x() - startPoint.x();
274 double dy = directionPoint.y() - startPoint.y();
275 double length = sqrt( dx * dx + dy * dy );
276 double scaleFactor = distance / length;
277 return QPointF( startPoint.x() + dx * scaleFactor, startPoint.y() + dy * scaleFactor );
282 QPointF itemPos = mapFromScene( pos );
284 int cursorSensitivity = 7;
286 if ( qAbs( itemPos.x() ) < cursorSensitivity && qAbs( itemPos.y() ) < cursorSensitivity )
291 bool left, right, up, down;
301 else if ( right && up )
305 else if ( left && down )
309 else if ( right && down )
341 switch ( moveAction )
344 return Qt::ArrowCursor;
347 return Qt::SizeAllCursor;
350 return Qt::SizeVerCursor;
353 return Qt::SizeHorCursor;
356 return Qt::SizeFDiagCursor;
359 return Qt::SizeBDiagCursor;
361 return Qt::ArrowCursor;
377 double dpmm =
mMapCanvas->logicalDpiX() / 25.4;
383 if ( itemElem.isNull() )
387 QDomElement annotationElem = doc.createElement(
"AnnotationItem" );
389 annotationElem.setAttribute(
"mapPosX", QString::number(
mMapPosition.
x() ) );
390 annotationElem.setAttribute(
"mapPosY", QString::number(
mMapPosition.
y() ) );
393 annotationElem.setAttribute(
"frameWidth", QString::number(
mFrameSize.width() ) );
394 annotationElem.setAttribute(
"frameHeight", QString::number(
mFrameSize.height() ) );
395 QPointF canvasPos = pos();
396 annotationElem.setAttribute(
"canvasPosX", QString::number( canvasPos.x() ) );
397 annotationElem.setAttribute(
"canvasPosY", QString::number( canvasPos.y() ) );
398 annotationElem.setAttribute(
"frameBorderWidth", QString::number(
mFrameBorderWidth ) );
399 annotationElem.setAttribute(
"frameColor",
mFrameColor.name() );
400 annotationElem.setAttribute(
"frameColorAlpha",
mFrameColor.alpha() );
403 annotationElem.setAttribute(
"visible", isVisible() );
407 if ( !symbolElem.isNull() )
409 annotationElem.appendChild( symbolElem );
412 itemElem.appendChild( annotationElem );
418 if ( annotationElem.isNull() )
423 pos.setX( annotationElem.attribute(
"canvasPosX",
"0" ).toDouble() );
424 pos.setY( annotationElem.attribute(
"canvasPosY",
"0" ).toDouble() );
427 mapPos.
setX( annotationElem.attribute(
"mapPosX",
"0" ).toDouble() );
428 mapPos.
setY( annotationElem.attribute(
"mapPosY",
"0" ).toDouble() );
430 mFrameBorderWidth = annotationElem.attribute(
"frameBorderWidth",
"0.5" ).toDouble();
431 mFrameColor.setNamedColor( annotationElem.attribute(
"frameColor",
"#000000" ) );
432 mFrameColor.setAlpha( annotationElem.attribute(
"frameColorAlpha",
"255" ).toInt() );
434 mFrameBackgroundColor.setAlpha( annotationElem.attribute(
"frameBackgroundColorAlpha",
"255" ).toInt() );
435 mFrameSize.setWidth( annotationElem.attribute(
"frameWidth",
"50" ).toDouble() );
436 mFrameSize.setHeight( annotationElem.attribute(
"frameHeight",
"50" ).toDouble() );
440 setVisible( annotationElem.attribute(
"visible",
"1" ).toInt() );
443 QDomElement symbolElem = annotationElem.firstChildElement(
"symbol" );
444 if ( !symbolElem.isNull() )