Skip to content

Commit

Permalink
Merge pull request Ultimaker#1698 from Ultimaker/feature_CURA-3574_to…
Browse files Browse the repository at this point in the history
…ggle_button

CURA-3574: Use a toggle button mode switching
  • Loading branch information
jackha authored Apr 19, 2017
2 parents f91037f + 232f975 commit 74726e3
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 12 deletions.
65 changes: 54 additions & 11 deletions resources/qml/Sidebar.qml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -407,14 +407,53 @@ Rectangle
}
}
ExclusiveGroup { id: modeMenuGroup; }
ListView{
id: modesList
property var index: 0
model: modesListModel
delegate: wizardDelegate
anchors.top: parent.top
anchors.left: parent.left
width: parent.width

Text
{
id: toggleLeftText
anchors.right: modeToggleSwitch.left
anchors.rightMargin: UM.Theme.getSize("toggle_button_text_anchoring_margin").width
anchors.verticalCenter: parent.verticalCenter
text: ""
color: UM.Theme.getColor("toggle_active_text")
font: UM.Theme.getFont("default")
}

Switch
{
id: modeToggleSwitch
checked: false
anchors.right: toggleRightText.left
anchors.rightMargin: UM.Theme.getSize("toggle_button_text_anchoring_margin").width
anchors.verticalCenter: parent.verticalCenter

onClicked:
{
var index = 0;
if (checked)
{
index = 1;
}
updateActiveMode(index);
}

function updateActiveMode(index)
{
base.currentModeIndex = index;
UM.Preferences.setValue("cura/active_mode", index);
}

style: UM.Theme.styles.toggle_button
}

Text
{
id: toggleRightText
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
text: ""
color: UM.Theme.getColor("toggle_active_text")
font: UM.Theme.getFont("default")
}
}

Expand Down Expand Up @@ -541,10 +580,14 @@ Rectangle
})
sidebarContents.push({ "item": modesListModel.get(base.currentModeIndex).item, "immediate": true });

var index = parseInt(UM.Preferences.getValue("cura/active_mode"))
if(index)
toggleLeftText.text = modesListModel.get(0).text;
toggleRightText.text = modesListModel.get(1).text;

var index = parseInt(UM.Preferences.getValue("cura/active_mode"));
if (index)
{
currentModeIndex = index;
modeToggleSwitch.checked = index > 0;
}
}

Expand All @@ -567,4 +610,4 @@ Rectangle
watchedProperties: [ "value" ]
storeIndex: 0
}
}
}
38 changes: 38 additions & 0 deletions resources/themes/cura/styles.qml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,44 @@ import QtQuick.Controls.Styles 1.1
import UM 1.1 as UM

QtObject {
property Component toggle_button: Component {
SwitchStyle {
groove: Rectangle {
implicitWidth: UM.Theme.getSize("toggle_button_background_implicit_size").width
implicitHeight: UM.Theme.getSize("toggle_button_background_implicit_size").height
radius: UM.Theme.getSize("toggle_button_radius").width
border.color: {
if (control.pressed || (control.checkable && control.checked)) {
return UM.Theme.getColor("sidebar_header_active");
} else if(control.hovered) {
return UM.Theme.getColor("sidebar_header_hover");
} else {
return UM.Theme.getColor("sidebar_header_bar");
}
}
Behavior on border.color { ColorAnimation { duration: 50; } }
border.width: 1
}

handle: Rectangle {
implicitWidth: UM.Theme.getSize("toggle_button_knob_implicit_size").width
implicitHeight: UM.Theme.getSize("toggle_button_knob_implicit_size").height
radius: UM.Theme.getSize("toggle_button_radius").width

color: {
if (control.pressed || (control.checkable && control.checked)) {
return UM.Theme.getColor("sidebar_header_active");
} else if(control.hovered) {
return UM.Theme.getColor("sidebar_header_hover");
} else {
return UM.Theme.getColor("sidebar_header_bar");
}
}
Behavior on color { ColorAnimation { duration: 50; } }
}
}
}

property Component sidebar_header_button: Component {
ButtonStyle {
background: Rectangle {
Expand Down
7 changes: 6 additions & 1 deletion resources/themes/cura/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,11 @@

"infill_button_margin": [0.5, 0.5],

"jobspecs_line": [2.0, 2.0]
"jobspecs_line": [2.0, 2.0],

"toggle_button_text_anchoring_margin": [1.0, 1.0],
"toggle_button_radius": [1.0, 1.0],
"toggle_button_background_implicit_size": [2.0, 1.0],
"toggle_button_knob_implicit_size": [1.0, 1.0]
}
}

0 comments on commit 74726e3

Please sign in to comment.