2 * Copyright (C) 2016 Canonical, Ltd.
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.
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.
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/>.
18 import Ubuntu.Components 1.3
19 import "MathUtils.js" as MathUtils
24 // Information about the environment
25 property int highlightedIndex: -1
26 property var model: null
27 property int leftMargin: 0
28 property var spreadFlickable
30 // some config options
31 property real contentMargin: 0.16 * root.height
32 property real contentTopMargin: contentMargin
33 property real contentBottomMargin: 0.35 * contentMargin
34 property real windowTitleTopMargin: 3/4 * (contentTopMargin - windowTitle.height)
35 property int stackItemCount: 3
36 property real leftRotationAngle: 22
37 property real rightRotationAngle: 32
38 property real leftStackScale: .82
39 property real rightStackScale: 1
40 property real rightEdgeBreakPoint: Math.min(units.gu(40) / root.width, .35)
45 readonly property int totalItemCount: model.count
46 readonly property real leftStackXPos: 0.03 * root.width + leftMargin
47 readonly property real rightStackXPos: root.width - 1.5 * leftStackXPos + leftMargin
49 readonly property real stackHeight: spreadItemHeight - appInfoHeight
50 readonly property real stackWidth: Math.min(leftStackXPos/3, units.gu(1.5))
52 readonly property real spreadWidth: rightStackXPos - leftStackXPos
53 readonly property real spreadHeight: root.height
54 readonly property real spreadItemHeight: spreadHeight - contentTopMargin - contentBottomMargin
55 readonly property real spreadItemWidth: stackHeight
57 readonly property real dynamicLeftRotationAngle: leftRotationAngle * rotationAngleFactor
58 readonly property real dynamicRightRotationAngle: rightRotationAngle * rotationAngleFactor
60 readonly property real appInfoHeight: {
61 var screenHeightReferencePoint = 40 // ref screen height in gu
62 var valueAtReferencePoint = 0.17 // of screen height at the reference point
63 var appInfoHeightValueChange = -0.0014 // units / gu
64 var minAppInfoHeight = 0.08
65 var maxAppInfoHeight = 0.2
66 var screenHeightInGU = root.height / units.gu(1) // screenHeight in gu
68 return MathUtils.clamp(valueAtReferencePoint + appInfoHeightValueChange * (screenHeightInGU - screenHeightReferencePoint), minAppInfoHeight, maxAppInfoHeight) * root.height
71 property real rotationAngleFactor: {
72 var spreadHeightReferencePoint = 28 // reference spread height in gu
73 var valueAtReferencePoint = 1.3
74 var rotationAngleValueChange = -0.008 // units / gu
75 var minRotationAngleFactor = 0.6
76 var maxRotationAngleFactor = 1.5
77 var spreadHeightInGU = spreadHeight / units.gu(1)
79 return MathUtils.clamp(valueAtReferencePoint + rotationAngleValueChange * (spreadHeightInGU - spreadHeightReferencePoint), minRotationAngleFactor, maxRotationAngleFactor)
81 readonly property real itemOverlap: {
82 var spreadAspectRatioReferencePoint = 1.0 // ref screen height in gu
83 var valueAtReferencePoint = 0.74 // of screen height at the reference point
84 var itemOverlapValueChange = -0.068
87 var spreadAspectRatio = spreadWidth / stackHeight // spread stack aspect ratio (app info not included)
89 return MathUtils.clamp(valueAtReferencePoint + itemOverlapValueChange * (spreadAspectRatio - spreadAspectRatioReferencePoint), minOverlap, maxOverlap)
92 readonly property real visibleItemCount: (spreadWidth / spreadItemWidth) / (1 - itemOverlap)
94 readonly property real spreadTotalWidth: Math.max(2,totalItemCount) * spreadWidth / visibleItemCount
96 readonly property real centeringOffset: Math.max(spreadWidth - spreadTotalWidth ,0) / (2 * spreadWidth)
99 readonly property var curve: BezierCurve {
100 controlPoint2: {'x': 0.19, 'y': 0.00}
101 controlPoint3: {'x': 0.91, 'y': 1.00}
107 width: Math.min(implicitWidth, 0.5*root.width)
108 elide: Qt.ElideMiddle
109 anchors.horizontalCenter: parent.horizontalCenter
110 y: windowTitleTopMargin
111 readonly property var highlightedSurface: root.model ? root.model.surfaceAt(root.highlightedIndex) : null
112 readonly property var highlightedApp: root.model ? root.model.applicationAt(root.highlightedIndex) : null
113 text: root.highlightedIndex >= 0 && highlightedSurface && highlightedSurface.name != "" ? highlightedSurface.name :
114 highlightedApp ? highlightedApp.name : ""
115 fontSize: root.height < units.gu(85) ? 'medium' : 'large'
117 opacity: root.highlightedIndex >= 0 ? 1 : 0
118 Behavior on opacity { UbuntuNumberAnimation { } }
125 selectPrevious(event.isAutoRepeat)
126 event.accepted = true;
130 selectNext(event.isAutoRepeat)
131 event.accepted = true;
134 highlightedIndex = -1
135 // Falling through intentionally
140 event.accepted = true;
145 function selectNext(isAutoRepeat) {
146 if (isAutoRepeat && highlightedIndex >= totalItemCount -1) {
147 return; // AutoRepeat is not allowed to wrap around
150 highlightedIndex = (highlightedIndex + 1) % totalItemCount;
151 spreadFlickable.snap(highlightedIndex)
154 function selectPrevious(isAutoRepeat) {
155 if (isAutoRepeat && highlightedIndex == 0) {
156 return; // AutoRepeat is not allowed to wrap around
159 highlightedIndex = highlightedIndex - 1 >= 0 ? highlightedIndex - 1 : totalItemCount - 1;
160 spreadFlickable.snap(highlightedIndex)