~dandrader/unity8/multiInstanceApp

« back to all changes in this revision

Viewing changes to qml/ScopeTool.qml

  • Committer: Michal Hruby
  • Date: 2013-12-20 15:27:59 UTC
  • mto: This revision was merged to the branch mainline in revision 613.
  • Revision ID: michal.mhr@gmail.com-20131220152759-7o59l2oqwleinknu
Cherrypick the unity-scope-tool

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import QtQuick 2.0
 
2
import Ubuntu.Components 0.1
 
3
import Ubuntu.Components.Popups 0.1
 
4
import Unity 0.1
 
5
import "Dash"
 
6
 
 
7
Rectangle {
 
8
    id: root
 
9
    width: units.gu(80)
 
10
    height: units.gu(72)
 
11
    color: "#88FFFFFF"
 
12
 
 
13
    // Fake shell object
 
14
    QtObject {
 
15
        id: shell
 
16
    }
 
17
 
 
18
    // Fake greeter object
 
19
    QtObject {
 
20
        id: greeter
 
21
        property bool shown
 
22
    }
 
23
 
 
24
    // Fake panel object
 
25
    QtObject {
 
26
        id: panel
 
27
        signal searchClicked
 
28
    }
 
29
 
 
30
 
 
31
    Scopes {
 
32
        id: scopes
 
33
    }
 
34
 
 
35
    Rectangle {
 
36
        anchors.fill: scopeView
 
37
        color: "#FCFCFC"
 
38
    }
 
39
 
 
40
    GenericScopeView {
 
41
        id: scopeView
 
42
 
 
43
        anchors {
 
44
            top: parent.top
 
45
            bottom: parent.bottom
 
46
            left: parent.left
 
47
            right: controls.left
 
48
        }
 
49
 
 
50
        scope: scopes.loaded ? scopes.get(scopeSelector.selectedIndex) : undefined
 
51
    }
 
52
 
 
53
    Rectangle {
 
54
        id: controls
 
55
        color: "lightgrey"
 
56
        width: units.gu(40)
 
57
        anchors {
 
58
            top: parent.top
 
59
            bottom: parent.bottom
 
60
            right: parent.right
 
61
        }
 
62
 
 
63
        Column {
 
64
            anchors { fill: parent; margins: units.gu(1) }
 
65
            spacing: units.gu(1)
 
66
 
 
67
            Label {
 
68
                text: "Search query"
 
69
            }
 
70
 
 
71
            TextField {
 
72
                id: searchField
 
73
                anchors { left: parent.left; right: parent.right }
 
74
 
 
75
                onTextChanged: scopeView.scope.searchQuery = text
 
76
 
 
77
                Connections {
 
78
                    target: scopeView.scope
 
79
                    onSearchQueryChanged: searchField.text = scopeView.scope.searchQuery
 
80
                }
 
81
            }
 
82
 
 
83
            Label {
 
84
                text: "Scope selection"
 
85
                height: units.gu(4)
 
86
                verticalAlignment: Text.AlignBottom
 
87
            }
 
88
 
 
89
            OptionSelector {
 
90
                id: scopeSelector
 
91
                anchors { left: parent.left; right: parent.right }
 
92
 
 
93
                model: scopes
 
94
                delegate: OptionSelectorDelegate {
 
95
                    text: model.title
 
96
                }
 
97
            }
 
98
 
 
99
            Label {
 
100
                text: "Category"
 
101
                height: units.gu(4)
 
102
                verticalAlignment: Text.AlignBottom
 
103
            }
 
104
 
 
105
            OptionSelector {
 
106
                id: categorySelector
 
107
                anchors { left: parent.left; right: parent.right }
 
108
 
 
109
                model: scopeView.scope ? scopeView.scope.categories : null
 
110
                delegate: OptionSelectorDelegate {
 
111
                    text: model.name
 
112
                }
 
113
 
 
114
                onSelectedIndexChanged: {
 
115
                    categoryJson.refreshText();
 
116
                }
 
117
            }
 
118
 
 
119
            Repeater {
 
120
                id: categoryRepeater
 
121
                model: categorySelector.model
 
122
                Item {
 
123
                    property var data: model.rawRendererTemplate
 
124
                    property var categoryId: model.categoryId
 
125
                    onDataChanged: {
 
126
                        if (model.index != categorySelector.selectedIndex) return;
 
127
                        categoryJson.refreshText();
 
128
                    }
 
129
                }
 
130
                onItemAdded: categoryJson.refreshText()
 
131
            }
 
132
 
 
133
            TextArea {
 
134
                id: categoryJson
 
135
                width: parent.width
 
136
                autoSize: true
 
137
 
 
138
                function refreshText() {
 
139
                    if (categoryRepeater.count > categorySelector.selectedIndex) {
 
140
                        var item = categoryRepeater.itemAt(categorySelector.selectedIndex);
 
141
                        if (item == null) return;
 
142
                        categoryJson.text = JSON.stringify(JSON.parse(item.data), null, "    ");
 
143
                    }
 
144
                }
 
145
            }
 
146
 
 
147
            Button {
 
148
                width: parent.width
 
149
                text: "Override category"
 
150
                onClicked: {
 
151
                    PopupUtils.open(categoryEditor)
 
152
                }
 
153
            }
 
154
        }
 
155
    }
 
156
 
 
157
    Component {
 
158
        id: categoryEditor
 
159
 
 
160
        ComposerSheet {
 
161
            id: sheet
 
162
            title: "Editing category definition"
 
163
 
 
164
            TextArea {
 
165
                id: categoryEditorArea
 
166
                anchors.fill: parent
 
167
                wrapMode: Text.WordWrap
 
168
                text: categoryJson.text
 
169
            }
 
170
 
 
171
            onCancelClicked: PopupUtils.close(sheet)
 
172
            onConfirmClicked: {
 
173
                PopupUtils.close(sheet);
 
174
                var categoryId = categoryRepeater.itemAt(categorySelector.selectedIndex).categoryId;
 
175
                scopeView.scope.categories.overrideCategoryJson(categoryId, categoryEditorArea.text);
 
176
            }
 
177
        }
 
178
    }
 
179
}