Kirigami2

CardsGridViewPrivate.qml
1 /*
2  * SPDX-FileCopyrightText: 2018 Marco Martin <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.0-or-later
5  */
6 
7 import QtQuick 2.10
8 import org.kde.kirigami 2.4 as Kirigami
9 
10 
11 GridView {
12  id: root
13 
14  property Component _delegateComponent
15 
16 
17  QtObject {
18  id: calculations
19 
20  // initialize array so length property can be read
21  property var leftMargins: []
22  readonly property int delegateWidth: Math.min(cellWidth, maximumColumnWidth) - Kirigami.Units.largeSpacing * 2
23  }
24 
25  delegate: Kirigami.DelegateRecycler {
26  width: calculations.delegateWidth
27 
28  anchors.left: GridView.view.contentItem.left
29 
30  sourceComponent: root._delegateComponent
31  onWidthChanged: {
32  const columnIndex = index % root.columns
33  if (index < root.columns) {
34  // calulate left margin per column
35  calculations.leftMargins[columnIndex] = (width + Kirigami.Units.largeSpacing * 2)
36  * (columnIndex) + root.width / 2
37  - (root.columns * (width + Kirigami.Units.largeSpacing * 2)) / 2;
38  }
39  anchors.leftMargin = calculations.leftMargins[columnIndex];
40  }
41  }
42  onWidthChanged: {
43  if (calculations.leftMargins.length !== root.columns) {
44  calculations.leftMargins = new Array(root.columns);
45  }
46  }
47 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Jan 29 2023 04:11:03 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.