QGIS API Documentation  2.5.0-Master
 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 : marco@hugis.net
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 );
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  //Overriden to return shape type
93  virtual QString displayName() const;
94 
95  protected:
96  /* reimplement drawFrame, since it's not a rect, but a custom shape */
97  virtual void drawFrame( QPainter* p );
98  /* reimplement drawBackground, since it's not a rect, but a custom shape */
99  virtual void drawBackground( QPainter* p );
102  virtual double estimatedFrameBleed() const;
103 
104  public slots:
108  void refreshSymbol();
109 
110  private:
113 
115 
117 
122 
123  /* draws the custom shape */
124  void drawShape( QPainter* p );
125 
126  /* draws the custom shape using symbol v2*/
127  void drawShapeUsingSymbol( QPainter* p );
128 
129  /* creates the default shape symbol */
130  void createDefaultShapeStyleSymbol();
131 
133  QPointF pointOnLineWithDistance( const QPointF& startPoint, const QPointF& directionPoint, double distance ) const;
134 
136  void updateBoundingRect();
137 };
138 
139 #endif // QGSCOMPOSERSHAPEITEM_H
QRectF mCurrentRectangle
Current bounding rectangle of shape.
virtual bool writeXML(QDomElement &elem, QDomDocument &doc) const
Stores item state in DOM element.
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.
virtual QString displayName() const
Get item display name.
A composer items that draws common shapes (ellipse, triangle, rectangle)
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
Sets item state from DOM element.
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.