-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_dialog.qml
125 lines (110 loc) · 3.7 KB
/
file_dialog.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
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
Dialog {
property int imgSize
property string selected
property list<string> toDelete
property bool deleteCheckVisible: false
id: fileDialog
title: "Load spiral config"
modal: true
standardButtons: Dialog.Cancel
height: parent.height
width: parent.width
anchors.centerIn: parent
onAccepted: destroy()
onRejected: destroy()
Rectangle {
color: "transparent"
anchors.fill: parent
GridView {
id: grid
cellWidth: fileDialog.imgSize + 5
cellHeight: fileDialog.imgSize + 30
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: deleteButton.top
clip: true
delegate: Column {
Image {
id: img
source: modelData.imgFileName ? "file://" + modelData.imgFileName : "/images/question_mark.png"
width: fileDialog.imgSize
height: fileDialog.imgSize
anchors.horizontalCenter: parent.horizontalCenter
MouseArea {
anchors.fill: parent
onClicked: {
if (fileDialog.deleteCheckVisible)
deleteCheckBox.toggle()
else
fileDialog.selectFile(modelData.jsonFileName)
}
onPressAndHold: {
fileDialog.deleteCheckVisible = true;
deleteCheckBox.checked = true
}
}
CheckBox {
id: deleteCheckBox
visible: fileDialog.deleteCheckVisible
onCheckedChanged: {
if (checked)
addToDelete(modelData.jsonFileName)
else
removeFromDelete(modelData.jsonFileName)
}
}
}
Label {
id: displayLabel
text: modelData.displayName
anchors.horizontalCenter: parent.horizontalCenter
}
}
}
Button {
id: deleteButton
text: "Delete"
visible: fileDialog.deleteCheckVisible
enabled: fileDialog.toDelete.length > 0
anchors.bottom: parent.bottom
onClicked: confirmDeleteDialog.open()
}
}
function addToDelete(file) {
if (!fileDialog.toDelete.includes(file))
fileDialog.toDelete.push(file);
}
function removeFromDelete(file) {
fileDialog.toDelete = fileDialog.toDelete.filter(item => item !== file);
if (fileDialog.toDelete.length === 0)
fileDialog.deleteCheckVisible = false;
}
function selectFile(file) {
fileDialog.selected = file;
fileDialog.toDelete = [];
accept();
}
function show(fileList, imgSz) {
grid.model = fileList;
imgSize = imgSz;
open();
}
Dialog {
id: confirmDeleteDialog
modal: true
standardButtons: Dialog.Yes | Dialog.No
anchors.centerIn: parent
Label {
text: confirmDeleteDialog.question()
}
function question() {
var n = fileDialog.toDelete.length;
return "Delete " + n + " configuration" + (n > 1 ? "s" : "") + "?";
}
onAccepted: fileDialog.accept()
}
}