~chris.gagnon/+junk/qtpim-coverage

« back to all changes in this revision

Viewing changes to examples/contacts/qmlcontactslistview/qmlcontactslistview.qml

  • Committer: chris.gagnon
  • Date: 2013-12-10 23:09:37 UTC
  • Revision ID: chris.gagnon@canonical.com-20131210230937-2akf1ft1edcttk87
first post

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the documentation of the Qt Pim Module.
 
7
**
 
8
** $QT_BEGIN_LICENSE:FDL$
 
9
** Commercial License Usage
 
10
** Licensees holding valid commercial Qt licenses may use this file in
 
11
** accordance with the commercial license agreement provided with the
 
12
** Software or, alternatively, in accordance with the terms contained in
 
13
** a written agreement between you and Digia.  For licensing terms and
 
14
** conditions see http://qt.digia.com/licensing.  For further information
 
15
** use the contact form at http://qt.digia.com/contact-us.
 
16
**
 
17
** GNU Free Documentation License Usage
 
18
** Alternatively, this file may be used under the terms of the GNU Free
 
19
** Documentation License version 1.3 as published by the Free Software
 
20
** Foundation and appearing in the file included in the packaging of
 
21
** this file.  Please review the following information to ensure
 
22
** the GNU Free Documentation License version 1.3 requirements
 
23
** will be met: http://www.gnu.org/copyleft/fdl.html.
 
24
** $QT_END_LICENSE$
 
25
**
 
26
****************************************************************************/
 
27
import QtQuick 2.0
 
28
import QtContacts 5.0
 
