aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2014-08-07 19:54:53 +0200
committerLars Knoll <lars.knoll@digia.com>2014-08-08 15:57:21 +0300
commit44799792c2b85ee039f18c1f7d1304f4926c1fa3 (patch)
treeb6989cc1c9b8f20132e545ea620745bbe798bf67
parent9c09e0e86bc5056c2bc34b711024bac8e09dbf74 (diff)
Fully implement RectangleNode
Change-Id: If03d1fbcac76035628254033121a822ce481fa38 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
-rw-r--r--softwarecontext/rectanglenode.cpp32
-rw-r--r--softwarecontext/rectanglenode.h7
2 files changed, 33 insertions, 6 deletions
diff --git a/softwarecontext/rectanglenode.cpp b/softwarecontext/rectanglenode.cpp
index 6dde7058c2..0a06175ad6 100644
--- a/softwarecontext/rectanglenode.cpp
+++ b/softwarecontext/rectanglenode.cpp
@@ -1,6 +1,8 @@
#include "rectanglenode.h"
RectangleNode::RectangleNode()
+ : m_penWidth(0)
+ , m_radius(0)
{
setMaterial((QSGMaterial*)1);
setGeometry((QSGGeometry*)1);
@@ -13,38 +15,58 @@ void RectangleNode::setRect(const QRectF &rect)
void RectangleNode::setColor(const QColor &color)
{
- m_brush = color;
+ m_color = color;
}
void RectangleNode::setPenColor(const QColor &color)
{
- m_pen.setColor(color);
+ m_penColor = color;
}
void RectangleNode::setPenWidth(qreal width)
{
- m_pen.setWidthF(width);
+ m_penWidth = width;
}
void RectangleNode::setGradientStops(const QGradientStops &stops)
{
+ m_stops = stops;
}
void RectangleNode::setRadius(qreal radius)
{
+ m_radius = radius;
}
-void RectangleNode::setAligned(bool aligned)
+void RectangleNode::setAligned(bool /*aligned*/)
{
}
void RectangleNode::update()
{
+ if (!m_penWidth || m_penColor == Qt::transparent) {
+ m_pen = Qt::NoPen;
+ } else {
+ m_pen = QPen(m_penColor);
+ m_pen.setWidthF(m_penWidth);
+ }
+
+ if (!m_stops.isEmpty()) {
+ QLinearGradient gradient(QPoint(0,0), QPoint(0,1));
+ gradient.setStops(m_stops);
+ gradient.setCoordinateMode(QGradient::ObjectBoundingMode);
+ m_brush = QBrush(gradient);
+ } else {
+ m_brush = QBrush(m_color);
+ }
}
void RectangleNode::paint(QPainter *painter)
{
painter->setPen(m_pen);
painter->setBrush(m_brush);
- painter->drawRect(m_rect);
+ if (m_radius)
+ painter->drawRoundedRect(m_rect, m_radius, m_radius);
+ else
+ painter->drawRect(m_rect);
}
diff --git a/softwarecontext/rectanglenode.h b/softwarecontext/rectanglenode.h
index 1b5f1af0a0..2f1051df52 100644
--- a/softwarecontext/rectanglenode.h
+++ b/softwarecontext/rectanglenode.h
@@ -25,9 +25,14 @@ public:
virtual void paint(QPainter *);
private:
+ QRectF m_rect;
+ QColor m_color;
+ QColor m_penColor;
+ double m_penWidth;
+ QGradientStops m_stops;
+ double m_radius;
QPen m_pen;
QBrush m_brush;
- QRectF m_rect;
};
#endif // RECTANGLENODE_H