on xenial help sign in
Bottombar: s/Revealer/DirectionalDragArea + refactoring.

Approved by PS Jenkins bot, Albert Astals Cid.

commit1e359e2319273017bd858301110f0915681f9858 authorDaniel d'Andrada <daniel.dandrada@canonical.com> dateThu 20 Jun 2013, 15:24 (13 years ago) parente90dbab8134bba
4 files changed+56−85
Bottombar/Bottombar.qml+48−82 Bottombar/HudButton.qml+3−2 Shell.qml+3 tests/autopilot/unity8/tests/helpers.py+2−1
Bottombar/Bottombar.qml+48−82
@@ -18,38 +18,42 @@ import QtQuick 2.0
1818import "../Components"
1919import "../Components/Math.js" as MathLocal
2020import Unity 0.1
21+import Ubuntu.Gestures 0.1
2122
2223Item {
2324 id: bottombar
24− width: shell.width
25− height: shell.height
25+
26+ // Whether there's an application on foreground (as opposed to have shell's Dash on foreground)
27+ property bool applicationIsOnForeground
2628
2729 property variant theHud
2830 property bool enabled: false
2931 readonly property real bottomEdgeButtonCenterDistance: units.gu(34)
30− readonly property real bottomEdgeShowButtonDistance: units.gu(2)
31−
32− property bool __applicationInFocus: false
3332
34− state: "hidden"
33+ state: dragArea.status === DirectionalDragArea.Recognized ? "shown" : "hidden"
3534
3635 HudButton {
3736 id: hudButton
3837
39− x: MathLocal.clamp(hudButtonRevealer.pressedX - width / 2, 0, bottombar.width - width)
40− y: bottombar.height - bottomEdgeButtonCenterDistance - height / 2 - bottomMargin
41− Behavior on bottomMargin {
42− NumberAnimation{duration: hudButton.opacity < 0.01 ? 200 : 70; easing.type: Easing.OutQuart}
43− }
44− mouse: {
45− if (hudButtonRevealer.draggingArea.pressed) {
46− var mapped = mapFromItem(hudButtonRevealer.draggingArea, hudButtonRevealer.draggingArea.mouseX, hudButtonRevealer.draggingArea.mouseY)
47− return Qt.point(mapped.x, mapped.y)
38+ x: MathLocal.clamp(dragArea.touchStartX - (width / 2), 0, bottombar.width - width)
39+ y: bottombar.height - bottomEdgeButtonCenterDistance - (height / 2) - bottomMargin
40+
41+ mouseOver: {
42+ if (dragArea.status === DirectionalDragArea.Recognized) {
43+ var touchLocal = mapFromItem(dragArea, dragArea.touchX, dragArea.touchY)
44+ return touchLocal.x > 0 && touchLocal.x < width
45+ && touchLocal.y > 0 && touchLocal.y < height
4846 } else {
49− return mouse
47+ return false
5048 }
5149 }
5250
51+ onClicked: theHud.show()
52+
53+ Behavior on bottomMargin {
54+ NumberAnimation{duration: hudButton.opacity < 0.01 ? 200 : 70; easing.type: Easing.OutQuart}
55+ }
56+
5357 Behavior on opacity {
5458 NumberAnimation{ duration: 200; easing.type: Easing.OutCubic}
5559 }
@@ -60,74 +64,36 @@ Item {
6064 onShownChanged: bottomBarVisibilityCommunicatorShell.forceHidden = theHud.shown
6165 }
6266
63− function updateApplicationInFocus() {
64− if (shell.applicationManager.mainStageFocusedApplication || shell.applicationManager.sideStageFocusedApplication) {
65− __applicationInFocus = true
66− } else {
67− __applicationInFocus = false
68− }
69− }
70−
71− Connections {
72− target: shell.applicationManager
73− ignoreUnknownSignals: true
74− onMainStageFocusedApplicationChanged: updateApplicationInFocus()
75− onSideStageFocusedApplicationChanged: updateApplicationInFocus()
76− }
77−
78− Showable {
79− id: hudButtonShowable
80−
81− opacity: 1.0
67+ DirectionalDragArea {
68+ id: dragArea
8269 width: parent.width
83− height: bottomEdgeShowButtonDistance
84− shown: false
85− showAnimation: StandardAnimation { property: "y"; duration: 350; to: hudButtonRevealer.openedValue; easing.type: Easing.OutCubic }
86− hideAnimation: StandardAnimation { property: "y"; duration: 350; to: hudButtonRevealer.closedValue; easing.type: Easing.OutCubic }
87− onYChanged: {
88− if (y == hudButtonRevealer.openedValue)
89− bottombar.state = "shown"
90− }
91−
92− // eater
93− MouseArea {
94− anchors.fill: parent
95− }
96− }
97−
98− Revealer {
99− id: hudButtonRevealer
100−
101− property double pressedX
102−
103− enabled: !theHud.shown && bottombar.enabled && __applicationInFocus
104− direction: Qt.RightToLeft
105− openedValue: bottombar.height - height
106− closedValue: bottombar.height
107− target: hudButtonShowable
108− width: hudButtonShowable.width
109− height: hudButtonShowable.height
110− anchors.bottom: bottombar.bottom
111− onOpenPressed: {
112− pressedX = mouseX
113− }
114−
115− onOpenReleased: {
116− if (hudButton.opacity != 0 && hudButton.mouseOver) {
117− hudButtonShowable.hide()
118− theHud.show()
119− } else {
120− hudButtonShowable.hide()
121− }
122− }
123− }
124−
125− Connections {
126− target: hudButtonShowable.hideAnimation
127− onRunningChanged: {
128− if (hudButtonShowable.hideAnimation.running) {
129− bottombar.state = "hidden"
70+ height: distanceThreshold
71+ anchors.bottom: parent.bottom
72+
73+ enabled: !theHud.shown && bottombar.enabled && applicationIsOnForeground
74+ direction: Direction.Upwards
75+
76+ // values to be tweaked and later removed from here and set in stone as defaults
77+ // once we are confident it's all good.
78+ maxDeviation: units.gu(1)
79+ wideningAngle: 30
80+ distanceThreshold: units.gu(3)
81+ minSpeed: units.gu(5)
82+
83+ property int previousStatus: -1
84+ property real touchStartX: -1
85+
86+ onStatusChanged: {
87+ if (status === DirectionalDragArea.WaitingForTouch) {
88+ if (previousStatus == DirectionalDragArea.Recognized) {
89+ if (hudButton.mouseOver) {
90+ hudButton.clicked()
91+ }
92+ }
93+ } else if (status === DirectionalDragArea.Undecided) {
94+ touchStartX = touchX
13095 }
96+ previousStatus = status
13197 }
13298 }
13399
Bottombar/HudButton.qml+3−2
@@ -20,10 +20,11 @@ import Ubuntu.Components 0.1
2020Item {
2121 id: item
2222
23+ property bool mouseOver
24+
2325 property int bottomMargin: units.gu(2)
24− property bool mouseOver: contains(mouse)
2526
26− property point mouse: Qt.point(-1,-1)
27+ signal clicked()
2728
2829 readonly property real scaleOnMouseOver: 1.2
2930
Shell.qml+3
@@ -188,6 +188,7 @@ FocusScope {
188188
189189 property bool fullyShown: shown && stages[stagesRevealer.boundProperty] == stagesRevealer.openedValue
190190 && parent.x == 0
191+
191192 property bool fullyHidden: !shown && stages[stagesRevealer.boundProperty] == stagesRevealer.closedValue
192193 available: !greeter.shown
193194 hides: [launcher, panel.indicators]
@@ -515,6 +516,8 @@ FocusScope {
515516 theHud: hud
516517 anchors.fill: parent
517518 enabled: !panel.indicators.shown
519+ applicationIsOnForeground: applicationManager.mainStageFocusedApplication
520+ || applicationManager.sideStageFocusedApplication
518521 }
519522
520523 InputFilterArea {
tests/autopilot/unity8/tests/helpers.py+2−1
@@ -98,7 +98,8 @@ class TestShellHelpers(object):
9898 # go to the void for the first time because there's no real way to know what the display has
9999 # painted already. Give it another (max retries) chance.
100100 try:
101− self.assertThat(lambda: getattr(bottombar, "__applicationInFocus"), Eventually(Equals(True)))
101+ self.assertThat(lambda: getattr(bottombar, "applicationIsOnForeground"),
102+ Eventually(Equals(True)))
102103 except:
103104 if retries > 0:
104105 logger.warning("Failed to launch app. Retrying...")