diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2014-08-08 14:46:37 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@digia.com> | 2014-08-08 15:57:53 +0300 |
commit | 0faad0c0e4d4aabbc521794a4b543d1feeeb41e1 (patch) | |
tree | eb8f6d13e1fce259f80b0530949605e82ca3579d | |
parent | 5fd71e9bd83935c907eb5ad8ffc270ae42ff05ae (diff) |
Add support for styling the nine patch nodes QtQuick.Controls creates
Change-Id: Ia1d4aeb55bc855770a3a2718114e18ed44cf9645
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
-rw-r--r-- | softwarecontext/context.cpp | 6 | ||||
-rw-r--r-- | softwarecontext/context.h | 1 | ||||
-rw-r--r-- | softwarecontext/ninepatchnode.cpp | 43 | ||||
-rw-r--r-- | softwarecontext/ninepatchnode.h | 24 | ||||
-rw-r--r-- | softwarecontext/renderingvisitor.cpp | 15 | ||||
-rw-r--r-- | softwarecontext/renderingvisitor.h | 2 | ||||
-rw-r--r-- | softwarecontext/softwarecontext.pro | 6 |
7 files changed, 93 insertions, 4 deletions
diff --git a/softwarecontext/context.cpp b/softwarecontext/context.cpp index d656125f0c..f4ed365264 100644 --- a/softwarecontext/context.cpp +++ b/softwarecontext/context.cpp @@ -45,6 +45,7 @@ #include "imagenode.h" #include "pixmaptexture.h" #include "glyphnode.h" +#include "ninepatchnode.h" #include "renderingvisitor.h" #include <QtCore/QCoreApplication> @@ -132,6 +133,11 @@ QSGGlyphNode *Context::createGlyphNode(QSGRenderContext */*rc*/, bool /*preferNa return new GlyphNode(); } +QSGNinePatchNode *Context::createQStyleNode() +{ + return new NinePatchNode(); +} + void RenderContext::initialize(QOpenGLContext *context) { QSGRenderContext::initialize(context); diff --git a/softwarecontext/context.h b/softwarecontext/context.h index b2d478d70a..c319b9a2ab 100644 --- a/softwarecontext/context.h +++ b/softwarecontext/context.h @@ -91,6 +91,7 @@ public: virtual QSGRectangleNode *createRectangleNode(); virtual QSGImageNode *createImageNode(); virtual QSGGlyphNode *createGlyphNode(QSGRenderContext *rc, bool preferNativeGlyphNode); + virtual QSGNinePatchNode *createQStyleNode(); private: }; diff --git a/softwarecontext/ninepatchnode.cpp b/softwarecontext/ninepatchnode.cpp new file mode 100644 index 0000000000..b53b9ed1d9 --- /dev/null +++ b/softwarecontext/ninepatchnode.cpp @@ -0,0 +1,43 @@ +#include "ninepatchnode.h" +#include "pixmaptexture.h" + +NinePatchNode::NinePatchNode() +{ + setMaterial((QSGMaterial*)1); + setGeometry((QSGGeometry*)1); +} + +void NinePatchNode::setTexture(QSGTexture *texture) +{ + PixmapTexture *pt = qobject_cast<PixmapTexture*>(texture); + if (!pt) { + qWarning() << "Image used with invalid texture format."; + return; + } + m_pixmap = pt->pixmap(); +} + +void NinePatchNode::setBounds(const QRectF &bounds) +{ + m_bounds = bounds; +} + +void NinePatchNode::setDevicePixelRatio(qreal ratio) +{ + +} + +void NinePatchNode::setPadding(int left, int top, int right, int bottom) +{ + +} + +void NinePatchNode::update() +{ + +} + +void NinePatchNode::paint(QPainter *painter) +{ + painter->drawPixmap(m_bounds, m_pixmap, QRectF(0, 0, m_pixmap.width(), m_pixmap.height())); +} diff --git a/softwarecontext/ninepatchnode.h b/softwarecontext/ninepatchnode.h new file mode 100644 index 0000000000..5ff7cc4c09 --- /dev/null +++ b/softwarecontext/ninepatchnode.h @@ -0,0 +1,24 @@ +#ifndef NINEPATCHNODE_H +#define NINEPATCHNODE_H + +#include <private/qsgadaptationlayer_p.h> + +class NinePatchNode : public QSGNinePatchNode +{ +public: + NinePatchNode(); + + virtual void setTexture(QSGTexture *texture); + virtual void setBounds(const QRectF &bounds); + virtual void setDevicePixelRatio(qreal ratio); + virtual void setPadding(int left, int top, int right, int bottom); + virtual void update(); + + void paint(QPainter *painter); + +private: + QPixmap m_pixmap; + QRectF m_bounds; +}; + +#endif // NINEPATCHNODE_H diff --git a/softwarecontext/renderingvisitor.cpp b/softwarecontext/renderingvisitor.cpp index 3a58600972..e83e1ca0ff 100644 --- a/softwarecontext/renderingvisitor.cpp +++ b/softwarecontext/renderingvisitor.cpp @@ -3,6 +3,7 @@ #include "imagenode.h" #include "rectanglenode.h" #include "glyphnode.h" +#include "ninepatchnode.h" RenderingVisitor::RenderingVisitor(QPainter *painter) : painter(painter) @@ -34,12 +35,12 @@ void RenderingVisitor::endVisit(QSGClipNode *) void RenderingVisitor::visit(QSGGeometryNode *node) { - Q_UNREACHABLE(); +// Q_UNREACHABLE(); } void RenderingVisitor::endVisit(QSGGeometryNode *node) { - Q_UNREACHABLE(); +// Q_UNREACHABLE(); } void RenderingVisitor::visit(QSGOpacityNode *node) @@ -79,3 +80,13 @@ void RenderingVisitor::visit(QSGGlyphNode *node) void RenderingVisitor::endVisit(QSGGlyphNode *) { } + +void RenderingVisitor::visit(QSGNinePatchNode *node) +{ + static_cast<NinePatchNode*>(node)->paint(painter); +} + +void RenderingVisitor::endVisit(QSGNinePatchNode *) +{ + +} diff --git a/softwarecontext/renderingvisitor.h b/softwarecontext/renderingvisitor.h index 213903aa5f..b4e9a8e6c0 100644 --- a/softwarecontext/renderingvisitor.h +++ b/softwarecontext/renderingvisitor.h @@ -22,6 +22,8 @@ public: virtual void endVisit(QSGRectangleNode *node); virtual void visit(QSGGlyphNode *node); virtual void endVisit(QSGGlyphNode *node); + virtual void visit(QSGNinePatchNode *node); + virtual void endVisit(QSGNinePatchNode *); private: QPainter *painter; diff --git a/softwarecontext/softwarecontext.pro b/softwarecontext/softwarecontext.pro index bde31d2773..d884729ffb 100644 --- a/softwarecontext/softwarecontext.pro +++ b/softwarecontext/softwarecontext.pro @@ -13,7 +13,8 @@ SOURCES += \ imagenode.cpp \ pixmaptexture.cpp \ glyphnode.cpp \ - renderingvisitor.cpp + renderingvisitor.cpp \ + ninepatchnode.cpp HEADERS += \ context.h \ @@ -23,7 +24,8 @@ HEADERS += \ imagenode.h \ pixmaptexture.h \ glyphnode.h \ - renderingvisitor.h + renderingvisitor.h \ + ninepatchnode.h OTHER_FILES += softwarecontext.json |