-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.qml
397 lines (372 loc) · 18 KB
/
Main.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
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
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import QtQuick.Dialogs
import QtCore
import hoisavegames
ApplicationWindow {
id: window
width: 1024
height: 768
visible: true
title: qsTr("钢铁雄心4存档管理器")
property var notify: ({})
Component.onCompleted: {
console.log(notify)
}
Settings {
id: windowSettings
property alias x: window.x
property alias y: window.y
property alias width: window.width
property alias height: window.height
property alias currentFolder: listeningFolderDialog.currentFolder
property alias listeningFolder: listeningFolderDialog.finalSelected
}
menuBar: MenuBar {
Menu {
title: qsTr("&设置")
Action {
text: qsTr("&选择监听目录")
onTriggered: listeningFolderDialog.open()
}
}
FolderDialog {
id: listeningFolderDialog
property url finalSelected
onAccepted: {
finalSelected = selectedFolder
}
}
}
SaveGameListener {
listeningFolder: windowSettings.listeningFolder
onFileChanged: path => {
console.log(path, typeof path)
if (!hoiModel.restoring) {
hoiModel.addSaveNodeFromPath(path)
}
}
}
SplitView {
anchors.fill: parent
anchors.topMargin: 10
Rectangle {
implicitWidth: 60
ListView {
id: fileNameList
anchors.fill: parent
clip: true
ScrollBar.vertical: ScrollBar {}
model: hoiModel.listeningFiles
signal cleanSelected
TapHandler {
onTapped: {
fileNameList.cleanSelected()
}
}
delegate: Rectangle {
id: fileNameRect
implicitHeight: fileNameText.height + 5
implicitWidth: fileNameList.width + 10
border.color: "#eee"
border.width: 2
radius: 3
Layout.alignment: Qt.AlignHCenter
states: [
State {
name: "hovered"
PropertyChanges {
target: fileNameRect
color: "#d8eaf9"
}
},
State {
name: "selected"
PropertyChanges {
target: fileNameRect
color: "#cce8ff"
}
}
]
Connections {
target: fileNameList
function onCleanSelected() {
fileNameRect.state = ""
}
}
Text {
id: fileNameText
anchors.centerIn: parent
text: modelData.substring(modelData.lastIndexOf(
"/") + 1)
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
propagateComposedEvents: true
onEntered: {
if (fileNameRect.state === "") {
fileNameRect.state = "hovered"
}
}
onExited: {
if (fileNameRect.state === "hovered") {
fileNameRect.state = ""
}
}
onPressed: {
fileNameList.cleanSelected()
fileNameRect.state = "selected"
hoiModel.currentFileName = modelData
}
}
}
}
}
Rectangle {
id: treeContainer
implicitWidth: parent.width - 60
ListView {
id: treeList
anchors.fill: parent
model: HoiModel {
id: hoiModel
onNotify: function (title, msg) {
var component = Qt.createComponent("Message.qml")
var dialog = component.createObject(window, {
"title": title,
"informativeText": msg
})
dialog.open()
}
onListeningFilesChanged: {
console.log(listeningFiles)
}
}
spacing: 10
clip: true
ScrollBar.vertical: ScrollBar {}
property var linePos: ({})
signal linePosAdd
signal cleanSelected
TapHandler {
onTapped: {
treeList.cleanSelected()
}
}
delegate: Rectangle {
implicitWidth: treeContainer.width
implicitHeight: 30
RowLayout {
implicitWidth: display.length * 100
anchors.centerIn: parent
spacing: 30
Repeater {
model: display
Rectangle {
id: nodeRect
required property var modelData
height: dateText.height + 10
width: dateText.width + 10
border.color: "#eee"
border.width: 2
radius: 3
Layout.alignment: Qt.AlignHCenter
states: [
State {
name: "hovered"
PropertyChanges {
target: nodeRect
color: "#d8eaf9"
}
},
State {
name: "selected"
PropertyChanges {
target: nodeRect
color: "#cce8ff"
}
}
]
Dialog {
id: detailDialog
title: modelData.date
parent: Overlay.overlay
x: (parent.width - width) / 2
y: (parent.height - height) / 2
width: parent.width * 0.7
modal: false
closePolicy: Dialog.NoAutoClose | Dialog.CloseOnEscape
header: Rectangle {
width: parent.width
height: 20
color: "#eee"
Text {
id: name
text: qsTr(modelData.date)
}
Rectangle {
id: closeRect
anchors.right: parent.right
anchors.rightMargin: 10
anchors.topMargin: 0
implicitWidth: 18
implicitHeight: 18
color: parent.color
states: [
State {
name: "hovered"
PropertyChanges {
target: closeRect
color: "#fb4d3f"
}
}
]
MouseArea {
anchors.fill: parent
hoverEnabled: true
onEntered: {
closeRect.state = "hovered"
}
onExited: {
closeRect.state = ""
}
onPressed: {
detailDialog.close()
}
}
Text {
id: closeText
text: "x"
anchors.centerIn: parent
font.bold: true
font.pixelSize: 16
}
}
MouseArea {
anchors.fill: parent
anchors.rightMargin: 30
propagateComposedEvents: true
property var startP
onPressed: mouse => {
startP = Qt.point(
mouse.x, mouse.y)
}
onPositionChanged: function (e) {
if (pressed) {
var offset = Qt.point(
e.x - startP.x,
e.y - startP.y)
if (detailDialog.x + offset.x < 0) {
return
}
if (detailDialog.y + offset.y < 0) {
return
}
detailDialog.x += offset.x
detailDialog.y += offset.y
}
}
}
}
ColumnLayout {
Layout.preferredWidth: parent.width
ColumnLayout {
Repeater {
model: ["id", "parentId", "srcPath", "filePath", "updateTime", "player", "ideology", "date", "difficulty", "version", "ironman"]
delegate: RowLayout {
required property var index
required property var modelData
Text {
text: qsTr(modelData + ":")
}
Text {
Layout.maximumWidth: 500
text: nodeRect.modelData[modelData]
wrapMode: Text.WrapAnywhere
}
}
}
}
RowLayout {
Layout.preferredWidth: parent.width
Button {
Layout.alignment: Qt.AlignRight
highlighted: true
text: qsTr("回档")
onClicked: {
hoiModel.restore(
nodeRect.modelData)
}
}
}
}
}
Connections {
target: treeList
function onCleanSelected() {
nodeRect.state = ""
}
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
propagateComposedEvents: true
onEntered: {
if (nodeRect.state === "") {
nodeRect.state = "hovered"
}
}
onExited: {
if (nodeRect.state === "hovered") {
nodeRect.state = ""
}
}
onPressed: {
treeList.cleanSelected()
nodeRect.state = "selected"
detailDialog.open()
}
}
Line {
id: line
anchors.horizontalCenter: parent.horizontalCenter
onScenePosChanged: {
treeList.linePos[modelData.id + ""]
= [scenePos, Qt.point(
parent.width,
parent.height)]
treeList.linePosAdd()
}
Connections {
target: treeList
function onLinePosAdd() {
if (!modelData.parentNode) {
return
}
var rect = treeList.linePos[modelData.parentNode.id
+ ""]
if (!rect) {
return
}
var pos = rect[0]
var wh = rect[1]
line.relativeX = pos.x - line.scenePos.x
line.relativeY = (pos.y + wh.y) - line.scenePos.y
}
}
}
Text {
id: dateText
anchors.centerIn: parent
text: qsTr(modelData.date)
}
}
}
}
}
}
}
}
}