29
 
 
30
Rectangle {
 
31
    id: contactsApplication
 
32
    width: 400
 
33
    height: 600
 
34
    state: "listView"
 
35
 
 
36
    Rectangle {
 
37
        id: browsingArea
 
38
        anchors {
 
39
            top: parent.top
 
40
            left: parent.left
 
41
            right: parent.right
 
42
        }
 
43
        height: contactsApplication.height - btnArea.height - statusBar.height
 
44
        color: "lightblue"
 
45
 
 
46
        ContactModel {
 
47
            id: contactsModel
 
48
            manager: "memory"
 
49
            Component.onCompleted: {
 
50
                    contactsModel.importContacts(Qt.resolvedUrl("example.vcf"))
 
51
            }
 
52
            sortOrders: [
 
53
                SortOrder {
 
54
                    detail: ContactDetail.Name
 
55
                    field: Name.FirstName
 
56
                    direction: Qt.AscendingOrder
 
57
                }
 
58
            ]
 
59
        }
 
60
 
 
61
        // ![Contact delegate]
 
62
        Component {
 
63
            id: contactDelegate
 
64
 
 
65
            Rectangle {
 
66
                id: delRect
 
67
                width: parent.width
 
68
                height: 60
 
69
                border.width: 1
 
70
                border.color: "darkgreen"
 
71
                color: delRect.ListView.isCurrentItem ? "#F5678A" : browsingArea.color
 
72
 
 
73
                Column {
 
74
                    anchors {
 
75
                        verticalCenter: parent.verticalCenter
 
76
                        left: parent.left
 
77
                        leftMargin: 6
 
78
                    }
 
79
                    Text {
 
80
                        text: contact.name.firstName
 
81
                        font.bold: true
 
82
                    }
 
83
                    Text { text: contact.phoneNumber.number }
 
84
                }
 
85
 
 
86
                Keys.onReturnPressed: {
 
87
                    contactEditor.contact = contact
 
88
                    goToEditView()
 
89
                }
 
90
 
 
91
                MouseArea {
 
92
                    anchors.fill: parent
 
93
                    onClicked: {
 
94
                        contactsView.currentIndex = index
 
95
                    }
 
96
                }
 
97
            }
 
98
        }
 
99
        // ![Contact delegate]
 
100
 
 
101
        // ![ListView for showing the contacts]
 
102
        ListView {
 
103
            id: contactsView
 
104
            anchors.fill: browsingArea
 
105
            width: browsingArea.width
 
106
            height: browsingArea.height
 
107
            model: contactsModel
 
108
            focus: true
 
109
            clip: true
 
110
            delegate: contactDelegate
 
111
        }
 
112
        // ![ListView for showing the contacts]
 
113
    }
 
114
 
 
115
    // ![Button area]
 
116
    Rectangle {
 
117
        id: btnArea
 
118
        width: parent.width
 
119
        height: 20
 
120
        color: "#C7BFBF"
 
121
        anchors {
 
122
            bottom: statusBar.top
 
123
            right: parent.right
 
124
            left: parent.left
 
125
        }
 
126
        Row {
 
127
            id: btnRow
 
128
            anchors.centerIn: parent
 
129
            spacing: 10
 
130
 
 
131
            // buttons for 'listView' state
 
132
            GenericButton {
 
133
                id: btnNew
 
134
                width: 160
 
135
                buttonText: "Add New Contact"
 
136
                visible: true
 
137
                onClicked: {
 
138
                    contactEditor.contact = 0
 
139
                    goToEditView()
 
140
                }
 
141
            }
 
142
            GenericButton {
 
143
                id: btnEdit
 
144
                width: 160
 
145
                buttonText: "Edit Contact"
 
146
                visible: true
 
147
                onClicked: {
 
148
                    contactEditor.contact = contactsView.model.contacts[contactsView.currentIndex]
 
149
                    goToEditView()
 
150
                }
 
151
            }
 
152
            // buttons for 'editView' state
 
153
            GenericButton {
 
154
                id: btnCancel
 
155
                width: 120
 
156
                buttonText: "Cancel"
 
157
                visible: false
 
158
                onClicked: {
 
159
                    contactEditor.cancel()
 
160
                    goToListView()
 
161
                }
 
162
            }
 
163
 
 
164
            GenericButton {
 
165
                id: btnDelete
 
166
                width: 120
 
167
                buttonText: "Delete"
 
168
                visible: false
 
169
                onClicked: {
 
170
                    contactEditor.deleteContact()
 
171
                    goToListView()
 
172
                }
 
173
            }
 
174
 
 
175
            GenericButton {
 
176
                id: btnSave
 
177
                width: 120
 
178
                buttonText: "Save"
 
179
                visible: false
 
180
                onClicked: {
 
181
                    contactEditor.updateContact()
 
182
                    goToListView()
 
183
                }
 
184
            }
 
185
        }
 
186
    }
 
187
    // ![Button area]
 
188
 
 
189
    // ![Status bar area]
 
190
    Rectangle {
 
191
        id: statusBar
 
192
        anchors {
 
193
            bottom: parent.bottom
 
194
            right: parent.right
 
195
            left: parent.left
 
196
        }
 
197
        width: parent.width
 
198
        height: 24
 
199
        color: "gainsboro"
 
200
 
 
201
        Text {
 
202
            id: barText
 
203
            anchors.centerIn: parent
 
204
            text: " "
 
205
        }
 
206
 
 
207
        Timer {
 
208
            id: barTimer
 
209
            interval: 2000
 
210
            running: false
 
211
            onTriggered: {
 
212
                barText.text = " "
 
213
            }
 
214
        }
 
215
 
 
216
        function updateMsg(msg) {
 
217
            barText.text = msg
 
218
            barTimer.restart()
 
219
        }
 
220
    }
 
221
    // ![Status bar area]
 
222
 
 
223
    // ![Custom contact editor]
 
224
    ContactEditor {
 
225
        id: contactEditor
 
226
        height: parent.height - statusBar.height - btnArea.height
 
227
        z: -1
 
228
    }
 
229
    // ![Custom contact editor]
 
230
 
 
231
    // ![Applications state changes]
 
232
    states: [
 
233
        State {
 
234
            name: "listView"
 
235
            PropertyChanges {
 
236
                target: contactEditor
 
237
                z: -1
 
238
            }
 
239
            PropertyChanges {
 
240
                target: contactsView
 
241
                focus: true
 
242
            }
 
243
        },
 
244
        State {
 
245
            name: "editView"
 
246
            PropertyChanges {
 
247
                target: contactEditor
 
248
                z: 1
 
249
            }
 
250
            PropertyChanges { target: btnNew; visible: false }
 
251
            PropertyChanges { target: btnEdit; visible: false }
 
252
            PropertyChanges { target: btnCancel; visible: true }
 
253
            PropertyChanges { target: btnDelete; visible: true }
 
254
            PropertyChanges { target: btnSave; visible: true }
 
255
            StateChangeScript { script: contactEditor.resetToDefaults() }
 
256
        }
 
257
    ]
 
258
    // ![Applications state changes]
 
259
 
 
260
    function goToListView() {
 
261
        contactEditor.contact = ""
 
262
        contactsApplication.state = "listView"
 
263
    }
 
264
 
 
265
    function goToEditView() {
 
266
        contactsApplication.state = "editView"
 
267
    }
 
268
}