16
16
import QtQuick 2.5
17
17
import QtQuick.Controls 2.0
18
18
import QtGraphicalEffects 1.0
19
+ import QtQuick.Layouts 1.3
19
20
import QgsQuick 0.1 as QgsQuick
20
21
21
22
/**
@@ -33,8 +34,19 @@ Item {
33
34
property var galleryIcon: customStyle .icons .gallery
34
35
property var brokenImageIcon: customStyle .icons .brokenImage
35
36
property var notAvailableImageIcon: customStyle .icons .notAvailable
36
- property real iconSize: customStyle .fields .height * 0.75
37
+ property real iconSize: customStyle .fields .height
37
38
property real textMargin: QgsQuick .Utils .dp * 10
39
+ // Ment to be use with the save callback - stores image source
40
+ property string sourceToDelete
41
+
42
+ Component .onCompleted : {
43
+ callbackOnSave = function () {
44
+ externalResourceHandler .onFormSave (fieldItem)
45
+ }
46
+ callbackOnCancel = function () {
47
+ externalResourceHandler .onFormCanceled (fieldItem)
48
+ }
49
+ }
38
50
39
51
id: fieldItem
40
52
enabled: true // its interactive widget
52
64
State {
53
65
name: " notSet"
54
66
},
55
- State {
56
- name: " broken"
57
- },
58
67
State {
59
68
name: " notAvailable"
60
69
}
@@ -101,7 +110,7 @@ Item {
101
110
102
111
function getSource () {
103
112
if (image .status === Image .Error ) {
104
- fieldItem .state = " broken "
113
+ fieldItem .state = " notAvailable "
105
114
return " "
106
115
}
107
116
else if (image .currentValue && QgsQuick .Utils .fileExists (homePath + " /" + image .currentValue )) {
@@ -112,10 +121,8 @@ Item {
112
121
fieldItem .state = " notSet"
113
122
return " "
114
123
}
115
- else {
116
- fieldItem .state = " notAvailable"
117
- return homePath + " /" + image .currentValue
118
- }
124
+ fieldItem .state = " notAvailable"
125
+ return homePath + " /" + image .currentValue
119
126
}
120
127
}
121
128
}
@@ -150,66 +157,77 @@ Item {
150
157
}
151
158
152
159
Item {
160
+ property real itemHeight: fieldItem .iconSize / 2
161
+
153
162
id: buttonsContainer
154
163
anchors .centerIn : imageContainer
155
164
anchors .fill : imageContainer
156
- anchors .margins : 10
165
+ anchors .margins : fieldItem . textMargin
157
166
visible: fieldItem .state !== " valid"
158
167
159
- QgsQuick .IconTextItem {
160
- id: photoButton
161
- iconSize: fieldItem .iconSize
162
- fontColor: customStyle .fields .fontColor
163
- fontPixelSize: fieldItem .iconSize / 2
164
- iconSource: fieldItem .cameraIcon
165
- labelText: qsTr (" Take a Photo" )
168
+ anchors .horizontalCenter : parent .horizontalCenter
169
+ anchors .verticalCenter : parent .verticalCenter
166
170
167
- visible: ! readOnly && fieldItem .state !== " valid"
168
- height: fieldItem .iconSize
171
+ ColumnLayout {
172
+ width: parent .width
173
+ height: photoButton .height * 2
169
174
anchors .horizontalCenter : parent .horizontalCenter
175
+ anchors .verticalCenter : parent .verticalCenter
170
176
171
- MouseArea {
172
- anchors .fill : parent
173
- onClicked: {
174
- photoCapturePanel .visible = true
175
- photoCapturePanel .targetDir = homePath
176
- photoCapturePanel .fieldItem = fieldItem
177
+ QgsQuick .IconTextItem {
178
+ id: photoButton
179
+ iconSize: buttonsContainer .itemHeight
180
+ fontColor: customStyle .fields .fontColor
181
+ fontPixelSize: customStyle .fields .fontPixelSize
182
+ iconSource: fieldItem .cameraIcon
183
+ labelText: qsTr (" Take a Photo" )
184
+
185
+ visible: ! readOnly && fieldItem .state !== " valid"
186
+ height: buttonsContainer .itemHeight
187
+ Layout .alignment : Qt .AlignHCenter | Qt .AlignVCenter
188
+
189
+ MouseArea {
190
+ anchors .fill : parent
191
+ onClicked: {
192
+ photoCapturePanel .visible = true
193
+ photoCapturePanel .targetDir = homePath
194
+ photoCapturePanel .fieldItem = fieldItem
195
+ }
177
196
}
178
197
}
179
- }
180
-
181
- QgsQuick .IconTextItem {
182
- id: browseButton
183
- iconSize: fieldItem .iconSize
184
- fontColor: customStyle .fields .fontColor
185
- fontPixelSize: fieldItem .iconSize / 2
186
- iconSource: fieldItem .galleryIcon
187
- labelText: qsTr (" Add From a Gallery" )
188
-
189
- visible: ! readOnly && fieldItem .state !== " valid"
190
- height: fieldItem .iconSize
191
- anchors .top : photoButton .bottom
192
- anchors .horizontalCenter : parent .horizontalCenter
193
198
194
- MouseArea {
195
- anchors .fill : parent
196
- onClicked: externalResourceHandler .chooseImage (fieldItem)
199
+ QgsQuick .IconTextItem {
200
+ id: browseButton
201
+ iconSize: buttonsContainer .itemHeight
202
+ fontColor: customStyle .fields .fontColor
203
+ fontPixelSize: customStyle .fields .fontPixelSize
204
+ iconSource: fieldItem .galleryIcon
205
+ labelText: qsTr (" Add From a Gallery" )
206
+
207
+ visible: ! readOnly && fieldItem .state !== " valid"
208
+ height: buttonsContainer .itemHeight
209
+ Layout .alignment : Qt .AlignHCenter | Qt .AlignVCenter
210
+
211
+ MouseArea {
212
+ anchors .fill : parent
213
+ onClicked: externalResourceHandler .chooseImage (fieldItem)
214
+ }
197
215
}
198
216
}
217
+ }
199
218
200
- QgsQuick .IconTextItem {
201
- id: infoItem
202
- iconSize: fieldItem .iconSize / 2
203
- fontColor: customStyle .fields .fontColor
204
- iconSource: fieldItem .brokenImageIcon
205
- labelText: qsTr (" Image is broken: " ) + image .currentValue
206
-
207
- visible: fieldItem .state === " broken" || fieldItem .state === " notAvailable"
208
- height: fieldItem .iconSize / 2
209
- anchors .bottom : parent .bottom
210
- anchors .horizontalCenter : parent .horizontalCenter
211
-
212
- }
219
+ QgsQuick .IconTextItem {
220
+ id: infoItem
221
+ iconSize: fieldItem .iconSize / 2
222
+ fontColor: customStyle .fields .fontColor
223
+ iconSource: fieldItem .brokenImageIcon
224
+ labelText: qsTr (" Image is not available: " ) + image .currentValue
225
+
226
+ visible: fieldItem .state === " notAvailable"
227
+ height: fieldItem .iconSize / 2
228
+ anchors .bottom : parent .bottom
229
+ anchors .bottomMargin : fieldItem .textMargin
230
+ anchors .horizontalCenter : parent .horizontalCenter
213
231
}
214
232
215
233
}
0 commit comments