[email protected] ha scritto:
Hi,

On 20/04/2010, at 8:06 PM, ext Gianni Valdambrini wrote:
I wrote a custom element that looks like a text element with a slide
effect on the text change.
The problem is in the transition. The element works in this way:
there are 2 text elements, one placed on the left and the other on the
right of the element. The latter has the same left and right anchor in
order to hide the element.
When the text changes the transition expands the text on the right
changing its left anchor and shrinks the left one.
Everything seems to work fine if I disable the transition, with the text
on the right not visibile. Using the old version of Qml from Qt Creator Qml 1.3.8 everything works fine even with transition enable (replacing "properties" with "matchProperties" and the easing syntax), so I cannot figure out what is wrong with this code.
Any help is appreciated.

In the past couple weeks there have been quite a few changes to AnchorChanges, 
and an AnchorAnimation element has been introduced. After updating your example 
to the latest syntax, I wasn't able to see any obvious issues. Are you able to 
update your build and see if it is working right for you?

Regards,
Michael

Unfortunately, It doesn't (with Qt from the branch 4.7-stable).
I made a few changes to the element to update it to the last sintax, but the result is the same than the previous version. Running the code, I noticed these things:
- In the initial status, the element text2 is visible but it shouldn't.
- there are 2 transitions, from the initial state to the state1 and from the state2 to the state3. In theory, these transitions should be the same, but this is not what happens.

Other notes:
- In the AnchorAnimation I can't specify the duration, so at the moment it isn't exactly what I need. - In the transition, I can't change the state using PropertyAction, unless it is used with an animation (as in the code), otherwise I get the error "Can't apply a state change as part of a state definition.".

Thank you,
Gianni
import Qt 4.7

Rectangle {
        id: slidetext
        property string text: ""
        property int duration: 2000
        property string easing: "Linear"
        property string horizontalAlignment: "AlignLeft"
        property string verticalAlignment: "AlignTop"

        Text {
                id: text1
                anchors.left: parent.left
                anchors.right: parent.right
                anchors.top: parent.top
                anchors.bottom: parent.bottom
                horizontalAlignment: parent.horizontalAlignment
                verticalAlignment: parent.verticalAlignment
        }

        Text {
                id: text2
                anchors.left: parent.right
                anchors.right: parent.right
                anchors.top: parent.top
                anchors.bottom: parent.bottom
                horizontalAlignment: parent.horizontalAlignment
                verticalAlignment: parent.verticalAlignment
        }

        Item {
                id: privateProps
                property bool isSliding: false
        }

        onTextChanged: {
                if (!privateProps.isSliding) {
                        if (slidetext.state == "") {
                                slidetext.state = "State1"
                                text2.text = text
                        }
                        else {
                                slidetext.state = "State3"
                                text1.text = text
                        }
                }
                else {
                        if (slidetext.state == "" || slidetext.state == 
"State2")
                                text1.text = text
                        else
                                text2.text = text
                }
        }

        onStateChanged: {
//              console.log("State changed: " + state)
        }

        states: [
                State {
                        AnchorChanges { target: text1; anchors.right: 
slidetext.left; }
                        AnchorChanges { target: text2; anchors.left: 
slidetext.left; }
                        PropertyChanges { target: privateProps; isSliding: true 
}
                        name: "State1"
                },
                State {
                        AnchorChanges { target: text1; anchors.left: 
slidetext.right; anchors.right: slidetext.right; }
                        AnchorChanges { target: text2; anchors.left: 
slidetext.left; anchors.right: slidetext.right; }
                        PropertyChanges { target: privateProps; isSliding: 
false }
                        name: "State2"
                },
                State {
                        AnchorChanges { target: text1; anchors.left: 
slidetext.left; }
                        AnchorChanges { target: text2; anchors.right: 
slidetext.left; }
                        PropertyChanges { target: privateProps; isSliding: true 
}
                        name: "State3"
                }
        ]
        transitions: [
                Transition {
                        from: ""; to: "State1"
                        SequentialAnimation {
                                AnchorAnimation { targets: text1, text2; }
                                PropertyAction { target: slidetext; property: 
"state"; value: "State2"; }
                        }
                },
                Transition {
                        from: "State2"; to: "State3"
                        SequentialAnimation {
                                AnchorAnimation { targets: text1, text2; }
                                PropertyAction { target: slidetext; property: 
"state"; value: ""; }
                        }
                }
        ]
}

_______________________________________________
Qt-qml mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt-qml

Reply via email to