summaryrefslogtreecommitdiffstats
path: root/tools/qqem/qml/main.qml
blob: fece9badc0d942769fc43fc91e2a5eb414c32762 (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
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
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

import QtQuick
import QtQuick.Window
import QtQuick.Controls
import QtQuick.Dialogs

ApplicationWindow {
    id: mainWindow

    property alias effectManager: mainView.effectManager
    readonly property string isUnsaved: effectManager.unsavedChanges ? "*" : ""
    readonly property string projectTitle: effectManager.projectName ? (isUnsaved + effectManager.projectName + " - ") : ""
    property alias propertyEditDialog: mainView.propertyEditDialog
    property alias currentEditorComponent: mainView.currentEditorComponent
    property bool canCut: !mainView.designMode
    property bool canCopy: !mainView.designMode
    property bool canPaste: !mainView.designMode && currentEditorComponent ? currentEditorComponent.canPaste : false
    property bool canUndo: !mainView.designMode && currentEditorComponent ? currentEditorComponent.canUndo : false
    property bool canRedo: !mainView.designMode && currentEditorComponent ? currentEditorComponent.canRedo : false
    property bool canFind: !mainView.designMode && currentEditorComponent
    property bool quitAccepted: false

    onClosing: function(close) {
        maybeQuitAction();
        close.accepted = mainWindow.quitAccepted;
    }

    width: 1200
    height: 800
    minimumWidth: 600
    minimumHeight: 400
    visible: true
    title: qsTr("%1Qt Quick Effect Maker ").arg(mainWindow.projectTitle)
    color: mainView.backgroundColor1
    menuBar: MenuBar {
        Menu {
            id: fileMenu
            title: qsTr("&File")
            Action {
                text: qsTr("&New Project")
                onTriggered: maybeNewProjectAction();
                enabled: !qdsMode
                shortcut: StandardKey.New
            }
            Action {
                text: qsTr("&Open Project")
                onTriggered: maybeOpenProjectAction();
                enabled: !qdsMode
                shortcut: StandardKey.Open
            }
            Menu {
                id: recentProjectsMenu
                title: "Recent Projects"
                enabled: !qdsMode && recentProjectsRepeater.count > 0
                Repeater {
                    id: recentProjectsRepeater
                    model: effectManager.settings.recentProjectsModel
                    MenuItem {
                        text: model.name
                        onTriggered: {
                            fileMenu.close();
                            maybeOpenProjectAction(model.file);
                        }
                    }
                }
            }
            Action {
                text: qsTr("Close Project")
                onTriggered: maybeCloseProjectAction();
                enabled: !qdsMode && effectManager.hasProjectFilename
                shortcut: StandardKey.Close
            }
            MenuSeparator { }
            Action {
                text: qsTr("&Save")
                onTriggered: saveProjectAction();
                shortcut: StandardKey.Save
            }
            Action {
                text: qsTr("Save &As...")
                onTriggered: saveProjectAsAction();
                enabled: !qdsMode && effectManager.hasProjectFilename
                shortcut: StandardKey.SaveAs
            }
            MenuSeparator { }
            Action {
                text: qsTr("&Export")
                onTriggered: exportAction();
                enabled: !qdsMode && effectManager.hasProjectFilename && effectManager.effectError.message === ""
                shortcut: "Ctrl+E"
            }
            Action {
                text: qsTr("Export As")
                onTriggered: exportAsAction();
                enabled: !qdsMode && effectManager.hasProjectFilename && effectManager.effectError.message === ""
            }
            MenuSeparator { }
            Action {
                text: qsTr("&Quit");
                onTriggered: maybeQuitAction();
                shortcut: StandardKey.Quit
            }
        }
        Menu {
            title: qsTr("&Edit")
            Action {
                text: qsTr("Undo");
                enabled: canUndo
                onTriggered: undoCodeAction();
            }
            Action {
                text: qsTr("Redo");
                enabled: canRedo
                onTriggered: redoCodeAction();
            }
            MenuSeparator { }
            Action {
                text: qsTr("Cut");
                enabled: canCut
                onTriggered: cutCodeAction();
            }
            Action {
                text: qsTr("Copy");
                enabled: canCopy
                onTriggered: copyCodeAction();
            }
            Action {
                text: qsTr("Paste");
                enabled: canPaste
                onTriggered: pasteCodeAction();
            }
            Action {
                text: qsTr("Find");
                enabled: canFind
                shortcut: StandardKey.Find
                onTriggered: showFindBarAction();
            }
            MenuSeparator { }
            Action {
                text: qsTr("Project Settings");
                onTriggered: projectSettingsAction();
            }
            Action {
                text: qsTr("Preferences");
                onTriggered: applicationSettingsAction();
            }
        }
        Menu {
            title: qsTr("&Node View")
            Action {
                text: qsTr("Add Node");
                onTriggered: addNodeAction();
            }
            Menu {
                title: "Selected"
                enabled: mainView.nodeViewItem.effectNodeSelected
                Action {
                    text: "Enable / Disable"
                    onTriggered: disableNodeAction();
                }
                Action {
                    text: "Rename"
                    onTriggered: renameNodeAction();
                }
                Action {
                    text: "Export"
                    onTriggered: exportNodeAction();
                }
                Action {
                    text: "Delete"
                    enabled: mainView.nodeViewItem.effectNodeSelected
                    onTriggered: deleteNodeAction();
                    shortcut: StandardKey.Delete
                }
            }
            MenuSeparator { }
            Action {
                text: qsTr("Clear");
                onTriggered: clearNodeViewAction();
            }
        }
        Menu {
            title: qsTr("&Tools")
            Action {
                text: qsTr("QSB Inspector");
                onTriggered: qsbInspectorAction();
            }
            Action {
                text: qsTr("Render to Image");
                onTriggered: renderToImageAction();
            }
        }
        Menu {
            title: qsTr("&Help")
            Action {
                text: qsTr("Quick Help")
                onTriggered: helpAction();
            }
            Action {
                text: qsTr("&About")
                onTriggered: aboutAction();
            }
        }
    }

    Menu {
        id: nodeContextMenu
        enabled: mainView.nodeViewItem.effectNodeSelected
        Action {
            text: "Enable / Disable"
            onTriggered: disableNodeAction();
        }
        Action {
            text: "Rename"
            onTriggered: renameNodeAction();
        }
        Action {
            text: "Export"
            onTriggered: exportNodeAction();
        }
        Action {
            text: "Delete"
            onTriggered: deleteNodeAction();
        }
    }

    FontLoader {
        id: codeFont
        source: effectManager.settings.codeFontFile
    }

    FileDialog {
        id: openEffectProjectDialog
        title: "Open an Effect Project File"
        nameFilters: ["Quick Effect Project (*.qep)"]
        onAccepted: {
            if (currentFile) {
                openProjectAction(currentFile);
            }
        }
    }

    FileDialog {
        id: saveProjectAsDialog
        fileMode: FileDialog.SaveFile
        nameFilters: ["Quick Effect Project (*.qep)"]
        onAccepted: {
            if (currentFile)
                effectManager.saveProject(currentFile)
        }
    }

    FileDialog {
        id: saveNodeAsDialog
        fileMode: FileDialog.SaveFile
        nameFilters: ["Quick Effect Node (*.qen)"]
        onAccepted: {
            if (currentFile)
                effectManager.saveSelectedNode(currentFile)
        }
    }

    FileDialog {
        id: saveImageAsDialog
        fileMode: FileDialog.SaveFile
        nameFilters: ["Portable Network Graphics (*.png)"]
        onAccepted: {
            if (currentFile)
                mainView.outputView.renderToImage(currentFile);
        }
    }

    SaveProjectDialog {
        id: saveProjectDialog
        parent: Overlay.overlay
        anchors.centerIn: parent

        function goToAction() {
            if (action === 0) {
                newProjectAction(true);
            } else if (action === 1) {
                openProjectAction(openFileName);
            } else if (action === 2) {
                closeProjectAction();
            } else if (action === 3) {
                quitAction();
            }
        }

        onAccepted: {
            // Save and then proceed to action
            effectManager.saveProject();
            goToAction();
        }
        onDiscarded: {
            // Discard saving, proceed to action directly
            goToAction();
            saveProjectDialog.close();
        }
        onRejected: {
            // Cancel the action
        }
    }

    AboutDialog {
        id: aboutDialog
        parent: Overlay.overlay
        anchors.centerIn: parent
    }

    NewProjectDialog {
        id: newProjectDialog
        parent: Overlay.overlay
        anchors.centerIn: parent
    }

    ExportEffectDialog {
        id: exportEffectDialog
        parent: Overlay.overlay
        anchors.centerIn: parent
    }

    DeleteNodeDialog {
        id: deleteNodeDialog
        parent: Overlay.overlay
        anchors.centerIn: parent
    }
    ClearNodeViewDialog {
        id: clearNodeViewDialog
        parent: Overlay.overlay
        anchors.centerIn: parent
    }
    ProjectSettingsDialog {
        id: projectSettingsDialog
        parent: Overlay.overlay
        anchors.centerIn: parent
    }
    ApplicationSettingsDialog {
        id: applicationSettingsDialog
    }
    QsbInspectorDialog {
        id: qsbInspectorDialog
        parent: Overlay.overlay
        anchors.centerIn: parent
    }

    function saveProjectAction() {
        if (qdsMode) {
            saveAndExportProjectAction();
        } else {
            if (effectManager.hasProjectFilename)
                effectManager.saveProject();
            else
                newProjectAction(false);
        }
    }

    function saveAndExportProjectAction() {
        if (effectManager.hasProjectFilename) {
            effectManager.saveProject();
            mainWindow.exportAction();
        } else {
            newProjectDialog.exportNext = true;
            mainWindow.newProjectAction(false);
        }
    }

    function maybeOpenProjectAction(openFileName) {
        if (effectManager.hasProjectFilename && effectManager.unsavedChanges) {
            saveProjectDialog.action = 1;
            if (openFileName !== undefined)
                saveProjectDialog.openFileName = openFileName;
            else
                saveProjectDialog.openFileName = "";
            saveProjectDialog.open();
        } else {
            openProjectAction(openFileName);
        }
    }

    // When filename is given, opens that.
    // Otherwise opens file dialog to browse the file.
    function openProjectAction(openFileName) {
        if (openFileName !== undefined && openFileName !== "") {
            mainView.mainToolbar.setDesignModeInstantly(true);
            effectManager.loadProject(openFileName);
            return;
        }
        if (effectManager.projectDirectory) {
            openEffectProjectDialog.currentFolder = effectManager.projectDirectory;
        }
        openEffectProjectDialog.open();
    }

    function maybeCloseProjectAction() {
        if (effectManager.hasProjectFilename && effectManager.unsavedChanges) {
            saveProjectDialog.action = 2;
            saveProjectDialog.open();
        } else {
            closeProjectAction();
        }
    }

    function closeProjectAction() {
        effectManager.closeProject();
    }

    function maybeNewProjectAction() {
        if (effectManager.hasProjectFilename && effectManager.unsavedChanges) {
            saveProjectDialog.action = 0;
            saveProjectDialog.open();
        } else {
            newProjectAction(true);
        }
    }

    function newProjectAction(clearNodeView) {
        newProjectDialog.clearNodeView = clearNodeView;
        newProjectDialog.open();
    }

    function saveProjectAsAction() {
        if (effectManager.projectFilename) {
            saveProjectAsDialog.currentFolder = effectManager.addFileToURL(effectManager.projectDirectory);
            saveProjectAsDialog.currentFile = effectManager.projectFilename;
        }
        saveProjectAsDialog.open();
    }

    function maybeQuitAction() {
        if (effectManager.hasProjectFilename && effectManager.unsavedChanges) {
            saveProjectDialog.action = 3;
            saveProjectDialog.open();
        } else {
            quitAction();
        }
    }

    function quitAction() {
        mainWindow.quitAccepted = true;
        Qt.quit();
    }

    function addNodeAction() {
        mainView.nodeViewItem.showAddNodeDialog(-1, -1);
    }

    function renameNodeAction() {
        mainView.nodeViewItem.showRenameNodeDialog();
    }

    function disableNodeAction() {
        mainView.nodeViewItem.toggleNodeDisabled();
        effectManager.updateQmlComponent();
        effectManager.bakeShaders(true);
    }

    function exportNodeAction() {
        saveNodeAsDialog.currentFile = effectManager.nodeView.selectedNodeName + ".qen";
        saveNodeAsDialog.open();
    }
    function deleteNodeAction() {
        deleteNodeDialog.open();
    }

    function clearNodeViewAction() {
        clearNodeViewDialog.open();
    }

    function aboutAction() {
        aboutDialog.open();
    }

    function helpAction() {
        mainView.outputView.showHelp();
    }

    function exportAction() {
        if (effectManager.exportFilename !== "") {
            // Export with the default/latest settings
            // without showing the dialog.
            exportEffectDialog.initializeDialog();
            exportEffectDialog.exportEffect();
        } else {
            exportAsAction();
        }
    }

    function exportAsAction() {
        exportEffectDialog.open();
    }

    function addPropertyAction() {
        propertyEditDialog.propertyIndex = -1;
        propertyEditDialog.initialType = 2;
        propertyEditDialog.initialName = "";
        propertyEditDialog.initialDescription = "";
        // Default to false or 0.0
        propertyEditDialog.initialDefaultValue = false;
        propertyEditDialog.initialMinValue = "0.0";
        propertyEditDialog.initialMaxValue = "1.0";
        propertyEditDialog.initialUseCustomValue = false;
        propertyEditDialog.initialCustomValue = "";
        propertyEditDialog.initialEnableMipmap = false;
        propertyEditDialog.initialExportImage = true;
        propertyEditDialog.open();
    }

    function undoCodeAction() {
        currentEditorComponent.undo();
    }

    function redoCodeAction() {
        currentEditorComponent.redo();
    }

    function cutCodeAction() {
        currentEditorComponent.cut();
    }

    function copyCodeAction() {
        currentEditorComponent.copy();
    }

    function pasteCodeAction() {
        currentEditorComponent.paste();
    }

    function projectSettingsAction() {
        projectSettingsDialog.itemPadding = effectManager.effectPadding;
        projectSettingsDialog.newItemPadding = effectManager.effectPadding;
        projectSettingsDialog.open();
    }

    function applicationSettingsAction() {
        applicationSettingsDialog.show();
    }

    function qsbInspectorAction(qsbFile) {
        if (qsbFile !== undefined)
            qsbInspectorDialog.setQsbFile(qsbFile);
        qsbInspectorDialog.open();
    }

    function showFindBarAction() {
        mainView.showFindBar = true;
        mainView.currentEditorComponent.findAction();
    }

    function renderToImageAction() {
        if (saveImageAsDialog.currentFile == "") {
            saveImageAsDialog.currentFolder = effectManager.addFileToURL(effectManager.projectDirectory);
            saveImageAsDialog.currentFile = "effect_render.png";
        }
        saveImageAsDialog.open();
    }

    MainView {
        id: mainView
    }
}