16 , m_fillMode(ImageItem::Stretch)
18 setFlag(ItemHasContents,
true);
21void ImageItem::setImage(
const QImage &image)
23 bool oldImageNull = m_image.isNull();
27 Q_EMIT nativeWidthChanged();
28 Q_EMIT nativeHeightChanged();
30 if (oldImageNull != m_image.isNull()) {
35QImage ImageItem::image()
const
40void ImageItem::resetImage()
45int ImageItem::nativeWidth()
const
47 return m_image.size().width() / m_image.devicePixelRatio();
50int ImageItem::nativeHeight()
const
52 return m_image.size().height() / m_image.devicePixelRatio();
55ImageItem::FillMode ImageItem::fillMode()
const
60void ImageItem::setFillMode(ImageItem::FillMode mode)
62 if (mode == m_fillMode) {
72void ImageItem::paint(
QPainter *painter)
74 if (m_image.isNull()) {
81 if (m_fillMode == TileVertically) {
82 painter->
scale(
width() / (qreal)m_image.width(), 1);
85 if (m_fillMode == TileHorizontally) {
86 painter->
scale(1,
height() / (qreal)m_image.height());
89 if (m_fillMode >= Tile) {
92 painter->
drawImage(m_paintedRect, m_image, m_image.rect());
98bool ImageItem::isNull()
const
100 return m_image.isNull();
103int ImageItem::paintedWidth()
const
105 if (m_image.isNull()) {
109 return m_paintedRect.width();
112int ImageItem::paintedHeight()
const
114 if (m_image.isNull()) {
118 return m_paintedRect.height();
121int ImageItem::verticalPadding()
const
123 if (m_image.isNull()) {
127 return (
height() - m_paintedRect.height()) / 2;
130int ImageItem::horizontalPadding()
const
132 if (m_image.isNull()) {
136 return (
width() - m_paintedRect.width()) / 2;
139void ImageItem::updatePaintedRect()
141 if (m_image.isNull()) {
145 QRect sourceRect = m_paintedRect;
149 switch (m_fillMode) {
150 case PreserveAspectFit: {
151 QSize scaled = m_image.size();
154 destRect = QRect(QPoint(0, 0), scaled);
158 case PreserveAspectCrop: {
159 QSize scaled = m_image.size();
162 destRect = QRect(QPoint(0, 0), scaled);
166 case TileVertically: {
171 case TileHorizontally: {
182 if (destRect != sourceRect) {
183 m_paintedRect = destRect;
184 Q_EMIT paintedHeightChanged();
185 Q_EMIT paintedWidthChanged();
186 Q_EMIT verticalPaddingChanged();
187 Q_EMIT horizontalPaddingChanged();
191void ImageItem::geometryChange(
const QRectF &newGeometry,
const QRectF &oldGeometry)
197#include "moc_imageitem.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)
void setHeight(int height)
QRect toRect() const const
void scale(const QSize &size, Qt::AspectRatioMode mode)
QTextStream & center(QTextStream &stream)