QGIS API Documentation  2.6.0-Brighton
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgscomposerlabel.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposerlabel.h
3  -------------------
4  begin : January 2005
5  copyright : (C) 2005 by Radim Blazek
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 #ifndef QGSCOMPOSERLABEL_H
18 #define QGSCOMPOSERLABEL_H
19 
20 #include "qgscomposeritem.h"
21 #include <QFont>
22 
23 class QgsVectorLayer;
24 class QgsFeature;
25 class QgsDistanceArea;
26 
30 class CORE_EXPORT QgsComposerLabel: public QgsComposerItem
31 {
32  Q_OBJECT
33  public:
34  QgsComposerLabel( QgsComposition *composition );
36 
38  virtual int type() const { return ComposerLabel; }
39 
41  void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
42 
44  void adjustSizeToText();
45 
46  QString text() { return mText; }
47  void setText( const QString& text );
48 
49  int htmlState() { return mHtmlState; }
50  void setHtmlState( int state );
51 
53  QString displayText() const;
54 
56  void setExpressionContext( QgsFeature* feature, QgsVectorLayer* layer, QMap<QString, QVariant> substitutions = ( QMap<QString, QVariant>() ) );
57 
58  QFont font() const;
59  void setFont( const QFont& f );
63  Qt::AlignmentFlag vAlign() const { return mVAlignment; }
67  Qt::AlignmentFlag hAlign() const { return mHAlignment; }
72  void setHAlign( Qt::AlignmentFlag a ) {mHAlignment = a;}
77  void setVAlign( Qt::AlignmentFlag a ) { mVAlignment = a; }
79  double margin() { return mMargin; }
81  void setMargin( double m ) { mMargin = m; }
82 
85  void setFontColor( const QColor& c ) { mFontColor = c; }
88  QColor fontColor() const { return mFontColor; }
89 
94  bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
95 
100  bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
101 
102  //Overriden to contain part of label's text
103  virtual QString displayName() const;
104 
105  public slots:
106  void refreshExpressionContext();
107 
108 
109  private slots:
110  void loadingHtmlFinished( bool );
111 
112  private:
113  // Text
114  QString mText;
115 
116  // Html state
117  int mHtmlState;
118  double mHtmlUnitsToMM;
119  double htmlUnitsToMM(); //calculate scale factor
120  bool mHtmlLoaded;
121 
123  void itemShiftAdjustSize( double newWidth, double newHeight, double& xShift, double& yShift ) const;
124 
125  // Font
126  QFont mFont;
127 
128  // Border between text and fram (in mm)
129  double mMargin;
130 
131  // Font color
132  QColor mFontColor;
133 
134  // Horizontal Alignment
135  Qt::AlignmentFlag mHAlignment;
136 
137  // Vertical Alignment
138  Qt::AlignmentFlag mVAlignment;
139 
141  void replaceDateText( QString& text ) const;
142 
143  QgsFeature* mExpressionFeature;
144  QgsVectorLayer* mExpressionLayer;
145  QMap<QString, QVariant> mSubstitutions;
146  QgsDistanceArea* mDistanceArea;
147 };
148 
149 #endif
150 
151