SwipeView: position the pages adjacent to each other initially

ListView only manages the positions of the visible delegates; but the
children of SwipeView are instantiated at startup. When we didn't set
their positions, if they are translucent, they were simply piled up
on top of each other until ListView got around to positioning them
during swiping. Between a055629f43 and
e10de033f4 SwipeView was calling
setCulled(true); we stopped doing that because of QTBUG-99547.
So now it makes sense to position the delegates the same way that
ListView will eventually position them... assuming there are no
other special cases for custom positioning. They are still
effectively "culled" by being outside the viewport, or the clip.

Fixes: QTBUG-102487
Task-number: QTBUG-51078
Task-number: QTBUG-51669
Task-number: QTBUG-99547
Pick-to: 5.15 6.2 6.3
Change-Id: I58afab55cc95a1d4a637111a9cca82e6177856ff
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
This commit is contained in:
Shawn Rutledge 2022-05-09 15:58:26 +02:00
parent 78483744b4
commit 7a5bbc2315
2 changed files with 32 additions and 3 deletions

View File

@ -158,11 +158,10 @@ void QQuickSwipeViewPrivate::resizeItems()
qmlWarning(item) << "SwipeView has detected conflicting anchors. Unable to layout the item.";
item->setProperty("_q_QQuickSwipeView_warned", true);
}
if (orientation == Qt::Horizontal)
item->setY(0);
item->setPosition({i * (contentItem->width() + spacing), 0});
else
item->setX(0);
item->setPosition({0, i * (contentItem->height() + spacing)});
item->setSize(QSizeF(contentItem->width(), contentItem->height()));
}
}

View File

@ -686,4 +686,34 @@ TestCase {
var image = grabImage(control)
compare(image.pixel(3, 3), "#ffff00")
}
Component {
id: translucentPages
SwipeView {
spacing: 10
padding: 10
Text { text: "page 0" }
Text { text: "page 1"; font.pointSize: 16 }
Text { text: "page 2"; font.pointSize: 24 }
Text { text: "page 3"; font.pointSize: 32 }
}
}
function test_initialPositions() { // QTBUG-102487
const control = createTemporaryObject(translucentPages, testCase, {width: 320, height: 200})
verify(control)
compare(control.orientation, Qt.Horizontal)
for (var i = 0; i < control.count; ++i) {
const page = control.itemAt(i)
// control.contentItem.width + control.spacing == 310; except Imagine style has contentItem.width == 320
compare(page.x, i * 310)
compare(page.y, 0)
}
control.orientation = Qt.Vertical
for (var i = 0; i < control.count; ++i) {
const page = control.itemAt(i)
compare(page.y, i * (control.contentItem.height + control.spacing))
compare(page.x, 0)
}
}
}