summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2009-12-10 11:22:29 (GMT)
committerAlan Alpert <alan.alpert@nokia.com>2009-12-10 11:22:29 (GMT)
commit57d6bf52074761a0c6e9a79829ec845a7b0061fa (patch)
treebaee7b86f5acd238689bb65591351f87dd0bb70e
parent8d3596fefc882a4194c665bcde4e8309dbdcc85f (diff)
downloadQt-57d6bf52074761a0c6e9a79829ec845a7b0061fa.zip
Qt-57d6bf52074761a0c6e9a79829ec845a7b0061fa.tar.gz
Qt-57d6bf52074761a0c6e9a79829ec845a7b0061fa.tar.bz2
Add anchors.margins
Task-number: QTBUG-6676
-rw-r--r--src/declarative/graphicsitems/qmlgraphicsanchors.cpp25
-rw-r--r--src/declarative/graphicsitems/qmlgraphicsanchors_p.h5
-rw-r--r--src/declarative/graphicsitems/qmlgraphicsanchors_p_p.h5
-rw-r--r--tests/auto/declarative/anchors/data/margins.qml13
-rw-r--r--tests/auto/declarative/anchors/tst_anchors.cpp30
5 files changed, 74 insertions, 4 deletions
diff --git a/src/declarative/graphicsitems/qmlgraphicsanchors.cpp b/src/declarative/graphicsitems/qmlgraphicsanchors.cpp
index c28ca02..96d76cf 100644
--- a/src/declarative/graphicsitems/qmlgraphicsanchors.cpp
+++ b/src/declarative/graphicsitems/qmlgraphicsanchors.cpp
@@ -859,6 +859,31 @@ void QmlGraphicsAnchors::setRightMargin(qreal offset)
emit rightMarginChanged();
}
+qreal QmlGraphicsAnchors::margins() const
+{
+ Q_D(const QmlGraphicsAnchors);
+ return d->margins;
+}
+
+void QmlGraphicsAnchors::setMargins(qreal offset)
+{
+ Q_D(QmlGraphicsAnchors);
+ if (d->margins == offset)
+ return;
+ //###Is it significantly faster to set them directly so we can call fillChanged only once?
+ if(!d->rightMargin || d->rightMargin == d->margins)
+ setRightMargin(offset);
+ if(!d->leftMargin || d->leftMargin == d->margins)
+ setLeftMargin(offset);
+ if(!d->topMargin || d->topMargin == d->margins)
+ setTopMargin(offset);
+ if(!d->bottomMargin || d->bottomMargin == d->margins)
+ setBottomMargin(offset);
+ d->margins = offset;
+ emit marginsChanged();
+
+}
+
qreal QmlGraphicsAnchors::horizontalCenterOffset() const
{
Q_D(const QmlGraphicsAnchors);
diff --git a/src/declarative/graphicsitems/qmlgraphicsanchors_p.h b/src/declarative/graphicsitems/qmlgraphicsanchors_p.h
index 2f2ca74..a67a9f8 100644
--- a/src/declarative/graphicsitems/qmlgraphicsanchors_p.h
+++ b/src/declarative/graphicsitems/qmlgraphicsanchors_p.h
@@ -67,6 +67,7 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsAnchors : public QObject
Q_PROPERTY(QmlGraphicsAnchorLine bottom READ bottom WRITE setBottom RESET resetBottom NOTIFY bottomChanged)
Q_PROPERTY(QmlGraphicsAnchorLine verticalCenter READ verticalCenter WRITE setVerticalCenter RESET resetVerticalCenter NOTIFY verticalCenterChanged)
Q_PROPERTY(QmlGraphicsAnchorLine baseline READ baseline WRITE setBaseline RESET resetBaseline NOTIFY baselineChanged)
+ Q_PROPERTY(qreal margins READ margins WRITE setMargins NOTIFY marginsChanged)
Q_PROPERTY(qreal leftMargin READ leftMargin WRITE setLeftMargin NOTIFY leftMarginChanged)
Q_PROPERTY(qreal rightMargin READ rightMargin WRITE setRightMargin NOTIFY rightMarginChanged)
Q_PROPERTY(qreal horizontalCenterOffset READ horizontalCenterOffset WRITE setHorizontalCenterOffset NOTIFY horizontalCenterOffsetChanged())
@@ -137,6 +138,9 @@ public:
qreal bottomMargin() const;
void setBottomMargin(qreal);
+ qreal margins() const;
+ void setMargins(qreal);
+
qreal verticalCenterOffset() const;
void setVerticalCenterOffset(qreal);
@@ -172,6 +176,7 @@ Q_SIGNALS:
void rightMarginChanged();
void topMarginChanged();
void bottomMarginChanged();
+ void marginsChanged();
void verticalCenterOffsetChanged();
void horizontalCenterOffsetChanged();
void baselineOffsetChanged();
diff --git a/src/declarative/graphicsitems/qmlgraphicsanchors_p_p.h b/src/declarative/graphicsitems/qmlgraphicsanchors_p_p.h
index be3b6dc..4f7fde0 100644
--- a/src/declarative/graphicsitems/qmlgraphicsanchors_p_p.h
+++ b/src/declarative/graphicsitems/qmlgraphicsanchors_p_p.h
@@ -98,8 +98,8 @@ public:
QmlGraphicsAnchorsPrivate()
: updatingMe(false), updatingHorizontalAnchor(0),
updatingVerticalAnchor(0), updatingFill(0), updatingCenterIn(0), item(0), usedAnchors(0), fill(0),
- centerIn(0), leftMargin(0), rightMargin(0), topMargin(0),
- bottomMargin(0), vCenterOffset(0), hCenterOffset(0), baselineOffset(0),
+ centerIn(0), leftMargin(0), rightMargin(0), topMargin(0), bottomMargin(0),
+ margins(0), vCenterOffset(0), hCenterOffset(0), baselineOffset(0),
componentComplete(true)
{
}
@@ -159,6 +159,7 @@ public:
qreal rightMargin;
qreal topMargin;
qreal bottomMargin;
+ qreal margins;
qreal vCenterOffset;
qreal hCenterOffset;
qreal baselineOffset;
diff --git a/tests/auto/declarative/anchors/data/margins.qml b/tests/auto/declarative/anchors/data/margins.qml
new file mode 100644
index 0000000..4a29e77
--- /dev/null
+++ b/tests/auto/declarative/anchors/data/margins.qml
@@ -0,0 +1,13 @@
+import Qt 4.6
+
+Rectangle {
+ width: 200; height: 200
+ Rectangle {
+ objectName: "filler"
+ width: 50; height: 50; color: "blue"
+ anchors.fill: parent;
+ anchors.margins: 10
+ anchors.leftMargin: 5
+ anchors.topMargin: 6
+ }
+}
diff --git a/tests/auto/declarative/anchors/tst_anchors.cpp b/tests/auto/declarative/anchors/tst_anchors.cpp
index 8967725..defc841 100644
--- a/tests/auto/declarative/anchors/tst_anchors.cpp
+++ b/tests/auto/declarative/anchors/tst_anchors.cpp
@@ -73,6 +73,7 @@ private slots:
void crash1();
void centerIn();
void fill();
+ void margins();
};
/*
@@ -389,8 +390,8 @@ void tst_anchors::fill()
view->execute();
qApp->processEvents();
QmlGraphicsRectangle* rect = findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("filler"));
- QCOMPARE(rect->x(), 0.0 + 10);
- QCOMPARE(rect->y(), 0.0 + 30);
+ QCOMPARE(rect->x(), 0.0 + 10.0);
+ QCOMPARE(rect->y(), 0.0 + 30.0);
QCOMPARE(rect->width(), 200.0 - 10.0 - 20.0);
QCOMPARE(rect->height(), 200.0 - 30.0 - 40.0);
//Alter Offsets (QTBUG-6631)
@@ -426,6 +427,31 @@ void tst_anchors::centerIn()
delete view;
}
+void tst_anchors::margins()
+{
+ QmlView *view = new QmlView;
+
+ view->setUrl(QUrl("file://" SRCDIR "/data/margins.qml"));
+
+ view->execute();
+ qApp->processEvents();
+ QmlGraphicsRectangle* rect = findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("filler"));
+ QCOMPARE(rect->x(), 5.0);
+ QCOMPARE(rect->y(), 6.0);
+ QCOMPARE(rect->width(), 200.0 - 5.0 - 10.0);
+ QCOMPARE(rect->height(), 200.0 - 6.0 - 10.0);
+
+ rect->anchors()->setTopMargin(0.0);
+ rect->anchors()->setMargins(20.0);
+
+ QCOMPARE(rect->x(), 5.0);
+ QCOMPARE(rect->y(), 20.0);
+ QCOMPARE(rect->width(), 200.0 - 5.0 - 20.0);
+ QCOMPARE(rect->height(), 200.0 - 20.0 - 20.0);
+
+ delete view;
+}
+
QTEST_MAIN(tst_anchors)
#include "tst_anchors.moc"