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