28 mUseSymbolV2( false ),
29 mShapeStyleSymbol( 0 ),
33 createDefaultShapeStyleSymbol();
47 mUseSymbolV2( false ),
48 mShapeStyleSymbol( 0 ),
53 createDefaultShapeStyleSymbol();
65 delete mShapeStyleSymbol;
70 mUseSymbolV2 = useSymbolV2;
76 delete mShapeStyleSymbol;
77 mShapeStyleSymbol = symbol;
90 void QgsComposerShape::createDefaultShapeStyleSymbol()
92 delete mShapeStyleSymbol;
94 properties.insert(
"color",
"white" );
95 properties.insert(
"style",
"solid" );
96 properties.insert(
"style_border",
"solid" );
97 properties.insert(
"color_border",
"black" );
98 properties.insert(
"width_border",
"0.3" );
99 properties.insert(
"joinstyle",
"miter" );
103 updateBoundingRect();
110 Q_UNUSED( itemStyle );
131 void QgsComposerShape::drawShape( QPainter* p )
135 drawShapeUsingSymbol( p );
141 p->setRenderHint( QPainter::Antialiasing );
146 p->drawEllipse( QRectF( 0, 0, rect().width(), rect().height() ) );
150 if ( mCornerRadius > 0 )
152 p->drawRoundedRect( QRectF( 0, 0, rect().width(), rect().height() ), mCornerRadius, mCornerRadius );
156 p->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
161 triangle << QPointF( 0, rect().height() );
162 triangle << QPointF( rect().width(), rect().height() );
163 triangle << QPointF( rect().width() / 2.0, 0 );
164 p->drawPolygon( triangle );
170 void QgsComposerShape::drawShapeUsingSymbol( QPainter* p )
173 p->setRenderHint( QPainter::Antialiasing );
176 double dotsPerMM = p->device()->logicalDpiX() / 25.4;
185 p->scale( 1 / dotsPerMM, 1 / dotsPerMM );
188 QList<QPolygonF> rings;
189 QPolygonF shapePolygon;
193 QTransform t = QTransform::fromScale( 100, 100 );
195 QTransform ti = t.inverted();
202 QPainterPath ellipsePath;
203 ellipsePath.addEllipse( QRectF( 0, 0, rect().width() * dotsPerMM, rect().height() * dotsPerMM ) );
204 QPolygonF ellipsePoly = ellipsePath.toFillPolygon( t );
205 shapePolygon = ti.map( ellipsePoly );
211 if ( mCornerRadius > 0 )
213 QPainterPath roundedRectPath;
214 roundedRectPath.addRoundedRect( QRectF( 0, 0, rect().width() * dotsPerMM, rect().height() * dotsPerMM ), mCornerRadius * dotsPerMM, mCornerRadius * dotsPerMM );
215 QPolygonF roundedPoly = roundedRectPath.toFillPolygon( t );
216 shapePolygon = ti.map( roundedPoly );
220 shapePolygon = QPolygonF( QRectF( 0, 0, rect().width() * dotsPerMM, rect().height() * dotsPerMM ) );
226 shapePolygon << QPointF( 0, rect().height() * dotsPerMM );
227 shapePolygon << QPointF( rect().width() * dotsPerMM, rect().height() * dotsPerMM );
228 shapePolygon << QPointF( rect().width() / 2.0 * dotsPerMM, 0 );
229 shapePolygon << QPointF( 0, rect().height() * dotsPerMM );
245 mShapeStyleSymbol->
renderPolygon( shapePolygon, &rings, 0, context );
255 if (
mFrame && p && !mUseSymbolV2 )
258 p->setBrush( Qt::NoBrush );
259 p->setRenderHint( QPainter::Antialiasing,
true );
268 p->setBrush( brush() );
269 p->setPen( Qt::NoPen );
270 p->setRenderHint( QPainter::Antialiasing,
true );
277 return mMaxSymbolBleed;
282 QDomElement composerShapeElem = doc.createElement(
"ComposerShape" );
283 composerShapeElem.setAttribute(
"shapeType", mShape );
284 composerShapeElem.setAttribute(
"cornerRadius", mCornerRadius );
287 composerShapeElem.appendChild( shapeStyleElem );
289 elem.appendChild( composerShapeElem );
290 return _writeXML( composerShapeElem, doc );
296 mCornerRadius = itemElem.attribute(
"cornerRadius",
"0" ).toDouble();
299 QDomNodeList composerItemList = itemElem.elementsByTagName(
"ComposerItem" );
300 if ( composerItemList.size() > 0 )
302 QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
305 if ( composerItemElem.attribute(
"rotation",
"0" ).toDouble() != 0 )
308 setItemRotation( composerItemElem.attribute(
"rotation",
"0" ).toDouble() );
314 QDomElement shapeStyleSymbolElem = itemElem.firstChildElement(
"symbol" );
315 if ( !shapeStyleSymbolElem.isNull() )
317 delete mShapeStyleSymbol;
318 mShapeStyleSymbol = QgsSymbolLayerV2Utils::loadSymbol<QgsFillSymbolV2>( shapeStyleSymbolElem );
323 delete mShapeStyleSymbol;
328 properties.insert(
"style",
"solid" );
332 properties.insert(
"style",
"no" );
336 properties.insert(
"style_border",
"solid" );
340 properties.insert(
"style_border",
"no" );
343 properties.insert(
"width_border", QString::number( pen().widthF() ) );
346 QDomNodeList outlineColorList = itemElem.elementsByTagName(
"OutlineColor" );
347 if ( outlineColorList.size() > 0 )
349 QDomElement frameColorElem = outlineColorList.at( 0 ).toElement();
350 bool redOk, greenOk, blueOk, alphaOk, widthOk;
351 int penRed, penGreen, penBlue, penAlpha;
354 penWidth = itemElem.attribute(
"outlineWidth" ).toDouble( &widthOk );
355 penRed = frameColorElem.attribute(
"red" ).toDouble( &redOk );
356 penGreen = frameColorElem.attribute(
"green" ).toDouble( &greenOk );
357 penBlue = frameColorElem.attribute(
"blue" ).toDouble( &blueOk );
358 penAlpha = frameColorElem.attribute(
"alpha" ).toDouble( &alphaOk );
360 if ( redOk && greenOk && blueOk && alphaOk && widthOk )
363 properties.insert(
"width_border", QString::number( penWidth ) );
366 QDomNodeList fillColorList = itemElem.elementsByTagName(
"FillColor" );
367 if ( fillColorList.size() > 0 )
369 QDomElement fillColorElem = fillColorList.at( 0 ).toElement();
370 bool redOk, greenOk, blueOk, alphaOk;
371 int fillRed, fillGreen, fillBlue, fillAlpha;
373 fillRed = fillColorElem.attribute(
"red" ).toDouble( &redOk );
374 fillGreen = fillColorElem.attribute(
"green" ).toDouble( &greenOk );
375 fillBlue = fillColorElem.attribute(
"blue" ).toDouble( &blueOk );
376 fillAlpha = fillColorElem.attribute(
"alpha" ).toDouble( &alphaOk );
378 if ( redOk && greenOk && blueOk && alphaOk )
381 properties.insert(
"style",
"solid" );
384 if ( itemElem.hasAttribute(
"transparentFill" ) )
387 bool hasOldTransparentFill = itemElem.attribute(
"transparentFill",
"0" ).toInt();
388 if ( hasOldTransparentFill )
390 properties.insert(
"style",
"no" );
418 mCornerRadius = radius;
423 return mCurrentRectangle;
426 void QgsComposerShape::updateBoundingRect()
428 QRectF rectangle = rect();
429 rectangle.adjust( -mMaxSymbolBleed, -mMaxSymbolBleed, mMaxSymbolBleed, mMaxSymbolBleed );
430 if ( rectangle != mCurrentRectangle )
432 prepareGeometryChange();
433 mCurrentRectangle = rectangle;
445 updateBoundingRect();
451 if ( !
id().isEmpty() )
459 return tr(
"<ellipse>" );
462 return tr(
"<rectangle>" );
465 return tr(
"<triangle>" );
469 return tr(
"<shape>" );