1import QtQuick 2.0
2import AsemanTools 1.0
3import TelegramQmlLib 1.0
4// import CutegramTypes 1.0
5
6Item {
7    id: ac_list
8    width: 100
9    height: 62
10
11    property alias telegram: cmodel.telegram
12    property alias selecteds: list.list
13
14    property bool messageDraging: false
15
16    signal selected(variant cid)
17
18    ContactsModel {
19        id: cmodel
20        onInitializingChanged: {
21            if( initializing )
22                indicator.start()
23            else
24                indicator.stop()
25        }
26    }
27
28    ListObject {
29        id: list
30    }
31
32    DropArea {
33        anchors.fill: parent
34    }
35
36    AsemanListView {
37        id: clist
38        anchors.fill: parent
39        clip: true
40        model: cmodel
41        spacing: 4*Devices.density
42        delegate: Item {
43            id: clist_item
44            width: clist.width
45            height: 50*Devices.density
46
47            property Contact citem: item
48            property User user: telegram.user(citem.userId)
49
50            property bool itemSelected: list.contains(citem.userId)
51
52            DragObject {
53                id: drag
54                mimeData: mime
55                source: marea
56                image: "files/message.png"
57                hotSpot: Qt.point(22,22)
58                dropAction: Qt.CopyAction
59            }
60
61            MimeData {
62                id: mime
63                dataMap: {"land.aseman.cutegram/contactId": citem.userId}
64                text: txt.text
65            }
66
67            Rectangle {
68                anchors.fill: parent
69                color: itemSelected || marea.pressed? Cutegram.currentTheme.masterColor : "#00000000"
70                opacity: 0.5
71            }
72
73            ContactImage {
74                id: profile_img
75                anchors.top: parent.top
76                anchors.bottom: parent.bottom
77                anchors.left: parent.left
78                anchors.margins: 4*Devices.density
79                width: height
80                user: clist_item.user
81                isChat: false
82                telegram: ac_list.telegram
83            }
84
85            Text {
86                id: txt
87                anchors.verticalCenter: parent.verticalCenter
88                anchors.left: profile_img.right
89                anchors.right: parent.right
90                anchors.margins: 4*Devices.density
91                horizontalAlignment: Text.AlignLeft
92                wrapMode: Text.WrapAtWordBoundaryOrAnywhere
93                elide: Text.ElideRight
94                maximumLineCount: 1
95                font.family: AsemanApp.globalFont.family
96                font.pixelSize: Math.floor(10*Devices.fontDensity)
97                text: user.firstName + " " + user.lastName
98                color: "#333333"
99            }
100
101            MouseArea {
102                id: marea
103                anchors.fill: parent
104                onClicked: {
105                    var uid = citem.userId
106                    if( list.contains(uid) )
107                        list.removeOne(uid)
108                    else
109                        list.append(uid)
110
111                    itemSelected = !itemSelected
112                    ac_list.selected(uid)
113                }
114                onPressed: {
115                    startPoint = Qt.point(mouseX, mouseY)
116                }
117                onPositionChanged: {
118                    var destX = mouseX-startPoint.x
119                    if(destX < 7)
120                        return
121                    if(messageDraging)
122                        return
123
124                    messageDraging = true
125                    drag.start()
126                    messageDraging = false
127                }
128
129                property point startPoint
130            }
131        }
132    }
133
134    NormalWheelScroll {
135        flick: clist
136        animated: Cutegram.smoothScroll
137    }
138
139    PhysicalScrollBar {
140        scrollArea: clist; height: clist.height; width: 6*Devices.density
141        anchors.right: clist.right; anchors.top: clist.top; color: textColor0
142    }
143
144    Indicator {
145        id: indicator
146        anchors.centerIn: parent
147        light: false
148        modern: true
149        indicatorSize: 20*Devices.density
150    }
151}
152