21 #include <QCoreApplication>
23 #include <QDomElement>
31 mHtmlLoaded( false ), mMargin( 1.0 ), mFontColor( QColor( 0, 0, 0 ) ),
32 mHAlignment( Qt::AlignLeft ), mVAlignment( Qt::AlignTop ),
33 mExpressionFeature( 0 ), mExpressionLayer( 0 )
39 QString defaultFontString = settings.value(
"/Composer/defaultFont" ).toString();
40 if ( !defaultFontString.isEmpty() )
42 mFont.setFamily( defaultFontString );
46 mFont.setPointSizeF( 10 );
62 Q_UNUSED( itemStyle );
72 double penWidth = pen().widthF();
73 QRectF painterRect( penWidth +
mMargin, penWidth +
mMargin, rect().width() - 2 * penWidth - 2 *
mMargin, rect().height() - 2 * penWidth - 2 *
mMargin );
81 QWebPage* webPage =
new QWebPage();
86 timeoutTimer.setSingleShot(
true );
89 QPalette palette = webPage->palette();
90 palette.setBrush( QPalette::Base, Qt::transparent );
91 webPage->setPalette( palette );
95 webPage->mainFrame()->setZoomFactor( 10.0 );
96 webPage->mainFrame()->setScrollBarPolicy( Qt::Horizontal, Qt::ScrollBarAlwaysOff );
97 webPage->mainFrame()->setScrollBarPolicy( Qt::Vertical, Qt::ScrollBarAlwaysOff );
105 webPage->settings()->setAttribute( QWebSettings::AutoLoadImages,
false );
109 connect( &timeoutTimer, SIGNAL( timeout() ), &loop, SLOT( quit() ) );
110 connect( webPage, SIGNAL( loadFinished(
bool ) ), &loop, SLOT( quit() ) );
118 webPage->mainFrame()->setHtml( textToDraw );
126 timeoutTimer.start( 20000 );
131 webPage->mainFrame()->render( painter );
135 painter->setPen( QPen( QColor(
mFontColor ) ) );
136 painter->setFont(
mFont );
138 QFontMetricsF fontSize(
mFont );
199 QString constant =
"$CURRENT_DATE";
200 int currentDatePos = text.indexOf( constant );
201 if ( currentDatePos != -1 )
205 int openingBracketPos = text.indexOf(
"(", currentDatePos );
206 int closingBracketPos = text.indexOf(
")", openingBracketPos + 1 );
207 if ( openingBracketPos != -1 &&
208 closingBracketPos != -1 &&
209 ( closingBracketPos - openingBracketPos ) > 1 &&
210 openingBracketPos == currentDatePos + constant.size() )
212 formatText = text.mid( openingBracketPos + 1, closingBracketPos - openingBracketPos - 1 );
213 text.replace( currentDatePos, closingBracketPos - currentDatePos + 1, QDate::currentDate().toString( formatText ) );
217 text.replace(
"$CURRENT_DATE", QDate::currentDate().toString() );
232 double width = textWidth + 2 *
mMargin + 2 * pen().widthF() + 1;
233 double height = fontAscent + 2 *
mMargin + 2 * pen().widthF() + 1;
240 setSceneRect( QRectF( pos().x() + xShift, pos().y() + yShift, width, height ) );
257 QDomElement composerLabelElem = doc.createElement(
"ComposerLabel" );
259 composerLabelElem.setAttribute(
"htmlState",
mHtmlState );
261 composerLabelElem.setAttribute(
"labelText",
mText );
262 composerLabelElem.setAttribute(
"margin", QString::number(
mMargin ) );
264 composerLabelElem.setAttribute(
"halign",
mHAlignment );
265 composerLabelElem.setAttribute(
"valign",
mVAlignment );
268 QDomElement labelFontElem = doc.createElement(
"LabelFont" );
269 labelFontElem.setAttribute(
"description",
mFont.toString() );
270 composerLabelElem.appendChild( labelFontElem );
273 QDomElement fontColorElem = doc.createElement(
"FontColor" );
274 fontColorElem.setAttribute(
"red",
mFontColor.red() );
275 fontColorElem.setAttribute(
"green",
mFontColor.green() );
276 fontColorElem.setAttribute(
"blue",
mFontColor.blue() );
277 composerLabelElem.appendChild( fontColorElem );
279 elem.appendChild( composerLabelElem );
280 return _writeXML( composerLabelElem, doc );
287 if ( itemElem.isNull() )
295 mText = itemElem.attribute(
"labelText" );
298 mHtmlState = itemElem.attribute(
"htmlState" ).toInt();
301 mMargin = itemElem.attribute(
"margin" ).toDouble();
304 mHAlignment = ( Qt::AlignmentFlag )( itemElem.attribute(
"halign" ).toInt() );
307 mVAlignment = ( Qt::AlignmentFlag )( itemElem.attribute(
"valign" ).toInt() );
310 QDomNodeList labelFontList = itemElem.elementsByTagName(
"LabelFont" );
311 if ( labelFontList.size() > 0 )
313 QDomElement labelFontElem = labelFontList.at( 0 ).toElement();
314 mFont.fromString( labelFontElem.attribute(
"description" ) );
318 QDomNodeList fontColorList = itemElem.elementsByTagName(
"FontColor" );
319 if ( fontColorList.size() > 0 )
321 QDomElement fontColorElem = fontColorList.at( 0 ).toElement();
322 int red = fontColorElem.attribute(
"red",
"0" ).toInt();
323 int green = fontColorElem.attribute(
"green",
"0" ).toInt();
324 int blue = fontColorElem.attribute(
"blue",
"0" ).toInt();
333 QDomNodeList composerItemList = itemElem.elementsByTagName(
"ComposerItem" );
334 if ( composerItemList.size() > 0 )
336 QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
339 if ( composerItemElem.attribute(
"rotation",
"0" ).toDouble() != 0 )
342 setItemRotation( composerItemElem.attribute(
"rotation",
"0" ).toDouble() );
354 double currentWidth = rect().width();
355 double currentHeight = rect().height();
363 xShift = - ( newWidth - currentWidth ) / 2.0;
367 xShift = - ( newWidth - currentWidth );
371 yShift = -( newHeight - currentHeight ) / 2.0;
375 yShift = - ( newHeight - currentHeight );
382 yShift = -( newHeight - currentHeight ) / 2.0;
386 yShift = -( newHeight - currentHeight );
390 xShift = -( newWidth - currentWidth );
394 xShift = -( newWidth - currentWidth / 2.0 );
401 xShift = -( newWidth - currentWidth ) / 2.0;
405 xShift = -( newWidth - currentWidth );
409 yShift = ( newHeight - currentHeight ) / 2.0;
413 yShift = ( newHeight - currentHeight );
420 yShift = -( newHeight - currentHeight ) / 2.0;
424 yShift = -( newHeight - currentHeight );
428 xShift = -( newWidth - currentWidth );
432 xShift = -( newWidth - currentWidth / 2.0 );