-
Notifications
You must be signed in to change notification settings - Fork 0
/
PingForm.qml
140 lines (125 loc) · 4.01 KB
/
PingForm.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
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Controls.Material 2.2
import QtQuick.Layouts 1.3
import Qt.labs.settings 1.0
import SProcess 1.0
Page {
property Menu menu: Menu {
title: qsTr("Ping actions")
MenuItem {
text: qsTr("Add device ...")
onClicked: addDeviceDialog.open()
}
MenuItem {
id: menuDeleteAction
text: qsTr("Delete")
checkable: true
enabled: pingModel.count > 0
}
}
title: qsTr("Ping")
ListModel {
id: pingModel
}
Settings {
category: "PingModel"
property string dataModel: "[]"
Component.onCompleted: {
var obj = JSON.parse(dataModel);
for(var item in obj) {
pingModel.append({"hostname":obj[item].hostname,"username":obj[item].username});
}
}
Component.onDestruction: {
var obj = [];
var count = pingModel.count;
for(var i = 0; i < count; i ++) {
var item = pingModel.get(i);
obj.push({"hostname":item.hostname,"username":item.username});
}
dataModel = JSON.stringify(obj);
}
}
ListView {
id:listView
anchors.fill: parent
model: pingModel
delegate: PingDelegate {
id: pingDelegate
width: parent.width
hostname: model.hostname
username: model.username
swipe.right: Button {
anchors.left: parent.left
anchors.right: parent.right
height: parent.height
visible: swipe.complete
text: qsTr("Delete")
onClicked: {
swipe.close();
pingModel.remove(index);
}
highlighted: true
}
onClicked: {
ListView.view.currentIndex = index;
if(menuDeleteAction.checked) {
pingDelegate.swipe.open(SwipeDelegate.Right)
}
}
ListView.onCurrentItemChanged: if(!ListView.isCurrentItem && pingDelegate.swipe.complete) pingDelegate.swipe.close()
}
displaced: Transition {
NumberAnimation { properties: "x,y"; duration: 500 }
}
ScrollBar.vertical: ScrollBar {}
}
Dialog {
id: addDeviceDialog
x: Math.round((window.width - width) / 2)
y: Math.round(window.height / 6)
width: Math.round(Math.min(window.width, window.height) / 3 * 2)
title: qsTr("Add device")
modal: true
standardButtons: Dialog.Ok | Dialog.Cancel
ColumnLayout {
spacing: 20
anchors.fill: parent
TextField {
id: addDeviceDialogHostname
focus: true
placeholderText: qsTr("Hostname or IP address")
Layout.fillWidth: true
}
TextField {
id: addDeviceDialogUsername
placeholderText: qsTr("Short description")
Layout.fillWidth: true
}
}
onAccepted: {
var hostname = addDeviceDialogHostname.text.trim();
var username = addDeviceDialogUsername.text.trim();
if(hostname.length > 0)
pingModel.append({"hostname":hostname,"username":username});
addDeviceDialogHostname.clear();
addDeviceDialogUsername.clear();
}
}
footer: Button {
id: deleteHintButton
anchors.left: parent.left
anchors.right: parent.right
text: qsTr("Click item to delete")
visible: menuDeleteAction.checked
onClicked: { menuDeleteAction.checked = false; listView.currentIndex = -1}
states: State {
when: deleteHintButton.hovered
PropertyChanges {
target: deleteHintButton
text: qsTr("Done")
}
}
}
}