2 * Copyright (C) 2014-2016 Canonical Ltd.
3 * Copyright (C) 2020-2026 UBports Foundation
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.
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.
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/>.
19import Lomiri.Components 1.3
20import Lomiri.Gestures 0.1
21import "../../../Components"
22import "../../Indicators"
27 property alias model: bar.model
28 property alias showDragHandle: __showDragHandle
29 property alias hideDragHandle: __hideDragHandle
30 property alias overFlowWidth: bar.overFlowWidth
31 property alias verticalVelocityThreshold: yVelocityCalculator.velocityThreshold
32 property int minimizedPanelHeight: units.gu(3)
33 property int expandedPanelHeight: units.gu(7)
34 property real openedHeight: units.gu(71)
35 property bool enableHint: true
36 property bool showOnClick: true
37 property color panelColor: Qt.hsla(0, 0, Math.round(theme.palette.normal.background.hslLightness), 1)
38 property real menuContentX: 0
40 property alias alignment: bar.alignment
41 property alias hideRow: bar.hideRow
42 property alias rowItemDelegate: bar.rowItemDelegate
43 property alias pageDelegate: content.pageDelegate
45 property var blurSource : null
46 property rect blurRect : Qt.rect(0, 0, 0, 0)
47 property alias screenIndex: bar.screenIndex
48 property alias orientation: bar.orientation
50 readonly property real unitProgress: Math.max(0, (height - minimizedPanelHeight) / (openedHeight - minimizedPanelHeight))
51 readonly property bool fullyOpened: unitProgress >= 1
52 readonly property bool partiallyOpened: unitProgress > 0 && unitProgress < 1.0
53 readonly property bool fullyClosed: unitProgress == 0
54 readonly property alias expanded: bar.expanded
55 readonly property int barWidth: bar.width
56 readonly property alias currentMenuIndex: bar.currentItemIndex
58 // Exposes the current contentX of the PanelBar's internal ListView. This
59 // must be used to offset absolute x values against the ListView, since
60 // we commonly add or remove elements and cause the contentX to change.
61 readonly property int rowContentX: bar.rowContentX
63 // The user tapped the panel and did not move.
64 // Note that this does not fire on mouse events, only touch events.
67 // TODO: Perhaps we need a animation standard for showing/hiding? Each showable seems to
68 // use its own values. Need to ask design about this.
69 showAnimation: SequentialAnimation {
74 duration: LomiriAnimation.BriskDuration
75 easing.type: Easing.OutCubic
77 // set binding in case units.gu changes while menu open, so height correctly adjusted to fit
78 ScriptAction { script: root.height = Qt.binding( function(){ return root.openedHeight; } ) }
81 hideAnimation: SequentialAnimation {
85 to: minimizedPanelHeight
86 duration: LomiriAnimation.BriskDuration
87 easing.type: Easing.OutCubic
89 // set binding in case units.gu changes while menu closed, so menu adjusts to fit
90 ScriptAction { script: root.height = Qt.binding( function(){ return root.minimizedPanelHeight; } ) }
94 height: minimizedPanelHeight
96 onUnitProgressChanged: d.updateState()
101 width: root.blurRect.width
102 height: root.blurRect.height
103 visible: root.height > root.minimizedPanelHeight
104 sourceItem: root.blurSource
105 blurRect: root.blurRect
114 bottom: parent.bottom
116 clip: root.partiallyOpened
119 color: Qt.rgba(root.panelColor.r,
129 anchors.fill: content
131 acceptedButtons: Qt.AllButtons
132 onWheel: wheel.accepted = true;
133 enabled: root.state != "initial"
134 visible: content.visible
139 objectName: "menuContent"
146 height: openedHeight - bar.height - handle.height
148 visible: root.unitProgress > 0
149 currentMenuIndex: bar.currentItemIndex
159 bottom: parent.bottom
162 active: d.activeDragHandle ? true : false
163 visible: !root.fullyClosed
169 visible: !root.fullyClosed
173 if (event.key === Qt.Key_Left) {
174 bar.selectPreviousItem();
175 event.accepted = true;
176 } else if (event.key === Qt.Key_Right) {
177 bar.selectNextItem();
178 event.accepted = true;
179 } else if (event.key === Qt.Key_Escape) {
181 event.accepted = true;
187 objectName: "indicatorsBar"
194 enableLateralChanges: false
195 finishedExpanding: !indicatorsBarHeightAnimation.running
197 unitProgress: root.unitProgress
199 height: expanded ? expandedPanelHeight : minimizedPanelHeight
202 id: indicatorsBarHeightAnimation
203 duration: LomiriAnimation.SnapDuration
204 easing: LomiriAnimation.StandardEasing
212 anchors.left: bar.left
215 forceScrollingPercentage: 0.33
216 stopScrollThreshold: units.gu(0.75)
217 direction: Qt.RightToLeft
220 onScroll: bar.addScrollOffset(-scrollAmount);
226 anchors.right: bar.right
229 forceScrollingPercentage: 0.33
230 stopScrollThreshold: units.gu(0.75)
231 direction: Qt.LeftToRight
234 onScroll: bar.addScrollOffset(scrollAmount);
238 anchors.bottom: parent.bottom
239 anchors.left: alignment == Qt.AlignLeft ? parent.left : __showDragHandle.left
240 anchors.right: alignment == Qt.AlignRight ? parent.right : __showDragHandle.right
241 height: minimizedPanelHeight
242 enabled: __showDragHandle.enabled && showOnClick
244 var barPosition = mapToItem(bar, mouseX, mouseY);
245 bar.selectItemAt(barPosition.x)
252 objectName: "showDragHandle"
253 anchors.bottom: parent.bottom
254 anchors.left: alignment == Qt.AlignLeft ? parent.left : undefined
255 anchors.leftMargin: -root.menuContentX
256 anchors.right: alignment == Qt.AlignRight ? parent.right : undefined
257 width: root.overFlowWidth + root.menuContentX
258 height: minimizedPanelHeight
259 direction: Direction.Downwards
260 enabled: !root.shown && root.available && !hideAnimation.running && !showAnimation.running
261 autoCompleteDragThreshold: maxTotalDragDistance / 2
266 touchPressTime = new Date().getTime();
268 var touchReleaseTime = new Date().getTime();
269 if (touchReleaseTime - touchPressTime <= 300 && distance < units.gu(1)) {
274 property var touchPressTime
276 // using hint regulates minimum to hint displacement, but in fullscreen mode, we need to do it manually.
277 overrideStartValue: enableHint ? minimizedPanelHeight : expandedPanelHeight + handle.height
278 maxTotalDragDistance: openedHeight - (enableHint ? minimizedPanelHeight : expandedPanelHeight + handle.height)
279 hintDisplacement: enableHint ? expandedPanelHeight - minimizedPanelHeight + handle.height : 0
283 anchors.fill: __hideDragHandle
284 enabled: __hideDragHandle.enabled
285 onClicked: root.hide()
290 objectName: "hideDragHandle"
292 direction: Direction.Upwards
293 enabled: root.shown && root.available && !hideAnimation.running && !showAnimation.running
294 hintDisplacement: units.gu(3)
295 autoCompleteDragThreshold: maxTotalDragDistance / 6
297 maxTotalDragDistance: openedHeight - expandedPanelHeight - handle.height
299 onTouchPositionChanged: {
300 if (root.state === "locked") {
301 d.xDisplacementSinceLock += (touchPosition.x - d.lastHideTouchX)
302 d.lastHideTouchX = touchPosition.x;
307 PanelVelocityCalculator {
308 id: yVelocityCalculator
309 velocityThreshold: d.hasCommitted ? 0.1 : 0.3
310 trackedValue: d.activeDragHandle ?
311 (Direction.isPositive(d.activeDragHandle.direction) ?
312 d.activeDragHandle.distance :
313 -d.activeDragHandle.distance)
316 onVelocityAboveThresholdChanged: d.updateState()
320 target: showAnimation
321 function onRunningChanged() {
322 if (showAnimation.running) {
323 root.state = "commit";
329 target: hideAnimation
330 function onRunningChanged() {
331 if (hideAnimation.running) {
332 root.state = "initial";
339 property var activeDragHandle: showDragHandle.dragging ? showDragHandle : hideDragHandle.dragging ? hideDragHandle : null
340 property bool hasCommitted: false
341 property real lastHideTouchX: 0
342 property real xDisplacementSinceLock: 0
343 onXDisplacementSinceLockChanged: d.updateState()
345 property real rowMappedLateralPosition: {
346 if (!d.activeDragHandle) return -1;
347 return d.activeDragHandle.mapToItem(bar, d.activeDragHandle.touchPosition.x, 0).x;
350 function updateState() {
351 if (!showAnimation.running && !hideAnimation.running && d.activeDragHandle) {
352 if (unitProgress <= 0) {
353 root.state = "initial";
354 // lock indicator if we've been committed and aren't moving too much laterally or too fast up.
355 } else if (d.hasCommitted && (Math.abs(d.xDisplacementSinceLock) < units.gu(2) || yVelocityCalculator.velocityAboveThreshold)) {
356 root.state = "locked";
358 root.state = "reveal";
367 PropertyChanges { target: d; hasCommitted: false; restoreEntryValues: false }
373 yVelocityCalculator.reset();
374 // initial item selection
375 if (!d.hasCommitted) bar.selectItemAt(d.rowMappedLateralPosition);
376 d.hasCommitted = false;
382 // changes to lateral touch position effect which indicator is selected
383 lateralPosition: d.rowMappedLateralPosition
384 // vertical velocity determines if changes in lateral position has an effect
385 enableLateralChanges: d.activeDragHandle &&
386 !yVelocityCalculator.velocityAboveThreshold
388 // left scroll bar handling
392 if (!d.activeDragHandle) return -1;
393 var mapped = d.activeDragHandle.mapToItem(leftScroller, d.activeDragHandle.touchPosition.x, 0);
397 // right scroll bar handling
399 target: rightScroller
401 if (!d.activeDragHandle) return -1;
402 var mapped = d.activeDragHandle.mapToItem(rightScroller, d.activeDragHandle.touchPosition.x, 0);
411 d.xDisplacementSinceLock = 0;
412 d.lastHideTouchX = hideDragHandle.touchPosition.x;
415 PropertyChanges { target: bar; expanded: true }
420 PropertyChanges { target: root; focus: true }
421 PropertyChanges { target: bar; interactive: true }
426 xDisplacementSinceLock: 0
427 restoreEntryValues: false