summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/graphicsitems/qmlgraphicsanchors.cpp55
-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/fill.qml14
-rw-r--r--tests/auto/declarative/anchors/data/margins.qml13
-rw-r--r--tests/auto/declarative/anchors/tst_anchors.cpp62
6 files changed, 144 insertions, 10 deletions
diff --git a/src/declarative/graphicsitems/qmlgraphicsanchors.cpp b/src/declarative/graphicsitems/qmlgraphicsanchors.cpp
index b72f010..96d76cf 100644
--- a/src/declarative/graphicsitems/qmlgraphicsanchors.cpp
+++ b/src/declarative/graphicsitems/qmlgraphicsanchors.cpp
@@ -833,7 +833,10 @@ void QmlGraphicsAnchors::setLeftMargin(qreal offset)
if (d->leftMargin == offset)
return;
d->leftMargin = offset;
- d->updateHorizontalAnchors();
+ if(d->fill)
+ d->fillChanged();
+ else
+ d->updateHorizontalAnchors();
emit leftMarginChanged();
}
@@ -849,10 +852,38 @@ void QmlGraphicsAnchors::setRightMargin(qreal offset)
if (d->rightMargin == offset)
return;
d->rightMargin = offset;
- d->updateHorizontalAnchors();
+ if(d->fill)
+ d->fillChanged();
+ else
+ d->updateHorizontalAnchors();
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);
@@ -865,7 +896,10 @@ void QmlGraphicsAnchors::setHorizontalCenterOffset(qreal offset)
if (d->hCenterOffset == offset)
return;
d->hCenterOffset = offset;
- d->updateHorizontalAnchors();
+ if(d->centerIn)
+ d->centerInChanged();
+ else
+ d->updateHorizontalAnchors();
emit horizontalCenterOffsetChanged();
}
@@ -881,7 +915,10 @@ void QmlGraphicsAnchors::setTopMargin(qreal offset)
if (d->topMargin == offset)
return;
d->topMargin = offset;
- d->updateVerticalAnchors();
+ if(d->fill)
+ d->fillChanged();
+ else
+ d->updateVerticalAnchors();
emit topMarginChanged();
}
@@ -897,7 +934,10 @@ void QmlGraphicsAnchors::setBottomMargin(qreal offset)
if (d->bottomMargin == offset)
return;
d->bottomMargin = offset;
- d->updateVerticalAnchors();
+ if(d->fill)
+ d->fillChanged();
+ else
+ d->updateVerticalAnchors();
emit bottomMarginChanged();
}
@@ -913,7 +953,10 @@ void QmlGraphicsAnchors::setVerticalCenterOffset(qreal offset)
if (d->vCenterOffset == offset)
return;
d->vCenterOffset = offset;
- d->updateVerticalAnchors();
+ if(d->centerIn)
+ d->centerInChanged();
+ else
+ d->updateVerticalAnchors();
emit verticalCenterOffsetChanged();
}
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/fill.qml b/tests/auto/declarative/anchors/data/fill.qml
new file mode 100644
index 0000000..902465c
--- /dev/null
+++ b/tests/auto/declarative/anchors/data/fill.qml
@@ -0,0 +1,14 @@
+import Qt 4.6
+
+Rectangle {
+ width: 200; height: 200
+ Rectangle {
+ objectName: "filler"
+ width: 50; height: 50; color: "blue"
+ anchors.fill: parent;
+ anchors.leftMargin: 10;
+ anchors.rightMargin: 20;
+ anchors.topMargin: 30;
+ anchors.bottomMargin: 40;
+ }
+}
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 bbe5ef1..defc841 100644
--- a/tests/auto/declarative/anchors/tst_anchors.cpp
+++ b/tests/auto/declarative/anchors/tst_anchors.cpp
@@ -72,6 +72,8 @@ private slots:
void nullItem_data();
void crash1();
void centerIn();
+ void fill();
+ void margins();
};
/*
@@ -379,6 +381,32 @@ void tst_anchors::crash1()
delete view;
}
+void tst_anchors::fill()
+{
+ QmlView *view = new QmlView;
+
+ view->setUrl(QUrl("file://" SRCDIR "/data/fill.qml"));
+
+ view->execute();
+ qApp->processEvents();
+ QmlGraphicsRectangle* rect = findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("filler"));
+ 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)
+ rect->anchors()->setLeftMargin(20.0);
+ rect->anchors()->setRightMargin(0.0);
+ rect->anchors()->setBottomMargin(0.0);
+ rect->anchors()->setTopMargin(10.0);
+ QCOMPARE(rect->x(), 0.0 + 20.0);
+ QCOMPARE(rect->y(), 0.0 + 10.0);
+ QCOMPARE(rect->width(), 200.0 - 20.0);
+ QCOMPARE(rect->height(), 200.0 - 10.0);
+
+ delete view;
+}
+
void tst_anchors::centerIn()
{
QmlView *view = new QmlView;
@@ -387,9 +415,39 @@ void tst_anchors::centerIn()
view->execute();
qApp->processEvents();
+ QmlGraphicsRectangle* rect = findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("centered"));
+ QCOMPARE(rect->x(), 75.0 + 10);
+ QCOMPARE(rect->y(), 75.0 + 30);
+ //Alter Offsets (QTBUG-6631)
+ rect->anchors()->setHorizontalCenterOffset(-20.0);
+ rect->anchors()->setVerticalCenterOffset(-10.0);
+ QCOMPARE(rect->x(), 75.0 - 20.0);
+ QCOMPARE(rect->y(), 75.0 - 10.0);
- QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("centered"))->x(), 85.0);
- QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("centered"))->y(), 105.0);
+ 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;
}