forked from AlphaX2/Captains-Log-Sailfish
-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
SearchQueryDialog.qml
394 lines (348 loc) · 15.2 KB
/
SearchQueryDialog.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
/*
* This file is part of Captain's Log.
* SPDX-FileCopyrightText: 2023 Mirian Margiani
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import QtQuick 2.6
import Sailfish.Silica 1.0
import SortFilterProxyModel 0.2
import Opal.InfoCombo 1.0 as I
import Opal.ComboData 1.0 as C
import Opal.LinkHandler 1.0 as L
import "../components"
Dialog {
id: root
allowedOrientations: Orientation.All
property bool enableFilterSelected: false
readonly property var activeQueries: _activeQueriesProxy
property var _activeQueriesProxy: SearchQueriesData {}
readonly property SearchQueriesData _queries: SearchQueriesData {
matchAllMode: true
text: textField.text
textMatchSyntax: textSyntax.currentItem.mode
textMatchMode: textMode.currentItem.mode
dateMin: !dateMin.selectedDate || isNaN(dateMin.selectedDate.valueOf()) ?
_queries.dateMinUnset : dateMin.selectedDate
dateMax: !dateMax.selectedDate || isNaN(dateMax.selectedDate.valueOf()) ?
_queries.dateMaxUnset : dateMax.selectedDate
bookmark: bookmarks.currentItem.mode
selected: enableFilterSelected ? onlySelected.currentItem.mode : Qt.PartiallyChecked
tags: ([])
tagsNormalized: ([])
moodMin: Math.min(moodMin.moodIndex, moodMax.moodIndex)
moodMax: Math.max(moodMin.moodIndex, moodMax.moodIndex)
}
function resetQueries(newQueries) {
_queries.matchAllMode = newQueries.matchAllMode
textField.text = newQueries.text
textSyntax.currentIndex = textSyntax.indexOfData(newQueries.textMatchSyntax)
textMode.currentIndex = textMode.indexOfData(newQueries.textMatchMode)
dateMin.selectedDate = (newQueries.dateMin.valueOf() ===
_queries.dateMinUnset.valueOf()) ? new Date(NaN) : newQueries.dateMin
dateMax.selectedDate = (newQueries.dateMax.valueOf() ===
_queries.dateMaxUnset.valueOf()) ? new Date(NaN) : newQueries.dateMax
bookmarks.currentIndex = bookmarks.indexOfData(newQueries.bookmark)
onlySelected.currentIndex = onlySelected.indexOfData(newQueries.selected)
_queries.tags = newQueries.tags
_queries.tagsNormalized = newQueries.tagsNormalized
moodMin.menu.selectedIndex = newQueries.moodMin
moodMax.menu.selectedIndex = newQueries.moodMax
}
function copyQueries(source, dest) {
// Copy the full query to a separate object so
// that changing any field on the query page does
// not automatically restart the search. Searching
// after every key press is slow in large databases.
dest.matchAllMode = source.matchAllMode
dest.text = source.text
dest.textMatchSyntax = source.textMatchSyntax
dest.textMatchMode = source.textMatchMode
dest.dateMin = source.dateMin
dest.dateMax = source.dateMax
dest.bookmark = source.bookmark
dest.selected = source.selected
dest.tags = source.tags
dest.tagsNormalized = source.tagsNormalized
dest.moodMin = source.moodMin
dest.moodMax = source.moodMax
}
onAcceptPendingChanged: {
if (acceptPending) {
copyQueries(_queries, activeQueries)
}
}
SilicaFlickable {
id: flick
anchors.fill: parent
contentHeight: column.height + Theme.horizontalPageMargin
VerticalScrollDecorator { flickable: flick }
PullDownMenu {
flickable: listView
MenuItem {
TextSwitch {
checked: !_queries.matchAllMode
text: " "
highlighted: parent.highlighted
height: Theme.itemSizeSmall
width: height
anchors.verticalCenter: parent.verticalCenter
}
text: qsTr("Any may match")
onClicked: _queries.matchAllMode = false
}
MenuItem {
TextSwitch {
checked: _queries.matchAllMode
text: " "
highlighted: parent.highlighted
height: parent.height
width: height
anchors.verticalCenter: parent.verticalCenter
}
text: qsTr("All must match")
onClicked: _queries.matchAllMode = true
}
}
Column {
id: column
width: parent.width
DialogHeader {
cancelText: qsTr("Back")
acceptText: qsTr("Search")
}
SectionHeader {
text: qsTr("Title and entry")
}
SearchField {
id: textField
width: parent.width
placeholderText: qsTr("Search contents")
canHide: false
EnterKey.iconSource: "image://theme/icon-m-enter-next"
EnterKey.onClicked: focus = false
}
SelectedTagsView {
width: parent.width
tagsList: _queries.tags
onRemoveRequested: {
tagsField.text = tag
var index = _queries.tags.indexOf(tag)
if (index >= 0) {
_queries.tags.splice(index, 1)
_queries.tagsNormalized.splice(index, 1)
_queries.tags = _queries.tags
_queries.tagsNormalized = _queries.tagsNormalized
}
}
}
SearchField {
id: tagsField
width: parent.width
placeholderText: qsTr("Search tags")
canHide: false
EnterKey.iconSource: "image://theme/icon-m-enter-next"
EnterKey.onClicked: focus = false
}
TagSuggestionsView {
width: parent.width
searchTerm: tagsField.text !== '' ?
tagsField.text : (tagsField.focus ? ' ' : '')
onTagSelected: {
if (_queries.tags.indexOf(tag.text) < 0) {
_queries.tags = _queries.tags.concat([tag.text])
_queries.tagsNormalized = _queries.tagsNormalized.concat([tag.normalized])
}
}
}
I.InfoCombo {
id: textSyntax
width: parent.width
currentIndex: 0
label: qsTr("Search syntax")
linkHandler: L.LinkHandler.openOrCopyUrl
property int currentData
property var indexOfData
C.ComboData { dataRole: "mode" }
I.InfoComboSection {
title: qsTr("Note")
text: qsTr("Simplified matching is only possible in “plain text” " +
"mode.")
placeAtTop: true
}
menu: ContextMenu {
I.InfoMenuItem {
text: qsTr("plain text")
property int mode: RegExpFilter.FixedString
info: qsTr(
"Search for the string as you entered it. Note: some " +
"simplifications will be applied to the search term " +
"if the “Search mode” is set to “simplified”.")
}
I.InfoMenuItem {
text: qsTr("wildcard")
property int mode: RegExpFilter.WildcardUnix
info: qsTr(
"This option allows to search for extended patterns. " +
"Use “?” to match any single character, and “*” to " +
"match zero or more characters. Groups of characters " +
"can be defined in square brackets. Use a backslash " +
"to search for literal “?” or “*”, e.g. “%1”.").arg("\\?")
}
I.InfoMenuItem {
text: qsTr("regular expression")
property int mode: RegExpFilter.RegExp
info: qsTr(
"Search using complex regular expressions. Use the " +
"vertical bar “|” to search for multiple terms. " +
"Search the Internet if you want to learn more about " +
"regular expressions.")
}
}
}
I.InfoCombo {
id: textMode
width: parent.width
currentIndex: 0
enabled: textSyntax.currentItem.mode === RegExpFilter.FixedString
label: qsTr("Search mode")
linkHandler: L.LinkHandler.openOrCopyUrl
Binding on currentIndex {
when: !textMode.enabled
value: 1
}
property int currentData
property var indexOfData
C.ComboData { dataRole: "mode" }
menu: ContextMenu {
I.InfoMenuItem {
text: qsTr("simplified")
property int mode: _queries.matchSimplified
info: qsTr(
"Ignore diacritics on characters, matching e.g. “ö”, “ó”, and " +
"“õ” when searching for “o”. Ignore any punctuation marks. " +
"Use this mode when you are unsure how you spelled something " +
"in the past.")
}
I.InfoMenuItem {
text: qsTr("strict")
property int mode: _queries.matchStrict
info: qsTr(
"Match the query string exactly. Use this mode when you know exactly " +
"what you are searching for, or when you want to search for a string " +
"containing punctuation marks like “-”, “!”, or “#”."
)
}
}
}
I.InfoCombo {
id: bookmarks
width: parent.width
currentIndex: 0
label: qsTr("Bookmarks")
linkHandler: L.LinkHandler.openOrCopyUrl
property int currentData
property var indexOfData
C.ComboData { dataRole: "mode" }
menu: ContextMenu {
I.InfoMenuItem {
text: qsTr("all entries", "search option, as in: " +
"“find all entries, whether they are " +
"bookmarked or not”")
property int mode: Qt.PartiallyChecked
info: qsTr(
"Find entries regardless of whether they are bookmarked " +
"or not.")
}
I.InfoMenuItem {
text: qsTr("marked", "search option, as in: " +
"“find only bookmarked entries”")
property int mode: Qt.Checked
info: qsTr("Find only bookmarked entries.")
}
I.InfoMenuItem {
text: qsTr("unmarked", "search option, as in: " +
"“find only entries that are not bookmarked”")
property int mode: Qt.Unchecked
info: qsTr("Find only entries that are not bookmarked.")
}
}
}
I.InfoCombo {
id: onlySelected
width: parent.width
visible: enableFilterSelected
currentIndex: 0
label: qsTr("Selection")
linkHandler: L.LinkHandler.openOrCopyUrl
property int currentData
property var indexOfData
C.ComboData { dataRole: "mode" }
menu: ContextMenu {
I.InfoMenuItem {
text: qsTr("all entries", "search option, as in: " +
"“find all entries, whether they are " +
"currently selected or not”")
property int mode: Qt.PartiallyChecked
info: qsTr(
"Find entries regardless of whether they are selected " +
"or not.")
}
I.InfoMenuItem {
text: qsTr("selected", "search option, as in: " +
"“find only selected entries”")
property int mode: Qt.Checked
info: qsTr("Find only currently selected entries.")
}
I.InfoMenuItem {
text: qsTr("unselected", "search option, as in: " +
"“find only entries that are not selected")
property int mode: Qt.Unchecked
info: qsTr("Find only entries that are currently not selected.")
}
}
}
SectionHeader {
text: qsTr("Mood")
}
Row {
width: parent.width
ComboBox {
id: moodMin
width: parent.width / 2
label: qsTr("From")
value: appWindow.moodTexts[menu.selectedIndex]
property int moodIndex: menu.selectedIndex
menu: MoodMenu { selectedIndex: appWindow.moodTexts.length-1 }
}
ComboBox {
id: moodMax
width: parent.width / 2
label: qsTr("To")
value: appWindow.moodTexts[menu.selectedIndex]
property int moodIndex: menu.selectedIndex
menu: MoodMenu { selectedIndex: 0 }
}
}
SectionHeader {
text: qsTr("Entry date")
}
Row {
width: parent.width
DatePickerCombo {
id: dateMin
width: parent.width / 2
label: qsTr("From")
emptyText: qsTr("anytime", "search option, as in: " +
"“match all entries regardless of their date”")
}
DatePickerCombo {
id: dateMax
width: parent.width / 2
label: qsTr("Till")
emptyText: qsTr("anytime", "search option, as in: " +
"“match all entries regardless of their date”")
}
}
}
}
}