~qqworini/ubuntu-rssreader-app/reboot-add-opml-support

« back to all changes in this revision

Viewing changes to shorts/qml/pages/TopicManagement.qml

  • Committer: Roman Shchekin
  • Date: 2015-07-21 19:42:29 UTC
  • Revision ID: mrqtros@gmail.com-20150721194229-8hwozqrsnh501cis
"Edit Topics" page reworked.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
 
13
13
    title: i18n.tr("Edit topics")
14
14
    flickable: content
15
 
    tools: toolbar
16
15
 
17
16
    signal feedEdit(int topicId)
18
17
    signal topicDeleted()
19
18
 
20
 
    property int editIndex
21
 
 
22
19
    Component.onCompleted: {
23
20
        reloadTopics ()
24
21
    }
25
22
 
26
 
    function reloadTopics ()
27
 
    {
 
23
    function reloadTopics () {
28
24
        topicModel.clear()
29
25
        var topics = DB.loadTags()
30
 
        for (var i=0; i < topics.rows.length; i++){
31
 
            topicModel.append(
32
 
                    {
33
 
                "id": topics.rows[i].id
34
 
                ,"name": topics.rows[i].name
35
 
            })
 
26
        for (var i = 0; i < topics.rows.length; i++){
 
27
            topicModel.append({"id": topics.rows[i].id
 
28
                                  ,"name": topics.rows[i].name } )
36
29
        }
37
30
    }
38
31
 
58
51
            bottom: fakePanel.top
59
52
        }
60
53
        contentHeight: contentItem.childrenRect.height
61
 
//        boundsBehavior: (contentHeight > topicManagement.height) ? Flickable.DragAndOvershootBounds : Flickable.StopAtBounds
62
54
 
63
55
        /*
64
56
          idea from music app, set interactive to false may work
65
57
        */
66
 
        state: "normal"
67
 
        states: [
68
 
            State {
69
 
                name: "normal"
70
 
                PropertyChanges {
71
 
                    target: content
72
 
                    interactive: true
73
 
                }
74
 
            },
75
 
            State {
76
 
                name: "reorder"
77
 
                PropertyChanges {
78
 
                    target: content
79
 
                    interactive: false
80
 
                }
81
 
            }
82
 
        ]
 
58
//        state: "normal"
 
59
//        states: [
 
60
//            State {
 
61
//                name: "normal"
 
62
//                PropertyChanges {
 
63
//                    target: content
 
64
//                    interactive: true
 
65
//                }
 
66
//            },
 
67
//            State {
 
68
//                name: "reorder"
 
69
//                PropertyChanges {
 
70
//                    target: content
 
71
//                    interactive: false
 
72
//                }
 
73
//            }
 
74
//        ]
83
75
 
84
76
        Column{
85
77
            anchors{ left: parent.left; right: parent.right }
112
104
                height: contentItem.childrenRect.height
113
105
                interactive: false
114
106
                currentIndex: -1
115
 
//                clip: true
116
107
 
117
108
                property int feedSelectedIndex: -1
118
 
                property alias flickState: content.state
119
 
                property real delegateRootY
 
109
                // property alias flickState: content.state
120
110
 
121
111
                signal collapseAllItem()
122
112
 
124
114
                    collapseAllItem()
125
115
                }
126
116
 
127
 
                function scrollView(itemy) {
128
 
//                    console.log("itemy: ", itemy - content.contentY)
129
 
                    if ((itemy - content.contentY) < units.gu(16)) {
130
 
                        if (!content.atYBeginning)
131
 
                            content.contentY -= 3
132
 
                    }
133
 
                    else if ((itemy - content.contentY) > ( content.height - units.gu(16))) {
134
 
                        if (!content.atYEnd)
135
 
                            content.contentY += 3
136
 
                    }
137
 
                }
138
 
 
139
117
                displaced: Transition {
140
118
                    NumberAnimation { properties: "x,y"; easing.type: Easing.OutQuad }
141
119
                }
142
120
 
143
 
                model: VisualDataModel {
144
 
                    id: visualModel
145
 
                    model: ListModel {
146
 
                        id: topicModel
147
 
                    }
148
 
                    delegate: MouseArea {
149
 
                        id: delegateRoot
150
 
 
151
 
                        property int visualIndex: VisualDataModel.itemsIndex
152
 
                        property alias isExpanded: topicItem.isExpanded
153
 
                        property alias isEditing: topicItem.isEditing
154
 
                        property bool isSelected: visualIndex == topicList.feedSelectedIndex
155
 
 
156
 
                        anchors{ left: parent.left; right: parent.right }
157
 
                        height: topicItem.height
158
 
 
159
 
                        function cancelEdit() {
160
 
                            topicItem.cancelEdit()
161
 
                        }
162
 
 
163
 
                        function confirmEdit() {
164
 
                            topicItem.confirmEdit()
165
 
                        }
166
 
 
167
 
                        function feedDrop(feedId, topicId) {
168
 
                            console.log("dropped item feed id", feedId)
169
 
                            console.log("dropped item topic id", topicId)
170
 
                            DB.deleteFeedTag(feedId, topicId)
171
 
                            DB.addFeedTag(feedId, model.id)
172
 
                            delegateRoot.isExpanded = true
173
 
                            feedEdit(topicId)
 
121
                model: ListModel {
 
122
                    id: topicModel
 
123
                }
 
124
 
 
125
                delegate: MouseArea {
 
126
                    id: delegateRoot
 
127
 
 
128
                    // property int visualIndex: VisualDataModel.itemsIndex
 
129
                    property alias isExpanded: topicItem.isExpanded
 
130
                    // property alias isEditing: topicItem.isEditing
 
131
 
 
132
                    anchors { left: parent.left; right: parent.right }
 
133
                    height: topicItem.height
 
134
 
 
135
                    function cancelEdit() {
 
136
                        topicItem.cancelEdit()
 
137
                    }
 
138
 
 
139
                    function confirmEdit() {
 
140
                        topicItem.confirmEdit()
 
141
                    }
 
142
 
 
143
                    TopicComponent {
 
144
                        id: topicItem
 
145
                        topicName: model.name
 
146
                        topicId: model.id
 
147
                        modelIndex: index
 
148
                        // isSelected: VisualDataModel.itemsIndex == topicList.feedSelectedIndex
 
149
 
 
150
                        onEdit: {
 
151
                            if (topicList.currentItem)
 
152
                                topicList.currentItem.cancelEdit()
 
153
                            topicManagement.state = "editMode"
 
154
                            topicList.currentIndex = index
 
155
                        }
 
156
 
 
157
                        onEditCanceled: {
 
158
                            if (topicList.currentItem)
 
159
                                topicList.currentItem.cancelEdit()
 
160
                            topicManagement.state = "default"
 
161
                            topicList.currentIndex = -1
 
162
                        }
 
163
 
 
164
                        onFeedDeleted: {
174
165
                            feedEdit(model.id)
175
166
                        }
176
167
 
177
 
                        TopicComponent{
178
 
                            id: topicItem
179
 
                            topicName: model.name
180
 
                            topicId: model.id
181
 
                            modelIndex: index
182
 
//                            isExpanded: delegateRoot.isExpanded
183
 
 
184
 
                            onEdit: {
185
 
                                if (topicList.currentItem)
186
 
                                    topicList.currentItem.cancelEdit()
187
 
                                topicManagement.editIndex = index
188
 
                                topicManagement.state = "editMode"
189
 
                                // editConfirm.visible = true
190
 
                                topicList.currentIndex = index
191
 
                            }
192
 
 
193
 
                            onEditCanceled: {
194
 
                                if (topicList.currentItem)
195
 
                                    topicList.currentItem.cancelEdit()
196
 
                                topicManagement.state = "default"
197
 
                                // editConfirm.visible = false
198
 
                                topicList.currentIndex = -1
199
 
                            }
200
 
 
201
 
                            onFeedDeleted: {
202
 
                                feedEdit(model.id)
203
 
                            }
204
 
 
205
 
                            states: [
206
 
                                State {
207
 
                                    name: ""
208
 
                                    PropertyChanges {
209
 
                                        target: topicItem
210
 
                                        isSelected: false
211
 
                                    }
212
 
                                },
213
 
                                State {
214
 
                                    name: "selected"
215
 
                                    when: delegateRoot.isSelected
216
 
                                    PropertyChanges {
217
 
                                        target: topicItem
218
 
                                        isSelected: true
219
 
                                    }
220
 
                                }
221
 
                            ]
222
 
                        }
223
 
 
224
 
                        /*
225
 
                          DropArea is useless here, because Drag.active will lead crash in device
226
 
                          so I use another more complicated way to act like DropArea
227
 
                        */
228
 
                        DropArea {
229
 
                            id: dropArea
230
 
                            anchors { fill: parent}
231
 
 
232
 
                            onEntered:{
233
 
                                console.log("enter", drag.source)
234
 
                                topicItem.selected = true
235
 
                            }
236
 
 
237
 
                            onExited:{
238
 
//                                console.log("exit", drag.source)
239
 
                                topicItem.selected = false
240
 
                            }
241
 
 
242
 
                            onDropped:{
243
 
//                                console.log("drop", drag.source)
244
 
                                topicItem.selected = false
245
 
                                drag.source.opacity = 0
246
 
                                console.log("dropped item feed id", drag.source.feedId)
247
 
                                console.log("dropped item topic id", drag.source.topicId)
248
 
                                DB.deleteFeedTag(drag.source.feedId, drag.source.topicId)
249
 
                                DB.addFeedTag(drag.source.feedId, model.id)
250
 
                                delegateRoot.isExpanded = true
251
 
                            }
252
 
                        }
253
 
 
254
 
//                        Connections {
255
 
//                            id: connKeyBroad
256
 
//                            target: Qt.inputMethod
257
 
 
258
 
//                            onVisibleChanged: {
259
 
//                                if (pageStack && (pageStack.currentPage == topicManagement) && Qt.inputMethod.visible) {
260
 
//                                    topicList.delegateRootY = topicList.currentItem.y
261
 
//                                    timerKeyboard.stop()
262
 
//                                    timerKeyboard.start()
 
168
//                        states: [
 
169
//                            State {
 
170
//                                name: ""
 
171
//                                PropertyChanges {
 
172
//                                    target: topicItem
 
173
//                                    isSelected: false
 
174
//                                }
 
175
//                            },
 
176
//                            State {
 
177
//                                name: "selected"
 
178
//                                when: delegateRoot.isSelected
 
179
//                                PropertyChanges {
 
180
//                                    target: topicItem
 
181
//                                    isSelected: true
263
182
//                                }
264
183
//                            }
265
 
//                        }
266
 
 
267
 
                        Connections{
268
 
                            id: connTopicList
269
 
                            target: topicList
270
 
 
271
 
                            onCollapseAllItem:
272
 
                            {
273
 
                                delegateRoot.isExpanded = false
274
 
                            }
275
 
                        }
276
 
 
277
 
                        Connections{
278
 
                            id: connEditFeed0
279
 
                            target: editFeed
280
 
 
281
 
                            onApply:{
282
 
                                if (model.id == newTopicId || model.id == previousTopicId){
283
 
                                    topicItem.reloadFeed()
284
 
                                    topicItem.isExpanded = true
285
 
                                    feedEdit(previousTopicId)
286
 
                                    feedEdit(newTopicId)
287
 
                                }
288
 
                            }
289
 
 
290
 
                            onDeleteFeed:{
291
 
                                if (model.id == topicId){
292
 
                                    topicItem.reloadFeed()
293
 
                                    topicItem.isExpanded = true
294
 
                                    feedEdit(topicId)
295
 
                                }
296
 
                            }
297
 
                        }
298
 
 
299
 
                    }
 
184
//                        ]
 
185
                    }
 
186
 
 
187
                    Connections {
 
188
                        id: connTopicList
 
189
                        target: topicList
 
190
 
 
191
                        onCollapseAllItem: {
 
192
                            delegateRoot.isExpanded = false
 
193
                        }
 
194
                    }
 
195
 
 
196
                    Connections {
 
197
                        id: connEditFeed0
 
198
                        target: editFeed
 
199
 
 
200
                        onApply:{
 
201
                            if (model.id == newTopicId || model.id == previousTopicId){
 
202
                                topicItem.reloadFeed()
 
203
                                topicItem.isExpanded = true
 
204
                                feedEdit(previousTopicId)
 
205
                                feedEdit(newTopicId)
 
206
                            }
 
207
                        }
 
208
 
 
209
                        onDeleteFeed:{
 
210
                            if (model.id == topicId){
 
211
                                topicItem.reloadFeed()
 
212
                                topicItem.isExpanded = true
 
213
                                feedEdit(topicId)
 
214
                            }
 
215
                        }
 
216
                    }
 
217
 
300
218
                }
301
219
            } // listview
302
220
 
330
248
                    Qt.inputMethod.hide()
331
249
                    topicList.currentItem.cancelEdit()
332
250
                    topicManagement.state = "default"
333
 
                    // editConfirm.visible = false
334
251
                    topicList.currentIndex = -1
335
252
                    timerHeader.start()
336
253
                }
348
265
                onClicked: {
349
266
                    topicList.currentItem.confirmEdit()
350
267
                    topicManagement.state = "default"
351
 
                    // editConfirm.visible = false
352
268
                    topicList.currentIndex = -1
353
269
                }
354
270
            }
389
305
 
390
306
        onTopicChoosen: {
391
307
            reloadTopics()
392
 
            for (var i=0; i<topicModel.count; i++){
 
308
            for (var i = 0; i < topicModel.count; i++){
393
309
                if (topicModel.get(i).id == topicId){
394
310
                    topicList.currentIndex = i
395
311
                    topicList.currentItem.isExpanded = true
401
317
    states: [
402
318
        State {
403
319
            name: "default"
404
 
//            PropertyChanges {
405
 
//                target: topicManagement
406
 
//                tools: toolbar
407
 
//            }
408
320
        },
409
321
        State {
410
322
            name: "editMode"
411
 
//            PropertyChanges {
412
 
//                target: topicManagement
413
 
//                tools: editConfirm
414
 
//            }
415
323
        }
416
324
    ]
417
325