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
5bd1a67Michael Terry
qml/Shell.qml+1−1
@@ -848,7 +848,7 @@ Item {
848 Tutorial {
848 Tutorial {
849 id: tutorial
849 id: tutorial
850 objectName: "tutorial"
850 objectName: "tutorial"
851− visible: AccountsService.demoEdges
851+ active: AccountsService.demoEdges
852 paused: LightDM.Greeter.active
852 paused: LightDM.Greeter.active
853 launcher: launcher
853 launcher: launcher
854 panel: panel
854 panel: panel
qml/Tutorial/Tutorial.qml+31−86
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright (C) 2013,2014 Canonical, Ltd.
2+ * Copyright (C) 2014 Canonical, Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
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
5 * it under the terms of the GNU General Public License as published by
@@ -20,115 +20,60 @@ import Ubuntu.Components 1.1
20Item {
20Item {
21 id: root
21 id: root
22
22
23+ property alias active: loader.active
24+ property bool paused
25+
23 property Item launcher
26 property Item launcher
24 property Item panel
27 property Item panel
25 property Item stages
28 property Item stages
26 property Item overlay
29 property Item overlay
27
30
28− readonly property bool launcherEnabled: !running ||
31+ readonly property bool launcherEnabled: loader.item ? loader.item.launcherEnabled : true
29− (!paused && loader.target === leftComponent)
30− readonly property bool stagesEnabled: !running
32+ readonly property bool stagesEnabled: loader.item ? loader.item.stagesEnabled : true
31− readonly property bool panelEnabled: !running
33+ readonly property bool panelEnabled: loader.item ? loader.item.panelEnabled : true
32− readonly property bool panelContentEnabled: !running
34+ readonly property bool panelContentEnabled: loader.item ? loader.item.panelContentEnabled : true
33− readonly property bool running: loader.sourceComponent !== null
35+ readonly property bool running: loader.item ? loader.item.running : false
34−
35− property bool paused: false
36
36
37 signal finished()
37 signal finished()
38
38
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−
66 Loader {
39 Loader {
67 id: loader
40 id: loader
68− objectName: "tutorialLoader"
41+ anchors.fill: parent
42+ source: "TutorialContent.qml"
69
43
44+ Binding {
45+ target: loader.item
70− property Component target: {
46+ property: "paused"
71− if (next) {
47+ value: root.paused
72− return next;
73− } else if (loader.item && loader.item.shown) {
74− return sourceComponent;
75− } else {
76− return null;
77− }
78 }
48 }
79
49
80− property Component next: null
50+ Binding {
81−
51+ target: loader.item
82− function load(comp) {
52+ property: "launcher"
83− if (loader.item) {
53+ value: root.launcher
84− next = comp;
85− loader.item.hide();
86− } else {
87− loader.sourceComponent = comp;
88− }
89 }
54 }
90
55
91− Connections {
56+ Binding {
92 target: loader.item
57 target: loader.item
93− onFinished: {
58+ property: "panel"
94− loader.sourceComponent = loader.next;
59+ value: root.panel
95− if (loader.next != null) {
96− loader.next = null;
97− } else {
98− root.finished();
99− }
100− }
101 }
60 }
102
61
103 Binding {
62 Binding {
104 target: loader.item
63 target: loader.item
105− property: "paused"
64+ property: "stages"
106− value: root.paused
65+ value: root.stages
107 }
66 }
108− }
109−
110− Component {
111− id: leftComponent
112− TutorialLeft {
113− objectName: "tutorialLeft"
114− parent: root.stages
115− anchors.fill: parent
116− launcher: root.launcher
117
67
118− onFinished: loader.load(leftFinishComponent)
68+ Binding {
69+ target: loader.item
70+ property: "overlay"
71+ value: root.overlay
119 }
72 }
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
130
73
74+ Connections {
75+ target: loader.item
131− onFinished: root.launcher.hide()
76+ onFinished: root.finished()
132 }
77 }
133 }
78 }
134}
79}
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+}