Skip to content

Commit

Permalink
Fix Rectangle implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kim Motoyoshi Kalland committed May 9, 2011
1 parent 2002baa commit 4fb6ee7
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 94 deletions.
60 changes: 39 additions & 21 deletions src/declarative/items/qsgrectangle.cpp
Expand Up @@ -55,64 +55,82 @@ QT_BEGIN_NAMESPACE
// XXX todo - should we change rectangle to draw entirely within its width/height?

QSGPen::QSGPen(QObject *parent)
: QObject(parent), _width(1), _color("#000000"), _valid(false)
: QObject(parent)
, m_width(1)
, m_color("#000000")
, m_aligned(true)
, m_valid(false)
{
}

qreal QSGPen::width() const
{
return m_width;
}

void QSGPen::setWidth(qreal w)
{
if (m_width == w && m_valid)
return;

m_width = w;
m_valid = m_color.alpha() && (qRound(m_width) >= 1 || (!m_aligned && m_width > 0));
emit penChanged();
}

QColor QSGPen::color() const
{
return _color;
return m_color;
}

void QSGPen::setColor(const QColor &c)
{
_color = c;
_valid = (_color.alpha() && _width >= 1) ? true : false;
m_color = c;
m_valid = m_color.alpha() && (qRound(m_width) >= 1 || (!m_aligned && m_width > 0));
emit penChanged();
}

int QSGPen::width() const
{
return _width;
bool QSGPen::aligned() const
{
return m_aligned;
}

void QSGPen::setWidth(int w)
void QSGPen::setAligned(bool aligned)
{
if (_width == w && _valid)
if (aligned == m_aligned)
return;

_width = w;
_valid = (_color.alpha() && _width >= 1) ? true : false;
m_aligned = aligned;
m_valid = m_color.alpha() && (qRound(m_width) >= 1 || (!m_aligned && m_width > 0));
emit penChanged();
}

bool QSGPen::isValid() const
{
return _valid;
return m_valid;
}

QSGGradientStop::QSGGradientStop(QObject *parent)
: QObject(parent)
: QObject(parent)
{
}

qreal QSGGradientStop::position() const
{
{
return m_position;
}

void QSGGradientStop::setPosition(qreal position)
{
{
m_position = position; updateGradient();
}

QColor QSGGradientStop::color() const
{
{
return m_color;
}

void QSGGradientStop::setColor(const QColor &color)
{
{
m_color = color; updateGradient();
}

Expand All @@ -128,12 +146,12 @@ QSGGradient::QSGGradient(QObject *parent)
}

QSGGradient::~QSGGradient()
{
{
delete m_gradient;
}

QDeclarativeListProperty<QSGGradientStop> QSGGradient::stops()
{
{
return QDeclarativeListProperty<QSGGradientStop>(this, m_stops);
}

Expand Down Expand Up @@ -257,8 +275,8 @@ QSGNode *QSGRectangle::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *da
if (d->pen && d->pen->isValid()) {
rectangle->setPenColor(d->pen->color());
rectangle->setPenWidth(d->pen->width());
rectangle->setAligned(d->pen->aligned());
} else {
rectangle->setPenColor(QColor());
rectangle->setPenWidth(0);
}

Expand Down
17 changes: 11 additions & 6 deletions src/declarative/items/qsgrectangle_p.h
Expand Up @@ -58,26 +58,31 @@ class Q_DECLARATIVE_PRIVATE_EXPORT QSGPen : public QObject
{
Q_OBJECT

Q_PROPERTY(int width READ width WRITE setWidth NOTIFY penChanged)
Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY penChanged)
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY penChanged)
Q_PROPERTY(bool aligned READ aligned WRITE setAligned NOTIFY penChanged)
public:
QSGPen(QObject *parent=0);

int width() const;
void setWidth(int w);
qreal width() const;
void setWidth(qreal w);

QColor color() const;
void setColor(const QColor &c);

bool aligned() const;
void setAligned(bool aligned);

bool isValid() const;

Q_SIGNALS:
void penChanged();

private:
int _width;
QColor _color;
bool _valid;
qreal m_width;
QColor m_color;
bool m_aligned : 1;
bool m_valid : 1;
};

class Q_AUTOTEST_EXPORT QSGGradientStop : public QObject
Expand Down
1 change: 1 addition & 0 deletions src/declarative/scenegraph/qsgadaptationlayer_p.h
Expand Up @@ -72,6 +72,7 @@ class Q_DECLARATIVE_EXPORT QSGRectangleNode : public QSGGeometryNode
virtual void setPenWidth(qreal width) = 0;
virtual void setGradientStops(const QGradientStops &stops) = 0;
virtual void setRadius(qreal radius) = 0;
virtual void setAligned(bool aligned) = 0;

virtual void update() = 0;
};
Expand Down

0 comments on commit 4fb6ee7

Please sign in to comment.