Properly handle dynamic initialization of Sidebar header

This commit is contained in:
Arjen Hiemstra 2015-09-12 20:01:31 +02:00
parent 67086b4d9f
commit fa9ab24959
2 changed files with 8 additions and 5 deletions

View File

@ -79,7 +79,7 @@ Rectangle
anchors.left: base.left anchors.left: base.left
anchors.right: base.right anchors.right: base.right
source: modesListModel.get(header.currentModeIndex).file; source: modesListModel.count > header.currentModeIndex ? modesListModel.get(header.currentModeIndex).file : "";
property Item sidebar: base; property Item sidebar: base;

View File

@ -12,7 +12,7 @@ Item
id: base; id: base;
// Machine Setup // Machine Setup
property variant modesModel; property variant modesModel;
property alias currentModeIndex: modesList.currentIndex; property int currentModeIndex: 0;
property Action addMachineAction; property Action addMachineAction;
property Action configureMachinesAction; property Action configureMachinesAction;
UM.I18nCatalog { id: catalog; name:"cura"} UM.I18nCatalog { id: catalog; name:"cura"}
@ -54,14 +54,16 @@ Item
width: parent.width / 2 width: parent.width / 2
text: model.text text: model.text
exclusiveGroup: modeMenuGroup; exclusiveGroup: modeMenuGroup;
onClicked: modesList.currentIndex = index checkable: true;
checked: base.currentModeIndex == index
onClicked: base.currentModeIndex = index
style: ButtonStyle { style: ButtonStyle {
background: Rectangle { 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; } } Behavior on color { ColorAnimation { duration: 50; } }
Label { Label {
anchors.centerIn: parent 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 font: UM.Theme.fonts.default
text: control.text; text: control.text;
} }
@ -80,6 +82,7 @@ Item
anchors.left: parent.left anchors.left: parent.left
width: parent.width width: parent.width
height: UM.Theme.sizes.sidebar_header.height height: UM.Theme.sizes.sidebar_header.height
currentIndex: base.currentIndex;
} }
} }
} }