Unity 8
 All Classes Functions Properties
Dash.qml
1 /*
2  * Copyright (C) 2013, 2014 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  */
16 
17 import QtQuick 2.0
18 import Ubuntu.Components 0.1
19 import Unity 0.2
20 import Utils 0.1
21 import "../Components"
22 
23 Showable {
24  id: dash
25  objectName: "dash"
26 
27  visible: shown
28 
29  property string showScopeOnLoaded: "clickscope"
30  property real contentScale: 1.0
31 
32  function setCurrentScope(scopeId, animate, reset) {
33  var scopeIndex = filteredScopes.findFirst(Scopes.RoleId, scopeId)
34 
35  if (scopeIndex == -1) {
36  console.warn("No match for scope with id: %1".arg(scopeId))
37  return
38  }
39 
40  closeOverlayScope();
41 
42  dashContent.closePreview();
43 
44  if (scopeIndex == dashContent.currentIndex && !reset) {
45  // the scope is already the current one
46  return
47  }
48 
49  dashContent.setCurrentScopeAtIndex(scopeIndex, animate, reset)
50  }
51 
52  function closeOverlayScope() {
53  if (dashContent.x != 0) {
54  dashContent.x = 0;
55  }
56  }
57 
58  SortFilterProxyModel {
59  id: filteredScopes
60  model: Scopes {
61  id: scopes
62  }
63  dynamicSortFilter: true
64 
65  filterRole: Scopes.RoleVisible
66  filterRegExp: RegExp("^true$")
67  }
68 
69  DashContent {
70  id: dashContent
71  objectName: "dashContent"
72  width: parent.width
73  height: parent.height
74  model: filteredScopes
75  scopes: scopes
76  visible: x != -width
77  onGotoScope: {
78  dash.setCurrentScope(scopeId, true, false);
79  }
80  onOpenScope: {
81  scopeItem.scope = scope;
82  x = -width;
83  }
84  onScopeLoaded: {
85  if (scopeId == dash.showScopeOnLoaded) {
86  dash.setCurrentScope(scopeId, false, false)
87  dash.showScopeOnLoaded = ""
88  }
89  }
90  scale: dash.contentScale
91  clip: scale != 1.0 || scopeItem.visible
92  Behavior on x {
93  UbuntuNumberAnimation {
94  onRunningChanged: {
95  if (!running && dashContent.x == 0) {
96  dashContent.closeScope(scopeItem.scope);
97  scopeItem.scope = null;
98  }
99  }
100  }
101  }
102  }
103 
104  GenericScopeView {
105  id: scopeItem
106  anchors.left: dashContent.right
107  width: parent.width
108  height: parent.height
109  scale: dash.contentScale
110  clip: scale != 1.0
111  visible: scope != null
112  hasBackAction: true
113  isCurrent: visible
114  onBackClicked: {
115  closeOverlayScope();
116  closePreview();
117  }
118 
119  Connections {
120  target: scopeItem.scope
121  onGotoScope: {
122  dashContent.gotoScope(scopeId);
123  }
124  onOpenScope: {
125  dashContent.openScope(scope);
126  }
127  }
128  }
129 }