summaryrefslogtreecommitdiffstats
path: root/src/declarative/fx/qfxanchors.cpp
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2009-05-22 00:32:16 (GMT)
committerMichael Brasser <michael.brasser@nokia.com>2009-05-22 00:37:31 (GMT)
commit61943383ccff409d60d9837d58e4372dc6f22f23 (patch)
treeb030d569a1c4a31a20b87c3b0b80f4ee6d2fec7a /src/declarative/fx/qfxanchors.cpp
parent942ea5202d4a329376c27015b07406c2018437ff (diff)
downloadQt-61943383ccff409d60d9837d58e4372dc6f22f23.zip
Qt-61943383ccff409d60d9837d58e4372dc6f22f23.tar.gz
Qt-61943383ccff409d60d9837d58e4372dc6f22f23.tar.bz2
Add support for baseline anchoring.
Diffstat (limited to 'src/declarative/fx/qfxanchors.cpp')
-rw-r--r--src/declarative/fx/qfxanchors.cpp52
1 files changed, 48 insertions, 4 deletions
diff --git a/src/declarative/fx/qfxanchors.cpp b/src/declarative/fx/qfxanchors.cpp
index 235511f..681a9fa 100644
--- a/src/declarative/fx/qfxanchors.cpp
+++ b/src/declarative/fx/qfxanchors.cpp
@@ -146,6 +146,7 @@ QFxAnchors::~QFxAnchors()
d->remDepend(d->bottom.item);
d->remDepend(d->vCenter.item);
d->remDepend(d->hCenter.item);
+ d->remDepend(d->baseline.item);
}
void QFxAnchorsPrivate::fillChanged()
@@ -210,6 +211,10 @@ void QFxAnchorsPrivate::clearItem(QFxItem *item)
hCenter.item = 0;
usedAnchors &= ~QFxAnchors::HasHCenterAnchor;
}
+ if (baseline.item == item) {
+ baseline.item = 0;
+ usedAnchors &= ~QFxAnchors::HasBaselineAnchor;
+ }
}
void QFxAnchorsPrivate::addDepend(QFxItem *item)
@@ -430,8 +435,6 @@ void QFxAnchorsPrivate::updateVerticalAnchors()
} else if (bottom.item->itemParent() == item->itemParent()) {
setItemY(position(bottom.item, bottom.anchorLine) - item->height() - bottomMargin);
}
-
-
} else if (usedAnchors & QFxAnchors::HasVCenterAnchor) {
//(stetching handled above)
@@ -442,6 +445,11 @@ void QFxAnchorsPrivate::updateVerticalAnchors()
} else if (vCenter.item->itemParent() == item->itemParent()) {
setItemY(position(vCenter.item, vCenter.anchorLine) - item->height()/2 + vCenterOffset);
}
+ } else if (usedAnchors & QFxAnchors::HasBaselineAnchor) {
+ //Handle baseline
+ if (baseline.item->itemParent() == item->itemParent()) {
+ setItemY(position(baseline.item, baseline.anchorLine) - item->baselineOffset());
+ }
}
updatingVerticalAnchor = false;
} else {
@@ -599,6 +607,36 @@ void QFxAnchors::resetVerticalCenter()
setVerticalCenter(QFxAnchorLine());
}
+QFxAnchorLine QFxAnchors::baseline() const
+{
+ Q_D(const QFxAnchors);
+ return d->baseline;
+}
+
+void QFxAnchors::setBaseline(const QFxAnchorLine &edge)
+{
+ Q_D(QFxAnchors);
+ if (!d->checkVAnchorValid(edge))
+ return;
+
+ if (edge.item)
+ d->usedAnchors |= HasBaselineAnchor;
+ else
+ d->usedAnchors &= ~HasBaselineAnchor;
+
+ d->checkVValid();
+
+ d->remDepend(d->baseline.item);
+ d->baseline = edge;
+ d->addDepend(d->baseline.item);
+ d->updateVerticalAnchors();
+}
+
+void QFxAnchors::resetBaseline()
+{
+ setBaseline(QFxAnchorLine());
+}
+
QFxAnchorLine QFxAnchors::left() const
{
Q_D(const QFxAnchors);
@@ -797,7 +835,7 @@ bool QFxAnchorsPrivate::checkHValid() const
if (usedAnchors & QFxAnchors::HasLeftAnchor &&
usedAnchors & QFxAnchors::HasRightAnchor &&
usedAnchors & QFxAnchors::HasHCenterAnchor) {
- qmlInfo(item) << "Can't specify left, right, and hcenter anchors";
+ qmlInfo(item) << "Can't specify left, right, and hcenter anchors.";
return false;
}
@@ -822,7 +860,13 @@ bool QFxAnchorsPrivate::checkVValid() const
if (usedAnchors & QFxAnchors::HasTopAnchor &&
usedAnchors & QFxAnchors::HasBottomAnchor &&
usedAnchors & QFxAnchors::HasVCenterAnchor) {
- qmlInfo(item) << "Can't specify top, bottom, and vcenter anchors";
+ qmlInfo(item) << "Can't specify top, bottom, and vcenter anchors.";
+ return false;
+ } else if (usedAnchors & QFxAnchors::HasBaselineAnchor &&
+ (usedAnchors & QFxAnchors::HasTopAnchor ||
+ usedAnchors & QFxAnchors::HasBottomAnchor ||
+ usedAnchors & QFxAnchors::HasVCenterAnchor)) {
+ qmlInfo(item) << "Baseline anchor can't be used in conjunction with top, bottom, or vcenter anchors.";
return false;
}