20 #include <QDomElement>
24 mHAlignment( Qt::AlignLeft ), mVAlignment( Qt::AlignTop )
27 mFont.setPointSizeF( 10 );
42 painter->setPen( QPen( QColor(
mFontColor ) ) );
43 painter->setFont(
mFont );
45 QFontMetricsF fontSize(
mFont );
48 double penWidth = pen().widthF();
49 QRectF painterRect( penWidth +
mMargin, penWidth +
mMargin, rect().width() - 2 * penWidth - 2 *
mMargin,
50 rect().height() - 2 * penWidth - 2 *
mMargin );
76 int currentDatePos = text.indexOf(
"$CURRENT_DATE" );
77 if ( currentDatePos != -1 )
81 int openingBracketPos = text.indexOf(
"(", currentDatePos );
82 int closingBracketPos = text.indexOf(
")", openingBracketPos + 1 );
83 if ( openingBracketPos != -1 && closingBracketPos != -1 && ( closingBracketPos - openingBracketPos ) > 1 )
85 formatText = text.mid( openingBracketPos + 1, closingBracketPos - openingBracketPos - 1 );
86 text.replace( currentDatePos, closingBracketPos - currentDatePos + 1, QDate::currentDate().toString( formatText ) );
90 text.replace(
"$CURRENT_DATE", QDate::currentDate().toString() );
105 setSceneRect( QRectF( transform().dx(), transform().dy(), textWidth + 2 *
mMargin + 2 * pen().widthF() + 1, \
106 fontAscent + 2 *
mMargin + 2 * pen().widthF() + 1 ) );
123 QDomElement composerLabelElem = doc.createElement(
"ComposerLabel" );
125 composerLabelElem.setAttribute(
"labelText",
mText );
126 composerLabelElem.setAttribute(
"margin", QString::number(
mMargin ) );
128 composerLabelElem.setAttribute(
"halign",
mHAlignment );
129 composerLabelElem.setAttribute(
"valign",
mVAlignment );
130 composerLabelElem.setAttribute(
"id",
mId );
134 QDomElement labelFontElem = doc.createElement(
"LabelFont" );
135 labelFontElem.setAttribute(
"description",
mFont.toString() );
136 composerLabelElem.appendChild( labelFontElem );
139 QDomElement fontColorElem = doc.createElement(
"FontColor" );
140 fontColorElem.setAttribute(
"red",
mFontColor.red() );
141 fontColorElem.setAttribute(
"green",
mFontColor.green() );
142 fontColorElem.setAttribute(
"blue",
mFontColor.blue() );
143 composerLabelElem.appendChild( fontColorElem );
145 elem.appendChild( composerLabelElem );
146 return _writeXML( composerLabelElem, doc );
153 if ( itemElem.isNull() )
161 mText = itemElem.attribute(
"labelText" );
164 mMargin = itemElem.attribute(
"margin" ).toDouble();
167 mHAlignment = ( Qt::AlignmentFlag )( itemElem.attribute(
"halign" ).toInt() );
170 mVAlignment = ( Qt::AlignmentFlag )( itemElem.attribute(
"valign" ).toInt() );
173 mId = itemElem.attribute(
"id",
"" );
176 QDomNodeList labelFontList = itemElem.elementsByTagName(
"LabelFont" );
177 if ( labelFontList.size() > 0 )
179 QDomElement labelFontElem = labelFontList.at( 0 ).toElement();
180 mFont.fromString( labelFontElem.attribute(
"description" ) );
184 QDomNodeList fontColorList = itemElem.elementsByTagName(
"FontColor" );
185 if ( fontColorList.size() > 0 )
187 QDomElement fontColorElem = fontColorList.at( 0 ).toElement();
188 int red = fontColorElem.attribute(
"red",
"0" ).toInt();
189 int green = fontColorElem.attribute(
"green",
"0" ).toInt();
190 int blue = fontColorElem.attribute(
"blue",
"0" ).toInt();
199 QDomNodeList composerItemList = itemElem.elementsByTagName(
"ComposerItem" );
200 if ( composerItemList.size() > 0 )
202 QDomElement composerItemElem = composerItemList.at( 0 ).toElement();