From 29bfe1db8a5b4480317701ae508f0c920c925525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Tue, 16 Oct 2012 17:55:46 +0200 Subject: Make Rectangle border be inner instead of centered on the outline. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This avoids awkward situations such as when clipping to a parent item of the same size and makes it easier to reason about the bounding rectangle of the item. Task-number: QTBUG-21341 Change-Id: If015cfbc5792429f4a407fc0547ea71eca779eda Reviewed-by: Lars Knoll Reviewed-by: Shawn Rutledge Reviewed-by: Laszlo Papp Reviewed-by: Tor Arne Vestbø --- src/quick/items/qquickrectangle.cpp | 45 +---------------------------------- src/quick/items/qquickrectangle_p.h | 3 --- src/quick/items/qquickrectangle_p_p.h | 4 +--- 3 files changed, 2 insertions(+), 50 deletions(-) (limited to 'src/quick/items') diff --git a/src/quick/items/qquickrectangle.cpp b/src/quick/items/qquickrectangle.cpp index 333946431b..46d486893e 100644 --- a/src/quick/items/qquickrectangle.cpp +++ b/src/quick/items/qquickrectangle.cpp @@ -317,23 +317,6 @@ QQuickRectangle::QQuickRectangle(QQuickItem *parent) void QQuickRectangle::doUpdate() { - Q_D(QQuickRectangle); - qreal penMargin = 0; - qreal penOffset = 0; - if (d->pen && d->pen->isValid()) { - if (d->pen->pixelAligned()) { - const int pw = qRound(d->pen->width()); - penMargin = qreal(0.5) * pw; - penOffset = (pw & 1) * qreal(0.5); - } else { - penMargin = qreal(0.5) * d->pen->width(); - } - } - if (penMargin != d->penMargin || penOffset != d->penOffset) { - d->penMargin = penMargin; - d->penOffset = penOffset; - d->dirty(QQuickItemPrivate::Size); // update clip - } update(); } @@ -348,21 +331,7 @@ void QQuickRectangle::doUpdate() \note The width of the rectangle's border does not affect the geometry of the rectangle itself or its position relative to other items if anchors are used. - If \c border.width is an odd number, the rectangle is painted at a half-pixel offset to retain - border smoothness. Also, the border is rendered evenly on either side of the - rectangle's boundaries, and the spare pixel is rendered to the right and below the - rectangle (as documented for QRect rendering). This can cause unintended effects if - \c border.width is 1 and the rectangle is \l{Item::clip}{clipped} by a parent item: - - \div {class="float-right"} - \inlineimage rect-border-width.png - \enddiv - - \snippet qml/rectangle/rect-border-width.qml 0 - - \clearfloat - Here, the innermost rectangle's border is clipped on the bottom and right edges by its - parent. To avoid this, the border width can be set to two instead of one. + The border is rendered within the rectangle's boundaries. */ QQuickPen *QQuickRectangle::border() { @@ -525,16 +494,4 @@ QSGNode *QQuickRectangle::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData return rectangle; } -QRectF QQuickRectangle::boundingRect() const -{ - Q_D(const QQuickRectangle); - return QRectF(d->penOffset - d->penMargin, d->penOffset - d->penMargin, - d->width + 2 * d->penMargin, d->height + 2 * d->penMargin); -} - -QRectF QQuickRectangle::clipRect() const -{ - return QQuickRectangle::boundingRect(); -} - QT_END_NAMESPACE diff --git a/src/quick/items/qquickrectangle_p.h b/src/quick/items/qquickrectangle_p.h index 102506a163..481033a445 100644 --- a/src/quick/items/qquickrectangle_p.h +++ b/src/quick/items/qquickrectangle_p.h @@ -156,9 +156,6 @@ public: qreal radius() const; void setRadius(qreal radius); - virtual QRectF boundingRect() const; - virtual QRectF clipRect() const; - Q_SIGNALS: void colorChanged(); void radiusChanged(); diff --git a/src/quick/items/qquickrectangle_p_p.h b/src/quick/items/qquickrectangle_p_p.h index d8f3d66968..3d4d019327 100644 --- a/src/quick/items/qquickrectangle_p_p.h +++ b/src/quick/items/qquickrectangle_p_p.h @@ -66,7 +66,7 @@ class QQuickRectanglePrivate : public QQuickItemPrivate public: QQuickRectanglePrivate() : - color(Qt::white), gradient(0), pen(0), radius(0), penMargin(0), penOffset(0) + color(Qt::white), gradient(0), pen(0), radius(0) { } @@ -79,8 +79,6 @@ public: QQuickGradient *gradient; QQuickPen *pen; qreal radius; - qreal penMargin; - qreal penOffset; static int doUpdateSlotIdx; QQuickPen *getPen() { -- cgit v1.2.3