20
20
#include < QDomElement>
21
21
#include < QPainter>
22
22
23
- QgsComposerLabel::QgsComposerLabel ( QgsComposition *composition ): QgsComposerItem( composition ), mMargin( 1.0 )
23
+ QgsComposerLabel::QgsComposerLabel ( QgsComposition *composition ): QgsComposerItem( composition ), mMargin( 1.0 ), mFontColor( QColor( 0 , 0 , 0 ) )
24
24
{
25
25
// default font size is 10 point
26
26
mFont .setPointSizeF ( 10 );
@@ -38,7 +38,7 @@ void QgsComposerLabel::paint( QPainter* painter, const QStyleOptionGraphicsItem*
38
38
}
39
39
40
40
drawBackground ( painter );
41
- painter->setPen ( QPen ( QColor ( 0 , 0 , 0 ) ) ); // draw all text black
41
+ painter->setPen ( QPen ( QColor ( mFontColor ) ) ); // draw all text black
42
42
painter->setFont ( mFont );
43
43
44
44
QFontMetricsF fontSize ( mFont );
@@ -128,6 +128,13 @@ bool QgsComposerLabel::writeXML( QDomElement& elem, QDomDocument & doc ) const
128
128
labelFontElem.setAttribute ( " description" , mFont .toString () );
129
129
composerLabelElem.appendChild ( labelFontElem );
130
130
131
+ // font color
132
+ QDomElement fontColorElem = doc.createElement ( " FontColor" );
133
+ fontColorElem.setAttribute ( " red" , mFontColor .red () );
134
+ fontColorElem.setAttribute ( " green" , mFontColor .green () );
135
+ fontColorElem.setAttribute ( " blue" , mFontColor .blue () );
136
+ composerLabelElem.appendChild ( fontColorElem );
137
+
131
138
elem.appendChild ( composerLabelElem );
132
139
return _writeXML ( composerLabelElem, doc );
133
140
}
@@ -155,6 +162,21 @@ bool QgsComposerLabel::readXML( const QDomElement& itemElem, const QDomDocument&
155
162
mFont .fromString ( labelFontElem.attribute ( " description" ) );
156
163
}
157
164
165
+ // font color
166
+ QDomNodeList fontColorList = itemElem.elementsByTagName ( " FontColor" );
167
+ if ( fontColorList.size () > 0 )
168
+ {
169
+ QDomElement fontColorElem = fontColorList.at ( 0 ).toElement ();
170
+ int red = fontColorElem.attribute ( " red" , " 0" ).toInt ();
171
+ int green = fontColorElem.attribute ( " green" , " 0" ).toInt ();
172
+ int blue = fontColorElem.attribute ( " blue" , " 0" ).toInt ();
173
+ mFontColor = QColor ( red, green, blue );
174
+ }
175
+ else
176
+ {
177
+ mFontColor = QColor ( 0 , 0 , 0 );
178
+ }
179
+
158
180
// restore general composer item properties
159
181
QDomNodeList composerItemList = itemElem.elementsByTagName ( " ComposerItem" );
160
182
if ( composerItemList.size () > 0 )
0 commit comments