Unity 8
 All Classes Functions Properties
ScopeTool.qml
1 /*
2 * Copyright (C) 2013 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 Ubuntu.Components.Popups 0.1
20 import Utils 0.1
21 import Unity 0.2
22 import "Components"
23 import "Dash"
24 
25 Rectangle {
26  id: root
27  width: units.gu(80)
28  height: units.gu(72)
29  color: "#88FFFFFF"
30 
31  // Fake shell object
32  QtObject {
33  id: shell
34  }
35 
36  // Fake greeter object
37  QtObject {
38  id: greeter
39  property bool shown
40  }
41 
42  // Fake panel object
43  QtObject {
44  id: panel
45  signal searchClicked
46  }
47 
48  SortFilterProxyModel {
49  id: filteredScopes
50  model: Scopes {
51  id: scopes
52  }
53  dynamicSortFilter: true
54 
55  filterRole: Scopes.RoleVisible
56  filterRegExp: RegExp("^true$")
57  }
58 
59  Rectangle {
60  anchors.fill: dashContent
61  color: "#FCFCFC"
62  }
63 
64  Image {
65  anchors.fill: dashContent
66  source: root.width > root.height ? "Dash/graphics/paper_landscape.png" : "Dash/graphics/paper_portrait.png"
67  fillMode: Image.PreserveAspectCrop
68  horizontalAlignment: Image.AlignRight
69  verticalAlignment: Image.AlignTop
70  }
71 
72  DashContent {
73  id: dashContent
74 
75  model: filteredScopes
76  searchHistory: SearchHistoryModel { }
77  property Scope scope: scopes.get(currentIndex)
78 
79  anchors {
80  top: parent.top
81  bottom: parent.bottom
82  left: parent.left
83  right: controls.left
84  }
85  }
86 
87  Rectangle {
88  id: controls
89  color: "lightgrey"
90  width: units.gu(40)
91  anchors {
92  top: parent.top
93  bottom: parent.bottom
94  right: parent.right
95  }
96 
97  MouseArea {
98  anchors.fill: parent
99  }
100 
101  Column {
102  anchors { fill: parent; margins: units.gu(1) }
103  spacing: units.gu(1)
104 
105  Label {
106  text: "Search query"
107  }
108 
109  TextField {
110  id: searchField
111  anchors { left: parent.left; right: parent.right }
112 
113  onTextChanged: dashContent.scope.searchQuery = text
114 
115  Connections {
116  target: dashContent.scope
117  onSearchQueryChanged: searchField.text = dashContent.scope.searchQuery
118  }
119  }
120 
121  Label {
122  text: "Category"
123  height: units.gu(4)
124  verticalAlignment: Text.AlignBottom
125  }
126 
127  OptionSelector {
128  id: categorySelector
129  anchors { left: parent.left; right: parent.right }
130  model: dashContent.scope ? dashContent.scope.categories : null
131 
132  property Item selectedItem
133 
134  delegate: OptionSelectorDelegate {
135  id: categoryDelegate
136  text: model.name
137  property string categoryId: model.categoryId
138  property string template: JSON.stringify(JSON.parse(model.rawRendererTemplate), null, " ");
139 
140  onSelectedChanged: if (selected) categorySelector.selectedItem = categoryDelegate
141  }
142  }
143 
144  TextArea {
145  id: categoryJson
146  width: parent.width
147  autoSize: true
148  readOnly: true
149  text: categorySelector.selectedItem && categorySelector.selectedItem.template
150  }
151 
152  Button {
153  width: parent.width
154  text: "Override category"
155  onClicked: {
156  PopupUtils.open(categoryEditor)
157  }
158  }
159  }
160  }
161 
162  Component {
163  id: categoryEditor
164 
165  ComposerSheet {
166  id: sheet
167  title: "Editing category definition"
168 
169  TextArea {
170  id: categoryEditorArea
171  anchors.fill: parent
172  wrapMode: Text.WordWrap
173  text: categoryJson.text
174  }
175 
176  onCancelClicked: PopupUtils.close(sheet)
177  onConfirmClicked: {
178  PopupUtils.close(sheet);
179  dashContent.scope.categories.overrideCategoryJson(categorySelector.selectedItem.categoryId, categoryEditorArea.text);
180  }
181  }
182  }
183 }