@@ -28,19 +28,38 @@ Item {
28
28
signal valueChanged (var value, bool isNull)
29
29
30
30
property var image: image
31
+ property var cameraIcon: QgsQuick .Utils .getThemeIcon (" ic_camera" )
32
+ property var deleteIcon: QgsQuick .Utils .getThemeIcon (" ic_delete_forever_white" )
33
+ property var galleryIcon: QgsQuick .Utils .getThemeIcon (" ic_gallery" )
31
34
property var brokenImageSource: QgsQuick .Utils .getThemeIcon (" ic_broken_image_black" )
32
35
property var notavailableImageSource: QgsQuick .Utils .getThemeIcon (" ic_photo_notavailable_white" )
33
36
property real iconSize: customStyle .height * 0.75
37
+ property real textMargin: QgsQuick .Utils .dp * 10
34
38
35
39
id: fieldItem
36
40
enabled: true // its interactive widget
37
- height: image . hasValidSource ? customStyle .height * 3 : customStyle . height
41
+ height: customStyle .height * 3
38
42
anchors {
39
43
left: parent .left
40
44
right: parent .right
41
45
rightMargin: 10 * QgsQuick .Utils .dp
42
46
}
43
47
48
+ states: [
49
+ State {
50
+ name: " valid"
51
+ },
52
+ State {
53
+ name: " notSet"
54
+ },
55
+ State {
56
+ name: " broken"
57
+ },
58
+ State {
59
+ name: " notAvailable"
60
+ }
61
+ ]
62
+
44
63
QgsQuick .PhotoCapture {
45
64
id: photoCapturePanel
46
65
visible: false
@@ -50,66 +69,72 @@ Item {
50
69
imageButtonSize: customStyle .height
51
70
}
52
71
53
- Image {
54
- property var currentValue: value
55
- property bool hasValidSource: false
72
+ Rectangle {
73
+ id: imageContainer
74
+ width: parent .width
75
+ height: customStyle .height * 3
76
+ color: customStyle .backgroundColor
77
+ radius: customStyle .cornerRadius
56
78
57
- id: image
58
- height: fieldItem .height
59
- sourceSize .height : image .hasValidSource ? customStyle .height * 3 : fieldItem .iconSize
60
- autoTransform: true
61
- fillMode: Image .PreserveAspectFit
62
- visible: hasValidSource
79
+ Image {
80
+ property var currentValue: value
63
81
64
- MouseArea {
82
+ id: image
83
+ height: imageContainer .height
84
+ sourceSize .height : imageContainer .height
85
+ autoTransform: true
86
+ fillMode: Image .PreserveAspectFit
87
+ visible: fieldItem .state === " valid"
88
+ anchors .verticalCenter : parent .verticalCenter
89
+ anchors .horizontalCenter : parent .horizontalCenter
90
+
91
+ MouseArea {
65
92
anchors .fill : parent
66
93
onClicked: externalResourceHandler .previewImage (homePath + " /" + image .currentValue )
67
- }
94
+ }
68
95
69
- onCurrentValueChanged: {
96
+ onCurrentValueChanged: {
70
97
image .source = image .getSource ()
98
+ }
99
+
100
+ Component .onCompleted : image .source = getSource ()
101
+
102
+ function getSource () {
103
+ if (image .status === Image .Error ) {
104
+ fieldItem .state = " broken"
105
+ return " "
106
+ }
107
+ else if (image .currentValue && QgsQuick .Utils .fileExists (homePath + " /" + image .currentValue )) {
108
+ fieldItem .state = " valid"
109
+ return homePath + " /" + image .currentValue
110
+ }
111
+ else if (! image .currentValue ) {
112
+ fieldItem .state = " notSet"
113
+ return " "
114
+ }
115
+ else {
116
+ fieldItem .state = " notAvailable"
117
+ return homePath + " /" + image .currentValue
118
+ }
119
+ }
71
120
}
72
-
73
- onSourceChanged: {
74
- hasValidSource = (image .source === fieldItem .brokenImageSource ||
75
- image .source === fieldItem .notavailableImageSource ) ? false : true
76
- }
77
-
78
- Component .onCompleted : image .source = getSource ()
79
-
80
- function getSource () {
81
- if (image .status === Image .Error )
82
- return fieldItem .brokenImageSource
83
- else if (image .currentValue && QgsQuick .Utils .fileExists (homePath + " /" + image .currentValue ))
84
- return homePath + " /" + image .currentValue
85
- else
86
- return fieldItem .notavailableImageSource
87
- }
88
- }
89
-
90
- ColorOverlay {
91
- anchors .fill : image
92
- source: image
93
- color: customStyle .fontColor
94
- visible: ! image .hasValidSource
95
121
}
96
122
97
123
Button {
98
124
id: deleteButton
99
- visible: ! readOnly && image . hasValidSource
125
+ visible: ! readOnly && fieldItem . state === " valid "
100
126
width: fieldItem .iconSize
101
127
height: width
102
128
padding: 0
103
129
104
- anchors .right : imageBrowserButton .left
105
- anchors .bottom : parent .bottom
106
- anchors .verticalCenter : parent .verticalCenter
130
+ anchors .right : imageContainer .right
131
+ anchors .bottom : imageContainer .bottom
107
132
108
133
onClicked: externalResourceHandler .removeImage (fieldItem, homePath + " /" + image .currentValue )
109
134
110
135
background: Image {
111
136
id: deleteIcon
112
- source: QgsQuick . Utils . getThemeIcon ( " ic_delete_forever_white " )
137
+ source: fieldItem . deleteIcon
113
138
width: deleteButton .width
114
139
height: deleteButton .height
115
140
sourceSize .width : width
@@ -118,73 +143,71 @@ Item {
118
143
}
119
144
120
145
ColorOverlay {
121
- anchors .fill : deleteIcon
122
- source: deleteIcon
123
- color: customStyle .attentionColor
146
+ anchors .fill : deleteIcon
147
+ source: deleteIcon
148
+ color: customStyle .attentionColor
124
149
}
125
150
}
126
151
127
- Button {
128
- id: imageBrowserButton
129
- visible: ! readOnly
130
- width: fieldItem .iconSize
131
- height: width
132
- padding: 0
133
-
134
- anchors .right : button .left
135
- anchors .bottom : parent .bottom
136
- anchors .verticalCenter : parent .verticalCenter
137
-
138
- onClicked: externalResourceHandler .chooseImage (fieldItem)
139
-
140
- background: Image {
141
- id: browseIcon
142
- source: QgsQuick .Utils .getThemeIcon (" ic_gallery" )
143
- width: imageBrowserButton .width
144
- height: imageBrowserButton .height
145
- sourceSize .width : width
146
- sourceSize .height : height
147
- fillMode: Image .PreserveAspectFit
148
- }
149
-
150
- ColorOverlay {
151
- anchors .fill : browseIcon
152
- source: browseIcon
153
- color: customStyle .fontColor
152
+ Item {
153
+ id: buttonsContainer
154
+ anchors .centerIn : imageContainer
155
+ anchors .fill : imageContainer
156
+ anchors .margins : 10
157
+ visible: fieldItem .state !== " valid"
158
+
159
+ QgsQuick .IconTextItem {
160
+ id: photoButton
161
+ iconSize: fieldItem .iconSize
162
+ fontColor: customStyle .fontColor
163
+ iconSource: fieldItem .cameraIcon
164
+ labelText: qsTr (" Take a Photo" )
165
+
166
+ visible: ! readOnly && fieldItem .state !== " valid"
167
+ height: fieldItem .iconSize
168
+ anchors .horizontalCenter : parent .horizontalCenter
169
+
170
+ MouseArea {
171
+ anchors .fill : parent
172
+ onClicked: {
173
+ photoCapturePanel .visible = true
174
+ photoCapturePanel .targetDir = homePath
175
+ photoCapturePanel .fieldItem = fieldItem
176
+ }
177
+ }
154
178
}
155
- }
156
179
157
- Button {
158
- id: button
159
- visible : ! readOnly
160
- width : fieldItem . iconSize
161
- height : width
162
- padding : 0
180
+ QgsQuick . IconTextItem {
181
+ id: browseButton
182
+ iconSize : fieldItem . iconSize
183
+ fontColor : customStyle . fontColor
184
+ iconSource : fieldItem . galleryIcon
185
+ labelText : qsTr ( " Add From a Gallery " )
163
186
164
- anchors .right : parent .right
165
- anchors .bottom : parent .bottom
166
- anchors .verticalCenter : parent .verticalCenter
187
+ visible: ! readOnly && fieldItem .state !== " valid"
188
+ height: fieldItem .iconSize
189
+ anchors .top : photoButton .bottom
190
+ anchors .horizontalCenter : parent .horizontalCenter
167
191
168
- onClicked : {
169
- photoCapturePanel . visible = true
170
- photoCapturePanel . targetDir = homePath
171
- photoCapturePanel . fieldItem = fieldItem
192
+ MouseArea {
193
+ anchors . fill : parent
194
+ onClicked : externalResourceHandler . chooseImage (fieldItem)
195
+ }
172
196
}
173
197
174
- background: Image {
175
- id: cameraIcon
176
- source: QgsQuick .Utils .getThemeIcon (" ic_camera" )
177
- width: button .width
178
- height: button .height
179
- sourceSize .width : width
180
- sourceSize .height : height
181
- fillMode: Image .PreserveAspectFit
182
- }
198
+ QgsQuick .IconTextItem {
199
+ id: infoItem
200
+ iconSize: fieldItem .iconSize / 2
201
+ fontColor: customStyle .fontColor
202
+ iconSource: fieldItem .brokenImageSource
203
+ labelText: qsTr (" Image is broken: " ) + image .currentValue
204
+
205
+ visible: fieldItem .state === " broken" || fieldItem .state === " notAvailable"
206
+ height: fieldItem .iconSize / 2
207
+ anchors .bottom : parent .bottom
208
+ anchors .horizontalCenter : parent .horizontalCenter
183
209
184
- ColorOverlay {
185
- anchors .fill : cameraIcon
186
- source: cameraIcon
187
- color: customStyle .fontColor
188
210
}
189
211
}
212
+
190
213
}
0 commit comments