QmlDesigner: Cleanup alignment button related code

Change-Id: Ib6b20c5a3d0e92040bbb268be7a1a4df43e22f0f
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Henning Gruendl
2021-09-24 17:23:28 +02:00
committed by Henning Gründl
parent 0a8545c068
commit 0db724eb25
3 changed files with 79 additions and 83 deletions

View File

@@ -34,10 +34,10 @@ Row {
property string scope: "Text" property string scope: "Text"
property bool blueHighlight: false property bool blueHighlight: false
property variant backendValue: backendValues.horizontalAlignment property variant backendValue: backendValues.horizontalAlignment
property variant value: backendValue.enumeration property variant value: root.backendValue.enumeration
property bool baseStateFlag: isBaseState property bool baseStateFlag: isBaseState
property color __currentColor: blueHighlight ? StudioTheme.Values.themeIconColorInteraction property color __currentColor: root.blueHighlight ? StudioTheme.Values.themeIconColorInteraction
: StudioTheme.Values.themeIconColor : StudioTheme.Values.themeIconColor
onValueChanged: { onValueChanged: {
buttonAlignLeft.checked = true buttonAlignLeft.checked = true
@@ -45,45 +45,45 @@ Row {
buttonAlignRight.checked = false buttonAlignRight.checked = false
buttonAlignJustify.checked = false buttonAlignJustify.checked = false
if (value !== undefined) { if (root.value !== undefined) {
if (value === "AlignLeft") if (root.value === "AlignLeft")
buttonAlignLeft.checked = true buttonAlignLeft.checked = true
else if (value === "AlignHCenter") else if (root.value === "AlignHCenter")
buttonAlignHCenter.checked = true buttonAlignHCenter.checked = true
else if (value === "AlignRight") else if (root.value === "AlignRight")
buttonAlignRight.checked = true buttonAlignRight.checked = true
else if (value === "AlignJustify") else if (root.value === "AlignJustify")
buttonAlignJustify.checked = true buttonAlignJustify.checked = true
} }
evaluate() root.evaluate()
} }
property bool isInModel: { property bool isInModel: {
if (backendValue !== undefined && backendValue.isInModel !== undefined) if (root.backendValue !== undefined && root.backendValue.isInModel !== undefined)
return backendValue.isInModel return root.backendValue.isInModel
return false return false
} }
onIsInModelChanged: evaluate() onIsInModelChanged: root.evaluate()
property bool isInSubState: { property bool isInSubState: {
if (backendValue !== undefined && backendValue.isInSubState !== undefined) if (root.backendValue !== undefined && root.backendValue.isInSubState !== undefined)
return backendValue.isInSubState return root.backendValue.isInSubState
return false return false
} }
onIsInSubStateChanged: evaluate() onIsInSubStateChanged: root.evaluate()
function evaluate() { function evaluate() {
if (baseStateFlag) { if (root.baseStateFlag) {
if (backendValue !== null && backendValue.isInModel) if (root.backendValue !== null && root.backendValue.isInModel)
blueHighlight = true root.blueHighlight = true
else else
blueHighlight = false root.blueHighlight = false
} else { } else {
if (backendValue !== null && backendValue.isInSubState) if (root.backendValue !== null && root.backendValue.isInSubState)
blueHighlight = true root.blueHighlight = true
else else
blueHighlight = false root.blueHighlight = false
} }
} }
@@ -109,10 +109,10 @@ Row {
checkable: true checkable: true
autoExclusive: true autoExclusive: true
StudioControls.ButtonGroup.group: group StudioControls.ButtonGroup.group: group
iconColor: __currentColor iconColor: root.__currentColor
onClicked: { onClicked: {
if (checked) if (buttonAlignLeft.checked)
backendValue.setEnumeration(root.scope, "AlignLeft") root.backendValue.setEnumeration(root.scope, "AlignLeft")
} }
} }
@@ -122,10 +122,10 @@ Row {
checkable: true checkable: true
autoExclusive: true autoExclusive: true
StudioControls.ButtonGroup.group: group StudioControls.ButtonGroup.group: group
iconColor: __currentColor iconColor: root.__currentColor
onClicked: { onClicked: {
if (checked) if (buttonAlignHCenter.checked)
backendValue.setEnumeration(root.scope, "AlignHCenter") root.backendValue.setEnumeration(root.scope, "AlignHCenter")
} }
} }
@@ -135,10 +135,10 @@ Row {
checkable: true checkable: true
autoExclusive: true autoExclusive: true
StudioControls.ButtonGroup.group: group StudioControls.ButtonGroup.group: group
iconColor: __currentColor iconColor: root.__currentColor
onClicked: { onClicked: {
if (checked) if (buttonAlignRight.checked)
backendValue.setEnumeration(root.scope, "AlignRight") root.backendValue.setEnumeration(root.scope, "AlignRight")
} }
} }
@@ -148,10 +148,10 @@ Row {
checkable: true checkable: true
autoExclusive: true autoExclusive: true
StudioControls.ButtonGroup.group: group StudioControls.ButtonGroup.group: group
iconColor: __currentColor iconColor: root.__currentColor
onClicked: { onClicked: {
if (checked) if (buttonAlignRight.checked)
backendValue.setEnumeration(root.scope, "AlignJustify") root.backendValue.setEnumeration(root.scope, "AlignJustify")
} }
} }
} }

