From f2919208964f32efd5d5d9a83bd856d069d070ad Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Thu, 7 Aug 2014 21:31:04 +0200 Subject: Implement all features required for Image BorderImage still needs some work. Change-Id: I37616f18ddc15d3071d9f8b40e29bd4b0e2ea0a4 Reviewed-by: Lars Knoll --- softwarecontext/imagenode.cpp | 27 +++++++++++++++++++++++++-- softwarecontext/imagenode.h | 4 ++++ 2 files changed, 29 insertions(+), 2 deletions(-) (limited to 'softwarecontext') diff --git a/softwarecontext/imagenode.cpp b/softwarecontext/imagenode.cpp index 1dddbaef10..a86b10bc75 100644 --- a/softwarecontext/imagenode.cpp +++ b/softwarecontext/imagenode.cpp @@ -300,6 +300,10 @@ static void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const } ImageNode::ImageNode() + : m_mirror(false) + , m_smooth(true) + , m_tileHorizontal(false) + , m_tileVertical(false) { setMaterial((QSGMaterial*)1); setGeometry((QSGGeometry*)1); @@ -338,22 +342,26 @@ void ImageNode::setTexture(QSGTexture *texture) void ImageNode::setMirror(bool mirror) { + m_mirror = mirror; } -void ImageNode::setMipmapFiltering(QSGTexture::Filtering filtering) +void ImageNode::setMipmapFiltering(QSGTexture::Filtering /*filtering*/) { } void ImageNode::setFiltering(QSGTexture::Filtering filtering) { + m_smooth = (filtering == QSGTexture::Nearest); } void ImageNode::setHorizontalWrapMode(QSGTexture::WrapMode wrapMode) { + m_tileHorizontal = (wrapMode == QSGTexture::Repeat); } void ImageNode::setVerticalWrapMode(QSGTexture::WrapMode wrapMode) { + m_tileVertical = (wrapMode == QSGTexture::Repeat); } void ImageNode::update() @@ -362,5 +370,20 @@ void ImageNode::update() void ImageNode::paint(QPainter *painter) { - painter->drawPixmap(m_targetRect, m_pixmap, m_innerSourceRect); + painter->setRenderHint(QPainter::SmoothPixmapTransform, m_smooth); + if (m_tileHorizontal || m_tileVertical) { + painter->save(); + qreal sx = m_targetRect.width()/(m_subSourceRect.width()*m_pixmap.width()); + qreal sy = m_targetRect.height()/(m_subSourceRect.height()*m_pixmap.height()); + QMatrix transform(sx, 0, 0, sy, 0, 0); + painter->setMatrix(transform, true); + painter->drawTiledPixmap(QRectF(m_targetRect.x()/sx, m_targetRect.y()/sy, m_targetRect.width()/sx, m_targetRect.height()/sy), + m_pixmap, + QPointF(m_subSourceRect.left()*m_pixmap.width(), m_subSourceRect.top()*m_pixmap.height())); + painter->restore(); + } else { + QRectF sr(m_subSourceRect.left()*m_pixmap.width(), m_subSourceRect.top()*m_pixmap.height(), + m_subSourceRect.width()*m_pixmap.width(), m_subSourceRect.height()*m_pixmap.height()); + painter->drawPixmap(m_targetRect, m_pixmap, sr); + } } diff --git a/softwarecontext/imagenode.h b/softwarecontext/imagenode.h index 956e4f75d8..bfa7447a83 100644 --- a/softwarecontext/imagenode.h +++ b/softwarecontext/imagenode.h @@ -30,6 +30,10 @@ private: QRectF m_subSourceRect; QPixmap m_pixmap; + bool m_mirror; + bool m_smooth; + bool m_tileHorizontal; + bool m_tileVertical; }; #endif // IMAGENODE_H -- cgit v1.2.3