14 , m_fillMode(QImageItem::Stretch)
16 setFlag(ItemHasContents,
true);
19QImageItem::~QImageItem()
23void QImageItem::setImage(
const QImage &image)
25 bool oldImageNull = m_image.isNull();
29 Q_EMIT nativeWidthChanged();
30 Q_EMIT nativeHeightChanged();
32 if (oldImageNull != m_image.isNull()) {
37QImage QImageItem::image()
const
42void QImageItem::resetImage()
47int QImageItem::nativeWidth()
const
49 return m_image.size().width() / m_image.devicePixelRatio();
52int QImageItem::nativeHeight()
const
54 return m_image.size().height() / m_image.devicePixelRatio();
57QImageItem::FillMode QImageItem::fillMode()
const
62void QImageItem::setFillMode(QImageItem::FillMode mode)
64 if (mode == m_fillMode) {
74void QImageItem::paint(
QPainter *painter)
76 if (m_image.isNull()) {
83 if (m_fillMode == TileVertically) {
84 painter->
scale(
width() / (qreal)m_image.width(), 1);
87 if (m_fillMode == TileHorizontally) {
88 painter->
scale(1,
height() / (qreal)m_image.height());
91 if (m_fillMode == Pad) {
92 QRect centeredRect = m_paintedRect;
93 centeredRect.
moveCenter(m_image.rect().center());
94 painter->
drawImage(m_paintedRect, m_image, centeredRect);
95 }
else if (m_fillMode >= Tile) {
98 painter->
drawImage(m_paintedRect, m_image, m_image.rect());
104bool QImageItem::isNull()
const
106 return m_image.isNull();
109int QImageItem::paintedWidth()
const
111 if (m_image.isNull()) {
115 return m_paintedRect.width();
118int QImageItem::paintedHeight()
const
120 if (m_image.isNull()) {
124 return m_paintedRect.height();
127void QImageItem::updatePaintedRect()
129 if (m_image.isNull()) {
133 QRectF sourceRect = m_paintedRect;
137 switch (m_fillMode) {
138 case PreserveAspectFit: {
139 QSizeF scaled = m_image.size();
142 destRect = QRectF(QPoint(0, 0), scaled);
146 case PreserveAspectCrop: {
147 QSizeF scaled = m_image.size();
150 destRect = QRectF(QPoint(0, 0), scaled);
154 case TileVertically: {
159 case TileHorizontally: {
171 if (destRect != sourceRect) {
172 m_paintedRect = destRect.
toRect();
173 Q_EMIT paintedHeightChanged();
174 Q_EMIT paintedWidthChanged();
177void QImageItem::geometryChange(
const QRectF &newGeometry,
const QRectF &oldGeometry)
183#include "moc_qimageitem.cpp"
void drawImage(const QPoint &point, const QImage &image)
void drawTiledPixmap(const QRect &rectangle, const QPixmap &pixmap, const QPoint &position)
void scale(qreal sx, qreal sy)
void setRenderHint(RenderHint hint, bool on)
QPixmap fromImage(QImage &&image, Qt::ImageConversionFlags flags)
virtual QRectF boundingRect() const const
virtual void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
QSizeF size() const const
void moveCenter(const QPoint &position)
qreal height() const const
void moveCenter(const QPointF &position)
void setHeight(qreal height)
void setWidth(qreal width)
QRect toRect() const const
qreal width() const const
void scale(const QSizeF &size, Qt::AspectRatioMode mode)
QTextStream & center(QTextStream &stream)