View File

@@ -34,53 +34,53 @@ Row {
property string scope: "Text" property string scope: "Text"
property bool blueHighlight: false property bool blueHighlight: false
property variant backendValue: backendValues.verticalAlignment property variant backendValue: backendValues.verticalAlignment
property variant value: backendValue.enumeration property variant value: root.backendValue.enumeration
property bool baseStateFlag: isBaseState property bool baseStateFlag: isBaseState
property color __currentColor: blueHighlight ? StudioTheme.Values.themeIconColorInteraction property color __currentColor: root.blueHighlight ? StudioTheme.Values.themeIconColorInteraction
: StudioTheme.Values.themeIconColor : StudioTheme.Values.themeIconColor
onValueChanged: { onValueChanged: {
buttonAlignTop.checked = true buttonAlignTop.checked = true
buttonAlignVCenter.checked = false buttonAlignVCenter.checked = false
buttonAlignBottom.checked = false buttonAlignBottom.checked = false
if (value !== undefined) { if (root.value !== undefined) {
if (value === "AlignTop") if (root.value === "AlignTop")
buttonAlignTop.checked = true buttonAlignTop.checked = true
else if (value === "AlignVCenter") else if (root.value === "AlignVCenter")
buttonAlignVCenter.checked = true buttonAlignVCenter.checked = true
else if (value === "AlignBottom") else if (root.value === "AlignBottom")
buttonAlignBottom.checked = true buttonAlignBottom.checked = true
} }
evaluate() root.evaluate()
} }
property bool isInModel: { property bool isInModel: {
if (backendValue !== undefined && backendValue.isInModel !== undefined) if (root.backendValue !== undefined && root.backendValue.isInModel !== undefined)
return backendValue.isInModel return root.backendValue.isInModel
return false return false
} }
onIsInModelChanged: evaluate() onIsInModelChanged: root.evaluate()
property bool isInSubState: { property bool isInSubState: {
if (backendValue !== undefined && backendValue.isInSubState !== undefined) if (root.backendValue !== undefined && root.backendValue.isInSubState !== undefined)
return backendValue.isInSubState return root.backendValue.isInSubState
return false return false
} }
onIsInSubStateChanged: evaluate() onIsInSubStateChanged: root.evaluate()
function evaluate() { function evaluate() {
if (baseStateFlag) { if (root.baseStateFlag) {
if (backendValue !== null && backendValue.isInModel) if (root.backendValue !== null && root.backendValue.isInModel)
blueHighlight = true root.blueHighlight = true
else else
blueHighlight = false root.blueHighlight = false
} else { } else {
if (backendValue !== null && backendValue.isInSubState) if (root.backendValue !== null && root.backendValue.isInSubState)
blueHighlight = true root.blueHighlight = true
else else
blueHighlight = false root.blueHighlight = false
} }
} }
@@ -108,10 +108,10 @@ Row {
checkable: true checkable: true
autoExclusive: true autoExclusive: true
StudioControls.ButtonGroup.group: group StudioControls.ButtonGroup.group: group
iconColor: __currentColor iconColor: root.__currentColor
onClicked: { onClicked: {
if (checked) if (buttonAlignTop.checked)
backendValue.setEnumeration(root.scope, "AlignTop") root.backendValue.setEnumeration(root.scope, "AlignTop")
} }
} }
StudioControls.AbstractButton { StudioControls.AbstractButton {
@@ -120,10 +120,10 @@ Row {
checkable: true checkable: true
autoExclusive: true autoExclusive: true
StudioControls.ButtonGroup.group: group StudioControls.ButtonGroup.group: group
iconColor: __currentColor iconColor: root.__currentColor
onClicked: { onClicked: {
if (checked) if (buttonAlignVCenter.checked)
backendValue.setEnumeration(root.scope, "AlignVCenter") root.backendValue.setEnumeration(root.scope, "AlignVCenter")
} }
} }
StudioControls.AbstractButton { StudioControls.AbstractButton {
@@ -132,10 +132,10 @@ Row {
checkable: true checkable: true
autoExclusive: true autoExclusive: true
StudioControls.ButtonGroup.group: group StudioControls.ButtonGroup.group: group
iconColor: __currentColor iconColor: root.__currentColor
onClicked: { onClicked: {
if (checked) if (buttonAlignBottom.checked)
backendValue.setEnumeration(root.scope, "AlignBottom") root.backendValue.setEnumeration(root.scope, "AlignBottom")
} }
} }
} }

