Lomiri
Loading...
Searching...
No Matches
PanelBar.qml
1/*
2 * Copyright (C) 2014 Canonical Ltd.
3 * Copyright (C) 2020-2026 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.15
19import Lomiri.Components 1.3
20import "../../../Components"
21
22Item {
23 id: root
24 property alias expanded: row.expanded
25 property alias finishedExpanding: row.finishedExpanding
26 property alias interactive: row.interactive
27 property alias model: row.model
28 property alias unitProgress: row.unitProgress
29 property alias enableLateralChanges: row.enableLateralChanges
30 property alias overFlowWidth: row.overFlowWidth
31 readonly property alias currentItemIndex: row.currentItemIndex
32 property real lateralPosition: -1
33 property int alignment: Qt.AlignRight
34 readonly property int rowContentX: row.contentX
35 property alias screenIndex: row.screenIndex
36 property alias orientation: row.screenOrientation
37
38 property alias hideRow: row.hideRow
39 property alias rowItemDelegate: row.delegate
40
41 implicitWidth: row.contentWidth
42
43 function selectItemAt(lateralPosition) {
44 if (!expanded) {
45 row.resetCurrentItem();
46 }
47 var mapped = root.mapToItem(row, lateralPosition, 0);
48 row.selectItemAt(mapped.x);
49 }
50
51 function selectPreviousItem() {
52 if (!expanded) {
53 row.resetCurrentItem();
54 }
55 row.selectPreviousItem();
56 }
57
58 function selectNextItem() {
59 if (!expanded) {
60 row.resetCurrentItem();
61 }
62 row.selectNextItem();
63 }
64
65 function setCurrentItemIndex(index) {
66 if (!expanded) {
67 row.resetCurrentItem();
68 }
69 row.setCurrentItemIndex(index);
70 }
71
72 function addScrollOffset(scrollAmount) {
73 if (root.alignment == Qt.AlignLeft) {
74 scrollAmount = -scrollAmount;
75 }
76 // If we are scrolling left and we are already on the first item, stop if the item is fully on screen
77 // this is necessary because of a hack in PanelItemRow (adds extra space to row.contentWidth)
78 if (scrollAmount < 0 && row.currentItemIndex === 0 && row.currentItem.mapToItem(root, 0, 0).x > 0) {
79 return;
80 }
81 row.contentX = Math.min(Math.max(row.contentX - scrollAmount, 0), row.contentWidth);
82 root.lateralPositionChanged();
83 }
84
85 Item {
86 id: rowContainer
87 anchors.fill: parent
88 clip: expanded || row.width > rowContainer.width
89
90 PanelItemRow {
91 id: row
92 objectName: "panelItemRow"
93 anchors.fill: parent
94
95 lateralPosition: {
96 if (root.lateralPosition == -1) return -1;
97
98 var mapped = root.mapToItem(row, root.lateralPosition, 0);
99 return Math.min(Math.max(mapped.x, 0), row.width);
100 }
101
102 MouseArea {
103 anchors.fill: parent
104 enabled: root.expanded
105 propagateComposedEvents: true
106 onClicked: {
107 row.selectItemAt(mouse.x);
108 mouse.accepted = false;
109 }
110 onPressed: {
111 row.selectItemAt(mouse.x);
112 mouse.accepted = false;
113 }
114 }
115 }
116 }
117}