Convert PrintSetupSelector to an ExpandableComponent

CURA-5785
This commit is contained in:
Jaime van Kessel 2018-11-12 11:14:39 +01:00
parent e641584021
commit b60977e435
2 changed files with 125 additions and 157 deletions

View File

@ -66,6 +66,7 @@ Item
Cura.PrintSetupSelector Cura.PrintSetupSelector
{ {
width: UM.Theme.getSize("print_setup_widget").width width: UM.Theme.getSize("print_setup_widget").width
height: prepareMenu.height
onShowTooltip: prepareMenu.showTooltip(item, location, text) onShowTooltip: prepareMenu.showTooltip(item, location, text)
onHideTooltip: prepareMenu.hideTooltip() onHideTooltip: prepareMenu.hideTooltip()
} }

View File

@ -10,22 +10,14 @@ import Cura 1.0 as Cura
import "Menus" import "Menus"
import "Menus/ConfigurationMenu" import "Menus/ConfigurationMenu"
Rectangle Cura.ExpandableComponent
{ {
id: base id: base
height: childrenRect.height height: childrenRect.height
property int currentModeIndex: -1 property int currentModeIndex: -1
property bool hideSettings: PrintInformation.preSliced property bool hideSettings: PrintInformation.preSliced
property variant printDuration: PrintInformation.currentPrintTime
property variant printMaterialLengths: PrintInformation.materialLengths
property variant printMaterialWeights: PrintInformation.materialWeights
property variant printMaterialCosts: PrintInformation.materialCosts
property variant printMaterialNames: PrintInformation.materialNames
color: UM.Theme.getColor("main_background")
UM.I18nCatalog { id: catalog; name: "cura"} UM.I18nCatalog { id: catalog; name: "cura"}
// This widget doesn't show tooltips by itself. Instead it emits signals so others can do something with it. // This widget doesn't show tooltips by itself. Instead it emits signals so others can do something with it.
@ -46,40 +38,12 @@ Rectangle
} }
} }
function strPadLeft(string, pad, length)
{
return (new Array(length + 1).join(pad) + string).slice(-length);
}
function getPrettyTime(time)
{
var hours = Math.floor(time / 3600)
time -= hours * 3600
var minutes = Math.floor(time / 60);
time -= minutes * 60
var seconds = Math.floor(time);
var finalTime = strPadLeft(hours, "0", 2) + ":" + strPadLeft(minutes, "0", 2) + ":" + strPadLeft(seconds, "0", 2);
return finalTime;
}
MouseArea
{
anchors.fill: parent
acceptedButtons: Qt.AllButtons
onWheel:
{
wheel.accepted = true;
}
}
onCurrentModeIndexChanged: onCurrentModeIndexChanged:
{ {
UM.Preferences.setValue("cura/active_mode", currentModeIndex); UM.Preferences.setValue("cura/active_mode", currentModeIndex);
} }
Label headerItem: Label
{ {
id: settingsModeLabel id: settingsModeLabel
text: !hideSettings ? catalog.i18nc("@label:listbox", "Print Setup") : catalog.i18nc("@label:listbox", "Print Setup disabled\nG-code files cannot be modified") text: !hideSettings ? catalog.i18nc("@label:listbox", "Print Setup") : catalog.i18nc("@label:listbox", "Print Setup disabled\nG-code files cannot be modified")
@ -98,146 +62,149 @@ Rectangle
color: UM.Theme.getColor("text") color: UM.Theme.getColor("text")
} }
popupItem: Item
ListView
{ {
// Settings mode selection toggle height: settingsModeSelection.height + sidebarContents.height
id: settingsModeSelection width: UM.Theme.getSize("print_setup_widget").width
model: modesListModel ListView
width: Math.round(parent.width * 0.55)
height: UM.Theme.getSize("print_setup_mode_toggle").height
visible: !hideSettings
anchors.right: parent.right
anchors.rightMargin: UM.Theme.getSize("thick_margin").width
anchors.top: settingsModeLabel.top
ButtonGroup
{ {
id: modeMenuGroup // Settings mode selection toggle
id: settingsModeSelection
model: modesListModel
width: Math.round(parent.width * 0.55)
height: UM.Theme.getSize("print_setup_mode_toggle").height
visible: !hideSettings
anchors.right: parent.right
anchors.rightMargin: UM.Theme.getSize("thick_margin").width
ButtonGroup
{
id: modeMenuGroup
}
delegate: Button
{
id: control
height: settingsModeSelection.height
width: Math.round(parent.width / 2)
anchors.left: parent.left
anchors.leftMargin: model.index * Math.round(settingsModeSelection.width / 2)
anchors.verticalCenter: parent.verticalCenter
ButtonGroup.group: modeMenuGroup
checkable: true
checked: base.currentModeIndex == index
onClicked: base.currentModeIndex = index
onHoveredChanged:
{
if (hovered)
{
tooltipDelayTimer.item = settingsModeSelection
tooltipDelayTimer.text = model.tooltipText
tooltipDelayTimer.start()
}
else
{
tooltipDelayTimer.stop()
base.hideTooltip()
}
}
background: Rectangle
{
border.width: control.checked ? UM.Theme.getSize("default_lining").width * 2 : UM.Theme.getSize("default_lining").width
border.color: (control.checked || control.pressed) ? UM.Theme.getColor("action_button_active_border") : control.hovered ? UM.Theme.getColor("action_button_hovered_border") : UM.Theme.getColor("action_button_border")
// for some reason, QtQuick decided to use the color of the background property as text color for the contentItem, so here it is
color: (control.checked || control.pressed) ? UM.Theme.getColor("action_button_active") : control.hovered ? UM.Theme.getColor("action_button_hovered") : UM.Theme.getColor("action_button")
}
contentItem: Label
{
text: model.text
font: UM.Theme.getFont("default")
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
renderType: Text.NativeRendering
elide: Text.ElideRight
color:
{
if(control.pressed)
{
return UM.Theme.getColor("action_button_active_text");
}
else if(control.hovered)
{
return UM.Theme.getColor("action_button_hovered_text");
}
return UM.Theme.getColor("action_button_text");
}
}
}
} }
delegate: Button Item
{ {
id: control id: sidebarContents
anchors.top: settingsModeSelection.bottom
height: settingsModeSelection.height anchors.topMargin: UM.Theme.getSize("thick_margin").height
width: Math.round(parent.width / 2)
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: model.index * Math.round(settingsModeSelection.width / 2) anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter height: UM.Theme.getSize("print_setup_widget").height
ButtonGroup.group: modeMenuGroup visible: !hideSettings
checkable: true // We load both of them at once (instead of using a loader) because the advanced sidebar can take
checked: base.currentModeIndex == index // quite some time to load. So in this case we sacrifice memory for speed.
onClicked: base.currentModeIndex = index SidebarAdvanced
onHoveredChanged:
{ {
if (hovered) anchors.fill: parent
{ visible: currentModeIndex == 1
tooltipDelayTimer.item = settingsModeSelection onShowTooltip: base.showTooltip(item, location, text)
tooltipDelayTimer.text = model.tooltipText onHideTooltip: base.hideTooltip()
tooltipDelayTimer.start()
}
else
{
tooltipDelayTimer.stop()
base.hideTooltip()
}
} }
background: Rectangle SidebarSimple
{ {
border.width: control.checked ? UM.Theme.getSize("default_lining").width * 2 : UM.Theme.getSize("default_lining").width anchors.fill: parent
border.color: (control.checked || control.pressed) ? UM.Theme.getColor("action_button_active_border") : control.hovered ? UM.Theme.getColor("action_button_hovered_border") : UM.Theme.getColor("action_button_border") visible: currentModeIndex != 1
onShowTooltip: base.showTooltip(item, location, text)
// for some reason, QtQuick decided to use the color of the background property as text color for the contentItem, so here it is onHideTooltip: base.hideTooltip()
color: (control.checked || control.pressed) ? UM.Theme.getColor("action_button_active") : control.hovered ? UM.Theme.getColor("action_button_hovered") : UM.Theme.getColor("action_button")
}
contentItem: Label
{
text: model.text
font: UM.Theme.getFont("default")
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
renderType: Text.NativeRendering
elide: Text.ElideRight
color:
{
if(control.pressed)
{
return UM.Theme.getColor("action_button_active_text");
}
else if(control.hovered)
{
return UM.Theme.getColor("action_button_hovered_text");
}
return UM.Theme.getColor("action_button_text");
}
} }
} }
}
Item // Setting mode: Recommended or Custom
{ ListModel
id: sidebarContents
anchors.top: settingsModeSelection.bottom
anchors.topMargin: UM.Theme.getSize("thick_margin").height
anchors.left: parent.left
anchors.right: parent.right
height: UM.Theme.getSize("print_setup_widget").height
visible: !hideSettings
// We load both of them at once (instead of using a loader) because the advanced sidebar can take
// quite some time to load. So in this case we sacrifice memory for speed.
SidebarAdvanced
{ {
anchors.fill: parent id: modesListModel
visible: currentModeIndex == 1
onShowTooltip: base.showTooltip(item, location, text)
onHideTooltip: base.hideTooltip()
} }
SidebarSimple Component.onCompleted:
{ {
anchors.fill: parent modesListModel.append({
visible: currentModeIndex != 1 text: catalog.i18nc("@title:tab", "Recommended"),
onShowTooltip: base.showTooltip(item, location, text) tooltipText: "<b>%1</b><br/><br/>%2".arg(catalog.i18nc("@tooltip:title", "Recommended Print Setup")).arg(catalog.i18nc("@tooltip", "Print with the recommended settings for the selected printer, material and quality."))
onHideTooltip: base.hideTooltip() })
} modesListModel.append({
} text: catalog.i18nc("@title:tab", "Custom"),
tooltipText: "<b>%1</b><br/><br/>%2".arg(catalog.i18nc("@tooltip:title", "Custom Print Setup")).arg(catalog.i18nc("@tooltip", "Print with finegrained control over every last bit of the slicing process."))
})
// Setting mode: Recommended or Custom var index = Math.round(UM.Preferences.getValue("cura/active_mode"))
ListModel
{
id: modesListModel
}
Component.onCompleted: if(index != null && !isNaN(index))
{ {
modesListModel.append({ currentModeIndex = index;
text: catalog.i18nc("@title:tab", "Recommended"), }
tooltipText: "<b>%1</b><br/><br/>%2".arg(catalog.i18nc("@tooltip:title", "Recommended Print Setup")).arg(catalog.i18nc("@tooltip", "Print with the recommended settings for the selected printer, material and quality.")) else
}) {
modesListModel.append({ currentModeIndex = 0;
text: catalog.i18nc("@title:tab", "Custom"), }
tooltipText: "<b>%1</b><br/><br/>%2".arg(catalog.i18nc("@tooltip:title", "Custom Print Setup")).arg(catalog.i18nc("@tooltip", "Print with finegrained control over every last bit of the slicing process."))
})
var index = Math.round(UM.Preferences.getValue("cura/active_mode"))
if(index != null && !isNaN(index))
{
currentModeIndex = index;
}
else
{
currentModeIndex = 0;
} }
} }
} }