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  property var scope: scopes.getScope(currentIndex)
77 
78  anchors {
79  top: parent.top
80  bottom: parent.bottom
81  left: parent.left
82  right: controls.left
83  }
84  }
85 
86  Rectangle {
87  id: controls
88  color: "lightgrey"
89  width: units.gu(40)
90  anchors {
91  top: parent.top
92  bottom: parent.bottom
93  right: parent.right
94  }
95 
96  MouseArea {
97  anchors.fill: parent
98  }
99 
100  Column {
101  anchors { fill: parent; margins: units.gu(1) }
102  spacing: units.gu(1)
103 
104  Label {
105  text: "Search query"
106  }
107 
108  TextField {
109  id: searchField
110  anchors { left: parent.left; right: parent.right }
111 
112  onTextChanged: dashContent.scope.searchQuery = text
113 
114  Connections {
115  target: dashContent.scope
116  onSearchQueryChanged: searchField.text = dashContent.scope.searchQuery
117  }
118  }
119 
120  Label {
121  text: "Category"
122  height: units.gu(4)
123  verticalAlignment: Text.AlignBottom
124  }
125 
126  OptionSelector {
127  id: categorySelector
128  anchors { left: parent.left; right: parent.right }
129  model: dashContent.scope ? dashContent.scope.categories : null
130 
131  property Item selectedItem
132 
133  delegate: OptionSelectorDelegate {
134  id: categoryDelegate
135  text: model.name
136  property string categoryId: model.categoryId
137  property string template: JSON.stringify(JSON.parse(model.rawRendererTemplate), null, " ");
138 
139  onSelectedChanged: if (selected) categorySelector.selectedItem = categoryDelegate
140  }
141  }
142 
143  TextArea {
144  id: categoryJson
145  width: parent.width
146  autoSize: true
147  readOnly: true
148  text: categorySelector.selectedItem && categorySelector.selectedItem.template
149  }
150 
151  Button {
152  width: parent.width
153  text: "Override category"
154  onClicked: {
155  PopupUtils.open(categoryEditor)
156  }
157  }
158  }
159  }
160 
161  Component {
162  id: categoryEditor
163 
164  ComposerSheet {
165  id: sheet
166  title: "Editing category definition"
167 
168  TextArea {
169  id: categoryEditorArea
170  anchors.fill: parent
171  wrapMode: Text.WordWrap
172  text: categoryJson.text
173  }
174 
175  onCancelClicked: PopupUtils.close(sheet)
176  onConfirmClicked: {
177  PopupUtils.close(sheet);
178  dashContent.scope.categories.overrideCategoryJson(categorySelector.selectedItem.categoryId, categoryEditorArea.text);
179  }
180  }
181  }
182 }