mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-12 17:48:59 +08:00
Move popups back on screen after opening them.
CURA-6867
This commit is contained in:
parent
0a4c7869e6
commit
7174861bba
@ -17,6 +17,9 @@ UM.MainWindow
|
|||||||
{
|
{
|
||||||
id: base
|
id: base
|
||||||
|
|
||||||
|
property var main_window_height: base.height
|
||||||
|
readonly property var mainWindow: base
|
||||||
|
|
||||||
// Cura application window title
|
// Cura application window title
|
||||||
title:
|
title:
|
||||||
{
|
{
|
||||||
|
@ -94,23 +94,17 @@ Cura.MenuItem
|
|||||||
|
|
||||||
property var flipped: false
|
property var flipped: false
|
||||||
|
|
||||||
x: parent.width - UM.Theme.getSize("default_lining").width
|
onOpened:
|
||||||
y: {
|
{
|
||||||
var popupHeight = materialTypesModel.material_types.count * UM.Theme.getSize("menu").height
|
var popupHeight = materialTypesModel.material_types.count * UM.Theme.getSize("menu").height
|
||||||
var spaceToBottom = materialBrandMenu.parent.height - parent.y // Space from hovered item to bottom of list
|
var parentGlobalY = parent.mapToItem(null, 0, 0).y
|
||||||
|
var overflowY = (parentGlobalY + popupHeight) - mainWindow.height
|
||||||
|
y = overflowY > 0 ? -overflowY : 0
|
||||||
|
|
||||||
if (popupHeight < spaceToBottom)
|
var defaultX = parent.width - UM.Theme.getSize("default_lining").width
|
||||||
{
|
var parentGlobalX = parent.mapToItem(null, 0, 0).x
|
||||||
return -UM.Theme.getSize("default_lining").height
|
var overflowX = (parentGlobalX + defaultX + menuPopup.width) - mainWindow.width
|
||||||
}
|
x = overflowX > 0 ? overflowX : defaultX
|
||||||
else
|
|
||||||
{
|
|
||||||
// The popup is longer than the distance between the hovered item and the bottom of the item list.
|
|
||||||
// This pushes the popup upwards until the bottom lines up with the parent bottom.
|
|
||||||
// Only when popup is longer than the parent, the popup will flow out below the parent.
|
|
||||||
var topOfParent = parent.y + UM.Theme.getSize("narrow_margin").height
|
|
||||||
return -Math.min(parent.y - (materialBrandMenu.parent.height - popupHeight ), topOfParent)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
padding: background.border.width
|
padding: background.border.width
|
||||||
@ -248,39 +242,16 @@ Cura.MenuItem
|
|||||||
id: colorPopup
|
id: colorPopup
|
||||||
width: materialColorsList.width + padding * 2
|
width: materialColorsList.width + padding * 2
|
||||||
height: materialColorsList.height + padding * 2
|
height: materialColorsList.height + padding * 2
|
||||||
x: parent.width
|
onOpened:
|
||||||
y: {
|
{
|
||||||
// This popup will always try to stay within the vertical space of the parent of MaterialBrandMenu
|
|
||||||
// If it is larger than the parent, it will expand downwards.
|
|
||||||
var popupHeight = model.colors.count * UM.Theme.getSize("menu").height
|
var popupHeight = model.colors.count * UM.Theme.getSize("menu").height
|
||||||
var spaceToBottom = materialTypesList.height - parent.y // Space from hovered item to bottom of list
|
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
|
||||||
|
|
||||||
if (popupHeight < spaceToBottom)
|
var parentGlobalX = materialTypesList.mapToItem(null, 0, 0).x
|
||||||
{
|
var overflowX = (parentGlobalX + parent.width + colorPopup.width) - mainWindow.width
|
||||||
return -UM.Theme.getSize("default_lining").width
|
x = overflowX > 0 ? parent.width - overflowX : parent.width
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var yAlignedWithTopOfRootPopup = - materialBrandMenu.y - UM.Theme.getSize("default_lining").height
|
|
||||||
|
|
||||||
if (popupHeight > rootHeight && popupHeight > menuPopup.height)
|
|
||||||
{
|
|
||||||
// The popup is taller than the root material popup and the popup is taller than it's parent popup
|
|
||||||
// This means it should align with the top of the root popup
|
|
||||||
if (menuPopup.height < rootHeight)
|
|
||||||
{
|
|
||||||
//The root is larger than than the parent popup. Align with root top
|
|
||||||
return -materialBrandMenu.y - UM.Theme.getSize("default_lining").height
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// The parent popup is larger than the root we only have to align to the top of the parent
|
|
||||||
return -brandMaterialBase.y - UM.Theme.getSize("default_lining").height
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// The bottom of the popup is aligned with the bottom of the parent popup
|
|
||||||
return materialTypesList.height - parent.y - popupHeight - UM.Theme.getSize("default_lining").height
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
property int itemHovered: 0
|
property int itemHovered: 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user