@@ -87,8 +87,7 @@ FocusScope {
8787 }
8888 subPageLoader.initialIndex = -1;
8989 subPageLoader.initialIndex = index;
90− subPageLoader.subPage = "preview";
91− subPageLoader.openSubPage();
90+ subPageLoader.openSubPage("preview");
9291 }
9392
9493 Binding {
@@ -107,8 +106,8 @@ FocusScope {
107106 }
108107
109108 onIsCurrentChanged: {
110− if (showPageHeader) {
111− pageHeaderLoader.item.resetSearch();
109+ if (pageHeaderLoader.item && showPageHeader) {
110+ pageHeaderLoader.item.resetSearch();
112111 }
113112 subPageLoader.closeSubPage();
114113 }
@@ -442,10 +441,7 @@ FocusScope {
442441
443442 onBackClicked: scopeView.backClicked()
444443
445− onSettingsClicked: {
446− subPageLoader.subPage = "settings";
447− subPageLoader.openSubPage();
448− }
444+ onSettingsClicked: subPageLoader.openSubPage("settings")
449445 }
450446 }
451447 }
@@ -471,59 +467,42 @@ FocusScope {
471467
472468 readonly property bool processing: item && item.processing || false
473469 readonly property int count: item && item.count || 0
474− readonly property int currentIndex: item && item.currentIndex || -1
475− readonly property var currentItem: item && item.currentItem || null
470+ readonly property int currentIndex: item && item.currentIndex || 0
471+ readonly property var currentItem: item && item.currentItem || null
476472
477473 property string subPage: ""
478− readonly property bool previewShown: open && subPage == "preview"
479− readonly property bool settingsShown: open && subPage == "settings"
480−
481− function updateBindings() {
482− if (status === Loader.Ready) {
483− item.scope = Qt.binding(function() { return subPageLoader.scope } )
484− item.scopeStyle = Qt.binding(function() { return subPageLoader.scopeStyle } )
485− if (item.hasOwnProperty("open")) item.open = Qt.binding(function() { return subPageLoader.open } )
486− if (item.hasOwnProperty("initialIndex")) item.initialIndex = Qt.binding(function() { return subPageLoader.initialIndex } )
487− if (item.hasOwnProperty("model")) item.model = Qt.binding(function() { return subPageLoader.model } )
488− }
489− }
490−
491− function updateSource() {
492− switch (subPage) {
493− case "preview": source = "PreviewListView.qml"; break;
494− case "settings": source = "ScopeSettingsPage.qml"; break;
495− default: source = ""; break;
496− }
497− }
474+ readonly property bool previewShown: visible && subPage == "preview"
475+ readonly property bool settingsShown: visible && subPage == "settings"
498476
499− function openSubPage() {
500− // FIXME adding the following check before opening makes more sense to me,
501− // but it doesn't seem to work in qmltestrunner::GenericScopeView::test_previewOpenClose()
502− // if (!visible && status === Loader.Ready), x is different to width.
503− // Let's just check status for now.
504− if (status === Loader.Ready) open = true;
477+ function openSubPage(page) {
478+ subPage = page;
479+ open = true;
505480 }
506481
507482 function closeSubPage() {
508483 open = false;
509− subPage = "";
510484 }
511485
512− onSubPageChanged: {
513− // let's update the source only when the loader is not visible
514− if (!visible) updateSource();
515− }
486+ source: visible && subPage && (subPage == "preview" ? "PreviewListView.qml" : "ScopeSettingsPage.qml") || ""
516487
517− onVisibleChanged: {
518− // let's update the source only when the loader is not visible
519− if (!visible) updateSource();
488+ onLoaded: {
489+ if (status === Loader.Ready) {
490+ item.scope = Qt.binding(function() { return subPageLoader.scope } )
491+ item.scopeStyle = Qt.binding(function() { return subPageLoader.scopeStyle } )
492+ if (subPage == "preview") {
493+ item.open = Qt.binding(function() { return subPageLoader.open } )
494+ item.initialIndex = Qt.binding(function() { return subPageLoader.initialIndex } )
495+ item.model = Qt.binding(function() { return subPageLoader.model } )
496+ }
497+ }
520498 }
521499
522− onLoaded: updateBindings()
500+ onOpenChanged: pageHeaderLoader.item.unfocus();
523501
524− onOpenChanged: {
525− if (open) updateBindings();
526− pageHeaderLoader.item.unfocus();
502+ onVisibleChanged: {
503+ if (!visible) {
504+ subPage = "";
505+ }
527506 }
528507
529508 Connections {