2020-08-25 09:00:03 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
import QtQml 2.14
|
2020-10-19 20:26:16 +00:00
|
|
|
import QtGraphicalEffects 1.13
|
2020-08-25 09:00:03 +00:00
|
|
|
import "../../imports"
|
|
|
|
import "../../shared"
|
|
|
|
|
|
|
|
Button {
|
|
|
|
property string type: "primary"
|
|
|
|
property string size: "large"
|
2020-09-11 14:50:22 +00:00
|
|
|
property string state: "default"
|
2021-01-13 20:26:30 +00:00
|
|
|
property color color: type === "warn" ? Style.current.danger : Style.current.buttonForegroundColor
|
2021-01-25 15:51:37 +00:00
|
|
|
property color bgColor: type === "warn" ? Style.current.buttonWarnBackgroundColor : Style.current.buttonBackgroundColor
|
2021-01-11 20:59:05 +00:00
|
|
|
property color borderColor: color
|
2021-01-29 10:00:37 +00:00
|
|
|
property color hoveredBorderColor: color
|
|
|
|
property bool forceBgColorOnHover: false
|
|
|
|
property int borderRadius: Style.current.radius
|
2021-01-28 16:16:16 +00:00
|
|
|
property color bgHoverColor: {
|
|
|
|
if (type === "warn") {
|
|
|
|
if (showBorder) {
|
2021-03-16 19:19:48 +00:00
|
|
|
return Style.current.buttonOutlineHoveredWarnBackgroundColor
|
2021-01-28 16:16:16 +00:00
|
|
|
}
|
2021-03-26 17:57:30 +00:00
|
|
|
return Style.current.buttonHoveredWarnBackgroundColor
|
2021-01-28 16:16:16 +00:00
|
|
|
}
|
2021-03-26 17:57:30 +00:00
|
|
|
return Style.current.buttonBackgroundColorHover
|
2021-01-28 16:16:16 +00:00
|
|
|
}
|
2020-12-29 17:10:22 +00:00
|
|
|
property bool disableColorOverlay: false
|
2021-01-11 20:59:05 +00:00
|
|
|
property bool showBorder: false
|
2020-10-19 20:26:16 +00:00
|
|
|
property int iconRotation: 0
|
2020-08-25 09:00:03 +00:00
|
|
|
|
|
|
|
id: control
|
|
|
|
font.pixelSize: size === "small" ? 13 : 15
|
2021-01-28 16:16:16 +00:00
|
|
|
font.family: Style.current.fontRegular.name
|
2020-08-25 09:00:03 +00:00
|
|
|
font.weight: Font.Medium
|
2020-12-04 10:31:08 +00:00
|
|
|
implicitHeight: flat ? 32 : (size === "small" ? 38 : 44)
|
|
|
|
implicitWidth: buttonLabel.implicitWidth + (flat ? 3* Style.current.halfPadding : 2 * Style.current.padding) +
|
2020-10-19 20:26:16 +00:00
|
|
|
(iconLoader.active ? iconLoader.width : 0)
|
2020-08-25 09:00:03 +00:00
|
|
|
enabled: state === "default"
|
|
|
|
|
|
|
|
contentItem: Item {
|
2020-12-04 10:31:08 +00:00
|
|
|
id: content
|
2020-08-25 09:00:03 +00:00
|
|
|
anchors.fill: parent
|
2020-12-04 10:31:08 +00:00
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
2020-10-19 20:26:16 +00:00
|
|
|
|
|
|
|
Loader {
|
|
|
|
id: iconLoader
|
2020-10-26 14:21:41 +00:00
|
|
|
active: !!control.icon && !!control.icon.source.toString()
|
2020-10-19 20:26:16 +00:00
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.leftMargin: Style.current.halfPadding
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
|
|
|
sourceComponent: SVGImage {
|
|
|
|
id: iconImg
|
|
|
|
source: control.icon.source
|
|
|
|
height: control.icon.height
|
|
|
|
width: control.icon.width
|
|
|
|
fillMode: Image.PreserveAspectFit
|
|
|
|
rotation: control.iconRotation
|
|
|
|
|
|
|
|
ColorOverlay {
|
2020-12-29 17:10:22 +00:00
|
|
|
enabled: !control.disableColorOverlay
|
2020-10-19 20:26:16 +00:00
|
|
|
anchors.fill: iconImg
|
|
|
|
source: iconImg
|
2020-12-29 17:10:22 +00:00
|
|
|
color: control.disableColorOverlay ? "transparent" : buttonLabel.color
|
2020-10-19 20:26:16 +00:00
|
|
|
antialiasing: true
|
|
|
|
smooth: true
|
|
|
|
rotation: control.iconRotation
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-25 09:00:03 +00:00
|
|
|
Text {
|
|
|
|
id: buttonLabel
|
|
|
|
text: control.text
|
|
|
|
font: control.font
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
2020-10-21 18:47:42 +00:00
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
anchors.right: iconLoader.active ? undefined : parent.right
|
|
|
|
anchors.left: iconLoader.active ? iconLoader.right : parent.left
|
|
|
|
anchors.leftMargin: iconLoader.active ? Style.current.smallPadding : 0
|
2021-01-28 16:16:16 +00:00
|
|
|
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
|
|
|
|
}
|
2020-09-06 01:18:50 +00:00
|
|
|
visible: !loadingIndicator.active
|
2020-08-25 09:00:03 +00:00
|
|
|
}
|
|
|
|
|
2020-09-06 01:18:50 +00:00
|
|
|
|
|
|
|
Component {
|
|
|
|
id: loadingComponent
|
2020-09-11 14:50:22 +00:00
|
|
|
LoadingImage {}
|
2020-09-06 01:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Loader {
|
2020-08-25 09:00:03 +00:00
|
|
|
id: loadingIndicator
|
2020-09-06 01:18:50 +00:00
|
|
|
active: control.state === "pending"
|
|
|
|
sourceComponent: loadingComponent
|
2020-08-25 09:00:03 +00:00
|
|
|
height: loadingIndicator.visible ?
|
|
|
|
control.size === "large" ?
|
|
|
|
23 : 17
|
|
|
|
: 0
|
|
|
|
width: loadingIndicator.height
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
background: Rectangle {
|
2021-01-29 10:00:37 +00:00
|
|
|
radius: borderRadius
|
2020-08-25 09:00:03 +00:00
|
|
|
anchors.fill: parent
|
2021-01-11 20:59:05 +00:00
|
|
|
border.width: flat || showBorder ? 1 : 0
|
2021-01-28 16:16:16 +00:00
|
|
|
border.color: {
|
|
|
|
if (hovered) {
|
2021-01-29 10:00:37 +00:00
|
|
|
return control.hoveredBorderColor !== control.borderColor ? control.hoveredBorderColor : control.borderColor
|
2021-01-28 16:16:16 +00:00
|
|
|
}
|
2021-01-29 10:00:37 +00:00
|
|
|
if (showBorder && enabled) {
|
2021-01-28 16:16:16 +00:00
|
|
|
return control.borderColor
|
|
|
|
}
|
|
|
|
return Style.current.transparent
|
|
|
|
}
|
2020-08-25 09:00:03 +00:00
|
|
|
color: {
|
2020-12-04 10:31:08 +00:00
|
|
|
if (flat) {
|
2021-01-29 10:00:37 +00:00
|
|
|
return hovered && forceBgColorOnHover ? control.bgHoverColor : "transparent"
|
2020-12-04 10:31:08 +00:00
|
|
|
}
|
2020-08-25 09:00:03 +00:00
|
|
|
if (type === "secondary") {
|
2020-10-29 19:02:32 +00:00
|
|
|
return hovered ? control.bgColor : "transparent"
|
2020-08-25 09:00:03 +00:00
|
|
|
}
|
2021-01-25 15:51:37 +00:00
|
|
|
return !enabled ? (control.bgColor === Style.current.transparent ? control.bgColor : Style.current.buttonDisabledBackgroundColor) :
|
|
|
|
(hovered ? control.bgHoverColor : control.bgColor)
|
2020-08-25 09:00:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
anchors.fill: parent
|
|
|
|
onPressed: mouse.accepted = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|