22 #include <QDomDocument>
23 #include <QDomElement>
25 #include <QImageReader>
27 #include <QSvgRenderer>
49 Q_UNUSED( itemStyle );
58 int newDpi = ( painter->device()->logicalDpiX() + painter->device()->logicalDpiY() ) / 2;
74 double boundRectWidthMM = boundRect.width() / newDpi * 25.4;
75 double boundRectHeightMM = boundRect.height() / newDpi * 25.4;
78 painter->translate( rect().width() / 2.0, rect().height() / 2.0 );
80 painter->translate( -boundRectWidthMM / 2.0, -boundRectHeightMM / 2.0 );
84 mSVG.render( painter, QRectF( 0, 0, boundRectWidthMM, boundRectHeightMM ) );
88 painter->drawImage( QRectF( 0, 0, boundRectWidthMM, boundRectHeightMM ),
mImage, QRectF( 0, 0,
mImage.width(),
mImage.height() ) );
111 QString sourceFileSuffix = sourceFileInfo.suffix();
112 if ( sourceFileSuffix.compare(
"svg", Qt::CaseInsensitive ) == 0 )
116 if (
mSVG.isValid() )
119 QRect viewBox =
mSVG.viewBox();
131 QImageReader imageReader(
mSourceFile.fileName() );
132 if ( imageReader.read( &
mImage ) )
144 setSceneRect( QRectF( transform().dx(), transform().dy(), rect().width(), rect().height() ) );
151 double imageToDeviceRatio;
152 if (
mImage.width() / deviceWidth >
mImage.height() / deviceHeight )
154 imageToDeviceRatio = deviceWidth /
mImage.width();
155 double height = imageToDeviceRatio *
mImage.height();
156 return QRectF( 0, 0, deviceWidth, height );
160 imageToDeviceRatio = deviceHeight /
mImage.height();
161 double width = imageToDeviceRatio *
mImage.width();
162 return QRectF( 0, 0, width, deviceHeight );
168 double imageToSvgRatio;
173 return QRectF( 0, 0, width, deviceHeight );
179 return QRectF( 0, 0, deviceWidth, height );
186 double imageToSvgRatio;
191 return QRectF( 0, 0, deviceWidth, height );
197 return QRectF( 0, 0, width, deviceHeight );
207 double newPictureWidth = rectangle.width();
208 double newPictureHeight = rectangle.height();
224 double x = transform().dx() + rect().width() / 2.0 - width / 2.0;
225 double y = transform().dy() + rect().height() / 2.0 - height / 2.0;
238 if ( composerMapId == -1 )
270 QDomElement composerPictureElem = doc.createElement(
"ComposerPicture" );
272 composerPictureElem.setAttribute(
"pictureWidth", QString::number(
mPictureWidth ) );
273 composerPictureElem.setAttribute(
"pictureHeight", QString::number(
mPictureHeight ) );
276 composerPictureElem.setAttribute(
"mapId", -1 );
284 elem.appendChild( composerPictureElem );
290 if ( itemElem.isNull() )
295 mPictureWidth = itemElem.attribute(
"pictureWidth",
"10" ).toDouble();
296 mPictureHeight = itemElem.attribute(
"pictureHeight",
"10" ).toDouble();
298 QDomNodeList composerItemList = itemElem.elementsByTagName(
"ComposerItem" );
299 if ( composerItemList.size() > 0 )
301 _readXML( composerItemList.at( 0 ).toElement(), doc );
311 int rotationMapId = itemElem.attribute(
"mapId",
"-1" ).toInt();
312 if ( rotationMapId == -1 )