QGIS API Documentation  2.8.2-Wien
 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 override { return ComposerShape; }
46 
48  void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget ) override;
49 
54  bool writeXML( QDomElement& elem, QDomDocument & doc ) const override;
55 
60  bool readXML( const QDomElement& itemElem, const QDomDocument& doc ) override;
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 override;
86 
90  void setSceneRect( const QRectF& rectangle ) override;
91 
92  //Overriden to return shape type
93  virtual QString displayName() const override;
94 
95  protected:
96  /* reimplement drawFrame, since it's not a rect, but a custom shape */
97  virtual void drawFrame( QPainter* p ) override;
98  /* reimplement drawBackground, since it's not a rect, but a custom shape */
99  virtual void drawBackground( QPainter* p ) override;
102  virtual double estimatedFrameBleed() const override;
103 
104  public slots:
108  void refreshSymbol();
109 
110  private:
112  Shape mShape;
113 
114  double mCornerRadius;
115 
116  bool mUseSymbolV2;
117 
118  QgsFillSymbolV2* mShapeStyleSymbol;
119  double mMaxSymbolBleed;
121  QRectF mCurrentRectangle;
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