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 ListModel searchHistory: SearchHistoryModel {}
30  property bool searchable: !dashContent.previewOpen && !scopeItem.previewOpen
31 
32  property string showScopeOnLoaded: "clickscope"
33  property real contentScale: 1.0
34 
35  function setCurrentScope(scopeId, animate, reset) {
36  var scopeIndex = filteredScopes.findFirst(Scopes.RoleId, scopeId)
37 
38  if (scopeIndex == -1) {
39  console.warn("No match for scope with id: %1".arg(scopeId))
40  return
41  }
42 
43  closeOverlayScope();
44 
45  dashContent.closePreview();
46 
47  if (scopeIndex == dashContent.currentIndex && !reset) {
48  // the scope is already the current one
49  return
50  }
51 
52  dashContent.setCurrentScopeAtIndex(scopeIndex, animate, reset)
53  }
54 
55  function closeOverlayScope() {
56  if (dashContent.x != 0) {
57  dashContent.x = 0;
58  }
59  }
60 
61  SortFilterProxyModel {
62  id: filteredScopes
63  model: Scopes {
64  id: scopes
65  }
66  dynamicSortFilter: true
67 
68  filterRole: Scopes.RoleVisible
69  filterRegExp: RegExp("^true$")
70  }
71 
72  DashContent {
73  id: dashContent
74  objectName: "dashContent"
75  width: parent.width
76  height: parent.height
77  model: filteredScopes
78  scopes: scopes
79  searchHistory: dash.searchHistory
80  visible: x != -width
81  onGotoScope: {
82  dash.setCurrentScope(scopeId, true, false);
83  }
84  onOpenScope: {
85  scopeItem.scope = scope;
86  x = -width;
87  }
88  onScopeLoaded: {
89  if (scopeId == dash.showScopeOnLoaded) {
90  dash.setCurrentScope(scopeId, false, false)
91  dash.showScopeOnLoaded = ""
92  }
93  }
94  scale: dash.contentScale
95  clip: scale != 1.0 || scopeItem.visible
96  Behavior on x {
97  UbuntuNumberAnimation {
98  onRunningChanged: {
99  if (!running && dashContent.x == 0) {
100  dashContent.closeScope(scopeItem.scope);
101  scopeItem.scope = null;
102  }
103  }
104  }
105  }
106  }
107 
108  ScopeItem {
109  id: scopeItem
110  anchors.left: dashContent.right
111  width: parent.width
112  height: parent.height
113  searchHistory: dash.searchHistory
114  scale: dash.contentScale
115  clip: scale != 1.0
116  visible: scope != null
117  onBack: {
118  closeOverlayScope();
119  }
120  onGotoScope: {
121  // TODO
122  console.log("gotoScope from an openScope scope is not implemented");
123  }
124  onOpenScope: {
125  // TODO
126  console.log("openScope from an openScope scope is not implemented");
127  }
128 
129  }
130 }