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 )
37 mFont.setPointSizeF( 10 );
46 Q_UNUSED( itemStyle );
56 double penWidth = pen().widthF();
58 painter->translate( rect().width() / 2.0, rect().height() / 2.0 );
66 QWebPage* webPage =
new QWebPage();
71 timeoutTimer.setSingleShot(
true );
74 QPalette palette = webPage->palette();
75 palette.setBrush( QPalette::Base, Qt::transparent );
76 webPage->setPalette( palette );
80 webPage->mainFrame()->setZoomFactor( 10.0 );
81 webPage->mainFrame()->setScrollBarPolicy( Qt::Horizontal, Qt::ScrollBarAlwaysOff );
82 webPage->mainFrame()->setScrollBarPolicy( Qt::Vertical, Qt::ScrollBarAlwaysOff );
90 webPage->settings()->setAttribute( QWebSettings::AutoLoadImages,
false );
94 connect( &timeoutTimer, SIGNAL( timeout() ), &loop, SLOT( quit() ) );
95 connect( webPage, SIGNAL( loadFinished(
bool ) ), &loop, SLOT( quit() ) );
111 timeoutTimer.start( 20000 );
116 webPage->mainFrame()->render( painter );
120 painter->setPen( QPen( QColor(
mFontColor ) ) );
121 painter->setFont(
mFont );
123 QFontMetricsF fontSize(
mFont );
184 QString constant =
"$CURRENT_DATE";
185 int currentDatePos = text.indexOf( constant );
186 if ( currentDatePos != -1 )
190 int openingBracketPos = text.indexOf(
"(", currentDatePos );
191 int closingBracketPos = text.indexOf(
")", openingBracketPos + 1 );
192 if ( openingBracketPos != -1 &&
193 closingBracketPos != -1 &&
194 ( closingBracketPos - openingBracketPos ) > 1 &&
195 openingBracketPos == currentDatePos + constant.size() )
197 formatText = text.mid( openingBracketPos + 1, closingBracketPos - openingBracketPos - 1 );
198 text.replace( currentDatePos, closingBracketPos - currentDatePos + 1, QDate::currentDate().toString( formatText ) );
202 text.replace(
"$CURRENT_DATE", QDate::currentDate().toString() );
245 double x = transform().dx() + rect().width() / 2.0 - width / 2.0;
246 double y = transform().dy() + rect().height() / 2.0 - height / 2.0;
252 if ( rectangle.width() != rect().width() || rectangle.height() != rect().height() )
254 double textBoxWidth = rectangle.width();
255 double textBoxHeight = rectangle.height();
272 QDomElement composerLabelElem = doc.createElement(
"ComposerLabel" );
274 composerLabelElem.setAttribute(
"htmlState",
mHtmlState );
276 composerLabelElem.setAttribute(
"labelText",
mText );
277 composerLabelElem.setAttribute(
"margin", QString::number(
mMargin ) );
279 composerLabelElem.setAttribute(
"halign",
mHAlignment );
280 composerLabelElem.setAttribute(
"valign",
mVAlignment );
283 QDomElement labelFontElem = doc.createElement(
"LabelFont" );
284 labelFontElem.setAttribute(
"description",
mFont.toString() );
285 composerLabelElem.appendChild( labelFontElem );
288 QDomElement fontColorElem = doc.createElement(
"FontColor" );
289 fontColorElem.setAttribute(
"red",
mFontColor.red() );
290 fontColorElem.setAttribute(
"green",
mFontColor.green() );
291 fontColorElem.setAttribute(
"blue",
mFontColor.blue() );
292 composerLabelElem.appendChild( fontColorElem );
294 elem.appendChild( composerLabelElem );
295 return _writeXML( composerLabelElem, doc );
302 if ( itemElem.isNull() )
310 mText = itemElem.attribute(
"labelText" );
313 mHtmlState = itemElem.attribute(
"htmlState" ).toInt();
316 mMargin = itemElem.attribute(
"margin" ).toDouble();
319 mHAlignment = ( Qt::AlignmentFlag )( itemElem.attribute(
"halign" ).toInt() );
322 mVAlignment = ( Qt::AlignmentFlag )( itemElem.attribute(
"valign" ).toInt() );
325 QDomNodeList labelFontList = itemElem.elementsByTagName(
"LabelFont" );
326 if ( labelFontList.size() > 0 )
328 QDomElement labelFontElem = labelFontList.at( 0 ).toElement();
329 mFont.fromString( labelFontElem.attribute(
"description" ) );
333 QDomNodeList fontColorList = itemElem.elementsByTagName(
"FontColor" );
334 if ( fontColorList.size() > 0 )
336 QDomElement fontColorElem = fontColorList.at( 0 ).toElement();
337 int red = fontColorElem.attribute(
"red",
"0" ).toInt();
338 int green = fontColorElem.attribute(
"green",
"0" ).toInt();
339 int blue = fontColorElem.attribute(
"blue",
"0" ).toInt();
348 QDomNodeList composerItemList = itemElem.elementsByTagName(
"ComposerItem" );
349 if ( composerItemList.size() > 0 )
351 QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
361 double currentWidth = rect().width();
362 double currentHeight = rect().height();
370 xShift = - ( newWidth - currentWidth ) / 2.0;
374 xShift = - ( newWidth - currentWidth );
378 yShift = -( newHeight - currentHeight ) / 2.0;
382 yShift = - ( newHeight - currentHeight );
389 yShift = -( newHeight - currentHeight ) / 2.0;
393 yShift = -( newHeight - currentHeight );
397 xShift = -( newWidth - currentWidth );
401 xShift = -( newWidth - currentWidth / 2.0 );
408 xShift = -( newWidth - currentWidth ) / 2.0;
412 xShift = -( newWidth - currentWidth );
416 yShift = ( newHeight - currentHeight ) / 2.0;
420 yShift = ( newHeight - currentHeight );
427 yShift = -( newHeight - currentHeight ) / 2.0;
431 yShift = -( newHeight - currentHeight );
435 xShift = -( newWidth - currentWidth );
439 xShift = -( newWidth - currentWidth / 2.0 );