aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquickanchors.cpp
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2012-05-09 11:25:31 +1000
committerQt by Nokia <qt-info@nokia.com>2012-05-11 07:22:25 +0200
commit50482f69af0b9392424dfdad5376fcb09be36d46 (patch)
tree5d0cbc6f95d28d03c82e0bf0dc96b4755e7877ce /src/quick/items/qquickanchors.cpp
parent67fb05034c9758d25464f2103ae6068dbc9bb110 (diff)
Make unaligned centered alignment optional.
Centered alignment was recently made unaligned by e99c5a3f113bbc1b8f8db996b4b0d5715eea2d89. This has the side-effect of sometimes making items appear fuzzy due to sub-pixel alignment. Since we have two conflicting goals, make this behavior configuarable. Change-Id: I5ed0e9532a64f4a986d148044f5871a7ec970f5f Reviewed-by: Bea Lam <bea.lam@nokia.com>
Diffstat (limited to 'src/quick/items/qquickanchors.cpp')
-rw-r--r--src/quick/items/qquickanchors.cpp45
1 files changed, 43 insertions, 2 deletions
diff --git a/src/quick/items/qquickanchors.cpp b/src/quick/items/qquickanchors.cpp
index b7071b9598..cc4239cc2e 100644
--- a/src/quick/items/qquickanchors.cpp
+++ b/src/quick/items/qquickanchors.cpp
@@ -53,12 +53,30 @@ QT_BEGIN_NAMESPACE
static inline qreal hcenter(QQuickItem *item)
{
- return item->width() / 2;
+ qreal width = item->width();
+ if (QQuickAnchors *anchors = QQuickItemPrivate::get(item)->_anchors) {
+ if (!QQuickAnchorsPrivate::get(anchors)->centerAligned)
+ return width / 2;
+ }
+ int iw = width;
+ if (iw % 2)
+ return (width + 1) / 2;
+ else
+ return width / 2;
}
static inline qreal vcenter(QQuickItem *item)
{
- return item->height() / 2;
+ qreal height = item->height();
+ if (QQuickAnchors *anchors = QQuickItemPrivate::get(item)->_anchors) {
+ if (!QQuickAnchorsPrivate::get(anchors)->centerAligned)
+ return height / 2;
+ }
+ int ih = height;
+ if (ih % 2)
+ return (height + 1) / 2;
+ else
+ return height / 2;
}
//### const item?
@@ -309,6 +327,29 @@ bool QQuickAnchors::mirrored()
return QQuickItemPrivate::get(d->item)->effectiveLayoutMirror;
}
+bool QQuickAnchors::alignWhenCentered() const
+{
+ Q_D(const QQuickAnchors);
+ return d->centerAligned;
+}
+
+void QQuickAnchors::setAlignWhenCentered(bool aligned)
+{
+ Q_D(QQuickAnchors);
+ if (aligned == d->centerAligned)
+ return;
+ d->centerAligned = aligned;
+ emit centerAlignedChanged();
+ if (d->centerIn) {
+ d->centerInChanged();
+ } else {
+ if (d->usedAnchors & QQuickAnchors::VCenterAnchor)
+ d->updateVerticalAnchors();
+ else if (d->usedAnchors & QQuickAnchors::HCenterAnchor)
+ d->updateHorizontalAnchors();
+ }
+}
+
bool QQuickAnchorsPrivate::isItemComplete() const
{
return componentComplete;