on xenial help sign in
Add a Loader between Shell and the actual content of the tutorial to save memory when tutorial isn't used
commit5bd1a677c66871a585e9bde095d34c4cd2d14d04 authorMichael Terry <michael.terry@canonical.com> dateTue 23 Dec 2014, 16:20 (12 years ago) parent40af579
3 files changed+162−87
qml/Shell.qml+1−1 qml/Tutorial/Tutorial.qml+31−86 qml/Tutorial/TutorialContent.qml+130
qml/Shell.qml+1−1
@@ -848,7 +848,7 @@ Item {
848848 Tutorial {
849849 id: tutorial
850850 objectName: "tutorial"
851− visible: AccountsService.demoEdges
851+ active: AccountsService.demoEdges
852852 paused: LightDM.Greeter.active
853853 launcher: launcher
854854 panel: panel
qml/Tutorial/Tutorial.qml+31−86
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2013,2014 Canonical, Ltd.
2+ * Copyright (C) 2014 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -20,115 +20,60 @@ import Ubuntu.Components 1.1
2020Item {
2121 id: root
2222
23+ property alias active: loader.active
24+ property bool paused
25+
2326 property Item launcher
2427 property Item panel
2528 property Item stages
2629 property Item overlay
2730
28− readonly property bool launcherEnabled: !running ||
29− (!paused && loader.target === leftComponent)
30− readonly property bool stagesEnabled: !running
31− readonly property bool panelEnabled: !running
32− readonly property bool panelContentEnabled: !running
33− readonly property bool running: loader.sourceComponent !== null
34−
35− property bool paused: false
31+ readonly property bool launcherEnabled: loader.item ? loader.item.launcherEnabled : true
32+ readonly property bool stagesEnabled: loader.item ? loader.item.stagesEnabled : true
33+ readonly property bool panelEnabled: loader.item ? loader.item.panelEnabled : true
34+ readonly property bool panelContentEnabled: loader.item ? loader.item.panelContentEnabled : true
35+ readonly property bool running: loader.item ? loader.item.running : false
3636
3737 signal finished()
3838
39− function finish() {
40− d.stop();
41− finished();
42− }
43−
44− ////
45−
46− visible: false
47− onVisibleChanged: {
48− d.stop();
49− if (visible) {
50− d.start();
51− }
52− }
53−
54− QtObject {
55− id: d
56−
57− function stop() {
58− loader.sourceComponent = null;
59− }
60−
61− function start() {
62− loader.load(leftComponent);
63− }
64− }
65−
6639 Loader {
6740 id: loader
68− objectName: "tutorialLoader"
41+ anchors.fill: parent
42+ source: "TutorialContent.qml"
6943
70− property Component target: {
71− if (next) {
72− return next;
73− } else if (loader.item && loader.item.shown) {
74− return sourceComponent;
75− } else {
76− return null;
77− }
44+ Binding {
45+ target: loader.item
46+ property: "paused"
47+ value: root.paused
7848 }
7949
80− property Component next: null
81−
82− function load(comp) {
83− if (loader.item) {
84− next = comp;
85− loader.item.hide();
86− } else {
87− loader.sourceComponent = comp;
88− }
50+ Binding {
51+ target: loader.item
52+ property: "launcher"
53+ value: root.launcher
8954 }
9055
91− Connections {
56+ Binding {
9257 target: loader.item
93− onFinished: {
94− loader.sourceComponent = loader.next;
95− if (loader.next != null) {
96− loader.next = null;
97− } else {
98− root.finished();
99− }
100− }
58+ property: "panel"
59+ value: root.panel
10160 }
10261
10362 Binding {
10463 target: loader.item
105− property: "paused"
106− value: root.paused
64+ property: "stages"
65+ value: root.stages
10766 }
108− }
109−
110− Component {
111− id: leftComponent
112− TutorialLeft {
113− objectName: "tutorialLeft"
114− parent: root.stages
115− anchors.fill: parent
116− launcher: root.launcher
11767
118− onFinished: loader.load(leftFinishComponent)
68+ Binding {
69+ target: loader.item
70+ property: "overlay"
71+ value: root.overlay
11972 }
120− }
121−
122− Component {
123− id: leftFinishComponent
124− TutorialLeftFinish {
125− objectName: "tutorialLeftFinish"
126− parent: root.stages
127− anchors.fill: parent
128− textXOffset: root.launcher.panelWidth
129− backgroundFadesOut: true
13073
131− onFinished: root.launcher.hide()
74+ Connections {
75+ target: loader.item
76+ onFinished: root.finished()
13277 }
13378 }
13479}
qml/Tutorial/TutorialContent.qmlnew file+130
@@ -0,0 +1,130 @@
1+/*
2+ * Copyright (C) 2013,2014 Canonical, Ltd.
3+ *
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.
7+ *
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.
12+ *
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/>.
15+ */
16+
17+import QtQuick 2.3
18+import Ubuntu.Components 1.1
19+
20+Item {
21+ id: root
22+
23+ property Item launcher
24+ property Item panel
25+ property Item stages
26+ property Item overlay
27+
28+ readonly property bool launcherEnabled: !running ||
29+ (!paused && loader.target === leftComponent)
30+ readonly property bool stagesEnabled: !running
31+ readonly property bool panelEnabled: !running
32+ readonly property bool panelContentEnabled: !running
33+ readonly property bool running: loader.sourceComponent !== null
34+
35+ property bool paused: false
36+
37+ signal finished()
38+
39+ function finish() {
40+ d.stop();
41+ finished();
42+ }
43+
44+ ////
45+
46+ Component.onCompleted: {
47+ d.start();
48+ }
49+
50+ QtObject {
51+ id: d
52+
53+ function stop() {
54+ loader.sourceComponent = null;
55+ }
56+
57+ function start() {
58+ loader.load(leftComponent);
59+ }
60+ }
61+
62+ Loader {
63+ id: loader
64+ objectName: "tutorialLoader"
65+
66+ property Component target: {
67+ if (next) {
68+ return next;
69+ } else if (loader.item && loader.item.shown) {
70+ return sourceComponent;
71+ } else {
72+ return null;
73+ }
74+ }
75+
76+ property Component next: null
77+
78+ function load(comp) {
79+ if (loader.item) {
80+ next = comp;
81+ loader.item.hide();
82+ } else {
83+ loader.sourceComponent = comp;
84+ }
85+ }
86+
87+ Connections {
88+ target: loader.item
89+ onFinished: {
90+ loader.sourceComponent = loader.next;
91+ if (loader.next != null) {
92+ loader.next = null;
93+ } else {
94+ root.finished();
95+ }
96+ }
97+ }
98+
99+ Binding {
100+ target: loader.item
101+ property: "paused"
102+ value: root.paused
103+ }
104+ }
105+
106+ Component {
107+ id: leftComponent
108+ TutorialLeft {
109+ objectName: "tutorialLeft"
110+ parent: root.stages
111+ anchors.fill: parent
112+ launcher: root.launcher
113+
114+ onFinished: loader.load(leftFinishComponent)
115+ }
116+ }
117+
118+ Component {
119+ id: leftFinishComponent
120+ TutorialLeftFinish {
121+ objectName: "tutorialLeftFinish"
122+ parent: root.stages
123+ anchors.fill: parent
124+ textXOffset: root.launcher.panelWidth
125+ backgroundFadesOut: true
126+
127+ onFinished: root.launcher.hide()
128+ }
129+ }
130+}