DelegateBase: added loader for buttons, fixed height calculation
[situare] / src / qmlui / DelegateBase.qml
1 import Qt 4.7
2
3 Item {
4     id: delegate
5     property alias image: image.source
6     property alias primaryText: primaryText.text
7     property alias details: details.sourceComponent
8     property alias buttons: buttons.sourceComponent
9
10     width: delegate.ListView.view.width
11     height: buttons.y + buttons.height + 5
12     clip: true
13
14     Rectangle {
15         id: background
16         anchors {
17             left: parent.left
18             right: parent.right
19             top: parent.top
20             bottom: parent.bottom
21             topMargin: 5
22 //            bottomMargin: -5
23         }
24
25         gradient: Gradient {
26             GradientStop {
27                 position: 0
28                 color: "#777777"
29             }
30
31             GradientStop {
32                 position: 1
33                 color: "#222222"
34             }
35         }
36         border { width: 1; color: "#777777" }
37         radius: 5
38     }
39
40     Image {
41         id: image
42         x: 10
43         y: 4
44     }
45
46     BorderImage {
47         id: borderImage
48         anchors.fill: image
49         anchors.margins: -8
50         source: "qrc:/res/images/profile_pic_border.png"
51         border.left: 24; border.top: 24
52         border.right: 24; border.bottom: 24
53         horizontalTileMode: BorderImage.Stretch
54         verticalTileMode: BorderImage.Stretch
55     }
56
57     Text {
58         id: primaryText
59         anchors { left: image.right; right: background.right; top: background.top; margins: 5; leftMargin: 10 }
60         clip: true;
61         elide: Text.ElideRight
62     }
63
64     Loader {
65         id: details
66         state: parent.state
67         anchors { left: primaryText.left; right: primaryText.right; top: primaryText.bottom }
68     }
69
70     Loader {
71         id: buttons
72         height: 0
73         anchors { horizontalCenter: parent.horizontalCenter; top: details.bottom }
74
75     }
76
77     MouseArea {
78         anchors.fill: parent
79         onClicked: {
80             if (delegate.state == 'expanded') {
81                 delegate.state = ''
82                 ListView.view.currentIndex =  -1
83             } else {
84                 delegate.state = 'expanded'
85                 ListView.view.currentIndex = index
86             }
87         }
88     }
89
90     states: [
91         State {
92             name: "expanded"
93             when: delegate.ListView.isCurrentItem
94             PropertyChanges {
95                 target: buttons
96                 height: buttons.item.childrenRect.height
97                 explicit: true
98             }
99         },
100         State {
101             name: ""
102             when: !delegate.ListView.isCurrentItem
103             PropertyChanges {
104                 target: buttons.item
105                 visible: false
106             }
107         }
108     ]
109
110     transitions: [
111         Transition {
112             from: ""
113             to: "expanded"
114 //            NumberAnimation { properties: "height"; duration: 100 }
115             PropertyAction { target: primaryText; property: "wrapMode"; value: Text.Wrap }
116             PropertyAction { target: primaryText; property: "elide"; value: Text.ElideNone }
117             PropertyAction { target: buttons.item; property: "visible"; value: true }
118             reversible: true
119         }
120     ]
121 }