~fuxixi1991/aesydict/mainline

« back to all changes in this revision

Viewing changes to app/search/PageSearch.qml

  • Committer: Joey Chan
  • Date: 2015-04-17 08:58:57 UTC
  • Revision ID: qqworini@gmail.com-20150417085857-rdc9wpthifrrwzkc
main functions completed: add history function

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
Page {
9
9
    id: pageSearch
10
10
    title: i18n.tr("AesyDict")
 
11
 
 
12
    flickable: null
11
13
    state: "search"
12
14
    states: [
13
15
        PageHeadState {
56
58
                inputMethodHints: Qt.ImhNoPredictiveText | Qt.ImhNoAutoUppercase
57
59
                placeholderText: i18n.tr("Please input a word")
58
60
 
59
 
                onTextChanged: { timerSearch.stop(); timerSearch.start() }
 
61
                onTextChanged: {
 
62
                    if (text === "") {
 
63
                        var historyArr = dictCenter.getHistories()
 
64
//                        print("dictCenter.getHistories(): ", historyArr.length)
 
65
                        lvHistory.setData(historyArr)
 
66
                    }
 
67
//                    else {
 
68
//                    }
 
69
                    timerSearch.stop()
 
70
                    timerSearch.start()
 
71
                }
 
72
 
 
73
                onFocusChanged: {
 
74
                    if (text === "") {
 
75
                        var historyArr = dictCenter.getHistories()
 
76
//                        print("dictCenter.getHistories(): ", historyArr.length)
 
77
                        lvHistory.setData(historyArr)
 
78
                    }
 
79
                }
 
80
 
 
81
                Keys.onReturnPressed: { if (tfSearchWord.text != "") {dictCenter.searchWords(tfSearchWord.text)} }
 
82
                Keys.onEnterPressed: { if (tfSearchWord.text != "") {dictCenter.searchWords(tfSearchWord.text)} }
60
83
            }
61
84
        }
62
85
    ]
63
86
 
64
 
    flickable: null
65
 
 
66
87
    Timer {
67
88
        id: timerSearch; interval: 700; running: false; repeat: false; triggeredOnStart: false
68
89
        onTriggered: {
117
138
        contentWidth: width
118
139
        contentHeight: columnInnerArea.height + units.gu(3)
119
140
        clip: true
 
141
        visible: tfSearchWord.text != ""
120
142
 
121
143
        Column {
122
144
            id: columnInnerArea
131
153
            }
132
154
            height: childrenRect.height
133
155
 
134
 
//            TextArea {
135
 
//                id: ta
136
 
//            }
137
 
 
138
 
//            ListItem.Caption {
139
 
//                text: "English - Chinese Dictionary"
140
 
//            }
141
 
//            ListItem.ThinDivider {}
142
 
 
143
 
//            ListItem.Standard {
144
 
//                text: "aaa"
145
 
//            }
146
 
 
147
 
//            ListItem.Standard {
148
 
//                text: "aaa"
149
 
//            }
150
 
 
151
 
//            ListItem.Standard {
152
 
//                text: "aaa"
153
 
//            }
154
 
 
155
 
//            ListItem.Standard {
156
 
//                text: "aaa"
157
 
//            }
158
 
 
159
 
//            ListItem.Caption {
160
 
//                text: "English - Chinese Dictionary"
161
 
//            }
162
 
//            ListItem.ThinDivider {}
163
 
 
164
 
//            ListItem.Standard {
165
 
//                text: "aaa"
166
 
//            }
167
 
 
168
 
//            ListItem.Standard {
169
 
//                text: "aaa"
170
 
//            }
171
 
 
172
 
//            ListItem.Standard {
173
 
//                text: "aaa"
174
 
//            }
175
 
 
176
 
//            ListItem.Standard {
177
 
//                text: "aaa"
178
 
//            }
179
 
 
180
 
//            ListItem.Caption {
181
 
//                text: "English - Chinese Dictionary"
182
 
//            }
183
 
//            ListItem.ThinDivider {}
184
 
 
185
 
//            ListItem.Standard {
186
 
//                text: "aaa"
187
 
//            }
188
 
 
189
 
//            ListItem.Standard {
190
 
//                text: "aaa"
191
 
//            }
192
 
 
193
 
//            ListItem.Standard {
194
 
//                text: "aaa"
195
 
//            }
196
 
 
197
 
//            ListItem.Standard {
198
 
//                text: "aaa"
199
 
//            }
200
 
 
201
156
        } // columnInnerArea
202
157
    }
 
158
 
 
159
    ListView {
 
160
        id: lvHistory
 
161
        anchors { left: parent.left; right: parent.right }
 
162
        height: contentItem.childrenRect.height
 
163
        clip: true
 
164
        visible: tfSearchWord.text === "" && pageSearch.state === "search"
 
165
 
 
166
        Component.onCompleted: {
 
167
            var historyArr = dictCenter.getHistories()
 
168
            lvHistory.setData(historyArr)
 
169
        }
 
170
 
 
171
        function setData(historyArr) {
 
172
            modelHistory.clear()
 
173
            for (var i=0; i<historyArr.length; i++) {
 
174
                modelHistory.append(historyArr[i])
 
175
            }
 
176
        }
 
177
 
 
178
        model: ListModel { id: modelHistory }
 
179
        delegate: Component {
 
180
            ListItem.Standard {
 
181
                text: word
 
182
 
 
183
                onClicked: { tfSearchWord.text = word }
 
184
            }
 
185
        }
 
186
 
 
187
        header: Component {
 
188
            ListItem.Caption {
 
189
                text: i18n.tr("History")
 
190
 
 
191
                ListItem.ThinDivider { anchors.bottom: parent.bottom }
 
192
            }
 
193
        }
 
194
 
 
195
    } // lvHistory
 
196
 
 
197
 
203
198
}
204
199