diff options
author | Lars Knoll <lars.knoll@digia.com> | 2014-08-08 20:32:41 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2014-08-08 22:39:13 +0300 |
commit | 7d516abb39081c7ce58bb78a644f5bb5ff88f98a (patch) | |
tree | b2aaa681ded6f3b09bd7bf4e2f5ebfa1b8768608 /softwarecontext | |
parent | 2b04743d352d8793057ec94bb1a64df1ee0fcc45 (diff) |
Add a simple rectangle node
This gets text cursor and selections working properly
together with the corresponding change in qtdeclarative.
Change-Id: I53acc39c959f9cde875ef5e8d1bcd4d660269d5e
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'softwarecontext')
-rw-r--r-- | softwarecontext/context.cpp | 5 | ||||
-rw-r--r-- | softwarecontext/context.h | 1 | ||||
-rw-r--r-- | softwarecontext/rectanglenode.cpp | 28 | ||||
-rw-r--r-- | softwarecontext/rectanglenode.h | 18 | ||||
-rw-r--r-- | softwarecontext/renderingvisitor.cpp | 10 | ||||
-rw-r--r-- | softwarecontext/renderingvisitor.h | 2 |
6 files changed, 64 insertions, 0 deletions
diff --git a/softwarecontext/context.cpp b/softwarecontext/context.cpp index 8b90d73496..69e05951c9 100644 --- a/softwarecontext/context.cpp +++ b/softwarecontext/context.cpp @@ -118,6 +118,11 @@ Context::Context(QObject *parent) setDistanceFieldEnabled(false); } +QSGSimpleRectangleNode *Context::createSimpleRectangleNode(const QRectF &rect, const QColor &color) +{ + return new SimpleRectangleNode(rect, color); +} + QSGRectangleNode *Context::createRectangleNode() { return new RectangleNode(); diff --git a/softwarecontext/context.h b/softwarecontext/context.h index c319b9a2ab..75d75ac369 100644 --- a/softwarecontext/context.h +++ b/softwarecontext/context.h @@ -88,6 +88,7 @@ public: QSGRenderContext *createRenderContext() { return new RenderContext(this); } + virtual QSGSimpleRectangleNode *createSimpleRectangleNode(const QRectF &rect, const QColor &color); virtual QSGRectangleNode *createRectangleNode(); virtual QSGImageNode *createImageNode(); virtual QSGGlyphNode *createGlyphNode(QSGRenderContext *rc, bool preferNativeGlyphNode); diff --git a/softwarecontext/rectanglenode.cpp b/softwarecontext/rectanglenode.cpp index 0a06175ad6..0c2575b3fd 100644 --- a/softwarecontext/rectanglenode.cpp +++ b/softwarecontext/rectanglenode.cpp @@ -1,5 +1,33 @@ #include "rectanglenode.h" +SimpleRectangleNode::SimpleRectangleNode(const QRectF &rect, const QColor &color) + : m_rect(rect) + , m_color(color) +{ + setMaterial((QSGMaterial*)1); + setGeometry((QSGGeometry*)1); +} + +void SimpleRectangleNode::setRect(const QRectF &rect) +{ + m_rect = rect; +} + +void SimpleRectangleNode::setColor(const QColor &color) +{ + m_color = color; +} + +void SimpleRectangleNode::update() +{ +} + +void SimpleRectangleNode::paint(QPainter *p) +{ + p->fillRect(m_rect, m_color); +} + + RectangleNode::RectangleNode() : m_penWidth(0) , m_radius(0) diff --git a/softwarecontext/rectanglenode.h b/softwarecontext/rectanglenode.h index 3405c8db84..52414de219 100644 --- a/softwarecontext/rectanglenode.h +++ b/softwarecontext/rectanglenode.h @@ -6,6 +6,24 @@ #include <QPen> #include <QBrush> +class SimpleRectangleNode : public QSGSimpleRectangleNode +{ +public: + SimpleRectangleNode(const QRectF &rect, const QColor &color); + + virtual void setRect(const QRectF &rect); + virtual void setColor(const QColor &color); + + virtual void update(); + + void paint(QPainter *); + +private: + QRectF m_rect; + QColor m_color; +}; + + class RectangleNode : public QSGRectangleNode { public: diff --git a/softwarecontext/renderingvisitor.cpp b/softwarecontext/renderingvisitor.cpp index e83e1ca0ff..667acb758a 100644 --- a/softwarecontext/renderingvisitor.cpp +++ b/softwarecontext/renderingvisitor.cpp @@ -63,6 +63,16 @@ void RenderingVisitor::endVisit(QSGImageNode *) { } +void RenderingVisitor::visit(QSGSimpleRectangleNode *node) +{ + static_cast<SimpleRectangleNode *>(node)->paint(painter); +} + +void RenderingVisitor::endVisit(QSGSimpleRectangleNode *) +{ + +} + void RenderingVisitor::visit(QSGRectangleNode *node) { static_cast<RectangleNode*>(node)->paint(painter); diff --git a/softwarecontext/renderingvisitor.h b/softwarecontext/renderingvisitor.h index b4e9a8e6c0..7533e00ad5 100644 --- a/softwarecontext/renderingvisitor.h +++ b/softwarecontext/renderingvisitor.h @@ -18,6 +18,8 @@ public: virtual void endVisit(QSGOpacityNode *node); virtual void visit(QSGImageNode *node); virtual void endVisit(QSGImageNode *node); + virtual void visit(QSGSimpleRectangleNode *node); + virtual void endVisit(QSGSimpleRectangleNode *node); virtual void visit(QSGRectangleNode *node); virtual void endVisit(QSGRectangleNode *node); virtual void visit(QSGGlyphNode *node); |