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