24 #include <QTextDocument>
27 class KDReports::ImageElementPrivate
49 : d(new ImageElementPrivate)
55 : d(new ImageElementPrivate)
62 , d(new ImageElementPrivate(*other.d))
82 d->m_pixmap = QVariant::fromValue(pixmap);
83 d->m_pixmapSize = pixmap.size();
88 return d->m_pixmap.value<QPixmap>();
93 d->m_pixmap = QVariant::fromValue(image);
94 d->m_pixmapSize = image.size();
99 return d->m_pixmap.value<QImage>();
107 d->m_fitToPage =
false;
117 d->m_height = height;
120 d->m_fitToPage =
false;
132 d->m_fitToPage =
true;
137 return d->m_fitToPage;
144 const QSize sz( qRound(
mmToPixels( d->m_width.width() ) ),
145 qRound(
mmToPixels( d->m_width.height() ) ) );
146 d->m_pixmap = d->m_pixmap.scaled( sz, Qt::KeepAspectRatio, Qt::SmoothTransformation );
147 qDebug() <<
"ImageElement: m_width (mm) =" << d->m_width <<
" sz (pixels) =" << sz;
151 if (d->m_pixmapSize.isNull())
154 static int imageNumber = 0;
155 const QString name = QStringLiteral(
"image%1.png").arg(++imageNumber);
156 builder.
currentDocument().addResource(QTextDocument::ImageResource, QUrl(name), d->m_pixmap);
159 QTextImageFormat imageFormat;
160 imageFormat.setName(name);
161 imageFormat.setWidth(d->m_pixmapSize.width());
162 imageFormat.setHeight(d->m_pixmapSize.height());
166 const qreal pixelWidth =
mmToPixels(d->m_width);
167 const qreal pixelHeight = pixelWidth * imageFormat.height() / imageFormat.width();
168 imageFormat.setWidth(pixelWidth);
169 imageFormat.setHeight(pixelHeight);
175 }
else if (d->m_height) {
177 const qreal pixelHeight = qRound(
mmToPixels(d->m_height));
178 const qreal pixelWidth = pixelHeight * imageFormat.width() / imageFormat.height();
179 imageFormat.setHeight(pixelHeight);
180 imageFormat.setWidth(pixelWidth);
182 imageFormat.setProperty(
ResizableImageProperty, QString(QLatin1Char(
'H') + QString::number(d->m_height)));
186 }
else if (d->m_fitToPage) {
191 QTextCursor &cursor = builder.
cursor();
192 cursor.insertImage(imageFormat);