QGIS API Documentation  2.4.0-Chugiak
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgscomposershape.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposershape.h
3  ----------------------
4  begin : November 2009
5  copyright : (C) 2009 by Marco Hugentobler
6  email : [email protected]
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSCOMPOSERSHAPE_H
19 #define QGSCOMPOSERSHAPE_H
20 
21 #include "qgscomposeritem.h"
22 #include <QBrush>
23 #include <QPen>
24 
25 class QgsFillSymbolV2;
26 
28 class CORE_EXPORT QgsComposerShape: public QgsComposerItem
29 {
30  Q_OBJECT
31  public:
32 
33  enum Shape
34  {
37  Triangle
38  };
39 
40  QgsComposerShape( QgsComposition* composition );
41  QgsComposerShape( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition );
43 
45  virtual int type() const { return ComposerShape; }
46 
48  void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
49 
54  bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
55 
60  bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
61 
62  //setters and getters
63  QgsComposerShape::Shape shapeType() const { return mShape; }
64  void setShapeType( QgsComposerShape::Shape s ) { mShape = s; }
65 
67  void setCornerRadius( double radius );
69  double cornerRadius() const { return mCornerRadius; };
70 
74  void setShapeStyleSymbol( QgsFillSymbolV2* symbol );
77  QgsFillSymbolV2* shapeStyleSymbol() { return mShapeStyleSymbol; }
78 
81  void setUseSymbolV2( bool useSymbolV2 );
82 
85  QRectF boundingRect() const;
86 
90  void setSceneRect( const QRectF& rectangle );
91 
92  protected:
93  /* reimplement drawFrame, since it's not a rect, but a custom shape */
94  virtual void drawFrame( QPainter* p );
95  /* reimplement drawBackground, since it's not a rect, but a custom shape */
96  virtual void drawBackground( QPainter* p );
99  virtual double estimatedFrameBleed() const;
100 
101  public slots:
105  void refreshSymbol();
106 
107  private:
110 
112 
114 
119 
120  /* draws the custom shape */
121  void drawShape( QPainter* p );
122 
123  /* draws the custom shape using symbol v2*/
124  void drawShapeUsingSymbol( QPainter* p );
125 
126  /* creates the default shape symbol */
127  void createDefaultShapeStyleSymbol();
128 
130  QPointF pointOnLineWithDistance( const QPointF& startPoint, const QPointF& directionPoint, double distance ) const;
131 
133  void updateBoundingRect();
134 };
135 
136 #endif // QGSCOMPOSERSHAPEITEM_H
QRectF mCurrentRectangle
Current bounding rectangle of shape.
void setShapeType(QgsComposerShape::Shape s)
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc)=0
sets state from Dom document
Shape mShape
Ellipse, rectangle or triangle.
virtual double estimatedFrameBleed() const
Returns the estimated amount the item's frame bleeds outside the item's actual rectangle.
A item that forms part of a map composition.
QgsComposerShape::Shape shapeType() const
virtual void drawFrame(QPainter *p)
Draw black frame around item.
QgsFillSymbolV2 * mShapeStyleSymbol
QgsFillSymbolV2 * shapeStyleSymbol()
Returns the QgsFillSymbolV2 used to draw the shape.
Graphics scene for map printing.
virtual int type() const
return correct graphics item type.
A composer items that draws common shapes (ellipse, triangle, rectangle)
virtual void drawBackground(QPainter *p)
Draw background.
virtual void setSceneRect(const QRectF &rectangle)
Sets this items bound in scene coordinates such that 1 item size units corresponds to 1 scene size un...
double cornerRadius() const
Returns the radius for rounded rectangle corners.
virtual bool writeXML(QDomElement &elem, QDomDocument &doc) const =0
stores state in Dom element