summaryrefslogtreecommitdiffstats
path: root/tools/qqem/qml/ApplicationSettingsDialog.qml
blob: 219a6905fa8eb31d0d5b4661c877758bb05996b3 (plain)
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
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

import QtQuick
import QtQuick.Controls
import QtQuick.Dialogs
import QtQuick.Layouts
import QtCore

Window {
    id: rootItem

    readonly property real baseMargin: 20

    title: qsTr("Preferences")
    width: 660
    height: 620
    minimumWidth: 400
    minimumHeight: 400
    color: mainView.backgroundColor1
    modality: Qt.ApplicationModal
    flags: Qt.Dialog

    function addPreviewSourceImage() {
        sourceImagesFileDialog.open();
    }

    FileDialog {
        id: sourceImagesFileDialog
        currentFolder: effectManager.getDefaultImagesDirectory()
        onAccepted: {
            if (selectedFile) {
                effectManager.settings.addSourceImage(selectedFile);
                mainView.outputView.effectPreview.selectLastPreviewSource();
            }
        }
    }

    FileDialog {
        id: codeFontFileDialog
        nameFilters: ["TrueType font (*.ttf)"]
        currentFolder: StandardPaths.writableLocation(StandardPaths.FontsLocation)
        onAccepted: {
            if (selectedFile) {
                effectManager.settings.setCodeFontFile(selectedFile);
            }
        }
    }

    FolderDialog {
        id: customNodePathDialog
        onAccepted: {
            if (currentFolder) {
                let added = effectManager.settings.addCustomNodesPath(currentFolder.toString());
                if (added)
                    effectManager.refreshAddNodesList();
            }
        }
    }

    ScrollView {
        id: scrollView
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.top: parent.top
        anchors.bottom: footer.top
        contentWidth: mainContent.implicitWidth
        contentHeight: mainContent.implicitHeight + 2 * baseMargin

        Column {
            id: mainContent
            width: rootItem.width - 2 * baseMargin
            x: baseMargin
            y: baseMargin

            Item {
                id: sourceImagesToolbar
                width: parent.width
                height: 40
                Text {
                    anchors.verticalCenter: parent.verticalCenter
                    color: mainView.foregroundColor2
                    font.pixelSize: 14
                    font.bold: true
                    text: "Source Images"
                }
                Button {
                    height: parent.height - 4
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.right: addSourceImageButton.left
                    anchors.rightMargin: 5
                    text: qsTr("Refresh");
                    onClicked: {
                        effectManager.settings.refreshSourceImagesModel();
                    }
                }
                Button {
                    id: addSourceImageButton
                    height: parent.height - 4
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.right: parent.right
                    text: qsTr("Add");
                    onClicked: {
                        sourceImagesFileDialog.open();
                    }
                }
            }

            Rectangle {
                id: sourceImagesTable
                width: parent.width
                height: 120
                color: mainView.backgroundColor2
                border.color: mainView.foregroundColor1
                border.width: 1
                ListView {
                    id: sourceImagesList
                    anchors.fill: parent
                    clip: true
                    ScrollBar.vertical: ScrollBar {
                        id: scrollBar
                        policy: ScrollBar.AlwaysOn
                    }
                    model: effectManager.settings.sourceImagesModel
                    delegate: Item {
                        width: sourceImagesList.width
                        height: 30
                        Row {
                            id: delegateRow
                            x: 10
                            width: parent.width - x * 2
                            height: parent.height
                            spacing: 10
                            Rectangle {
                                id: sourceImageItem
                                y: 4
                                width: 100
                                height: parent.height - 8
                                border.width: 1
                                border.color: mainView.foregroundColor1
                                color: mainView.backgroundColor1
                                Image {
                                    anchors.fill: parent
                                    anchors.margins: 1
                                    fillMode: Image.PreserveAspectCrop
                                    source: model.file
                                    mipmap: true
                                }
                            }
                            Text {
                                anchors.verticalCenter: parent.verticalCenter
                                width: parent.width - scrollBar.width - sourceImageItem.width - sizeItem.width - removeButton.width - delegateRow.spacing * 3
                                text: model.file
                                color: mainView.foregroundColor2
                                elide: Text.ElideLeft
                            }
                            Text {
                                id: sizeItem
                                anchors.verticalCenter: parent.verticalCenter
                                text: "(" + model.width + " x " + model.height + ")"
                                color: mainView.foregroundColor2
                                elide: Text.ElideLeft
                            }
                            CustomIconButton {
                                id: removeButton
                                anchors.verticalCenter: parent.verticalCenter
                                height: parent.height * 0.6
                                width: height
                                icon: "images/icon_remove_shadow.png"
                                description: "Remove"
                                enabled: model.canRemove
                                onClicked: {
                                    effectManager.settings.removeSourceImage(model.index);
                                }
                            }
                        }
                    }
                }
            }
            Item {
                width: 1
                height: 20
            }
            Item {
                id: customNodesToolbar
                width: parent.width
                height: 40
                Text {
                    anchors.verticalCenter: parent.verticalCenter
                    color: mainView.foregroundColor2
                    font.pixelSize: 14
                    font.bold: true
                    text: "Custom Nodes"
                }
                Button {
                    id: addCustomNodesPathButton
                    height: parent.height - 4
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.right: parent.right
                    text: qsTr("Add");
                    onClicked: {
                        customNodePathDialog.open();
                    }
                }
            }
            Rectangle {
                id: customNodesTable
                width: parent.width
                height: 60
                color: mainView.backgroundColor2
                border.color: mainView.foregroundColor1
                border.width: 1
                ListView {
                    id: customNodesList
                    anchors.fill: parent
                    clip: true
                    ScrollBar.vertical: ScrollBar {
                        id: nodesListScrollBar
                        policy: ScrollBar.AlwaysOn
                    }
                    model: effectManager.settings.customNodesModel
                    delegate: Item {
                        width: customNodesList.width
                        height: 30
                        Row {
                            id: customNodesDelegateRow
                            x: 10
                            width: parent.width - x * 2
                            height: parent.height
                            spacing: 10
                            Text {
                                anchors.verticalCenter: parent.verticalCenter
                                width: parent.width - nodesListScrollBar.width - removeNodePathButton.width - customNodesDelegateRow.spacing
                                text: model.path
                                color: mainView.foregroundColor2
                                elide: Text.ElideLeft
                            }
                            CustomIconButton {
                                id: removeNodePathButton
                                anchors.verticalCenter: parent.verticalCenter
                                height: parent.height * 0.6
                                width: height
                                icon: "images/icon_remove_shadow.png"
                                description: "Remove"
                                onClicked: {
                                    effectManager.settings.removeCustomNodesPath(model.index);
                                }
                            }
                        }
                    }
                }
            }
            Item {
                width: 1
                height: 20
            }
            Row {
                height: 40
                spacing: 10
                Text {
                    anchors.verticalCenter: parent.verticalCenter
                    color: mainView.foregroundColor2
                    font.pixelSize: 14
                    font.bold: true
                    text: "Recent Projects menu"
                }
                Button {
                    height: parent.height - 4
                    anchors.verticalCenter: parent.verticalCenter
                    text: qsTr("Clear");
                    onClicked: {
                        effectManager.settings.clearRecentProjectsModel();
                    }
                }
            }
            Item {
                width: 1
                height: 20
            }
            Column {
                width: parent.width
                CheckBox {
                    text: "Enable legacy GLSL versions"
                    checked: effectManager.settings.useLegacyShaders
                    onToggled: {
                        effectManager.settings.useLegacyShaders = checked;
                    }
                }
                Text {
                    width: parent.width
                    color: mainView.foregroundColor2
                    font.pixelSize: 11
                    wrapMode: Text.WordWrap
                    text: "This will include also OpenGL 2.1 and OpenGL ES 2.0 versions into baked shaders. Note: Some effect nodes do not work when the legacy mode is enabled."
                }
            }
            Item {
                width: 1
                height: 20
            }
            RowLayout {
                id: fontSelection
                width: parent.width
                height: 40
                Text {
                    color: mainView.foregroundColor2
                    font.pixelSize: 14
                    font.bold: true
                    text: "Source Font:"
                }
                Text {
                    Layout.fillWidth: true
                    elide: Text.ElideMiddle
                    text: effectManager.settings.codeFontFile
                    font.pixelSize: 14
                    font.italic: true
                    color: mainView.foregroundColor2
                }
                Button {
                    Layout.preferredHeight: 40
                    text: qsTr("Select");
                    onClicked: {
                        codeFontFileDialog.open();
                    }
                }
                ComboBox {
                    id: fontSizeSelector
                    Layout.preferredWidth: 80
                    Layout.preferredHeight: 40
                    model: [6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72]
                    onActivated: {
                        effectManager.settings.setCodeFontSize(currentValue);
                    }
                    Component.onCompleted: {
                        currentIndex = indexOfValue(effectManager.settings.codeFontSize);
                    }
                    Connections {
                        target: effectManager.settings
                        function onCodeFontSizeChanged() {
                            fontSizeSelector.currentIndex = fontSizeSelector.indexOfValue(effectManager.settings.codeFontSize);
                        }
                    }
                }
                CustomIconButton {
                    height: 20
                    width: height
                    icon: "images/icon_reset.png"
                    onClicked: {
                        effectManager.settings.resetCodeFont();
                    }
                }
            }
        }
    }

    DialogButtonBox {
        id: footer
        anchors.bottom: parent.bottom
        width: parent.width
        standardButtons: DialogButtonBox.Close
        onRejected: {
            rootItem.close();
        }
    }
}