Added animation for expanding/collapsing list items
[situare] / src / qmlui / DetailRow.qml
1 import Qt 4.7
2
3 Item {
4     property alias image: image.source
5     property alias text: text.text
6
7     property int textSingleLineHeight: 0
8
9     anchors.left: parent.left
10     anchors.right: parent.right
11     width: childrenRect.width
12     height: text.height > image.height ? text.height : image.height
13
14     state: parent.state
15
16     Image {
17         id: image
18         anchors { left: parent.left; top: parent.top }
19     }
20
21     Text {
22         id: text
23         anchors { leftMargin: 5; left: image.right; right: parent.right; top: parent.top }
24         font.pixelSize: image.height * 0.7
25         clip: true;
26         elide: Text.ElideRight
27         state: parent.state
28         Behavior on height {
29             id: textHeightBehavior
30             NumberAnimation { duration: 150 }
31         }
32     }
33
34     Component.onCompleted: {
35         textSingleLineHeight = text.height
36     }
37
38     states: [
39         State {
40             name: "expanded"
41                 PropertyChanges {
42                     target: text
43                     height: paintedHeight
44                 }
45         },
46         State {
47             name: ""
48             PropertyChanges {
49                 target: text
50                 explicit: true
51                 height: textSingleLineHeight
52             }
53         }
54     ]
55
56     transitions: [
57         Transition {
58             from: ""
59             to: "expanded"
60             SequentialAnimation {
61                 PropertyAction { target: textHeightBehavior; property: "enabled"; value: true }
62                 PropertyAction { target: text; property: "wrapMode"; value: Text.Wrap }
63                 PropertyAction { target: text; property: "elide"; value: Text.ElideNone }
64             }
65         },
66         Transition {
67             from: "expanded"
68             to: ""
69             SequentialAnimation {
70                 PropertyAction { target: textHeightBehavior; property: "enabled"; value: false }
71                 NumberAnimation { target: text; properties: "height"; duration: 150 }
72                 PropertyAction { target: text; property: "wrapMode"; value: Text.NoWrap }
73                 PropertyAction { target: text; property: "elide"; value: Text.ElideRight }
74             }
75         }
76     ]
77 }