mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-10-04 06:36:30 +08:00
Add scrollview to nested material list
CURA-6867
This commit is contained in:
parent
d4679515b6
commit
e0a091e768
@ -105,6 +105,9 @@ Cura.MenuItem
|
|||||||
var parentGlobalX = parent.mapToItem(null, 0, 0).x
|
var parentGlobalX = parent.mapToItem(null, 0, 0).x
|
||||||
var overflowX = (parentGlobalX + defaultX + menuPopup.width) - mainWindow.width
|
var overflowX = (parentGlobalX + defaultX + menuPopup.width) - mainWindow.width
|
||||||
x = overflowX > 0 ? overflowX : defaultX
|
x = overflowX > 0 ? overflowX : defaultX
|
||||||
|
|
||||||
|
scrollViewMaterialType.height = popupHeight > mainWindow.height ? mainWindow.height: popupHeight
|
||||||
|
menuPopup.height = popupHeight > mainWindow.height ? mainWindow.height: popupHeight
|
||||||
}
|
}
|
||||||
|
|
||||||
padding: background.border.width
|
padding: background.border.width
|
||||||
@ -128,238 +131,255 @@ Cura.MenuItem
|
|||||||
border.width: UM.Theme.getSize("default_lining").width
|
border.width: UM.Theme.getSize("default_lining").width
|
||||||
}
|
}
|
||||||
|
|
||||||
Column
|
ScrollView
|
||||||
{
|
{
|
||||||
id: materialTypesList
|
id: scrollViewMaterialType
|
||||||
spacing: 0
|
width: UM.Theme.getSize("menu").width + scrollbar.width
|
||||||
|
height: parent.height
|
||||||
|
clip: true
|
||||||
|
|
||||||
property var brandMaterials: materialTypesModel.material_types
|
ScrollBar.vertical: UM.ScrollBar
|
||||||
|
|
||||||
Repeater
|
|
||||||
{
|
{
|
||||||
model: parent.brandMaterials
|
id: scrollbar
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.top: parent.top
|
||||||
|
anchors.bottom: parent.bottom
|
||||||
|
}
|
||||||
|
|
||||||
//Use a MouseArea and Rectangle, not a button, because the button grabs mouse events which makes the parent pop-up think it's no longer being hovered.
|
Column
|
||||||
//With a custom MouseArea, we can prevent the events from being accepted.
|
{
|
||||||
delegate: Rectangle
|
id: materialTypesList
|
||||||
|
width: UM.Theme.getSize("menu").width
|
||||||
|
height: parent.height
|
||||||
|
spacing: 0
|
||||||
|
|
||||||
|
property var brandMaterials: materialTypesModel.material_types
|
||||||
|
|
||||||
|
Repeater
|
||||||
{
|
{
|
||||||
id: brandMaterialBase
|
model: parent.brandMaterials
|
||||||
height: UM.Theme.getSize("menu").height
|
|
||||||
width: UM.Theme.getSize("menu").width
|
|
||||||
|
|
||||||
color: materialTypeButton.containsMouse ? UM.Theme.getColor("background_2") : UM.Theme.getColor("background_1")
|
//Use a MouseArea and Rectangle, not a button, because the button grabs mouse events which makes the parent pop-up think it's no longer being hovered.
|
||||||
|
//With a custom MouseArea, we can prevent the events from being accepted.
|
||||||
property var isFlipped: menuPopup.flipped
|
delegate: Rectangle
|
||||||
|
|
||||||
RowLayout
|
|
||||||
{
|
{
|
||||||
spacing: 0
|
id: brandMaterialBase
|
||||||
opacity: materialBrandMenu.enabled ? 1 : 0.5
|
height: UM.Theme.getSize("menu").height
|
||||||
height: parent.height
|
width: UM.Theme.getSize("menu").width
|
||||||
width: parent.width
|
|
||||||
|
|
||||||
Item
|
color: materialTypeButton.containsMouse ? UM.Theme.getColor("background_2") : UM.Theme.getColor("background_1")
|
||||||
|
|
||||||
|
property var isFlipped: menuPopup.flipped
|
||||||
|
|
||||||
|
RowLayout
|
||||||
{
|
{
|
||||||
// Spacer
|
spacing: 0
|
||||||
width: UM.Theme.getSize("default_margin").width
|
opacity: materialBrandMenu.enabled ? 1 : 0.5
|
||||||
}
|
|
||||||
|
|
||||||
UM.Label
|
|
||||||
{
|
|
||||||
text: model.name
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.fillHeight: true
|
|
||||||
elide: Label.ElideRight
|
|
||||||
wrapMode: Text.NoWrap
|
|
||||||
}
|
|
||||||
|
|
||||||
Item
|
|
||||||
{
|
|
||||||
Layout.fillWidth: true
|
|
||||||
}
|
|
||||||
|
|
||||||
UM.ColorImage
|
|
||||||
{
|
|
||||||
height: UM.Theme.getSize("default_arrow").height
|
|
||||||
width: UM.Theme.getSize("default_arrow").width
|
|
||||||
color: UM.Theme.getColor("setting_control_text")
|
|
||||||
source: UM.Theme.getIcon("ChevronSingleRight")
|
|
||||||
}
|
|
||||||
|
|
||||||
Item
|
|
||||||
{
|
|
||||||
// Right side margin
|
|
||||||
width: UM.Theme.getSize("default_margin").width
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MouseArea
|
|
||||||
{
|
|
||||||
id: materialTypeButton
|
|
||||||
anchors.fill: parent
|
|
||||||
|
|
||||||
hoverEnabled: true
|
|
||||||
acceptedButtons: Qt.NoButton
|
|
||||||
|
|
||||||
onEntered:
|
|
||||||
{
|
|
||||||
menuPopup.itemHovered += 1;
|
|
||||||
showSubTimer.restartTimer();
|
|
||||||
}
|
|
||||||
onExited:
|
|
||||||
{
|
|
||||||
menuPopup.itemHovered -= 1;
|
|
||||||
hideSubTimer.restartTimer();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Timer
|
|
||||||
{
|
|
||||||
id: showSubTimer
|
|
||||||
interval: 250
|
|
||||||
function restartTimer()
|
|
||||||
{
|
|
||||||
restart();
|
|
||||||
running = Qt.binding(function() { return materialTypeButton.containsMouse; });
|
|
||||||
hideSubTimer.running = false;
|
|
||||||
}
|
|
||||||
onTriggered: colorPopup.open()
|
|
||||||
}
|
|
||||||
Timer
|
|
||||||
{
|
|
||||||
id: hideSubTimer
|
|
||||||
interval: 250
|
|
||||||
function restartTimer() //Restart but re-evaluate the running property then.
|
|
||||||
{
|
|
||||||
restart();
|
|
||||||
running = Qt.binding(function() { return !materialTypeButton.containsMouse && !colorPopup.itemHovered > 0; });
|
|
||||||
showSubTimer.running = false;
|
|
||||||
}
|
|
||||||
onTriggered: colorPopup.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
Popup
|
|
||||||
{
|
|
||||||
id: colorPopup
|
|
||||||
width: materialColorsList.width + padding * 2
|
|
||||||
height: materialColorsList.height + padding * 2
|
|
||||||
onOpened:
|
|
||||||
{
|
|
||||||
// This will be resolved before opening the popup if directly assigned to the properties
|
|
||||||
// This forces these values to update whenever a popup is opened
|
|
||||||
var popupHeight = model.colors.count * UM.Theme.getSize("menu").height
|
|
||||||
var parentGlobalY = parent.mapToItem(null, 0, 0).y
|
|
||||||
var overflowY = (parentGlobalY + popupHeight) - mainWindow.height
|
|
||||||
y = overflowY > 0 ? - overflowY - UM.Theme.getSize("default_lining").height: - UM.Theme.getSize("default_lining").height
|
|
||||||
|
|
||||||
var parentGlobalX = materialTypesList.mapToItem(null, 0, 0).x
|
|
||||||
var overflowX = (parentGlobalX + parent.width + colorPopup.width) - mainWindow.width
|
|
||||||
x = overflowX > 0 ? parent.width - overflowX : parent.width
|
|
||||||
|
|
||||||
var popupHeight = model.colors.count * UM.Theme.getSize("menu").height
|
|
||||||
scrollView.height = popupHeight > mainWindow.height ? mainWindow.height: popupHeight
|
|
||||||
colorPopup.height = popupHeight > mainWindow.height ? mainWindow.height: popupHeight
|
|
||||||
}
|
|
||||||
|
|
||||||
property int itemHovered: 0
|
|
||||||
padding: background.border.width
|
|
||||||
|
|
||||||
background: Rectangle
|
|
||||||
{
|
|
||||||
color: UM.Theme.getColor("main_background")
|
|
||||||
border.color: UM.Theme.getColor("lining")
|
|
||||||
border.width: UM.Theme.getSize("default_lining").width
|
|
||||||
}
|
|
||||||
ScrollView
|
|
||||||
{
|
|
||||||
id: scrollView
|
|
||||||
width: UM.Theme.getSize("menu").width + scrollbar.width
|
|
||||||
height: parent.height
|
height: parent.height
|
||||||
clip: true
|
width: parent.width
|
||||||
|
|
||||||
ScrollBar.vertical: UM.ScrollBar
|
Item
|
||||||
{
|
{
|
||||||
id: scrollbar
|
// Spacer
|
||||||
anchors.right: parent.right
|
width: UM.Theme.getSize("default_margin").width
|
||||||
anchors.top: parent.top
|
|
||||||
anchors.bottom: parent.bottom
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Column
|
UM.Label
|
||||||
{
|
{
|
||||||
id: materialColorsList
|
text: model.name
|
||||||
property var brandColors: model.colors
|
Layout.fillWidth: true
|
||||||
width: UM.Theme.getSize("menu").width
|
Layout.fillHeight: true
|
||||||
|
elide: Label.ElideRight
|
||||||
|
wrapMode: Text.NoWrap
|
||||||
|
}
|
||||||
|
|
||||||
|
Item
|
||||||
|
{
|
||||||
|
Layout.fillWidth: true
|
||||||
|
}
|
||||||
|
|
||||||
|
UM.ColorImage
|
||||||
|
{
|
||||||
|
height: UM.Theme.getSize("default_arrow").height
|
||||||
|
width: UM.Theme.getSize("default_arrow").width
|
||||||
|
color: UM.Theme.getColor("setting_control_text")
|
||||||
|
source: UM.Theme.getIcon("ChevronSingleRight")
|
||||||
|
}
|
||||||
|
|
||||||
|
Item
|
||||||
|
{
|
||||||
|
// Right side margin
|
||||||
|
width: UM.Theme.getSize("default_margin").width
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MouseArea
|
||||||
|
{
|
||||||
|
id: materialTypeButton
|
||||||
|
anchors.fill: parent
|
||||||
|
|
||||||
|
hoverEnabled: true
|
||||||
|
acceptedButtons: Qt.NoButton
|
||||||
|
|
||||||
|
onEntered:
|
||||||
|
{
|
||||||
|
menuPopup.itemHovered += 1;
|
||||||
|
showSubTimer.restartTimer();
|
||||||
|
}
|
||||||
|
onExited:
|
||||||
|
{
|
||||||
|
menuPopup.itemHovered -= 1;
|
||||||
|
hideSubTimer.restartTimer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Timer
|
||||||
|
{
|
||||||
|
id: showSubTimer
|
||||||
|
interval: 250
|
||||||
|
function restartTimer()
|
||||||
|
{
|
||||||
|
restart();
|
||||||
|
running = Qt.binding(function() { return materialTypeButton.containsMouse; });
|
||||||
|
hideSubTimer.running = false;
|
||||||
|
}
|
||||||
|
onTriggered: colorPopup.open()
|
||||||
|
}
|
||||||
|
Timer
|
||||||
|
{
|
||||||
|
id: hideSubTimer
|
||||||
|
interval: 250
|
||||||
|
function restartTimer() //Restart but re-evaluate the running property then.
|
||||||
|
{
|
||||||
|
restart();
|
||||||
|
running = Qt.binding(function() { return !materialTypeButton.containsMouse && !colorPopup.itemHovered > 0; });
|
||||||
|
showSubTimer.running = false;
|
||||||
|
}
|
||||||
|
onTriggered: colorPopup.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
Popup
|
||||||
|
{
|
||||||
|
id: colorPopup
|
||||||
|
width: materialColorsList.width + padding * 2
|
||||||
|
height: materialColorsList.height + padding * 2
|
||||||
|
onOpened:
|
||||||
|
{
|
||||||
|
// This will be resolved before opening the popup if directly assigned to the properties
|
||||||
|
// This forces these values to update whenever a popup is opened
|
||||||
|
var popupHeight = model.colors.count * UM.Theme.getSize("menu").height
|
||||||
|
var parentGlobalY = parent.mapToItem(null, 0, 0).y
|
||||||
|
var overflowY = (parentGlobalY + popupHeight) - mainWindow.height
|
||||||
|
y = overflowY > 0 ? - overflowY - UM.Theme.getSize("default_lining").height: - UM.Theme.getSize("default_lining").height
|
||||||
|
|
||||||
|
var parentGlobalX = materialTypesList.mapToItem(null, 0, 0).x
|
||||||
|
var overflowX = (parentGlobalX + parent.width + colorPopup.width) - mainWindow.width
|
||||||
|
x = overflowX > 0 ? parent.width - overflowX : parent.width
|
||||||
|
|
||||||
|
scrollView.height = popupHeight > mainWindow.height ? mainWindow.height: popupHeight
|
||||||
|
colorPopup.height = popupHeight > mainWindow.height ? mainWindow.height: popupHeight
|
||||||
|
}
|
||||||
|
|
||||||
|
property int itemHovered: 0
|
||||||
|
padding: background.border.width
|
||||||
|
|
||||||
|
background: Rectangle
|
||||||
|
{
|
||||||
|
color: UM.Theme.getColor("main_background")
|
||||||
|
border.color: UM.Theme.getColor("lining")
|
||||||
|
border.width: UM.Theme.getSize("default_lining").width
|
||||||
|
}
|
||||||
|
ScrollView
|
||||||
|
{
|
||||||
|
id: scrollView
|
||||||
|
width: UM.Theme.getSize("menu").width + scrollbar.width
|
||||||
height: parent.height
|
height: parent.height
|
||||||
spacing: 0
|
clip: true
|
||||||
|
|
||||||
Repeater
|
ScrollBar.vertical: UM.ScrollBar
|
||||||
{
|
{
|
||||||
model: parent.brandColors
|
id: scrollbar
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.top: parent.top
|
||||||
|
anchors.bottom: parent.bottom
|
||||||
|
}
|
||||||
|
|
||||||
delegate: Rectangle
|
Column
|
||||||
|
{
|
||||||
|
id: materialColorsList
|
||||||
|
property var brandColors: model.colors
|
||||||
|
width: UM.Theme.getSize("menu").width
|
||||||
|
height: parent.height
|
||||||
|
spacing: 0
|
||||||
|
|
||||||
|
Repeater
|
||||||
{
|
{
|
||||||
height: UM.Theme.getSize("menu").height
|
model: parent.brandColors
|
||||||
width: parent.width
|
|
||||||
|
|
||||||
// color: materialColorButton.containsMouse ? UM.Theme.getColor("background_2") : UM.Theme.getColor("background_1")
|
delegate: Rectangle
|
||||||
|
|
||||||
Rectangle
|
|
||||||
{
|
{
|
||||||
height: parent.height
|
height: UM.Theme.getSize("menu").height
|
||||||
width: parent.width
|
width: parent.width
|
||||||
opacity: materialBrandMenu.enabled ? 1 : 0.5
|
|
||||||
anchors.fill: parent
|
|
||||||
|
|
||||||
//Checkmark, if the material is selected.
|
color: materialColorButton.containsMouse ? UM.Theme.getColor("background_2") : UM.Theme.getColor("background_1")
|
||||||
UM.ColorImage
|
|
||||||
|
Rectangle
|
||||||
{
|
{
|
||||||
id: checkmark
|
height: parent.height
|
||||||
visible: model.id === materialMenu.activeMaterialId
|
width: parent.width
|
||||||
height: UM.Theme.getSize("default_arrow").height
|
opacity: materialBrandMenu.enabled ? 1 : 0.5
|
||||||
width: height
|
anchors.fill: parent
|
||||||
anchors.left: parent.left
|
|
||||||
anchors.leftMargin: UM.Theme.getSize("default_margin").width
|
//Checkmark, if the material is selected.
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
UM.ColorImage
|
||||||
source: UM.Theme.getIcon("Check", "low")
|
{
|
||||||
color: UM.Theme.getColor("setting_control_text")
|
id: checkmark
|
||||||
|
visible: model.id === materialMenu.activeMaterialId
|
||||||
|
height: UM.Theme.getSize("default_arrow").height
|
||||||
|
width: height
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.leftMargin: UM.Theme.getSize("default_margin").width
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
source: UM.Theme.getIcon("Check", "low")
|
||||||
|
color: UM.Theme.getColor("setting_control_text")
|
||||||
|
}
|
||||||
|
|
||||||
|
UM.Label
|
||||||
|
{
|
||||||
|
text: model.name
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.leftMargin: UM.Theme.getSize("default_margin").width + UM.Theme.getSize("default_arrow").height
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.rightMargin: UM.Theme.getSize("default_margin").width
|
||||||
|
|
||||||
|
elide: Label.ElideRight
|
||||||
|
wrapMode: Text.NoWrap
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UM.Label
|
MouseArea
|
||||||
{
|
{
|
||||||
text: model.name
|
id: materialColorButton
|
||||||
anchors.left: parent.left
|
anchors.fill: parent
|
||||||
anchors.leftMargin: UM.Theme.getSize("default_margin").width + UM.Theme.getSize("default_arrow").height
|
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
|
||||||
anchors.right: parent.right
|
|
||||||
anchors.rightMargin: UM.Theme.getSize("default_margin").width
|
|
||||||
|
|
||||||
elide: Label.ElideRight
|
hoverEnabled: true
|
||||||
wrapMode: Text.NoWrap
|
onClicked:
|
||||||
}
|
{
|
||||||
}
|
Cura.MachineManager.setMaterial(extruderIndex, model.container_node);
|
||||||
|
menuPopup.close();
|
||||||
MouseArea
|
colorPopup.close();
|
||||||
{
|
materialMenu.close();
|
||||||
id: materialColorButton
|
}
|
||||||
anchors.fill: parent
|
onEntered:
|
||||||
|
{
|
||||||
hoverEnabled: true
|
menuPopup.itemHovered += 1;
|
||||||
onClicked:
|
colorPopup.itemHovered += 1;
|
||||||
{
|
}
|
||||||
Cura.MachineManager.setMaterial(extruderIndex, model.container_node);
|
onExited:
|
||||||
menuPopup.close();
|
{
|
||||||
colorPopup.close();
|
menuPopup.itemHovered -= 1;
|
||||||
materialMenu.close();
|
colorPopup.itemHovered -= 1;
|
||||||
}
|
}
|
||||||
onEntered:
|
|
||||||
{
|
|
||||||
menuPopup.itemHovered += 1;
|
|
||||||
colorPopup.itemHovered += 1;
|
|
||||||
}
|
|
||||||
onExited:
|
|
||||||
{
|
|
||||||
menuPopup.itemHovered -= 1;
|
|
||||||
colorPopup.itemHovered -= 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user