DelegateBase: Fixed collapsing/expangind primaryText work like DetailRow texts do.
authorSami Rämö <sami.ramo@ixonos.com>
Wed, 17 Nov 2010 10:53:48 +0000 (12:53 +0200)
committerSami Rämö <sami.ramo@ixonos.com>
Wed, 17 Nov 2010 10:53:48 +0000 (12:53 +0200)
src/qmlui/DelegateBase.qml

index 3ae3f7f..e8f0859 100644 (file)
@@ -7,6 +7,8 @@ Item {
     property alias details: details.sourceComponent
     property alias buttons: buttons.sourceComponent
 
+    property int textSingleLineHeight: 0
+
     width: delegate.ListView.view.width
     height: buttons.y + buttons.height + 5
     clip: true
@@ -61,6 +63,10 @@ Item {
         anchors { left: image.right; right: background.right; top: background.top; margins: 5; leftMargin: 10 }
         clip: true;
         elide: Text.ElideRight
+        Behavior on height {
+            id: textHeightBehavior
+            NumberAnimation { duration: 150 }
+        }
     }
 
     Loader {
@@ -92,6 +98,10 @@ Item {
         }
     }
 
+    Component.onCompleted: {
+        textSingleLineHeight = primaryText.height
+    }
+
     states: [
         State {
             name: "expanded"
@@ -101,10 +111,19 @@ Item {
                 height: buttons.status == Loader.Ready ? buttons.item.childrenRect.height : 0
                 explicit: true
             }
+            PropertyChanges {
+                target: primaryText
+                height: paintedHeight
+            }
         },
         State {
             name: ""
             when: !delegate.ListView.isCurrentItem
+            PropertyChanges {
+                target: primaryText
+                explicit: true
+                height: textSingleLineHeight
+            }
         }
     ]
 
@@ -118,10 +137,21 @@ Item {
         Transition {
             from: ""
             to: "expanded"
-            NumberAnimation { properties: "height"; duration: 150 }
-            PropertyAction { target: primaryText; property: "wrapMode"; value: Text.Wrap }
-            PropertyAction { target: primaryText; property: "elide"; value: Text.ElideNone }
-            reversible: true
+            SequentialAnimation {
+                PropertyAction { target: textHeightBehavior; property: "enabled"; value: true }
+                PropertyAction { target: primaryText; property: "wrapMode"; value: Text.Wrap }
+                PropertyAction { target: primaryText; property: "elide"; value: Text.ElideNone }
+            }
+        },
+        Transition {
+            from: "expanded"
+            to: ""
+            SequentialAnimation {
+                PropertyAction { target: textHeightBehavior; property: "enabled"; value: false }
+                NumberAnimation { target: primaryText; properties: "height"; duration: 150 }
+                PropertyAction { target: primaryText; property: "wrapMode"; value: Text.NoWrap }
+                PropertyAction { target: primaryText; property: "elide"; value: Text.ElideRight }
+            }
         }
     ]
 }