on 02f0ecb help sign in
unity8/qml/Tutorial/TutorialBottom.qml
97 lines 3.7 kB history raw
1/*
2 * Copyright (C) 2015 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17import QtQuick 2.4
18import Ubuntu.Components 1.3
19import Ubuntu.Gestures 0.1
21TutorialPage {
22 id: root
24 // This page is a bit fragile. It relies on knowing how the app beneath
25 // the shell will react to a drag. What we do is put a monitor-only DDA
26 // at the bottom of the page (so that we know when the drag is finished)
27 // and pass the events on through to the app. Thus, it sees the drag and
28 // brings its bottom edge up.
29 //
30 // Unfortunately, each app is on its own when implementing the bottom edge
31 // drag. Most share copied-and-pasted code right now, but they will
32 // eventually consolidate on a version of DirectionalDragArea that will
33 // land in the SDK (making our guessing job easier). Though, also in the
34 // future, this whole bottom tutorial component will also land in the SDK,
35 // rendering our version here obsolete.
36 //
37 // Anyway, for the moment, we base our guesses on the copied-and-pasted
38 // code used in several of the core apps and only bring this component
39 // up if we are in those core apps.
41 function canShowForApp(appId) {
42 return appId === "address-book-app" ||
43 appId === "com.ubuntu.calculator_calculator" ||
44 appId === "com.ubuntu.clock_clock" ||
45 appId === "dialer-app" ||
46 appId === "messaging-app";
47 }
49 readonly property real dragAreaHeight: units.gu(3) // based on PageWithBottomEdge.qml
50 readonly property real targetDistance: height * 0.2 + dragAreaHeight // based on PageWithBottomEdge.qml
52 opacityOverride: dragArea.dragging ? 1 - (-dragArea.distance / targetDistance) : 1
54 mouseArea {
55 anchors.bottomMargin: root.dragAreaHeight
56 }
58 background {
59 sourceSize.height: 1080
60 sourceSize.width: 1916
61 source: Qt.resolvedUrl("graphics/background2.png")
62 rotation: 180
63 }
65 arrow {
66 anchors.bottom: root.bottom
67 anchors.bottomMargin: units.gu(4)
68 anchors.horizontalCenter: root.horizontalCenter
69 rotation: -90
70 }
72 label {
73 text: i18n.tr("Swipe from the bottom edge to manage the app")
74 anchors.bottom: arrow.top
75 anchors.bottomMargin: units.gu(3)
76 anchors.horizontalCenter: root.horizontalCenter
77 anchors.horizontalCenterOffset: (label.width - label.contentWidth) / 2
78 width: root.width - units.gu(8)
79 }
81 // Watches drag events but does not intercept them, so that the app beneath
82 // will still drag the bottom edge up.
83 DirectionalDragArea {
84 id: dragArea
85 monitorOnly: true
86 direction: Direction.Upwards
87 anchors.left: parent.left
88 anchors.right: parent.right
89 anchors.bottom: parent.bottom
90 height: root.dragAreaHeight
92 // Because apps currently don't use DDA, and DDA will stop a gesture if
93 // horizontal motion is detected. But our apps wont'. So turn off
94 // that gesture cleverness on our part, it will only get us out of sync.
95 immediateRecognition: true
96 }