fix(StatusButton): fix UI issues with component

StatusButton has a lot of issues when it comes to consistent behaviour
and look & feel. This includes things like calculating incorrect
hover colors as well as not being flexible enough to be used in various
scenarios

This commit changes StatusButton so that it's able to handle outlined
versions of warn buttons, calculates proper colors and more.

Many of these changes introduce heuristics to make things work.
In the long run, we should revisit the different variants that exists
(primary, secondary, outlined, warn etc) to encode them properly
in the API.
This commit is contained in:
Pascal Precht 2021-01-28 17:16:16 +01:00 committed by Pascal Precht
parent 200285399d
commit 52eb8dd852
3 changed files with 31 additions and 5 deletions

View File

@ -60,6 +60,7 @@ Theme {
property color buttonDisabledForegroundColor: buttonSecondaryColor property color buttonDisabledForegroundColor: buttonSecondaryColor
property color buttonDisabledBackgroundColor: evenDarkerGrey property color buttonDisabledBackgroundColor: evenDarkerGrey
property color buttonWarnBackgroundColor: "#FFEAEE" property color buttonWarnBackgroundColor: "#FFEAEE"
property color buttonHoveredWarnBackgroundColor: red
property color buttonHoveredBackgroundColor: blue property color buttonHoveredBackgroundColor: blue
property color roundedButtonForegroundColor: white property color roundedButtonForegroundColor: white

View File

@ -59,6 +59,7 @@ Theme {
property color buttonDisabledForegroundColor: buttonSecondaryColor property color buttonDisabledForegroundColor: buttonSecondaryColor
property color buttonDisabledBackgroundColor: grey property color buttonDisabledBackgroundColor: grey
property color buttonWarnBackgroundColor: "#FFEAEE" property color buttonWarnBackgroundColor: "#FFEAEE"
property color buttonHoveredWarnBackgroundColor: red
property color buttonHoveredBackgroundColor: blue property color buttonHoveredBackgroundColor: blue
property color roundedButtonForegroundColor: buttonForegroundColor property color roundedButtonForegroundColor: buttonForegroundColor

View File

@ -12,14 +12,23 @@ Button {
property color color: type === "warn" ? Style.current.danger : Style.current.buttonForegroundColor property color color: type === "warn" ? Style.current.danger : Style.current.buttonForegroundColor
property color bgColor: type === "warn" ? Style.current.buttonWarnBackgroundColor : Style.current.buttonBackgroundColor property color bgColor: type === "warn" ? Style.current.buttonWarnBackgroundColor : Style.current.buttonBackgroundColor
property color borderColor: color property color borderColor: color
property color bgHoverColor: bgColor !== Style.current.transparent ? Qt.darker(control.bgColor, 1.1) : property color hoveredBorderColor
type === "warn" ? Style.current.buttonWarnBackgroundColor : Style.current.buttonBackgroundColor property color bgHoverColor: {
if (type === "warn") {
if (showBorder) {
return Style.current.buttonWarnBackgroundColor
}
return Utils.setColorAlpha(Style.current.buttonHoveredWarnBackgroundColor, 0.2)
}
return Utils.setColorAlpha(Style.current.buttonHoveredBackgroundColor, 0.2)
}
property bool disableColorOverlay: false property bool disableColorOverlay: false
property bool showBorder: false property bool showBorder: false
property int iconRotation: 0 property int iconRotation: 0
id: control id: control
font.pixelSize: size === "small" ? 13 : 15 font.pixelSize: size === "small" ? 13 : 15
font.family: Style.current.fontRegular.name
font.weight: Font.Medium font.weight: Font.Medium
implicitHeight: flat ? 32 : (size === "small" ? 38 : 44) implicitHeight: flat ? 32 : (size === "small" ? 38 : 44)
implicitWidth: buttonLabel.implicitWidth + (flat ? 3* Style.current.halfPadding : 2 * Style.current.padding) + implicitWidth: buttonLabel.implicitWidth + (flat ? 3* Style.current.halfPadding : 2 * Style.current.padding) +
@ -69,8 +78,15 @@ Button {
anchors.right: iconLoader.active ? undefined : parent.right anchors.right: iconLoader.active ? undefined : parent.right
anchors.left: iconLoader.active ? iconLoader.right : parent.left anchors.left: iconLoader.active ? iconLoader.right : parent.left
anchors.leftMargin: iconLoader.active ? Style.current.smallPadding : 0 anchors.leftMargin: iconLoader.active ? Style.current.smallPadding : 0
color: !enabled ? Style.current.buttonDisabledForegroundColor : color: {
(type !== "warn" && (hovered || highlighted)) ? Style.current.blue : control.color if (!enabled) {
return Style.current.buttonDisabledForegroundColor
} else if (type !== "warn" && (hovered || highlighted)) {
return control.color !== Style.current.buttonForegroundColor ?
control.color : Style.current.blue
}
return control.color
}
visible: !loadingIndicator.active visible: !loadingIndicator.active
} }
@ -98,7 +114,15 @@ Button {
radius: Style.current.radius radius: Style.current.radius
anchors.fill: parent anchors.fill: parent
border.width: flat || showBorder ? 1 : 0 border.width: flat || showBorder ? 1 : 0
border.color: hovered || showBorder ? control.borderColor : Style.current.transparent border.color: {
if (hovered) {
return !!control.hoveredBorderColor ? control.hoveredBorderColor : control.borderColor
}
if (showBorder) {
return control.borderColor
}
return Style.current.transparent
}
color: { color: {
if (flat) { if (flat) {
return "transparent" return "transparent"