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.right: base.right
source: modesListModel.get(header.currentModeIndex).file;
source: modesListModel.count > header.currentModeIndex ? modesListModel.get(header.currentModeIndex).file : "";
property Item sidebar: base;

View file

@ -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;
}
}
}