Nest all controls inside the mousearea of SettingItem

This makes hover events work properly without all the hassle
This commit is contained in:
Arjen Hiemstra 2016-05-16 18:16:08 +02:00
parent f5e97c5001
commit 3531e4c3e8

View File

@ -16,7 +16,7 @@ Item {
height: UM.Theme.getSize("section").height; height: UM.Theme.getSize("section").height;
property alias contents: controlContainer.children; property alias contents: controlContainer.children;
property bool hovered: false property alias hovered: mouse.containsMouse
signal contextMenuRequested() signal contextMenuRequested()
signal showTooltip(string text); signal showTooltip(string text);
@ -52,118 +52,103 @@ Item {
onTriggered: base.showTooltip(definition.description); onTriggered: base.showTooltip(definition.description);
} }
}
Label Label
{ {
id: label; id: label;
anchors.left: parent.left; anchors.left: parent.left;
anchors.leftMargin: (UM.Theme.getSize("section_icon_column").width + 5) + ((definition.depth - 1) * UM.Theme.getSize("setting_control_depth_margin").width) anchors.leftMargin: (UM.Theme.getSize("section_icon_column").width + 5) + ((definition.depth - 1) * UM.Theme.getSize("setting_control_depth_margin").width)
anchors.right: settingControls.left; anchors.right: settingControls.left;
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
height: UM.Theme.getSize("section").height; height: UM.Theme.getSize("section").height;
verticalAlignment: Text.AlignVCenter; verticalAlignment: Text.AlignVCenter;
text: definition.label text: definition.label
elide: Text.ElideMiddle; elide: Text.ElideMiddle;
color: UM.Theme.getColor("setting_control_text"); color: UM.Theme.getColor("setting_control_text");
font: UM.Theme.getFont("default"); font: UM.Theme.getFont("default");
}
Row
{
id: settingControls
height: parent.height / 2
spacing: UM.Theme.getSize("default_margin").width / 2
anchors {
right: controlContainer.left
rightMargin: UM.Theme.getSize("default_margin").width / 2
verticalCenter: parent.verticalCenter
} }
UM.SimpleButton Row
{ {
id: revertButton; id: settingControls
// visible: base.overridden && base.is_enabled height: parent.height / 2
spacing: UM.Theme.getSize("default_margin").width / 2
height: parent.height; anchors {
width: height; right: controlContainer.left
rightMargin: UM.Theme.getSize("default_margin").width / 2
backgroundColor: UM.Theme.getColor("setting_control"); verticalCenter: parent.verticalCenter
hoverBackgroundColor: UM.Theme.getColor("setting_control_highlight")
color: UM.Theme.getColor("setting_control_button")
hoverColor: UM.Theme.getColor("setting_control_button_hover")
iconSource: UM.Theme.getIcon("reset")
onClicked: {
base.resetRequested()
controlContainer.notifyReset();
} }
onEntered: base.showTooltip(catalog.i18nc("@label", "This setting has a value that is different from the profile.\n\nClick to restore the value of the profile.")) UM.SimpleButton
onExited:
{ {
if(controlContainer.item && controlContainer.item.hovered) id: revertButton;
{
return; visible: propertyProvider.properties.state == "InstanceState.User"
height: parent.height;
width: height;
backgroundColor: UM.Theme.getColor("setting_control");
hoverBackgroundColor: UM.Theme.getColor("setting_control_highlight")
color: UM.Theme.getColor("setting_control_button")
hoverColor: UM.Theme.getColor("setting_control_button_hover")
iconSource: UM.Theme.getIcon("reset")
onClicked: {
base.resetRequested()
controlContainer.notifyReset();
} }
base.hovered = false; onEntered: base.showTooltip(catalog.i18nc("@label", "This setting has a value that is different from the profile.\n\nClick to restore the value of the profile."))
base.hideTooltip(); onExited: base.showTooltip(definition.description);
} }
UM.SimpleButton
{
// This button shows when the setting has an inherited function, but is overriden by profile.
id: inheritButton;
//visible: has_profile_value && base.has_inherit_function && base.is_enabled
visible: propertyProvider.properties.state == "InstanceState.User"
height: parent.height;
width: height;
onClicked: {
base.resetToDefaultRequested();
controlContainer.notifyReset();
}
backgroundColor: UM.Theme.getColor("setting_control");
hoverBackgroundColor: UM.Theme.getColor("setting_control_highlight")
color: UM.Theme.getColor("setting_control_button")
hoverColor: UM.Theme.getColor("setting_control_button_hover")
iconSource: UM.Theme.getIcon("notice");
onEntered: base.showTooltip(catalog.i18nc("@label", "This setting is normally calculated, but it currently has an absolute value set.\n\nClick to restore the calculated value."))
onExited: base.showTooltip(definition.description);
}
} }
UM.SimpleButton Item
{ {
// This button shows when the setting has an inherited function, but is overriden by profile. id: controlContainer;
id: inheritButton;
// visible: has_profile_value && base.has_inherit_function && base.is_enabled anchors.right: parent.right;
height: parent.height; anchors.rightMargin: UM.Theme.getSize("default_margin").width
width: height; anchors.verticalCenter: parent.verticalCenter;
width: UM.Theme.getSize("setting_control").width;
onClicked: { height: UM.Theme.getSize("setting_control").height
base.resetToDefaultRequested();
controlContainer.notifyReset();
}
backgroundColor: UM.Theme.getColor("setting_control");
hoverBackgroundColor: UM.Theme.getColor("setting_control_highlight")
color: UM.Theme.getColor("setting_control_button")
hoverColor: UM.Theme.getColor("setting_control_button_hover")
iconSource: UM.Theme.getIcon("notice");
onEntered: base.showTooltip(catalog.i18nc("@label", "This setting is normally calculated, but it currently has an absolute value set.\n\nClick to restore the calculated value."))
onExited: {
if(controlContainer.item && controlContainer.item.hovered) {
return;
}
base.hovered = false;
base.hideTooltip();
}
} }
}
Item
{
id: controlContainer;
anchors.right: parent.right;
anchors.rightMargin: UM.Theme.getSize("default_margin").width
anchors.verticalCenter: parent.verticalCenter;
width: UM.Theme.getSize("setting_control").width;
height: UM.Theme.getSize("setting_control").height
} }
UM.I18nCatalog { id: catalog; name: "cura" } UM.I18nCatalog { id: catalog; name: "cura" }