Fluid 1.3.0
Material Design for QtQuick and Qml
Loading...
Searching...
No Matches
Loadable.qml
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2018 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
2// SPDX-License-Identifier: MPL-2.0
3
4import QtQuick
5
13Item {
14 id: root
15 Accessible.ignored: true
19 property Component component
20
24 property var showAnimation
25
29 property var hideAnimation
30
34 property alias asynchronous: loader.asynchronous
35
39 property alias item: loader.item
40 // Loaded components may expose optional show/hide methods and animations.
41 // Keep this interface dynamic to support custom components as well as Showable.
42 readonly property var _loadedItem: loader.item
43 visible: false
44
45 Loader {
46 id: loader
47 anchors.fill: parent
48 asynchronous: true
49 onStatusChanged: {
50 if (status != Loader.Ready)
51 return;
52 if (root._loadedItem.showAnimation == undefined && root.showAnimation != undefined)
53 root._loadedItem.showAnimation = root.showAnimation;
54 if (root._loadedItem.hideAnimation == undefined && root.hideAnimation != undefined)
55 root._loadedItem.hideAnimation = root.hideAnimation;
56 root.visible = true;
57 if (root._loadedItem.show != undefined)
58 root._loadedItem.show();
59 }
60 }
61
62 Connections {
63 target: loader.item
64
65 function onVisibleChanged() {
66 // Unload component as soon as it's hidden and hide this item as well
67 if (!(loader.item as Item).visible) {
68 loader.sourceComponent = undefined;
69 root.visible = false;
70 }
71 }
72 }
73
77 function show() {
78 loader.sourceComponent = root.component;
79 }
80
84 function hide() {
85 if (root._loadedItem && root._loadedItem.hide !== undefined)
86 root._loadedItem.hide();
87 }
88}