View File

@@ -34,46 +34,42 @@ StudioControls.Button {
property variant backendValue property variant backendValue
property bool isHighlighted: false property bool isHighlighted: false
iconColor: isHighlighted ? StudioTheme.Values.themeIconColorInteraction iconColor: button.isHighlighted ? StudioTheme.Values.themeIconColorInteraction
: StudioTheme.Values.themeIconColor : StudioTheme.Values.themeIconColor
actionIndicatorVisible: true actionIndicatorVisible: true
checkable: true checkable: true
QtObject { QtObject {
id: innerObject id: innerObject
function evaluate() { function evaluate() {
if (innerObject.baseStateFlag) { if (innerObject.baseStateFlag) {
if (button.backendValue !== null if (button.backendValue !== null && innerObject.isInModel)
&& innerObject.isInModel) { button.isHighlighted = true
isHighlighted = true else
} else { button.isHighlighted = false
isHighlighted = false
}
} else { } else {
if (button.backendValue !== null if (button.backendValue !== null && innerObject.isInSubState)
&& innerObject.isInSubState) { button.isHighlighted = true
isHighlighted = true else
} else { button.isHighlighted = false
isHighlighted = false
}
} }
} }
property bool baseStateFlag: isBaseState property bool baseStateFlag: isBaseState
onBaseStateFlagChanged: evaluate() onBaseStateFlagChanged: innerObject.evaluate()
property bool isInModel: button.backendValue === undefined ? false property bool isInModel: button.backendValue === undefined ? false
: button.backendValue.isInModel : button.backendValue.isInModel
onIsInModelChanged: evaluate() onIsInModelChanged: innerObject.evaluate()
property bool isInSubState: button.backendValue === undefined ? false property bool isInSubState: button.backendValue === undefined ? false
: button.backendValue.isInSubState : button.backendValue.isInSubState
onIsInSubStateChanged: evaluate() onIsInSubStateChanged: innerObject.evaluate()
property variant theValue: button.backendValue === undefined ? 0 : button.backendValue.value property variant theValue: button.backendValue === undefined ? 0 : button.backendValue.value
onTheValueChanged: { onTheValueChanged: {
evaluate() innerObject.evaluate()
button.checked = innerObject.theValue button.checked = innerObject.theValue
} }
} }