== App Developer Week -- Qt Quick: Elements/Animations/States -- jryannel -- Thu, Apr 14th, 2011 == {{{#!irc [17:05] Everyone welcome the first speaker of today. It's Qt's jryannel, who's going to talk about Qt Quick: Elements/Animations/States [17:05] jryannel: hello :) [17:06] Hi all, [17:06] Before we do, plase download: http://get.qt.nokia.com/training/QtQuickforCppDevelopers/slides/qml-composing-uis.pdf [17:06] wait a sec, why hasnt Classbot +m'd the place yet? shouldn't it be doing that? [17:07] Can I continue? [17:08] There are also the examples/labs available at: http://get.qt.nokia.com/training/QtQuickforCppDevelopers/addons/addon-qml-composing-uis.zip [17:09] This is part of our Qt Quick Essentials Training Material. Available to download from: http://qt.nokia.com/developer/learning/online/training/materials/qt-essentials-qt-quick-edition === basso_ is now known as basso [17:10] We skip the first slides (we covered it roughtly yesterday) and go ahead to slide 21 (Anchors) [17:10] We learned yesterday we can position elements by x, y and width/height. [17:11] Often we want to layout elements [17:11] this is done with anchors [17:11] A anchors is another contract [17:12] It says roughly this element shall always be on the left site of the other element [17:12] anchors.left: other.left [17:12] So also when you move one element the other will always follow [17:13] You have top/bottom/left/right anchors [17:13] and also horizontalCenter/verticalCenter [17:13] Slide 22:Anchors [17:13] This is an example how to use anchors [17:14] remember you can reference other elements by id [17:14] anchors.centerIn: rectangle1 [17:14] centerIn centers rectangle1 in this element (width and height is not changed) [17:15] We jump to slide 25: Margins === ChanServ changed the topic of #ubuntu-classroom to: Welcome to the Ubuntu Classroom - https://wiki.ubuntu.com/Classroom || Support in #ubuntu || Upcoming Schedule: http://is.gd/8rtIi || Questions in #ubuntu-classroom-chat || Event: Ubuntu App Developer Week - Current Session: Qt Quick: Elements/Animations/States - Instructors: jryannel [17:16] An anchors fixes on eelement to another element. [17:16] Logs for this session will be available at http://irclogs.ubuntu.com/2011/04/14/%23ubuntu-classroom.html following the conclusion of the session. [17:17] For reference: We use the slides at: http://qt.nokia.com/developer/learning/online/training/materials/qt-essentials-qt-quick-edition [17:17] Called; Composing User Interfaces [17:17] We are on slide 25 [17:17] A margin provides some space between the anchoring [17:17] Slide: 26 [17:18] Here we see a rectangle containing 2 elements (image + text) [17:18] image and text shall be vertical centered and have some spacing between [17:19] The image is anchored on the left side of the parent's left side [17:19] and has on the left side 1/16th of space of the width of the parent [17:19] and sure the image is vertical centered [17:20] similar applies to the text. But instead of anchored to the parent it's anchored to the image [17:20] The anchors.baseline is important for text to anchors according to the textbaseline [17:21] Anchors are also described in more detail at: http://doc.qt.nokia.com/4.7-snapshot/qml-anchor-layout.html#anchor-layout [17:21] So besides of positioning elements by x,y we can also anchors them with margins. [17:22] Often you want to anchor element in a row or column or a grid. For this we have spezialised elements [17:23] They are called Column, Row, Grid [17:23] They are helper elements to avoid writing common code [17:24] See http://doc.qt.nokia.com/4.7-snapshot/qml-positioners.html for more information [17:25] anchors can be used to produce very powerful ui and also felxible from the screen dimensions [17:26] Okay. Let's go to the next module. We jump over module user interaction and go direct to states [17:26] Please download: http://get.qt.nokia.com/training/QtQuickforCppDevelopers/slides/qml-states-transitions.pdf [17:27] A state describes your ui in different "phases" [17:27] E.g. in simple terms it defines how properties values shall be in these different phases [17:28] If you problem downloading: http://qt.nokia.com/developer/learning/online/training/materials/qt-essentials-qt-quick-edition [17:28] Then choose: States and Transitions [17:29] So think about a stop and a go light. Both are represented by a rectangle [17:29] See 6 [17:29] Slide Nr. 6 [17:30] in a "go" state we want one rectangle green in the "stop" state we want the other rectangle red. [17:30] Slide: 7 [17:31] We describe the states with the states property. [17:31] Which is an array of State elements [17:31] a property array is marked with [ ] [17:32] state go has the name "go" and state "stop" is names stop. [17:32] Both describe changes to properties to elements declared earlier [17:32] "stop" state changes the color of stop_light to red [17:32] and go_light's color to "black" [17:33] How to switch between the states? [17:33] use the state property and assign the state name [17:33] Slide: 8 [17:33] Setting the State [17:34] each element has a state property and a states property [17:34] states is the array of states and state contains the name of the current state. [17:35] onClicked: parent.state == "stop" ? parent.state = "go" : parent.state = "stop" [17:35] onClicked is a clicked handler from the mousearea. [17:35] A mousearea is an area which received mouse clicks, presses, releases... [17:36] we first ask for the current state and if it's "stop" we change it to "go". [17:36] Qt Quick recognizes the change and updates the ui based on the state [17:37] very simple [17:37] We jump to slide: 12 [17:37] Another example, little bit more complicated. [17:38] Qe have a text in a rectangle [17:38] Additional we have a image (clear_button) which is clickable through the mousearea. [17:38] When the image is clicked the text of the text_field is set to "" [17:39] Slide: 13 [17:39] we define 2 states "with text" and "without text" [17:40] "with text" shall be active when the text_field is NOT empty [17:40] the "without text" shall be active when text_field is empty [17:42] Based on the property change notification which allows the property binding "when" is evaluated everytime the text changes [17:42] Side note: A text element will only accept input when it's focused. [17:43] This can be done by clicking in the TextInput or requesting focus with "focus : true" [17:43] When going from one state to another we have a state transition [17:44] State A -> (Transition) -> State B [17:44] Slide: 16 (Transition) [17:45] The red button changes it's color to black via a transition. [17:45] This transition in this case shall be a color animation. [17:45] (Same applies to the black/green button our go button) [17:46] Slide: 17 [17:46] Remember we have the states "go" and "stop" in an earlier example [17:47] We add transitions with the transitions [ ] array property [17:47] Each Transition element describes a transition from one state to another state [17:47] from, to describe when transition is called [17:48] Inside we use an animation (more about animations later) [17:48] so States -> Transitions -> Animations [17:48] We will see animations can also be used standalone and in other situations. [17:49] Let's leave this module and go to: QML Animations [17:49] Please download: http://get.qt.nokia.com/training/QtQuickforCppDevelopers/slides/qml-animations.pdf [17:49] I hope you all have flatrates :_) [17:50] An animation generally describes a property change according to a easing curve and duration. [17:51] So instead for example an elements position shall be changes from x:0 to x:100 it shall not go immediately [17:51] It should go in a defined way from 0 to 100 in maybe 1second and first a little bit faster and then slower. [17:52] There are 10 minutes remaining in the current session. [17:52] Slide: 6 in the qml-animations.pdf titled "Number Animations" [17:53] We have in general NumberAnimation, ColorAnimations, RotationAnimations and PropertyAnimations [17:54] We use here: NumberAnimation on x { .... } [17:54] Means it will animate x from 0 to 150 in 1 sec (1000msecs) [17:55] This will done automatically when the component (qml file) is loaded [17:55] Slide 8: PropertAnimations [17:56] Here we use an animation as a standalone animation. We need to specify the target and which properties we want to animate. with running: true you specify it shall run when the component is loaded. [17:57] There are 5 minutes remaining in the current session. [17:57] If you would give the animation an id (e.g. id: anim ) you could also start it with anim.start() [17:57] You can find more about Animations and Transitions at: http://doc.qt.nokia.com/4.7-snapshot/qdeclarativeanimation.html [17:58] I think this it it for now. I will make a 10min break and be back with the next session [17:59] Thanks for listening :) }}}