Unity 8
 All Classes Functions
ResultList.qml
1 /*
2  * Copyright (C) 2012, 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 
20 Column {
21  property var model: undefined
22 
23  // Hud gives lots of results, make sure we have 5 at most
24  // FIXME This should use SortFilterProxyModel
25  // but there is a problem with the hud-service refreshing the
26  // data for no reason so we use the internal model + timer
27  // to fix those issues
28  ListModel {
29  id: internalModel
30  }
31 
32  Connections {
33  target: model
34  // Accumulate count changes since hud clears
35  // and then readds items to the models which means
36  // even if the result is the same we get lots of count changes
37  onCountChanged: updateModelTimer.restart()
38  }
39 
40  onModelChanged: updateModelTimer.restart()
41 
42  Timer {
43  id: updateModelTimer
44  interval: 30
45  onTriggered: updateModel()
46  }
47 
48  function updateModel() {
49  internalModel.clear()
50  for (var i = 0; i < 5 && i < model.count; ++i) {
51  var itemData = model.get(i)
52  internalModel.append({"name": itemData.column_1, "highlights": itemData.column_2, "context": itemData.column_3, "contextHighlights": itemData.column_4})
53  }
54  }
55 
56  signal activated(int index)
57 
58  height: repeater.height
59 
60  Repeater {
61  id: repeater
62  objectName: "resultListRepeater"
63  model: internalModel
64 
65  delegate: MouseArea {
66  id: delegate
67  height: result.height + separatorLine.height * 2
68  anchors.left: parent.left
69  anchors.right: parent.right
70 
71  onClicked: activated(index)
72 
73  BorderImage {
74  id: separatorLine
75  anchors.top: parent.top
76  anchors.left: parent.left
77  anchors.right: parent.right
78  source: "graphics/divider.sci"
79  visible: index == 0
80  }
81 
82  Result {
83  id: result
84  height: units.gu(6)
85  anchors.top: separatorLine.bottom
86  anchors.left: parent.left
87  anchors.right: parent.right
88 
89  nameText: name
90  nameHighlights: highlights
91  contextSnippetText: context
92  contextSnippetHighlights: contextHighlights
93  }
94 
95  BorderImage {
96  anchors.top: result.bottom
97  anchors.left: parent.left
98  anchors.right: parent.right
99  source: "graphics/divider.sci"
100  }
101 
102  Component.onCompleted: fadeIn.start()
103  NumberAnimation { id: fadeIn; target: resultList; alwaysRunToEnd: true; property: "opacity"; duration: 200; from: 0; to: 1 }
104  }
105  }
106 }