1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
|
/****************************************************************************
**
** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Design Studio documentation.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
**
****************************************************************************/
/*!
\example loginui4
\ingroup studioexamples
\ingroup gstutorials
\title Log In UI - Part 4
\brief Illustrates how to use the timeline and states to animate UI
components.
\previouspage {Log In UI - Part 3}
\image loginui4.gif "Log In UI"
\e{Log In UI - Part 4} is the fourth in a series of examples that build
on each other to illustrate how to use \QDS to create a simple UI with
some basic UI components, such as pages, buttons, and entry fields. Part 4
describes how to use the timeline and states to animate UI components.
In Part 3, you learned how to use states to simulate page changes in a UI
and connections to provide user interaction with it. In Part 4, you will now
learn another way of animating the UI by using timeline animations that you
bind to states.
These instructions build on:
\list
\li \l {Log In UI - Part 1}
\li \l {Log In UI - Part 2}
\li \l {Log In UI - Part 3}
\endlist
The \e {Learn Qt Quick} sections provide additional information about the
features of QML and Qt Quick that are relevant to the task at hand.
\section1 Animating UI Components
In Part 3, you changed the visibility property in different states to
simulate changing pages. To make sure that those changes won't interfere
with the changes to the opacity property you will make in Part 4, you will
first remove the states.
In addition, you will need to remove the line that sets the default state
from the \e Screen01.ui.qml file in the \uicontrol {Text Editor}.
Then, you will add a timeline and insert keyframes for the opacity property
to hide the password verification field and back button on the login page
and the login button on the registration page. Because we want the password
verification field to appear to slide down from the password field, you will
also need to insert a keyframe for its anchor margin property. To be able to
animate the anchor, you also need to pull out the fields from the fields
column and anchor them to the page and to each other instead.
To preview the changes that you make to the UI while you make
them, select the \inlineimage live_preview.png
(\uicontrol {Show Live Preview}) button on the \uicontrol {Form Editor}
toolbar or press \key {Alt+P}.
\section2 Replacing Columns with Anchors
First, you will prepare the page for adding animation:
\list 1
\li Open \e {Screen01.ui.qml} in the Design mode for editing.
\li In the \uicontrol States view, select the \inlineimage close.png
(\uicontrol Close) button in \e loginState and \e registerState
to remove the states.
\li In the \uicontrol {Text Editor}, remove the following line:
\code
{state: "loginState"}
\endcode
\li Select the fields in \e fieldColumn in the \uicontrol Navigator
and drag and drop them to \e loginPage.
\li Select \e fieldColumn in the \uicontrol Navigator and press
\key Delete to delete it.
\li Select \e usernameField in the \uicontrol Navigator.
\li In \uicontrol Properties > \uicontrol Layout, select the
\inlineimage anchor-top.png
(\uicontrol Top) button to anchor the top of the field to the top
of its parent (the \e loginPage). \QDS will suggest an appropriate
margin based on the current Y-position of the field.
\li Select the \inlineimage anchor-horizontal-center.png
(\uicontrol {Horizontal Center}) button to anchor
the horizontal center of the field to that of its parent.
\li Select \e passwordField, and then select the \uicontrol Top
button in \uicontrol Properties > \uicontrol Layout.
\li In the \uicontrol Target field, select \e usernameField to anchor
the top of \e passwordField to the bottom of \e usernameField
with a 5-pixel margin.
\li Select the \uicontrol {Horizontal Center} button to anchor the
horizontal center of \e passwordField to that of \e usernameField.
\li Repeat the above steps to anchor the top of \e verifyPasswordField
to the bottom of the \e passwordField with a 5-pixel margin and to
anchor its horizontal center to that of \e passwordField.
\li Select \uicontrol File > \uicontrol Save or press \key {Ctrl+S}
to save your changes.
\endlist
You could also animate the Y-position property of the verify password
field for a similar effect. In that case, you would need to use absolute
positioning for the field. This is less flexible if you export your
design from a design tool, such as Adobe Photoshop, and decide to change
your design and export it again at some point. In that case, the margins
would probably stay the same, even if the positions of the fields on the
page would change.
Your page now should look something like this in the Design mode and live preview:
\image loginui4-page.png "UI with all the buttons and fields in the Design mode"
\section2 Adding a Timeline and Animation Settings
You are now ready to add the \l{Creating Animations}{timeline}. You will
need two animations, one for moving into the registration page and another
for returning to the login page. You can use the same animation for both
cases, by running it either from the beginning to the end or from the
end to the beginning.
To add a timeline with settings for running the animation:
\image loginui4-timeline-settings.png
\list 1
\li In the \uicontrol Timeline view, select \inlineimage plus.png
to add a 1000-frame timeline and settings for running the animation.
\li In the \uicontrol {Animation ID} field, enter \e toLoginState.
\li Deselect the \uicontrol {Running in base state} check box, because
you want the animation to run only after the user clicks the
\uicontrol {Create Account} button. You can use the default settings
for the other fields.
\li Select \inlineimage plus.png
next to the \uicontrol {Animation Settings} group to add settings
for running the animation when the user clicks the back button.
\li In the \uicontrol {Animation ID} field, enter \e toRegisterState.
\li To run the animation backwards when the user clicks the back button,
enter \e 1000 in the \uicontrol {Start frame} field and \e 0 in the
\uicontrol {End frame} field.
\li Select \uicontrol Close in the \uicontrol {Timeline Settings} view
to save the timeline and the animation settings.
\endlist
Next, you will record the animation in the \uicontrol Timeline view.
\section2 Inserting Keyframes
You will now insert keyframes and record property changes in the
\uicontrol Timeline view:
\list 1
\li Select \e backButton in the \uicontrol Navigator.
\li In \uicontrol Properties > \uicontrol Opacity > \uicontrol Settings,
select \uicontrol {Insert Keyframe} to insert a keyframe for the
opacity property of the button.
\li Check that the playhead is in frame 0, and select the
\inlineimage recordfill.png
(Per Property Recording) button for the \uicontrol opacity property
of \e backButton to start recording property changes.
\image loginui4-timeline-opacity.png "Record button for the opacity property"
\li In the field next to the opacity property name on that same line,
type 0 to hide the button, and press \key Enter to save the value.
\li Move the playhead to frame 1000 and change the opacity value to 1
to show the button.
\li Select the record button again to stop recording property changes.
If you forget this, all the following changes will be recorded, and
the results will be unpredictable.
\li Select \e verifyPasswordField in the \uicontrol Navigator,
and repeat the above steps to insert a keyframe for the
\uicontrol opacity property of the field and to record
changes for it.
\li Select the \e loginButton in the \uicontrol Navigator, and repeat
the above steps to insert a keyframe for the \uicontrol opacity
property of the button and to record changes for it. However, this
time the opacity value needs to be 1 in frame 0 and 0 in frame 1000.
\li Select \uicontrol File > \uicontrol Save or press \key {Ctrl+S}
to save your changes.
\endlist
When you move the playhead along the timeline, you can see how the login
button fades out while the verify password field and back button fade in.
You will now animate the top anchor margin of the verify password field
to make it appear to slide down from the password field.
\section2 Animating Anchors
To animate the top anchor margin of the verify password field:
\list 1
\li Select \e verifyPasswordField in the \uicontrol Navigator.
\li Select \uicontrol Properties > \uicontrol Layout > \uicontrol Margin
> \uicontrol {Insert Keyframe} to insert a keyframe for the top
anchor margin of \e verifyPasswordField.
\li In the \uicontrol Timeline view, check that the playhead is in
frame 0, and select the record button for the \e anchors.topMargin
property of \e verifyPasswordField.
\li In the field next to the property, set a negative value for the
top anchor margin, -40, to place \e verifyPasswordField on top of
\e passwordField.
\li Move the playhead to frame 1000 and change the top anchor margin to
5, so that \e verifyPasswordField appears to slide down and settle
below \e passwordField.
\li Select the record button again to stop recording property changes.
\li Select \uicontrol File > \uicontrol Save or press \key {Ctrl+S}
to save your changes.
\endlist
\section2 Adding Easing Curves
You will now add an \l{Editing Easing Curves}{easing curve} to the anchor
margin animation that will make the transition seem smoother:
\list 1
\li Click the keyframe marker \inlineimage keyframe_linear_inactive.png
for the \e anchors.topMargin property at frame 1000 on the
timeline to select it.
\li Right-click the keyframe marker to open a context menu, and
select \uicontrol {Edit Easing Curve} to add an easing curve
to the animation.
\li In the \uicontrol {Easing Curve Editor}, select \e easeOutSine.
\image loginui4-easing-curve.png
\li Select \uicontrol OK to close the editor.
\endlist
When you attach easing curves to keyframes, the shape of the keyframe
marker changes from \inlineimage keyframe_linear_inactive.png
to \inlineimage keyframe_manualbezier_inactive.png
.
Your timeline now should look something like this:
\image loginui4-timeline.png "Timeline view with the recorded property changes"
Next, you create states for the login and registration pages and bind them
to the animation settings.
\section1 Binding Animation to States
You will now bring back the \l{Adding States}{states} in the
\uicontrol States view and bind them to the animation settings
in the \uicontrol Timeline view:
\list 1
\li In the \uicontrol States view, select the \inlineimage plus.png
button twice to add two states called \e loginState and
\e registerState. You don't need to make any property changes this
time, because you'll bind the states to property animations.
\li In the \uicontrol Timeline view, select the \inlineimage animation.png
(\uicontrol {Timeline Settings (S)}) button on the toolbar (or press
\key S to open the \uicontrol {Timeline Settings} dialog.
\image loginui4-timeline-settings-states.png
\li Double-click the cell in the \uicontrol Timeline column on the
\e loginState row, and select \e timeline in the list.
\li Double-click the cell in the \uicontrol Animation column on the
\e loginState row, and select \e toRegisterState.
\li Repeat these steps for \e registerState row, but select
\e toLoginState in the \uicontrol Animation column.
\li Click \uicontrol Close to save the timeline settings.
\endlist
In the live preview, you can now click the \uicontrol {Create Account}
button to go to the registration page and the back button to return to
the login page.
\image loginui4.gif "Moving between login page and registration page"
\section2 Learn Qt Quick - Timeline
The Qt Quick Timeline module provides QML types to use timelines and
keyframes to animate component properties in UIs. Animating properties
enables their values to move through intermediate values instead of
immediately changing to the target value.
The Keyframe type specifies the value of a keyframe on a timeline. \QDS
automatically adds keyframes between two keyframes, and sets their values
evenly to create an appearance of movement or transformation.
An easing curve can be attached to the keyframe to change the appearance
of the animation. For more information about easing curve types, see the
documentation for \l [QML] {PropertyAnimation}{easing curves}.
To be able to use the functionality of Qt Quick Timeline types, \QDS adds
the following \e import statement to the QML files where it uses the types:
\quotefromfile loginui4/Screen01.ui.qml
\skipto QtQuick.Timeline
\printuntil 1.0
All the properties and functions of the QML types from this module are
available in the Design mode, and therefore it is enough to learn how to
use the \uicontrol Timeline view, as described in \l {Creating Animations}.
\section1 Next Steps
For more examples about using timelines, see \l{Examples and Tutorials}.
To watch a video tutorial about creating timelines and adding keyframes,
select \e {Learn to use Qt Design Studio Part 2} in the \uicontrol Tutorials
tab in the \uicontrol Welcome mode.
*/
|