Lomiri
Loading...
Searching...
No Matches
DrawerGridView.qml
1/*
2 * Copyright (C) 2016 Canonical Ltd.
3 * Copyright (C) 2020 UBports Foundation
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18import QtQuick 2.12
19import Lomiri.Components 1.3
20import "../Components"
21
22FocusScope {
23 id: root
24
25 property int delegateWidth: units.gu(11)
26 property int delegateHeight: units.gu(11)
27 property alias delegate: gridView.delegate
28 property alias model: gridView.model
29 property alias interactive: gridView.interactive
30 property alias currentIndex: gridView.currentIndex
31 property alias draggingVertically: gridView.draggingVertically
32
33 property alias header: gridView.header
34 property alias topMargin: gridView.topMargin
35 property alias bottomMargin: gridView.bottomMargin
36
37 readonly property int columns: Math.floor(width / delegateWidth)
38 readonly property int rows: Math.ceil(gridView.model.count / root.columns)
39
40 property alias refreshing: pullToRefresh.refreshing
41 signal refresh();
42
43 GridView {
44 id: gridView
45 anchors.fill: parent
46 anchors.topMargin: units.gu(2)
47 focus: true
48
49 readonly property int overflow: width - (root.columns * root.delegateWidth)
50 readonly property real spacing: Math.floor(overflow / root.columns)
51
52 cellWidth: root.delegateWidth + spacing
53 cellHeight: root.delegateHeight
54
55 PullToRefresh {
56 id: pullToRefresh
57 parent: gridView
58 target: gridView
59
60 readonly property real contentY: gridView.contentY - gridView.originY
61 y: -contentY - units.gu(5)
62
63 readonly property color pullLabelColor: "white"
64 style: PullToRefreshScopeStyle {
65 activationThreshold: Math.min(units.gu(14), gridView.height / 5)
66 }
67
68 onRefresh: root.refresh();
69 }
70 }
71
72 ProgressBar {
73 anchors {
74 left: parent.left
75 right: parent.right
76 bottom: parent.bottom
77 }
78 visible: refreshing
79 indeterminate: true
80 }
81
82 function getFirstAppId() {
83 return model.appId(0);
84 }
85}