File size: 9,876 Bytes
a4cf109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import QtQuick 2.5
import QtQuick.Controls 2.4
import QtQuick.Layouts 1.0
import QuickKeyboard 1.0
import "modes"

Item {
    property variant storeFront;
    property bool firstOpen: true;

    id: searchUI
    visible: false

    function openSearch(open) {
        if (open) {
            searchUI.visible = true
            keyboard.dispatcher.setFocusObject(textInput);
            if (firstOpen) {
                firstOpen = false;
                fromYear.setDefault(storeFront.fromYear);
                toYear.setDefault(storeFront.toYear);
                fromYear.activated(fromYear.curIndex);

                language.setDefault(storeFront.language);
                extension.setDefault(storeFront.extension);
                order.setDefault(storeFront.order);
                storeFront.exactMatch == "1" && exactMatch.toggle();
                storeFront.query.length && (textInput.text = storeFront.query);
            }
        } else {
            searchUI.visible = false;
        }
    }

    function getParams() {
        storeFront.exactMatch = exactMatch.position;
        storeFront.fromYear = fromYear.value();
        storeFront.toYear = toYear.value();
        storeFront.language = language.value();
        storeFront.extension = extension.value();
        storeFront.order = order.value();
        storeFront.query = textInput.text;
    }

    function sendQuery() {
        getParams();
        storeFront.newQuery(0);
    }

    Rectangle {
        id: background
        anchors.fill: parent

        MouseArea {
            anchors.fill: parent
        }
    }

    Rectangle {
        id: searchBox
        color: "black"
        height: 110
        anchors {
            left: parent.left
            right: parent.right
            top: parent.top
        }

        Image {
            source: "png/search"
            anchors.verticalCenter: parent.verticalCenter
            anchors.left: parent.left
            anchors.leftMargin: 40
            width: 50
            height: 50
        }

        TextField  {
            id: textInput
            font.pixelSize: 35
            color: "white"
            font.family: "Maison Neue"
            anchors { fill: parent; verticalCenter: parent.verticalCenter; topMargin: 10 }
            clip: true
            verticalAlignment: Text.AlignVCenter
            anchors.leftMargin: 120
            anchors.rightMargin: 40 + 150
            placeholderText: "Search for title, author, ISBN, publisher, md5..."
            background: Rectangle {
                anchors.fill: parent
                color: "black"
            }
        }

        Rectangle {
            visible: textInput.text.length > 0
            color: "black"
            border.color: "white"
            border.width: 3
            width: 130
            height: 50
            radius: 4
            anchors {
                right: parent.right
                verticalCenter: parent.verticalCenter
                rightMargin: 40
            }
            Text {
                text: "Clear"
                font.pixelSize: 25
                color: "white"
                font.family: "Maison Neue"
                font.bold: true
                anchors.centerIn: parent
                anchors.verticalCenterOffset: 2
            }
            MouseArea {
                anchors.fill: parent
                onClicked: textInput.text = ""
            }
        }
    }

    Row {
        anchors {
            left: parent.left
            leftMargin: screenMargin
            top: searchBox.bottom
            topMargin: 30
        }
        spacing: 33

        Filter {
            id: fromYear
            model: {
                let a = ["Any"];
                let thisYear = (new Date).getFullYear();
                while (thisYear >= 1800) {
                    a.push(thisYear);
                    thisYear--;
                }
                return a;
            }
            width: 150
            text: "From"
            onActivated: {
                let oldIndex = toYear.curIndex;
                toYear.model = index > 0 ? fromYear.model.slice(0, index + 1) : fromYear.model;
                if (oldIndex <= index) {
                    toYear.curIndex = oldIndex;
                } else {
                    toYear.curIndex = index;
                }
            }
        }

        Filter {
            id: toYear
            model: fromYear.model
            text: "To"
            width: 150
        }

        Filter {
            id: language
            model: ["Any","Afrikaans","Albanian","Arabic","Armenian","Azerbaijani","Bashkir","Belarusian","Bengali","Berber","Bulgarian","Catalan","Chinese","Crimean Tatar","Croatian","Czech","Danish","Dutch","English","Esperanto","Finnish","French","Georgian","German","Greek","Gujarati","Hebrew","Hindi","Hungarian","Icelandic","Indigenous","Indonesian","Italian","Japanese","Kannada","Kazakh","Kirghiz","Korean","Latin","Latvian","Lithuanian","Malayalam","Marathi","Mongolian","Nepali","Norwegian","Odia","Persian","Polish","Portuguese","Romanian","Russian","Sanskrit","Serbian","Sinhala","Slovak","Slovenian","Somali","Spanish","Swahili","Swedish","Tajik","Tamil","Tatar","Telugu","Turkish","Ukrainian","Urdu","Uzbek","Vietnamese"]
            text: "Language"
            width: 350
        }

        Filter {
            id: extension
            model: ["Any","pdf","epub","djvu","fb2","txt","rar","mobi","lit","doc","rtf","azw3"]
            text: "Extension"
            width: 200
        }

        Filter {
            id: order
            model: [ "Most Popular", "Best Match", "Recently added", "By Title (A-Z)", "By Title (Z-A)", "By Year", "File Size Asc.", "File Size Des." ]
            text: "Sort by"
            width: 350
        }
    }

    Switch {
        id : exactMatch
        x: screenMargin
        y: 280

        indicator: Rectangle {
            width: 80
            height: 40
            y: parent.height / 2 - height / 2
            radius: 20
            color: exactMatch.checked ? "black" : "white"
            border.color: "black"
            border.width: 1

            Rectangle {
                x: exactMatch.checked ? parent.width - width : 0
                width: 40
                height: 40
                radius: 20
                color: "white"
                border.color: "black"
                border.width: 1
            }
        }

        contentItem: Text {
            text: "          Exact match"
            font.family: "Maison Neue"
            font.bold: true
            font.pixelSize: 35
            color: "black"
            height: 40
            verticalAlignment: Text.AlignVCenter
        }
    }

    FlatButton {
        id: startQuery
        width: 200
        bgColor: "black"
        fgColor: "white"
        text: "Search"
        y: 400
        anchors {
            right: parent.right
            rightMargin: 40
        }
        onTapped: sendQuery()
    }

    FlatButton {
        id: setDefaultQuery
        width: 350
        bgColor: "white"
        fgColor: "black"
        text: "Set as default query"
        borderWidth: 3
        y: 400
        anchors {
            left: parent.left
            leftMargin: 40
        }
        onTapped: {
            getParams();
            storeFront.setConfig();

            setDefaultQuery.text = "✔";
            resetButtonText.start();
        }
        Timer {
            id: resetButtonText
            interval: 3000; running: false; repeat: false
            onTriggered: setDefaultQuery.text = "Set as default query";
        }
    }
    
    FlatButton {
        id: resetFilter
        width: 250
        bgColor: "white"
        fgColor: "black"
        text: "Reset query"
        borderWidth: 3
        y: 400
        anchors {
            left: setDefaultQuery.right
            leftMargin: 30
        }
        onTapped: {
            if (exactMatch.position == 1.0)
                exactMatch.toggle();

            fromYear.reset();
            toYear.reset();
            language.reset();
            extension.reset();
            order.reset();
            textInput.text = "";
        }
    }

    Keyboard {
        id: keyboard
        anchors { left: parent.left; right: parent.right; bottom: parent.bottom }
        height: 626

        Rectangle {
            anchors.fill: parent
            color: "black"
        }

        mode: standard

        Standard {
            id: standard
            anchors.fill: parent
            anchors.topMargin: 93
            onSymbolsModeSwitched: keyboard.mode = symbols
            onEnter: sendQuery()
        }

        Symbols {
            id: symbols
            anchors.fill: parent
            anchors.topMargin: 93
            onStandardModeSwitched: keyboard.mode = standard
            onSymbolsModeSwitched: keyboard.mode = symbols2
            onEnter: sendQuery()
        }

        Symbols2 {
            id: symbols2
            anchors.fill: parent
            anchors.topMargin: 93
            onStandardModeSwitched: keyboard.mode = standard
            onSymbolsModeSwitched: keyboard.mode = symbols
            onEnter: sendQuery()
        }
    }

    Rectangle {
        id: closeSearchUI
        width: 80
        height: 80
        radius: 40
        color: "black"
        anchors {
            right: parent.right
            bottom: keyboard.top
            margins: 40
        }
        Text {
            text: "v"
            font.family: "Maison Neue"
            font.bold: true
            color: "white"
            anchors.centerIn: parent
            font.pixelSize:40
        }
        MouseArea {
            anchors.fill: parent
            onClicked: openSearch(false)
        }
    }

    Item {
        id: keyboardOverlay
        anchors.fill: keyboard
    }
}