fix(StatusBaseButton): Mouse events ignored when button is disabled (#707)

* fix(StatusBaseButton): Mouse events ignored when button is disabled
This commit is contained in:
Igor Sirotin 2022-06-07 14:56:45 +03:00 committed by GitHub
parent 0b855bfb48
commit 890ef86e1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 37 deletions

View File

@ -4,6 +4,7 @@ import QtQuick.Dialogs 1.3
import StatusQ.Controls 0.1 import StatusQ.Controls 0.1
import StatusQ.Popups 0.1 import StatusQ.Popups 0.1
import StatusQ.Core 0.1
import StatusQ.Core.Theme 0.1 import StatusQ.Core.Theme 0.1
Column { Column {
@ -317,4 +318,5 @@ Column {
colorSelected = true; colorSelected = true;
} }
} }
} }

View File

@ -86,14 +86,16 @@ Rectangle {
radius: size !== StatusBaseButton.Size.Tiny ? 8 : 6 radius: size !== StatusBaseButton.Size.Tiny ? 8 : 6
color: { color: {
if (statusBaseButton.enabled) { if (statusBaseButton.enabled)
return sensor.containsMouse || highlighted ? hoverColor return sensor.containsMouse || highlighted ? hoverColor
: normalColor : normalColor;
} else { return disaledColor
return disaledColor
}
} }
QtObject {
id: d
readonly property color textColor: statusBaseButton.enabled ? statusBaseButton.textColor : statusBaseButton.disabledTextColor
}
MouseArea { MouseArea {
id: sensor id: sensor
@ -102,17 +104,16 @@ Rectangle {
cursorShape: loading ? Qt.ArrowCursor cursorShape: loading ? Qt.ArrowCursor
: Qt.PointingHandCursor : Qt.PointingHandCursor
hoverEnabled: !loading
enabled: !loading
hoverEnabled: true
enabled: !loading && statusBaseButton.enabled
Loader { Loader {
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
active: loading active: loading
sourceComponent: StatusLoadingIndicator { sourceComponent: StatusLoadingIndicator {
color: statusBaseButton.enabled ? textColor color: d.textColor
: disabledTextColor
} // Indicator } // Indicator
} // Loader } // Loader
@ -130,8 +131,7 @@ Rectangle {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
opacity: !loading && statusBaseButton.icon.name !== "" opacity: !loading && statusBaseButton.icon.name !== ""
visible: statusBaseButton.icon.name !== "" visible: statusBaseButton.icon.name !== ""
color: statusBaseButton.enabled ? textColor color: d.textColor
: disabledTextColor
} // Icon } // Icon
StatusBaseText { StatusBaseText {
id: label id: label
@ -139,8 +139,7 @@ Rectangle {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
font.pixelSize: size === StatusBaseButton.Size.Large ? 15 : 13 // by design font.pixelSize: size === StatusBaseButton.Size.Large ? 15 : 13 // by design
color: statusBaseButton.enabled ? textColor color: d.textColor
: disabledTextColor
} // Text } // Text
} // Ro } // Ro

View File

@ -48,9 +48,6 @@ Rectangle {
Primary, Primary,
Secondary Secondary
} }
/// Implementation /// Implementation
QtObject { QtObject {
@ -84,27 +81,31 @@ Rectangle {
} }
} }
QtObject {
id: d
readonly property color iconColor: statusRoundButton.enabled ? statusRoundButton.icon.color : statusRoundButton.icon.disabledColor
}
implicitWidth: 44 implicitWidth: 44
implicitHeight: 44 implicitHeight: 44
radius: width / 2; radius: width / 2;
color: { color: {
if (statusRoundButton.enabled) { if (statusRoundButton.enabled)
return sensor.containsMouse || highlighted ? backgroundSettings.hoverColor return sensor.containsMouse || highlighted ? backgroundSettings.hoverColor
: backgroundSettings.color : backgroundSettings.color;
} else { return backgroundSettings.disabledColor
return backgroundSettings.disabledColor
}
} }
MouseArea { MouseArea {
id: sensor id: sensor
anchors.fill: parent anchors.fill: parent
cursorShape: loading ? Qt.ArrowCursor cursorShape: loading ? Qt.ArrowCursor
: Qt.PointingHandCursor : Qt.PointingHandCursor
hoverEnabled: !loading
enabled: !loading
hoverEnabled: true
enabled: !loading && statusRoundButton.enabled
StatusIcon { StatusIcon {
id: statusIcon id: statusIcon
@ -117,25 +118,13 @@ Rectangle {
width: statusRoundButton.icon.width width: statusRoundButton.icon.width
height: statusRoundButton.icon.height height: statusRoundButton.icon.height
color: { color: d.iconColor
if (statusRoundButton.enabled) {
return statusRoundButton.icon.color
} else {
return statusRoundButton.icon.disabledColor
}
}
} // Icon } // Icon
Loader { Loader {
active: loading active: loading
anchors.centerIn: parent anchors.centerIn: parent
sourceComponent: StatusLoadingIndicator { sourceComponent: StatusLoadingIndicator {
color: { color: d.iconColor
if (statusRoundButton.enabled) {
return statusRoundButton.icon.color
} else {
return statusRoundButton.icon.disabledColor
}
}
} // Indicator } // Indicator
} // Loader } // Loader