~zeller-benjamin/address-book-app/sdkcompat

« back to all changes in this revision

Viewing changes to src/imports/Ubuntu/Contacts/MostCalledList.qml

  • Committer: CI bot
  • Author(s): Renato Araujo Oliveira Filho
  • Date: 2014-08-28 21:27:04 UTC
  • mfrom: (277.2.10 release-2014-08-26)
  • Revision ID: ps-jenkins@lists.canonical.com-20140828212704-i5f91dqbuqrtqoiy
[Contacts] Split ContactListView in two components (ContactListView and ContactListModel).
[Contacts] Fixed most called list margin.
[ContactEditor] Changed from add field dialog to use ComboButtonAddField (requested by designers).
[I18n] Fixed desktop i18n rules. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2012-2014 Canonical, Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; version 3.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 */
 
16
 
 
17
import QtQuick 2.2
 
18
 
 
19
Column {
 
20
    id: root
 
21
 
 
22
    property alias parentView: scrollAnimation.target
 
23
    readonly property alias count: callerRepeat.count
 
24
 
 
25
    /* internal */
 
26
    property int _nextCurrentIndex: -1
 
27
 
 
28
 
 
29
    function makeItemVisible(item)
 
30
    {
 
31
        if (!item) {
 
32
            return
 
33
        }
 
34
 
 
35
        var itemY = parent.y + root.y + item.y
 
36
        var areaY = parentView.contentY
 
37
        if (itemY < areaY) {
 
38
            // move foward
 
39
            scrollAnimation.to = itemY
 
40
        } else if ((areaY + parentView.height) < (itemY + item.height)) {
 
41
            // move backward
 
42
            scrollAnimation.to = itemY + item.height
 
43
        } else {
 
44
            return
 
45
        }
 
46
        scrollAnimation.restart()
 
47
    }
 
48
 
 
49
    SmoothedAnimation {
 
50
        id: scrollAnimation
 
51
 
 
52
        property: "contentY"
 
53
        velocity: parentView.highlightMoveVelocity
 
54
        duration: parentView.highlightMoveDuration
 
55
    }
 
56
 
 
57
    SectionDelegate {
 
58
        anchors {
 
59
            left: parent.left
 
60
            right: parent.right
 
61
            margins: units.gu(2)
 
62
        }
 
63
        text: i18n.dtr("address-book-app", "Frequently called")
 
64
        visible: (root.count > 0)
 
65
    }
 
66
 
 
67
    Repeater {
 
68
        id: callerRepeat
 
69
 
 
70
        model: MostCalledModel {
 
71
            id: calledModel
 
72
 
 
73
            onInfoRequested: parentView.infoRequested(contact)
 
74
            onDetailClicked: parentView.detailClicked(contact, detail, action)
 
75
            onAddDetailClicked: parentView.addDetailClicked(contact, detailType)
 
76
            onAddContactClicked: parentView.addContactClicked(label)
 
77
            onCurrentIndexChanged: {
 
78
                if (currentIndex !== -1) {
 
79
                    parentView.currentIndex = -1
 
80
                    root._nextCurrentIndex = currentIndex
 
81
                }
 
82
            }
 
83
 
 
84
            // WORKAROUND: The SDK header causes the contactY to move to a wrong postion
 
85
            // calling the positionViewAtBeginning after the list created fix that
 
86
            onLoaded: moveToBegining.restart()
 
87
        }
 
88
    }
 
89
 
 
90
    Connections {
 
91
        target: parentView
 
92
        onCurrentIndexChanged: {
 
93
            if (parentView.currentIndex !== -1) {
 
94
                calledModel.currentIndex = -1
 
95
            }
 
96
        }
 
97
    }
 
98
 
 
99
    onHeightChanged: {
 
100
        if (root._nextCurrentIndex != -1) {
 
101
            heightChangedTimeout.restart()
 
102
        }
 
103
    }
 
104
 
 
105
    Timer {
 
106
        id: heightChangedTimeout
 
107
        interval: 100
 
108
        onTriggered: {
 
109
            makeItemVisible(callerRepeat.itemAt(root._nextCurrentIndex))
 
110
            root._nextCurrentIndex = -1
 
111
        }
 
112
    }
 
113
 
 
114
    onVisibleChanged: {
 
115
        // update the model every time that it became visible
 
116
        // in fact calling update only reloads the model data if it has changed
 
117
        if (visible) {
 
118
            calledModel.model.update()
 
119
        }
 
120
    }
 
121
}