QGIS API Documentation  2.0.1-Dufour
 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 
26 class CORE_EXPORT QgsComposerShape: public QgsComposerItem
27 {
28  Q_OBJECT
29  public:
30 
31  enum Shape
32  {
35  Triangle
36  };
37 
38  QgsComposerShape( QgsComposition* composition );
39  QgsComposerShape( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition );
41 
43  virtual int type() const { return ComposerShape; }
44 
46  void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
47 
52  bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
53 
58  bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
59 
60  //setters and getters
61  QgsComposerShape::Shape shapeType() const {return mShape;}
62  void setShapeType( QgsComposerShape::Shape s ) {mShape = s;}
63 
66  void setSceneRect( const QRectF& rectangle );
67 
68  public slots:
70  virtual void setRotation( double r );
71 
72 
73  protected:
74  /* reimplement drawFrame, since it's not a rect, but a custom shape */
75  virtual void drawFrame( QPainter* p );
76  /* reimplement drawBackground, since it's not a rect, but a custom shape */
77  virtual void drawBackground( QPainter* p );
78 
79 
80  private:
83 
84  /* draws the custom shape */
85  void drawShape( QPainter* p );
86 
87 
89  QPointF pointOnLineWithDistance( const QPointF& startPoint, const QPointF& directionPoint, double distance ) const;
90 };
91 
92 #endif // QGSCOMPOSERSHAPEITEM_H