aboutsummaryrefslogtreecommitdiffstats
path: root/softwarecontext
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2014-08-08 15:58:36 +0200
committerLars Knoll <lars.knoll@digia.com>2014-08-08 17:42:39 +0300
commit2b04743d352d8793057ec94bb1a64df1ee0fcc45 (patch)
tree0a0b90ec9f91335a56626f05ac6845799f445ee3 /softwarecontext
parentcfa953df53f62e71acf0e17c54cc36e6c86b05f5 (diff)
Fix the nine patch rendering used by the qtquick controls
Change-Id: I2064e5d2cb9596cc5fed3ebf15fccf22d2ad79d0 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'softwarecontext')
-rw-r--r--softwarecontext/imagenode.cpp41
-rw-r--r--softwarecontext/imagenode.h45
-rw-r--r--softwarecontext/ninepatchnode.cpp12
-rw-r--r--softwarecontext/ninepatchnode.h2
4 files changed, 59 insertions, 41 deletions
diff --git a/softwarecontext/imagenode.cpp b/softwarecontext/imagenode.cpp
index a86b10bc75..869beff5d8 100644
--- a/softwarecontext/imagenode.cpp
+++ b/softwarecontext/imagenode.cpp
@@ -6,44 +6,9 @@
// Helper from widgets/styles/qdrawutil.cpp
-typedef QVarLengthArray<QPainter::PixmapFragment, 16> QPixmapFragmentsArray;
+namespace SoftwareContext {
-struct QTileRules
-{
- inline QTileRules(Qt::TileRule horizontalRule, Qt::TileRule verticalRule)
- : horizontal(horizontalRule), vertical(verticalRule) {}
- inline QTileRules(Qt::TileRule rule = Qt::StretchTile)
- : horizontal(rule), vertical(rule) {}
- Qt::TileRule horizontal;
- Qt::TileRule vertical;
-};
-
-#ifndef Q_QDOC
-// For internal use only.
-namespace QDrawBorderPixmap
-{
- enum DrawingHint
- {
- OpaqueTopLeft = 0x0001,
- OpaqueTop = 0x0002,
- OpaqueTopRight = 0x0004,
- OpaqueLeft = 0x0008,
- OpaqueCenter = 0x0010,
- OpaqueRight = 0x0020,
- OpaqueBottomLeft = 0x0040,
- OpaqueBottom = 0x0080,
- OpaqueBottomRight = 0x0100,
- OpaqueCorners = OpaqueTopLeft | OpaqueTopRight | OpaqueBottomLeft | OpaqueBottomRight,
- OpaqueEdges = OpaqueTop | OpaqueLeft | OpaqueRight | OpaqueBottom,
- OpaqueFrame = OpaqueCorners | OpaqueEdges,
- OpaqueAll = OpaqueCenter | OpaqueFrame
- };
-
- Q_DECLARE_FLAGS(DrawingHints, DrawingHint)
-}
-#endif
-
-static void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargins &targetMargins,
+void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargins &targetMargins,
const QPixmap &pixmap, const QRect &sourceRect,const QMargins &sourceMargins,
const QTileRules &rules, QDrawBorderPixmap::DrawingHints hints)
{
@@ -299,6 +264,8 @@ static void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const
painter->setRenderHint(QPainter::Antialiasing, true);
}
+}
+
ImageNode::ImageNode()
: m_mirror(false)
, m_smooth(true)
diff --git a/softwarecontext/imagenode.h b/softwarecontext/imagenode.h
index 5b59da2f3b..6270d05f75 100644
--- a/softwarecontext/imagenode.h
+++ b/softwarecontext/imagenode.h
@@ -4,6 +4,51 @@
#include <private/qsgadaptationlayer_p.h>
#include <private/qsgtexturematerial_p.h>
+typedef QVarLengthArray<QPainter::PixmapFragment, 16> QPixmapFragmentsArray;
+
+struct QTileRules
+{
+ inline QTileRules(Qt::TileRule horizontalRule, Qt::TileRule verticalRule)
+ : horizontal(horizontalRule), vertical(verticalRule) {}
+ inline QTileRules(Qt::TileRule rule = Qt::StretchTile)
+ : horizontal(rule), vertical(rule) {}
+ Qt::TileRule horizontal;
+ Qt::TileRule vertical;
+};
+
+#ifndef Q_QDOC
+// For internal use only.
+namespace QDrawBorderPixmap
+{
+ enum DrawingHint
+ {
+ OpaqueTopLeft = 0x0001,
+ OpaqueTop = 0x0002,
+ OpaqueTopRight = 0x0004,
+ OpaqueLeft = 0x0008,
+ OpaqueCenter = 0x0010,
+ OpaqueRight = 0x0020,
+ OpaqueBottomLeft = 0x0040,
+ OpaqueBottom = 0x0080,
+ OpaqueBottomRight = 0x0100,
+ OpaqueCorners = OpaqueTopLeft | OpaqueTopRight | OpaqueBottomLeft | OpaqueBottomRight,
+ OpaqueEdges = OpaqueTop | OpaqueLeft | OpaqueRight | OpaqueBottom,
+ OpaqueFrame = OpaqueCorners | OpaqueEdges,
+ OpaqueAll = OpaqueCenter | OpaqueFrame
+ };
+
+ Q_DECLARE_FLAGS(DrawingHints, DrawingHint)
+}
+#endif
+
+namespace SoftwareContext {
+
+void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargins &targetMargins,
+ const QPixmap &pixmap, const QRect &sourceRect,const QMargins &sourceMargins,
+ const QTileRules &rules, QDrawBorderPixmap::DrawingHints hints);
+
+}
+
class ImageNode : public QSGImageNode
{
public:
diff --git a/softwarecontext/ninepatchnode.cpp b/softwarecontext/ninepatchnode.cpp
index 01b38b761e..6fcc3019cf 100644
--- a/softwarecontext/ninepatchnode.cpp
+++ b/softwarecontext/ninepatchnode.cpp
@@ -1,5 +1,6 @@
#include "ninepatchnode.h"
#include "pixmaptexture.h"
+#include "imagenode.h"
NinePatchNode::NinePatchNode()
{
@@ -24,20 +25,23 @@ void NinePatchNode::setBounds(const QRectF &bounds)
void NinePatchNode::setDevicePixelRatio(qreal ratio)
{
-
+ m_pixelRatio = ratio;
}
void NinePatchNode::setPadding(qreal left, qreal top, qreal right, qreal bottom)
{
-
+ m_margins = QMargins(qRound(left), qRound(top), qRound(right), qRound(bottom));
}
void NinePatchNode::update()
{
-
}
void NinePatchNode::paint(QPainter *painter)
{
- painter->drawPixmap(m_bounds, m_pixmap, QRectF(0, 0, m_pixmap.width(), m_pixmap.height()));
+ if (m_margins.isNull())
+ painter->drawPixmap(m_bounds, m_pixmap, QRectF(0, 0, m_pixmap.width(), m_pixmap.height()));
+ else
+ SoftwareContext::qDrawBorderPixmap(painter, m_bounds.toRect(), m_margins, m_pixmap, QRect(0, 0, m_pixmap.width(), m_pixmap.height()),
+ m_margins, Qt::StretchTile, QDrawBorderPixmap::DrawingHints(0));
}
diff --git a/softwarecontext/ninepatchnode.h b/softwarecontext/ninepatchnode.h
index 454aadb180..fd7ae5416e 100644
--- a/softwarecontext/ninepatchnode.h
+++ b/softwarecontext/ninepatchnode.h
@@ -19,6 +19,8 @@ public:
private:
QPixmap m_pixmap;
QRectF m_bounds;
+ qreal m_pixelRatio;
+ QMargins m_margins;
};
#endif // NINEPATCHNODE_H