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"
|
2020-10-05 15:08:26 +00:00
|
|
|
property color color: Style.current.buttonForegroundColor
|
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
|
|
|
|
font.weight: Font.Medium
|
|
|
|
implicitHeight: size === "small" ? 38 : 44
|
2020-10-19 20:26:16 +00:00
|
|
|
implicitWidth: buttonLabel.implicitWidth + 2 * Style.current.padding +
|
|
|
|
(iconLoader.active ? iconLoader.width : 0)
|
2020-08-25 09:00:03 +00:00
|
|
|
enabled: state === "default"
|
|
|
|
|
|
|
|
contentItem: Item {
|
|
|
|
anchors.fill: parent
|
2020-10-19 20:26:16 +00:00
|
|
|
|
|
|
|
Loader {
|
|
|
|
id: iconLoader
|
|
|
|
active: !!control.icon && !!control.icon.source
|
|
|
|
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 {
|
|
|
|
anchors.fill: iconImg
|
|
|
|
source: iconImg
|
|
|
|
color: control.icon.color
|
|
|
|
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
|
|
|
|
anchors.fill: parent
|
2020-10-03 19:00:07 +00:00
|
|
|
color: !enabled ? Style.current.buttonDisabledForegroundColor : 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 {
|
|
|
|
radius: Style.current.radius
|
|
|
|
anchors.fill: parent
|
|
|
|
color: {
|
|
|
|
if (type === "secondary") {
|
|
|
|
return hovered ? Style.current.buttonBackgroundColor : "transparent"
|
|
|
|
}
|
|
|
|
return !enabled ? Style.current.buttonDisabledBackgroundColor :
|
|
|
|
hovered ? Qt.darker(Style.current.buttonBackgroundColor, 1.1) :
|
|
|
|
Style.current.buttonBackgroundColor
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
anchors.fill: parent
|
|
|
|
onPressed: mouse.accepted = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|