18#include <QTextDocument>
21class KDReports::ImageElementPrivate
30 bool m_fitToPage =
false;
36 : d(new ImageElementPrivate)
42 : d(new ImageElementPrivate)
49 , d(new ImageElementPrivate(*other.d))
71 d->m_pixmapSize = pixmap.
size();
76 return d->m_pixmap.value<
QPixmap>();
82 d->m_pixmapSize = image.
size();
87 return d->m_pixmap.value<
QImage>();
95 d->m_fitToPage =
false;
105 d->m_height = height;
108 d->m_fitToPage =
false;
120 d->m_fitToPage =
true;
125 return d->m_fitToPage;
133 qRound(
mmToPixels( d->m_width.height() ) ) );
135 qDebug() <<
"ImageElement: m_width (mm) =" << d->m_width <<
" sz (pixels) =" << sz;
139 if (d->m_pixmapSize.isNull())
142 static int imageNumber = 0;
143 const QString name = QStringLiteral(
"image%1.png").
arg(++imageNumber);
149 imageFormat.
setWidth(d->m_pixmapSize.width());
150 imageFormat.
setHeight(d->m_pixmapSize.height());
151#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
158 const qreal pixelWidth =
mmToPixels(d->m_width);
159 const qreal pixelHeight = pixelWidth * imageFormat.
height() / imageFormat.
width();
167 }
else if (d->m_height) {
169 const qreal pixelHeight = qRound(
mmToPixels(d->m_height));
170 const qreal pixelWidth = pixelHeight * imageFormat.
width() / imageFormat.
height();
178 }
else if (d->m_fitToPage) {
Element & operator=(const Element &other)
void setHeight(qreal height, Unit unit=Millimeters)
void setImage(const QImage &image)
ImageElement & operator=(const ImageElement &other)
void build(ReportBuilder &) const override
ImageElement(const QPixmap &pixmap)
void setWidth(qreal width, Unit unit=Millimeters)
void setId(const QString &id)
Element * clone() const override
void setPixmap(const QPixmap &pixmap)
TextDocumentData & currentDocumentData()
QTextDocument & currentDocument()
void addResourceName(const QString &resourceName)
static void updatePercentSize(QTextImageFormat &format, QSizeF size)
void setHasResizableImages()
@ Millimeters
Millimeters (the default)
KDREPORTS_EXPORT qreal mmToPixels(qreal mm)
static const int ResizableImageProperty
QImage toImage() const const
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString number(int n, int base)
void insertImage(const QTextImageFormat &format, QTextFrameFormat::Position alignment)
void addResource(int type, const QUrl &name, const QVariant &resource)
void setProperty(int propertyId, const QVariant &value)
qreal height() const const
void setHeight(qreal height)
void setName(const QString &name)
void setQuality(int quality)
void setWidth(qreal width)
qreal width() const const
QVariant fromValue(const T &value)