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
|
// Copyright (C) 2021 The Qt Company Ltd.
// Copyright (C) 2019 Luxoft Sweden AB
// Copyright (C) 2018 Pelagicore AG
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\example applicationmanager/animated-windows
\brief Learn how to animate windows to appear and disappear.
\ingroup applicationmanager-examples
\title Animated Windows System UI Example
\image animated-windows-example.jpg The Animated Windows example with two applications running.
\note Please \l{wayland-dev-packages}{read this} if you want to build the example on a Linux machine.
\section1 Introduction
This example shows you how to animate windows to appear and disappear, in a System UI.
\b Prerequisites: You're already familiar with the concepts and topics introduced in the
\l {System UI Example: "Hello World!"}.
Unlike with the \l{System UI Example: "Hello World!"}{Hello World} example, most Graphical User
Interfaces (GUIs) avoid making sudden, abrupt, changes as they can confuse the user and are not
visually pleasant. So, when the WindowManager creates a new WindowObject, we want to animate its
appearance instead of simply having it pop up on the screen. Likewise, once a WindowObject loses
its surface - because the application closed this window or stopped altogether - and is removed
from the WindowManager's model, we want to animate its disappearance instead of having it vanish
immediately.
If you're using a ready-made, advanced layout such as ListView, you can assign Transitions to
different actions like add, remove, displaced, and so on, and keep using WindowManager as your
model. But in many situations this is not the case. Instead, you have to create your own model,
such as a ListModel, so that a WindowObject only leaves the model when you have finished
animating its delegate's disappearance. This example showcases this technique.
\section1 The Windows Model
The model we use to instantiate our \l{WindowItem}{windows} is the key point in this example.
Instead of using WindowManager directly as our model we use a plain ListModel:
\quotefromfile applicationmanager/animated-windows/system-ui/main.qml
\skipto Each WindowObject
\skipline Each WindowObject
\printuntil delegate: Rectangle
We remove a WindowObject from that model only after it has reached its end state:
WindowObject.NoSurface and is no longer being shown on screen; any state transition has already
finished.
\skipto property bool safeToRemove
\printuntil onSafeToRemoveChanged
Then, we add a WindowObject to it, and display it on screen as soon as WindowManager creates
a WindowObject.
\skipto Connections
\printuntil /\s+\}/
*/
|