2 * Copyright (C) 2013 Canonical Ltd.
3 * Copyright (C) 2019 UBports Foundation
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 property bool available: true
24 property bool shown: true
26 /* If your showable supports on demand content creation/destruction,
27 set this to false when destroyed and true when ready to be shown.
28 NOTE: You should load your content when "required" is true and
29 destroy when "required" is false
31 property bool created: true
32 property bool required
33 property bool __shouldShow: false
34 property bool __skipShowAnimation: false
35 property bool __skipHideAnimation: false
37 property list<QtObject> hides
38 property Animation showAnimation
39 property Animation hideAnimation
41 // automatically set the target on showAnimation and hideAnimation to be the
43 onShowAnimationChanged: if (showAnimation && showAnimation.hasOwnProperty("target")) showAnimation["target"] = showable
44 onHideAnimationChanged: if (hideAnimation && hideAnimation.hasOwnProperty("target")) hideAnimation["target"] = showable
46 Component.onCompleted: required = shown;
48 function __hideOthers() {
50 for (i=0; i<hides.length; i++) {
65 __skipShowAnimation = true;
70 if (created && __shouldShow) {
76 function __reallyShow() {
77 if (showAnimation != undefined && showAnimation.running)
81 __skipShowAnimation = false;
87 if (hideAnimation != undefined && hideAnimation.running) {
91 if (showAnimation != undefined) {
92 showAnimation.restart()
93 if (__skipShowAnimation || shown) {
94 showAnimation.complete();
101 __skipShowAnimation = false;
106 Will be called right before starting the hideAnimation.
108 property var prepareToHide: function(){}
111 if (hideAnimation != undefined && hideAnimation.running)
114 if (showAnimation != undefined && showAnimation.running) {
118 if (typeof prepareToHide === "function") {
121 console.warn("Showable.prepareToHide should be a function, but it's a " +
122 (typeof prepareToHide) + " instead");
125 if (hideAnimation != undefined) {
126 hideAnimation.restart()
127 if (__skipHideAnimation || !shown) {
128 hideAnimation.complete();
136 __skipHideAnimation = false;
140 __skipHideAnimation = true;
145 target: hideAnimation ? hideAnimation: null
147 if (!hideAnimation.running) {