Repository navigation
Expand file tree
/
Copy pathPanel.qml
More file actions
433 lines (384 loc) · 13.4 KB
/
Copy pathPanel.qml
File metadata and controls
433 lines (384 loc) · 13.4 KB
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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
import QtQuick
import Quickshell
import Quickshell.Io
import qs.Commons
import qs.Ui
import "Quran.js" as Quran
import "Model.js" as Model
Panel {
id: root
moduleName: "io.github.arhamthedeveloper.mushaf"
manageIpc: false
property var anchorItem: null
property var hostWidget: null
readonly property var barIdentity: hostWidget || root
property var quran: null
property int surah: Quran.DEFAULT_SURAH
property int ayah: Quran.DEFAULT_AYAH
property string searchText: ""
property string searchError: ""
property string browseMode: "read" // read | surahs
property bool stateReady: false
readonly property color contentForeground: bar ? bar.barForeground : Color.foreground
readonly property color mutedForeground: Color.muted
readonly property color accentColor: Color.accent
readonly property string contentFontFamily: bar ? bar.fontFamily : Style.font.family
// Quran-specialized face for Uthmani Arabic text, bundled in the repo so
// users need no font install. Generic fonts render shadda+kasra (بِّ) and
// the dagger alif / small meem marks incorrectly.
FontLoader {
id: amiriQuran
source: Qt.resolvedUrl("assets/fonts/AmiriQuran.ttf")
}
readonly property string arabicFontFamily: amiriQuran.status === FontLoader.Ready
? amiriQuran.name : "sans-serif"
readonly property var currentAyahs: Model.ayahsFor(root.quran, root.surah)
readonly property string basmala: Model.basmalaFor(root.quran, root.surah)
readonly property var surahInfo: Quran.surahById(root.surah)
readonly property string label: Quran.formatRef(root.surah, root.ayah, false)
readonly property string chipLabel: Quran.formatRef(root.surah, root.ayah, true)
readonly property string tooltipLabel: root.label + " · Sahih International"
function open() {
root.controller.show()
Qt.callLater(function() {
if (root.opened) setCenterHoverRevealSuppressed(true)
root.scrollToAyah()
})
}
function close() {
setCenterHoverRevealSuppressed(false)
root.persist()
root.controller.hide()
}
function toggle() {
if (root.opened) root.close()
else root.open()
}
function switchPanel(direction) {
if (root.bar && typeof root.bar.switchPanelFrom === "function")
return root.bar.switchPanelFrom(root.barIdentity, direction)
return false
}
function setCenterHoverRevealSuppressed(value) {
if (root.bar && "centerHoverRevealSuppressed" in root.bar)
root.bar.centerHoverRevealSuppressed = value
}
function persist() {
if (!root.stateReady) return
stateFile.setText(Model.serializeState(root.surah, root.ayah))
}
function applyPlace(surahId, ayahNum, persistNow) {
if (!Quran.surahById(surahId)) return false
root.surah = surahId
root.ayah = Model.clampAyah(root.quran, surahId, ayahNum || 1)
root.searchError = ""
root.browseMode = "read"
if (persistNow !== false) root.persist()
Qt.callLater(root.scrollToAyah)
return true
}
function stepAyah(delta) {
var next = delta > 0
? Quran.nextAyah(root.surah, root.ayah)
: Quran.prevAyah(root.surah, root.ayah)
root.applyPlace(next.surah, next.ayah, true)
}
function stepSurah(delta) {
var next = delta > 0
? Quran.nextSurah(root.surah)
: Quran.prevSurah(root.surah)
root.applyPlace(next, 1, true)
}
function submitSearch() {
var parsed = Quran.parseReference(root.searchText)
if (!parsed) {
root.searchError = "Not a known surah or reference"
return
}
if (!root.applyPlace(parsed.surah, parsed.ayah, true))
root.searchError = "Not a known surah or reference"
else
root.searchText = ""
}
function scrollToAyah() {
if (!ayahList.count) return
var idx = Math.max(0, Math.min(ayahList.count - 1, root.ayah - 1))
ayahList.positionViewAtIndex(idx, ListView.Contain)
}
function openSurahs() {
root.browseMode = "surahs"
}
function pickSurah(id) {
root.applyPlace(id, 1, true)
}
FileView {
id: quranFile
path: Model.fileUrlToPath(Qt.resolvedUrl("data/quran.json"))
printErrors: false
onLoaded: {
try { root.quran = JSON.parse(text()) } catch (e) { root.quran = null }
stateFile.reload()
}
onLoadFailed: console.warn("Quran: failed to load data/quran.json")
}
FileView {
id: stateFile
path: Quickshell.env("HOME") + "/.local/state/omarchy/settings/quran-reader.json"
watchChanges: true
atomicWrites: true
printErrors: false
onLoaded: {
var place = Model.parseState(text(), root.quran)
root.applyPlace(place.surah, place.ayah, false)
root.stateReady = true
}
onLoadFailed: {
root.applyPlace(Quran.DEFAULT_SURAH, Quran.DEFAULT_AYAH, false)
root.stateReady = true
}
onFileChanged: reload()
}
KeyboardPanel {
id: panel
anchorItem: root.anchorItem
owner: root.barIdentity
bar: root.bar
open: root.opened
focusTarget: keyCatcher
contentWidth: panel.fittedContentWidth(Style.space(400))
contentHeight: panel.fittedContentHeight(Style.space(560))
PanelKeyCatcher {
id: keyCatcher
anchors.fill: parent
blocked: searchField.activeFocus
onMoveRequested: function(dx, dy) {
if (dx !== 0) root.stepSurah(dx)
if (dy < 0) root.stepAyah(-1)
if (dy > 0) root.stepAyah(1)
}
onCloseRequested: root.close()
onTabRequested: function(direction) { root.switchPanel(direction) }
onActivateRequested: {
if (root.browseMode === "read") root.persist()
}
Column {
id: content
anchors.fill: parent
spacing: Style.space(10)
Item {
width: parent.width
height: headerRow.implicitHeight
Row {
id: headerRow
anchors.left: parent.left
anchors.right: parent.right
spacing: Style.space(8)
Button {
width: Style.space(28)
implicitHeight: Style.space(28)
horizontalPadding: 0
verticalPadding: 0
iconText: ""
foreground: contentForeground
tooltipText: "Previous surah"
onClicked: root.stepSurah(-1)
}
Column {
width: parent.width - Style.space(120)
spacing: Style.space(2)
anchors.verticalCenter: parent.verticalCenter
Text {
width: parent.width
text: root.label
color: contentForeground
font.family: contentFontFamily
font.pixelSize: Style.font.subtitle
font.bold: true
elide: Text.ElideRight
horizontalAlignment: Text.AlignHCenter
}
Text {
width: parent.width
text: root.surahInfo ? root.surahInfo.name_ar : ""
color: mutedForeground
font.family: contentFontFamily
font.pixelSize: Style.font.title
horizontalAlignment: Text.AlignHCenter
elide: Text.ElideRight
}
}
Button {
width: Style.space(28)
implicitHeight: Style.space(28)
horizontalPadding: 0
verticalPadding: 0
iconText: ""
foreground: contentForeground
tooltipText: "Next surah"
onClicked: root.stepSurah(1)
}
Button {
width: Style.space(28)
implicitHeight: Style.space(28)
horizontalPadding: 0
verticalPadding: 0
iconText: ""
foreground: root.browseMode === "read" ? mutedForeground : accentColor
tooltipText: "Browse surahs"
onClicked: {
if (root.browseMode === "read") root.openSurahs()
else root.browseMode = "read"
}
}
}
}
TextField {
id: searchField
width: parent.width
placeholderText: "2:255 · al-baqarah 255"
foreground: contentForeground
font.family: contentFontFamily
text: root.searchText
onTextChanged: {
root.searchText = text
root.searchError = ""
}
Keys.onReturnPressed: root.submitSearch()
Keys.onEnterPressed: root.submitSearch()
}
Text {
width: parent.width
visible: root.searchError !== ""
text: root.searchError
color: root.bar ? root.bar.urgent : contentForeground
font.family: contentFontFamily
font.pixelSize: Style.font.caption
}
ListView {
id: ayahList
width: parent.width
height: parent.height - headerRow.height - searchField.height - browseToggle.height - Style.space(40)
clip: true
visible: root.browseMode === "read"
spacing: Style.space(10)
boundsBehavior: Flickable.StopAtBounds
model: root.currentAyahs
header: Item {
width: ayahList.width
height: root.basmala !== "" ? basmalaText.implicitHeight + Style.space(6) : 0
Text {
id: basmalaText
width: parent.width
text: root.basmala
color: contentForeground
font.family: root.arabicFontFamily
font.pixelSize: Style.font.displayLarge
horizontalAlignment: Text.AlignRight
wrapMode: Text.WordWrap
}
}
delegate: Item {
required property var modelData
width: ayahList.width
height: arabicText.implicitHeight + englishText.implicitHeight + Style.space(4)
readonly property bool current: modelData.n === root.ayah
Text {
id: arabicText
width: parent.width
text: modelData.n + " " + Model.arabicFor(root.quran, root.surah, modelData.n, modelData.ar)
color: parent.current ? accentColor : contentForeground
font.family: root.arabicFontFamily
font.pixelSize: Style.font.displayLarge
horizontalAlignment: Text.AlignRight
wrapMode: Text.WordWrap
}
Text {
id: englishText
anchors.top: arabicText.bottom
anchors.topMargin: Style.space(2)
width: parent.width
text: modelData.n + ". " + modelData.en
color: parent.current ? accentColor : mutedForeground
font.family: contentFontFamily
font.pixelSize: Style.font.bodySmall
wrapMode: Text.WordWrap
}
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: {
root.ayah = modelData.n
root.persist()
}
}
}
}
Column {
width: parent.width
height: ayahList.height
visible: root.browseMode === "surahs"
spacing: Style.space(8)
ListView {
width: parent.width
height: parent.height
clip: true
boundsBehavior: Flickable.StopAtBounds
model: Quran.SURAHS
delegate: Item {
required property var modelData
width: parent.width
height: Style.space(30)
Text {
anchors.left: parent.left
anchors.leftMargin: Style.space(4)
anchors.verticalCenter: parent.verticalCenter
width: Style.space(36)
text: modelData.id
color: modelData.id === root.surah ? accentColor : mutedForeground
font.family: contentFontFamily
font.pixelSize: Style.font.bodySmall
}
Text {
anchors.left: parent.left
anchors.leftMargin: Style.space(40)
anchors.verticalCenter: parent.verticalCenter
text: modelData.name_translit
color: modelData.id === root.surah ? accentColor : contentForeground
font.family: contentFontFamily
font.pixelSize: Style.font.bodySmall
}
Text {
anchors.right: parent.right
anchors.rightMargin: Style.space(40)
anchors.verticalCenter: parent.verticalCenter
text: modelData.name_ar
color: modelData.id === root.surah ? accentColor : contentForeground
font.family: root.arabicFontFamily
font.pixelSize: Style.font.bodySmall
}
Text {
anchors.right: parent.right
anchors.rightMargin: Style.space(4)
anchors.verticalCenter: parent.verticalCenter
text: modelData.ayahs
color: mutedForeground
font.family: contentFontFamily
font.pixelSize: Style.font.caption
}
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: root.pickSurah(modelData.id)
}
}
}
}
Item {
id: browseToggle
width: parent.width
height: 1
}
}
}
}
}