forked from Esri/arcgis-appstudio-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyApp.qml
345 lines (290 loc) · 13.3 KB
/
MyApp.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
/* Copyright 2021 Esri
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import QtQuick 2.9
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.2
import QtQuick.Controls.Material 2.2
import QtGraphicalEffects 1.0
import QtQuick.Dialogs 1.2
import ArcGIS.AppFramework 1.0
import ArcGIS.AppFramework.Platform 1.0
import "controls" as Controls
App {
id: app
width: 414
height: 736
property real scaleFactor: AppFramework.displayScaleFactor
property int baseFontSize : app.info.propertyValue("baseFontSize", 16 * scaleFactor) + (isSmallScreen ? 0 : 3)
property bool isSmallScreen: (width || height) < 400 * scaleFactor
property bool isIOS: Qt.platform.os === "ios"
property bool isWin: Qt.platform.os === "windows"
property bool isAndroid: Qt.platform.os === "android"
property url shareURL
property FileFolder destFolder: AppFramework.userHomeFolder.folder("ArcGIS/AppStudio/Data")
function copyFile(fileName) {
if (!destFolder.exists) destFolder.makeFolder();
shareURL.copyFile(fileName, destFolder.filePath(fileName));
console.log(destFolder.filePath(fileName));
return destFolder.filePath(fileName);
}
Page {
anchors.fill: parent
header: ToolBar {
id:header
width: parent.width
height: 50 * scaleFactor
Material.background: "#8f499c"
Controls.HeaderBar{}
}
// sample starts here ------------------------------------------------------------------
contentItem: Rectangle {
anchors.top:header.bottom
ColumnLayout {
anchors.fill: parent
spacing: 8 * scaleFactor
Item {
Layout.preferredHeight: 16 * scaleFactor
}
Item {
Layout.fillWidth: true
Layout.preferredHeight: col1.height
Layout.leftMargin: 16 * scaleFactor
Layout.rightMargin: 16 * scaleFactor
Pane {
anchors.fill: parent
Material.elevation: 1
padding: 0
ColumnLayout {
id: col1
width: parent.width
spacing: 0
Label {
text: qsTr("Share Text or URL")
font.pixelSize: baseFontSize
font.bold: true
elide: Text.ElideRight
Layout.fillWidth: true
Layout.topMargin: 16 * scaleFactor
Layout.rightMargin: 16 * scaleFactor
Layout.leftMargin: 16 * scaleFactor
}
TextField {
id:inputText
placeholderText: AppFramework.clipboard.supportsShare?"Enter Text or Url":qsTr("Sharing via Clipboard is not supported.")
font.pixelSize: baseFontSize
Material.accent: "#8f499c"
Layout.fillWidth: true
Layout.topMargin: 8 * scaleFactor
Layout.rightMargin: 16 * scaleFactor
Layout.leftMargin: 16 * scaleFactor
}
Item {
Layout.fillWidth: true
Layout.preferredHeight: row1.height
Layout.topMargin: 8 * scaleFactor
Layout.rightMargin: 16 * scaleFactor
Layout.leftMargin: 16 * scaleFactor
Layout.bottomMargin: 16 * scaleFactor
RowLayout {
id: row1
width: parent.width
spacing: 0
Button {
text: "Share as text"
enabled: AppFramework.clipboard.supportsShare === true
onClicked: {
if (inputText.text.length > 0) {
AppFramework.clipboard.share(inputText.text)
} else {
toast.displayToast("Enter a valid text")
}
}
}
Item {
Layout.fillWidth: true
}
Button {
text: "Share as Url"
enabled: AppFramework.clipboard.supportsShare === true
onClicked: {
if (inputText.text.length > 0) {
shareURL = inputText.text
AppFramework.clipboard.share(shareURL)
} else {
toast.displayToast("Enter a valid URL")
}
}
}
}
}
}
}
}
Item {
Layout.fillWidth: true
Layout.margins: 16 * scaleFactor
Layout.preferredHeight: pane.height
Pane {
id: pane
width: parent.width
height: col2.height
Material.elevation: 3
padding: 0
ColumnLayout {
id: col2
width: parent.width
spacing: 0
Label {
text: qsTr("View and Share a File")
font.pixelSize: baseFontSize
font.bold: true
elide: Text.ElideRight
Layout.fillWidth: true
Layout.topMargin: 16 * scaleFactor
Layout.rightMargin: 16 * scaleFactor
Layout.leftMargin: 16 * scaleFactor
Layout.bottomMargin: 8 * scaleFactor
}
Button {
id: selectFile
text: qsTr("Select a File")
Layout.alignment: Qt.AlignLeft
Layout.leftMargin: 16 * scaleFactor
Layout.bottomMargin: 8 * scaleFactor
onClicked: {
if (Permission.checkPermission(Permission.PermissionTypeStorage) !== Permission.PermissionResultGranted) {
permissionDialog.open()
} else {
doc.open()
}
}
}
Label {
id: selectedFileName
wrapMode: Label.Wrap
elide: Text.ElideRight
Layout.fillWidth: true
Layout.leftMargin: 16 * scaleFactor
Layout.rightMargin: 16 * scaleFactor
visible: false
font.pixelSize: baseFontSize * 0.8
}
Item {
Layout.preferredHeight: 8 * scaleFactor
}
Label {
id: selectedFilePath
wrapMode: Label.Wrap
elide: Label.ElideRight
Layout.fillWidth: true
Layout.leftMargin: 16 * scaleFactor
Layout.rightMargin: 16 * scaleFactor
visible: false
font.pixelSize: baseFontSize * 0.8
}
Item {
Layout.preferredHeight: 8 * scaleFactor
Layout.alignment: Qt.AlignLeft
Layout.leftMargin: 16 * scaleFactor
}
Button {
id: viewFile
text: qsTr("View File")
Layout.alignment: Qt.AlignLeft
Layout.leftMargin: 16 * scaleFactor
enabled: selectedFilePath.text.length > 0
onClicked: {
AppFramework.openUrlExternally(shareURL)
}
}
Item {
Layout.preferredHeight: 8 * scaleFactor
Layout.alignment: Qt.AlignLeft
Layout.leftMargin: 16 * scaleFactor
}
Button {
id: shareFile
text: qsTr("Share File")
Layout.alignment: Qt.AlignLeft
Layout.leftMargin: 16 * scaleFactor
enabled: selectedFilePath.text.length > 0
onClicked: {
AppFramework.clipboard.share(shareURL)
}
}
Item {
Layout.preferredHeight: 16 * scaleFactor
}
}
}
}
Item {
Layout.fillWidth: true
Layout.fillHeight: true
}
}
}
}
PermissionDialog {
id: permissionDialog
openSettingsWhenDenied: true
permission: PermissionDialog.PermissionDialogTypeStorage
onAccepted: {
doc.open()
}
onRejected: {
toast.displayToast("Permission Not Granted")
}
}
DocumentDialog {
id: doc
onAccepted: {
shareURL = fileUrl
selectedFilePath.visible = true
var fileInfo = AppFramework.fileInfo(shareURL.toString().replace(Qt.platform.os == "windows"? "file:///": "file://",""));
var fileFolder = AppFramework.fileFolder(shareURL.toString().replace(Qt.platform.os == "windows"? "file:///": "file://",""))
selectedFileName.text = "Selected File Name: " + fileInfo.fileName
//in android system, document dialog returns the content uri of the file instead of file url
if(isAndroid)
selectedFilePath.text = "Selected Content Uri: " + fileInfo.filePath
else
selectedFilePath.text = "Selected File Path: " + fileInfo.filePath
selectedFileName.visible = true
}
onRejected: {
if (status == DocumentDialog.DocumentDialogCancelledByUser) {
toast.displayToast("File not selected")
}
if (status == DocumentDialog.DocumentDialogPermissionDenied) {
toast.displayToast("Storage permission not granted")
}
if (status == DocumentDialog.DocumentDialogNotSupported) {
toast.displayToast("Operation not supported")
}
if (status == DocumentDialog.DocumentDialogFileReadError) {
toast.displayToast("Error while reading file")
}
}
}
// sample ends here ------------------------------------------------------------------------
Controls.DescriptionPage{
id:descPage
visible: false
}
Controls.ToastMessage {
id: toast
}
}