From fa9ab24959c8e1c5d7d5b475cf3d9585578e1961 Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Sat, 12 Sep 2015 20:01:31 +0200 Subject: [PATCH] Properly handle dynamic initialization of Sidebar header --- resources/qml/Sidebar.qml | 2 +- resources/qml/SidebarHeader.qml | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/resources/qml/Sidebar.qml b/resources/qml/Sidebar.qml index bc1157fd6a..ffdce05fda 100644 --- a/resources/qml/Sidebar.qml +++ b/resources/qml/Sidebar.qml @@ -79,7 +79,7 @@ Rectangle anchors.left: base.left anchors.right: base.right - source: modesListModel.get(header.currentModeIndex).file; + source: modesListModel.count > header.currentModeIndex ? modesListModel.get(header.currentModeIndex).file : ""; property Item sidebar: base; diff --git a/resources/qml/SidebarHeader.qml b/resources/qml/SidebarHeader.qml index 6d065ad7ee..eecba3262e 100644 --- a/resources/qml/SidebarHeader.qml +++ b/resources/qml/SidebarHeader.qml @@ -12,7 +12,7 @@ Item id: base; // Machine Setup property variant modesModel; - property alias currentModeIndex: modesList.currentIndex; + property int currentModeIndex: 0; property Action addMachineAction; property Action configureMachinesAction; UM.I18nCatalog { id: catalog; name:"cura"} @@ -54,14 +54,16 @@ Item width: parent.width / 2 text: model.text exclusiveGroup: modeMenuGroup; - onClicked: modesList.currentIndex = index + checkable: true; + checked: base.currentModeIndex == index + onClicked: base.currentModeIndex = index style: ButtonStyle { background: Rectangle { - color: modesList.currentIndex == index ? UM.Theme.colors.toggle_active : UM.Theme.colors.toggle_disabled + color: control.checked ? UM.Theme.colors.toggle_active : UM.Theme.colors.toggle_disabled Behavior on color { ColorAnimation { duration: 50; } } Label { anchors.centerIn: parent - color: modesList.currentIndex == index ? UM.Theme.colors.toggle_active_text : UM.Theme.colors.toggle_disabled_text + color: control.checked ? UM.Theme.colors.toggle_active_text : UM.Theme.colors.toggle_disabled_text font: UM.Theme.fonts.default text: control.text; } @@ -80,6 +82,7 @@ Item anchors.left: parent.left width: parent.width height: UM.Theme.sizes.sidebar_header.height + currentIndex: base.currentIndex; } } }