9import QtQuick.Controls as QQC2
10import org.kde.kirigami as Kirigami
11import org.kde.kirigami.templates as KT
82 property bool refreshing:
false
89 property bool supportsRefreshing:
false
95 property Flickable flickable: Flickable {}
96 onFlickableChanged: scrollView.contentItem = flickable;
102 property int verticalScrollBarPolicy
108 property int horizontalScrollBarPolicy: QQC2.ScrollBar.AlwaysOff
110 default property alias scrollablePageData: itemsParent.data
111 property alias scrollablePageChildren: itemsParent.children
116 property QtObject mainItem
118 print(
"Warning: the mainItem property is deprecated");
119 scrollablePageData.push(mainItem);
131 property bool keyboardNavigationEnabled:
true
134 implicitWidth: flickable?.contentItem?.implicitWidth
135 ?? Math.max(implicitBackgroundWidth + leftInset + rightInset,
136 contentWidth + leftPadding + rightPadding,
140 implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
141 contentHeight + topPadding + bottomPadding
142 + (implicitHeaderHeight > 0 ? implicitHeaderHeight + spacing : 0)
143 + (implicitFooterHeight > 0 ? implicitFooterHeight + spacing : 0))
145 contentHeight: flickable?.contentHeight ?? 0
147 Kirigami.Theme.inherit:
false
148 Kirigami.Theme.colorSet: flickable?.hasOwnProperty(
"model") ? Kirigami.Theme.View : Kirigami.Theme.Window
151 if (root.keyboardNavigationEnabled && root.flickable) {
152 if ((
"currentItem" in root.flickable) && root.flickable.currentItem) {
153 return [ root.flickable.currentItem, root.flickable ];
155 return [ root.flickable ];
162 contentItem: QQC2.ScrollView {
165 top: root.header?.visible
168 bottom: root.footer?.visible ? root.footer.top : parent.bottom
173 QQC2.ScrollBar.horizontal.policy: root.horizontalScrollBarPolicy
174 QQC2.ScrollBar.vertical.policy: root.verticalScrollBarPolicy
181 width: root.horizontalScrollBarPolicy === QQC2.ScrollBar.AlwaysOff ? root.flickable.width : Math.max(root.flickable.width, implicitWidth)
182 height: Math.max(root.flickable.height, implicitHeight)
185 for (
const child of itemsParent.visibleChildren) {
186 if (child.implicitWidth <= 0) {
187 implicit = Math.max(implicit, child.width);
189 implicit = Math.max(implicit, child.implicitWidth);
192 return implicit + itemsParent.anchors.leftMargin + itemsParent.anchors.rightMargin;
196 for (
const child of itemsParent.visibleChildren) {
197 if (child.implicitHeight <= 0) {
198 implicit = Math.max(implicit, child.height);
200 implicit = Math.max(implicit, child.implicitHeight);
203 return implicit + itemsParent.anchors.topMargin + itemsParent.anchors.bottomMargin;
207 property Flickable flickable
210 topMargin: root.topPadding
211 leftMargin: root.leftPadding
212 rightMargin: root.rightPadding
213 bottomMargin: root.bottomPadding
216 const child = children[children.length - 1];
217 if (child instanceof QQC2.ScrollView) {
218 print(
"Warning: it's not supported to have ScrollViews inside a ScrollablePage")
223 target: root.flickable
224 property:
"bottomMargin"
225 value: root.bottomPadding
226 restoreMode: Binding.RestoreBinding
231 id: busyIndicatorLoader
232 active: root.supportsRefreshing
235 active: root.refreshing
236 onTriggered: root.refreshing =
true
241 Component.onCompleted: {
242 let flickableFound =
false;
243 for (
const child of itemsParent.data) {
244 if (child instanceof Flickable) {
247 child.activeFocusOnTab =
true;
248 root.flickable = child;
249 flickableFound =
true;
250 if (child instanceof ListView) {
251 child.keyNavigationEnabled =
true;
252 child.keyNavigationWraps =
false;
254 }
else if (child instanceof
Item) {
255 child.anchors.left = itemsParent.left;
256 child.anchors.right = itemsParent.right;
257 }
else if (child instanceof KT.OverlaySheet) {
259 if (child.parent === itemsParent || child.parent === null) {
265 if (flickableFound) {
266 scrollView.contentItem = root.flickable;
267 root.flickable.parent = scrollView;
270 if (root.activeFocus) {
271 root.flickable.forceActiveFocus();
275 root.flickable.anchors.fill = undefined;
276 root.flickable.anchors.top = undefined;
277 root.flickable.anchors.left = undefined;
278 root.flickable.anchors.right = undefined;
279 root.flickable.anchors.bottom = undefined;
280 scrollingArea.visible =
false;
282 scrollView.contentItem = root.flickable;
283 scrollingArea.parent = root.flickable.contentItem;
284 scrollingArea.visible =
true;
285 root.flickable.contentHeight =
Qt.binding(() => scrollingArea.implicitHeight - root.flickable.topMargin - root.flickable.bottomMargin);
286 root.flickable.contentWidth =
Qt.binding(() => scrollingArea.implicitWidth);
287 scrollView.forceActiveFocus(
Qt.TabFocusReason);
289 root.flickable.flickableDirection = Flickable.VerticalFlick;
292 root.flickable.flickDeceleration = 1500;
293 root.flickable.maximumFlickVelocity = 5000;
A pull-down to refresh indicator that can be added to any Flickable or ScrollablePage.