EditContactDialog.qml 9.68 KB
Newer Older
Camilo higuita's avatar
Camilo higuita committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
import QtQuick 2.9
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
import QtGraphicalEffects 1.0

import org.kde.mauikit 1.0 as Maui
import org.kde.kirigami 2.2 as Kirigami

import FMList 1.0

Maui.Dialog
{
    id: control

    maxWidth: unit * 500
    maxHeight: parent.height

    property var contact : ({})
    acceptButton.text: qsTr("Save")
    rejectButton.visible: false

22
    signal newContact(var contact)
Camilo higuita's avatar
Camilo higuita committed
23

24 25 26 27 28 29 30 31
    onAccepted:
    {
        var contact =({
                          n: _nameField.text +" "+ _lastNameField.text,
                          tel: _telField.text,
                          email: _emailField.text,
                          org: _orgField.text,
                          adr: _adrField.text,
32
                          gender: _genderField.currentText,
33 34 35
                          photo: _img.source
                      })
        newContact(contact)
Camilo higuita's avatar
Camilo higuita committed
36
        control.close()
37
    }
Camilo higuita's avatar
Camilo higuita committed
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

    ColumnLayout
    {
        id: _layout
        height: parent.height
        width: parent.width * 0.8

        anchors.centerIn: parent

        Item
        {
            id: _contactPic
            Layout.fillWidth: true
            Layout.preferredHeight: iconSizes.huge

            Rectangle
            {
                height: Math.min(parent.height, control.width)
                width: height
                anchors.centerIn: parent
                radius: Math.min(width, height)
                color: Qt.rgba(Math.random(),Math.random(),Math.random(),1);
                border.color: Qt.darker(color, 1.5)

                MouseArea
                {
                    anchors.fill: parent
                    onClicked:{

                        _fileDialog.mode = _fileDialog.modes.OPEN
                        _fileDialog.filterType= FMList.IMAGE
                        _fileDialog.show(function(paths)
                        {
                            console.log("selected image", paths)
72
                            _img.source = "file://"+paths[0]
Camilo higuita's avatar
Camilo higuita committed
73 74 75 76 77 78
                        })
                    }
                }


                Image
79
                {
Camilo higuita's avatar
Camilo higuita committed
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
                    id: _img
                    width: parent.width
                    height: width

                    anchors.centerIn: parent

                    sourceSize.width: parent.width
                    sourceSize.height: parent.height

                    fillMode: Image.PreserveAspectCrop
                    cache: true
                    antialiasing: true
                    smooth: true
                    asynchronous: true

                    layer.enabled: true
                    layer.effect: OpacityMask
                    {
                        maskSource: Item
                        {
                            width: _img.width
                            height: _img.height

                            Rectangle
                            {
                                anchors.centerIn: parent
                                width: _img.width
                                height: _img.height
                                radius: Math.min(width, height)
                                border.color: borderColor
                            }
                        }
                    }
                }

                Maui.ToolButton
                {
                    iconName: "list-add"
                    iconColor: "white"
                    enabled: false
                    size: iconSizes.big
                    anchors.centerIn: parent
                }
            }
        }

        Item
        {
            Layout.fillWidth: true
            Layout.fillHeight: true

            ScrollView
            {
                anchors.fill: parent
                contentHeight: _formLayout.implicitHeight
135 136
                clip: true
                ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
Camilo higuita's avatar
Camilo higuita committed
137 138 139
                ColumnLayout
                {
                    id: _formLayout
140 141
                    width: _layout.width * 0.95
                    //                    implicitHeight: control.height
Camilo higuita's avatar
Camilo higuita committed
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
                    spacing: space.large

                    Column
                    {
                        Layout.fillWidth: true
                        spacing: space.small
                        Label
                        {
                            text: qsTr("Name")
                            font.pointSize: fontSizes.default
                            font.bold: true
                            font.weight: Font.Bold
                        }

                        Maui.TextField
                        {
158
                            id: _nameField
Camilo higuita's avatar
Camilo higuita committed
159
                            width: parent.width
160
                            text: contact.n.split(" ")[0]
Camilo higuita's avatar
Camilo higuita committed
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
                        }
                    }


                    Column
                    {
                        Layout.fillWidth: true
                        spacing: space.small
                        Label
                        {
                            text: qsTr("Last name")
                            font.pointSize: fontSizes.default
                            font.bold: true
                            font.weight: Font.Bold
                        }

                        Maui.TextField
                        {
179
                            id: _lastNameField
Camilo higuita's avatar
Camilo higuita committed
180
                            width: parent.width
181
                            text: contact.n.split(" ")[1] ? contact.n.split(" ")[1] : ""
Camilo higuita's avatar
Camilo higuita committed
182 183 184
                        }
                    }

185 186 187 188 189 190 191 192 193 194 195 196 197 198
                    Column
                    {
                        Layout.fillWidth: true
                        spacing: space.small
                        Label
                        {
                            text: qsTr("Genre")
                            font.pointSize: fontSizes.default
                            font.bold: true
                            font.weight: Font.Bold
                        }

                        ComboBox
                        {
199 200
                            id: _genderField
                            width: parent.width
201
                            model: ["Male", "Female", "Other"]
202 203
                            popup.z: control.z+1
                            //                            currentText: contact.gender
204 205 206
                        }
                    }

Camilo higuita's avatar
Camilo higuita committed
207 208 209 210 211 212 213 214 215 216 217 218 219 220
                    Column
                    {
                        Layout.fillWidth: true
                        spacing: space.small
                        Label
                        {
                            text: qsTr("Organization")
                            font.pointSize: fontSizes.default
                            font.bold: true
                            font.weight: Font.Bold
                        }

                        Maui.TextField
                        {
221
                            id: _orgField
Camilo higuita's avatar
Camilo higuita committed
222
                            width: parent.width
223
                            text: contact.org
Camilo higuita's avatar
Camilo higuita committed
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
                        }
                    }


                    Column
                    {
                        Layout.fillWidth: true
                        spacing: space.small
                        Label
                        {
                            text: qsTr("Mobile phone")
                            font.pointSize: fontSizes.default
                            font.bold: true
                            font.weight: Font.Bold
                        }

                        Maui.TextField
                        {
242
                            id: _telField
Camilo higuita's avatar
Camilo higuita committed
243
                            width: parent.width
244
                            text: contact.tel
Camilo higuita's avatar
Camilo higuita committed
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
                        }
                    }

                    Column
                    {
                        Layout.fillWidth: true
                        spacing: space.small
                        Label
                        {
                            text: qsTr("Phone")
                            font.pointSize: fontSizes.default
                            font.bold: true
                            font.weight: Font.Bold
                        }

                        Maui.TextField
                        {
                            width: parent.width
263
                            text: contact.tel
Camilo higuita's avatar
Camilo higuita committed
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
                        }
                    }

                    Column
                    {
                        Layout.fillWidth: true
                        spacing: space.small
                        Label
                        {
                            text: qsTr("Email")
                            font.pointSize: fontSizes.default
                            font.bold: true
                            font.weight: Font.Bold
                        }

                        Maui.TextField
                        {
281 282
                            id: _emailField
                            width: parent.width
283
                            text: contact.email
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
                        }
                    }

                    Column
                    {
                        Layout.fillWidth: true
                        spacing: space.small
                        Label
                        {
                            text: qsTr("Address")
                            font.pointSize: fontSizes.default
                            font.bold: true
                            font.weight: Font.Bold
                        }

                        Maui.TextField
                        {
                            id: _adrField
Camilo higuita's avatar
Camilo higuita committed
302
                            width: parent.width
303
                            text: contact.adr
Camilo higuita's avatar
Camilo higuita committed
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
                        }
                    }
                }

            }
        }
    }


    function show(data)
    {
        control.contact = data
        control.open()
    }
}