2 * Copyright (C) 2013 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 property bool available: true
23 property bool shown: true
25 /* If your showable supports on demand content creation/destruction,
26 set this to false when destroyed and true when ready to be shown.
27 NOTE: You should load your content when "required" is true and
28 destroy when "required" is false
30 property bool created: true
31 property bool required
32 property bool __shouldShow: false
33 property bool __skipShowAnimation: false
34 property bool __skipHideAnimation: false
36 property list<QtObject> hides
37 property var showAnimation
38 property var hideAnimation
40 // automatically set the target on showAnimation and hideAnimation to be the
42 onShowAnimationChanged: if (showAnimation) showAnimation["target"] = showable
43 onHideAnimationChanged: if (hideAnimation) hideAnimation["target"] = showable
45 Component.onCompleted: required = shown;
47 function __hideOthers() {
49 for (i=0; i<hides.length; i++) {
64 __skipShowAnimation = true;
69 if (created && __shouldShow) {
75 function __reallyShow() {
77 __skipShowAnimation = false;
83 if (hideAnimation != undefined && hideAnimation.running) {
87 if (showAnimation != undefined) {
88 if (!showAnimation.running) {
89 showAnimation.restart()
91 if (__skipShowAnimation) {
92 showAnimation.complete();
99 __skipShowAnimation = false;
104 Will be called right before starting the hideAnimation.
106 property var prepareToHide: function(){}
109 if (showAnimation != undefined && showAnimation.running) {
113 if (typeof prepareToHide === "function") {
116 console.warn("Showable.prepareToHide should be a function, but it's a " +
117 (typeof prepareToHide) + " instead");
120 if (hideAnimation != undefined) {
121 if (!hideAnimation.running) {
122 hideAnimation.restart()
124 if (__skipHideAnimation) {
125 hideAnimation.complete();
133 __skipHideAnimation = false;
137 __skipHideAnimation = true;
142 target: hideAnimation ? hideAnimation: null
144 if (!hideAnimation.running) {