aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2015-05-23 11:53:42 +0200
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2015-05-23 09:55:36 +0000
commitf0ceecaf0b51809a076ed0add159c95cada528bf (patch)
tree482e80cc6dd707ba2858d95d6f8fe00c5dd13d78
parentbac9cc5b55294655ba08f424f402d21f46c00c15 (diff)
Improve Control::background automatic resizing
- width follows only if x and width are both not specified - height follows only if y and height are both not specified Change-Id: Ib881daa9da339baac53f7f9d4de6e5bdad7723e2 Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
-rw-r--r--src/controls/qquickcontrol.cpp4
-rw-r--r--tests/auto/controls/data/tst_control.qml46
2 files changed, 48 insertions, 2 deletions
diff --git a/src/controls/qquickcontrol.cpp b/src/controls/qquickcontrol.cpp
index 26e68b9f..ac4c257d 100644
--- a/src/controls/qquickcontrol.cpp
+++ b/src/controls/qquickcontrol.cpp
@@ -127,11 +127,11 @@ void QQuickControlPrivate::resizeBackground()
Q_Q(QQuickControl);
if (background) {
QQuickItemPrivate *p = QQuickItemPrivate::get(background);
- if (!p->widthValid) {
+ if (!p->widthValid && qFuzzyIsNull(background->x())) {
background->setWidth(q->width());
p->widthValid = false;
}
- if (!p->heightValid) {
+ if (!p->heightValid && qFuzzyIsNull(background->y())) {
background->setHeight(q->height());
p->heightValid = false;
}
diff --git a/tests/auto/controls/data/tst_control.qml b/tests/auto/controls/data/tst_control.qml
index 3d46ff16..da0a979c 100644
--- a/tests/auto/controls/data/tst_control.qml
+++ b/tests/auto/controls/data/tst_control.qml
@@ -129,4 +129,50 @@ TestCase {
control.destroy()
}
+
+ function test_background() {
+ var control = component.createObject(testCase)
+
+ control.background = component.createObject(control)
+
+ // background has no x or width set, so its width follows control's width
+ control.width = 320
+ compare(control.background.width, control.width)
+
+ // background has no y or height set, so its height follows control's height
+ compare(control.background.height, control.height)
+ control.height = 240
+
+ // has width => width does not follow
+ control.background.width /= 2
+ control.width += 20
+ verify(control.background.width !== control.width)
+
+ // reset width => width follows again
+ control.background.width = undefined
+ control.width += 20
+ compare(control.background.width, control.width)
+
+ // has x => width does not follow
+ control.background.x = 10
+ control.width += 20
+ verify(control.background.width !== control.width)
+
+ // has height => height does not follow
+ control.background.height /= 2
+ control.height -= 20
+ verify(control.background.height !== control.height)
+
+ // reset height => height follows again
+ control.background.height = undefined
+ control.height -= 20
+ compare(control.background.height, control.height)
+
+ // has y => height does not follow
+ control.background.y = 10
+ control.height -= 20
+ verify(control.background.height !== control.height)
+
+ control.destroy()
+ }
}