Fix hover & highlighting for the qualities& intent menu

CURA-6598
This commit is contained in:
Jaime van Kessel 2019-08-06 17:08:23 +02:00
parent 5ab31df738
commit 0891abf8af
2 changed files with 66 additions and 48 deletions

View file

@ -0,0 +1,47 @@
import QtQuick 2.0
import QtQuick.Controls 2.3
import Cura 1.6 as Cura
import UM 1.2 as UM
Button
{
// This is a work around for a qml issue. Since the default button uses a private implementation for contentItem
// (the so called IconText), which handles the mnemonic conversion (aka; ensuring that &Button) text property
// is rendered with the B underlined. Since we're also forced to mix controls 1.0 and 2.0 actions together,
// we need a special property for the text of the label if we do want it to be rendered correclty, but don't want
// another shortcut to be added (which will cause for "QQuickAction::event: Ambiguous shortcut overload: " to
// happen.
property string labelText: ""
id: button
hoverEnabled: true
background: Rectangle
{
id: backgroundRectangle
border.width: 1
border.color: button.checked ? UM.Theme.getColor("setting_control_border_highlight") : "transparent"
color: button.hovered ? UM.Theme.getColor("action_button_hovered") : "transparent"
}
// Workarround to ensure that the mnemonic highlighting happens correctly
function replaceText(txt)
{
var index = txt.indexOf("&")
if(index >= 0)
{
txt = txt.replace(txt.substr(index, 2), ("<u>" + txt.substr(index + 1, 1) + "</u>"))
}
return txt
}
contentItem: Label
{
id: textLabel
text: button.text != "" ? replaceText(button.text) : replaceText(button.labelText)
height: contentHeight
verticalAlignment: Text.AlignVCenter
anchors.left: button.left
anchors.leftMargin: UM.Theme.getSize("default_margin").width
}
}

View file

@ -52,9 +52,7 @@ Popup
anchors anchors
{ {
left: parent.left left: parent.left
leftMargin: defaultMargin
right: parent.right right: parent.right
rightMargin: defaultMargin
} }
Label Label
@ -64,6 +62,8 @@ Popup
height: visible ? contentHeight: 0 height: visible ? contentHeight: 0
enabled: false enabled: false
visible: qualitiesList.visibleChildren.length > 0 visible: qualitiesList.visibleChildren.length > 0
anchors.left: parent.left
anchors.leftMargin: UM.Theme.getSize("narrow_margin").width
} }
Column Column
@ -88,16 +88,16 @@ Popup
{ {
visible: false visible: false
model: subItemModel model: subItemModel
Button MenuButton
{ {
id: button id: button
onClicked: Cura.IntentManager.selectIntent(model.intent_category, model.quality_type) onClicked: Cura.IntentManager.selectIntent(model.intent_category, model.quality_type)
width: parent.width width: parent.width
height: buttonHeight
checkable: true checkable: true
visible: model.available visible: model.available
text: model.name + " - " + model.layer_height + " mm"
checked: checked:
{ {
if(Cura.MachineManager.hasCustomQuality) if(Cura.MachineManager.hasCustomQuality)
@ -108,34 +108,7 @@ Popup
return Cura.MachineManager.activeQualityType == model.quality_type && Cura.MachineManager.activeIntentCategory == model.intent_category return Cura.MachineManager.activeQualityType == model.quality_type && Cura.MachineManager.activeIntentCategory == model.intent_category
} }
ButtonGroup.group: buttonGroup ButtonGroup.group: buttonGroup
background: Item {}
contentItem: Item
{
Rectangle
{
id: checkmark
width: checkmarkSize
height: checkmarkSize
anchors.verticalCenter: parent.verticalCenter
color: "black"
visible: button.checked
}
Label
{
id: label
text: model.name + " - " + model.layer_height + " mm"
verticalAlignment: Text.AlignVCenter
anchors
{
left: checkmark.right
leftMargin: defaultMargin
top: parent.top
bottom: parent.bottom
right: parent.right
}
}
}
} }
} }
} }
@ -149,46 +122,43 @@ Popup
anchors.right: parent.right anchors.right: parent.right
color: borderColor color: borderColor
} }
Button MenuButton
{ {
text: Cura.Actions.addProfile.text labelText: Cura.Actions.addProfile.text
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: defaultMargin anchors.right: parent.right
enabled: Cura.Actions.addProfile.enabled enabled: Cura.Actions.addProfile.enabled
background: Item {}
onClicked: onClicked:
{ {
Cura.Actions.addProfile.trigger() Cura.Actions.addProfile.trigger()
popup.visible = false popup.visible = false
} }
} }
Button MenuButton
{ {
text: Cura.Actions.updateProfile.text labelText: Cura.Actions.updateProfile.text
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: defaultMargin anchors.right: parent.right
enabled: Cura.Actions.updateProfile.enabled enabled: Cura.Actions.updateProfile.enabled
background: Item {}
onClicked: onClicked:
{ {
popup.visible = false popup.visible = false
Cura.Actions.updateProfile.trigger() Cura.Actions.updateProfile.trigger()
} }
} }
Button MenuButton
{ {
text: catalog.i18nc("@action:button", "Discard current changes") text: catalog.i18nc("@action:button", "Discard current changes")
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: defaultMargin anchors.right: parent.right
enabled: Cura.MachineManager.hasUserSettings enabled: Cura.MachineManager.hasUserSettings
background: Item {}
onClicked: onClicked:
{ {
popup.visible = false popup.visible = false
@ -202,20 +172,19 @@ Popup
anchors.right: parent.right anchors.right: parent.right
color: borderColor color: borderColor
} }
Button
MenuButton
{ {
id: manageProfilesButton id: manageProfilesButton
text: Cura.Actions.manageProfiles.text text: Cura.Actions.manageProfiles.text
anchors anchors
{ {
left: parent.left left: parent.left
leftMargin: defaultMargin
right: parent.right right: parent.right
rightMargin: defaultMargin
} }
height: textLabel.contentHeight + 2 * UM.Theme.getSize("narrow_margin").height height: textLabel.contentHeight + 2 * UM.Theme.getSize("narrow_margin").height
background: Item {}
contentItem: Item contentItem: Item
{ {
width: manageProfilesButton.width width: manageProfilesButton.width
@ -224,6 +193,8 @@ Popup
id: textLabel id: textLabel
text: manageProfilesButton.text text: manageProfilesButton.text
height: contentHeight height: contentHeight
anchors.left: button.left
anchors.leftMargin: UM.Theme.getSize("default_margin").width
} }
Label Label
{ {