2020-08-25 11:15:18 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
import QtGraphicalEffects 1.13
|
|
|
|
import QtQml 2.14
|
|
|
|
import "../../imports"
|
|
|
|
import "../../shared"
|
|
|
|
|
|
|
|
RoundButton {
|
2021-02-12 16:32:04 +00:00
|
|
|
property string type: "primary"
|
2020-08-25 11:15:18 +00:00
|
|
|
property string size: "large"
|
2020-11-11 14:46:13 +00:00
|
|
|
property int pressedIconRotation: 0
|
|
|
|
property alias iconX: iconImg.x
|
2020-08-25 11:15:18 +00:00
|
|
|
id: control
|
|
|
|
|
|
|
|
font.pixelSize: 15
|
|
|
|
font.weight: Font.Medium
|
|
|
|
|
2020-08-28 11:39:23 +00:00
|
|
|
implicitWidth: {
|
|
|
|
switch(size) {
|
|
|
|
case "large":
|
|
|
|
return 44
|
|
|
|
case "medium":
|
|
|
|
return 40
|
|
|
|
case "small":
|
|
|
|
return 32
|
|
|
|
default:
|
|
|
|
return 44
|
|
|
|
}
|
|
|
|
}
|
|
|
|
implicitHeight: implicitWidth
|
2020-11-11 14:46:13 +00:00
|
|
|
enabled: state === "default" || state === "pressed"
|
|
|
|
rotation: 0
|
|
|
|
state: "default"
|
|
|
|
states: [
|
|
|
|
State {
|
|
|
|
name: "default"
|
|
|
|
PropertyChanges {
|
|
|
|
target: iconColorOverlay
|
|
|
|
visible: true
|
|
|
|
rotation: 0
|
|
|
|
}
|
|
|
|
PropertyChanges {
|
|
|
|
target: loadingIndicator
|
|
|
|
active: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: "pressed"
|
|
|
|
PropertyChanges {
|
|
|
|
target: iconColorOverlay
|
|
|
|
rotation: control.pressedIconRotation
|
|
|
|
visible: true
|
|
|
|
}
|
|
|
|
PropertyChanges {
|
|
|
|
target: loadingIndicator
|
|
|
|
active: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: "pending"
|
|
|
|
PropertyChanges {
|
|
|
|
target: loadingIndicator
|
|
|
|
active: true
|
|
|
|
}
|
|
|
|
PropertyChanges {
|
|
|
|
target: iconColorOverlay
|
|
|
|
visible: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
transitions: [
|
|
|
|
Transition {
|
|
|
|
from: "default"
|
|
|
|
to: "pressed"
|
2020-08-25 11:15:18 +00:00
|
|
|
|
2020-11-11 14:46:13 +00:00
|
|
|
RotationAnimation {
|
|
|
|
duration: 150
|
|
|
|
direction: RotationAnimation.Clockwise
|
|
|
|
easing.type: Easing.InCubic
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
Transition {
|
|
|
|
from: "pressed"
|
|
|
|
to: "default"
|
|
|
|
RotationAnimation {
|
|
|
|
duration: 150
|
|
|
|
direction: RotationAnimation.Counterclockwise
|
|
|
|
easing.type: Easing.OutCubic
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2020-08-25 11:15:18 +00:00
|
|
|
|
2020-08-28 11:39:23 +00:00
|
|
|
icon.height: {
|
|
|
|
switch(size) {
|
|
|
|
case "large":
|
|
|
|
return 20
|
|
|
|
case "medium":
|
|
|
|
return 14
|
|
|
|
case "small":
|
|
|
|
return 12
|
|
|
|
default:
|
|
|
|
return 20
|
|
|
|
}
|
|
|
|
}
|
|
|
|
icon.width: {
|
|
|
|
switch(size) {
|
|
|
|
case "large":
|
|
|
|
return 20
|
|
|
|
case "medium":
|
|
|
|
return 14
|
|
|
|
case "small":
|
|
|
|
return 12
|
|
|
|
default:
|
|
|
|
return 20
|
|
|
|
}
|
|
|
|
}
|
2021-03-16 19:19:48 +00:00
|
|
|
icon.color: type === "secondary" ?
|
2021-02-12 16:32:04 +00:00
|
|
|
!enabled ?
|
2020-08-25 11:15:18 +00:00
|
|
|
Style.current.roundedButtonSecondaryDisabledForegroundColor :
|
|
|
|
Style.current.roundedButtonSecondaryForegroundColor
|
|
|
|
:
|
|
|
|
!enabled ?
|
2021-02-12 16:32:04 +00:00
|
|
|
Style.current.roundedButtonDisabledForegroundColor :
|
2020-08-25 11:15:18 +00:00
|
|
|
Style.current.roundedButtonForegroundColor
|
|
|
|
|
2020-08-28 11:39:23 +00:00
|
|
|
onIconChanged: {
|
|
|
|
icon.source = icon.name ? "../../app/img/" + icon.name + ".svg" : ""
|
|
|
|
}
|
|
|
|
|
2020-08-25 11:15:18 +00:00
|
|
|
background: Rectangle {
|
|
|
|
anchors.fill: parent
|
2021-03-16 19:19:48 +00:00
|
|
|
opacity: hovered && size === "large" && type !== "secondary" ? 0.2 : 1
|
2020-08-25 11:15:18 +00:00
|
|
|
color: {
|
2021-03-16 19:19:48 +00:00
|
|
|
if (size === "medium" || size === "small" || type === "secondary") {
|
2020-08-25 11:15:18 +00:00
|
|
|
return !enabled ? Style.current.roundedButtonSecondaryDisabledBackgroundColor :
|
2021-02-12 16:32:04 +00:00
|
|
|
hovered ? (control.type === "warn" ? Style.current.red : Style.current.roundedButtonSecondaryHoveredBackgroundColor) :
|
|
|
|
(control.type === "warn" ? Style.current.lightRed : Style.current.roundedButtonSecondaryBackgroundColor)
|
2020-08-25 11:15:18 +00:00
|
|
|
}
|
|
|
|
return !enabled ?
|
|
|
|
Style.current.roundedButtonDisabledBackgroundColor :
|
2021-02-12 16:32:04 +00:00
|
|
|
hovered ? (control.type === "warn" ? Style.current.red : Style.current.buttonHoveredBackgroundColor) :
|
|
|
|
(control.type === "warn" ? Style.current.lightRed : Style.current.roundedButtonBackgroundColor)
|
2020-08-25 11:15:18 +00:00
|
|
|
}
|
|
|
|
radius: parent.width / 2
|
|
|
|
}
|
|
|
|
|
2020-08-25 12:24:18 +00:00
|
|
|
contentItem: Item {
|
|
|
|
anchors.fill: parent
|
2020-08-25 11:15:18 +00:00
|
|
|
|
2020-09-25 12:15:13 +00:00
|
|
|
SVGImage {
|
2020-08-25 12:24:18 +00:00
|
|
|
id: iconImg
|
|
|
|
visible: false
|
|
|
|
source: control.icon.source
|
|
|
|
height: control.icon.height
|
|
|
|
width: control.icon.width
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
fillMode: Image.PreserveAspectFit
|
|
|
|
}
|
|
|
|
|
2020-09-06 01:18:50 +00:00
|
|
|
Component {
|
|
|
|
id: loadingComponent
|
|
|
|
LoadingImage {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Loader {
|
2020-08-25 12:24:18 +00:00
|
|
|
id: loadingIndicator
|
2020-09-06 01:18:50 +00:00
|
|
|
sourceComponent: loadingComponent
|
2020-08-28 11:39:23 +00:00
|
|
|
height: size === "small" ? 14 : 18
|
2020-08-25 12:24:18 +00:00
|
|
|
width: loadingIndicator.height
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
}
|
|
|
|
|
2020-09-06 01:18:50 +00:00
|
|
|
|
2020-08-25 12:24:18 +00:00
|
|
|
ColorOverlay {
|
2020-11-11 14:46:13 +00:00
|
|
|
id: iconColorOverlay
|
2020-08-25 12:24:18 +00:00
|
|
|
anchors.fill: iconImg
|
|
|
|
source: iconImg
|
2020-09-30 12:33:26 +00:00
|
|
|
color: {
|
2021-03-16 19:19:48 +00:00
|
|
|
if (type === "secondary") {
|
2020-09-30 12:33:26 +00:00
|
|
|
return !control.enabled ?
|
|
|
|
Style.current.roundedButtonSecondaryDisabledForegroundColor :
|
2021-02-12 16:32:04 +00:00
|
|
|
(control.type === "warn" ? Style.current.danger : Style.current.roundedButtonSecondaryForegroundColor)
|
2020-09-30 12:33:26 +00:00
|
|
|
}
|
|
|
|
return !control.enabled ?
|
|
|
|
Style.current.roundedButtonDisabledForegroundColor :
|
2021-02-12 16:32:04 +00:00
|
|
|
(control.type === "warn" ? Style.current.danger : Style.current.roundedButtonForegroundColor)
|
2020-09-30 12:33:26 +00:00
|
|
|
}
|
2020-08-25 12:24:18 +00:00
|
|
|
antialiasing: true
|
|
|
|
}
|
|
|
|
|
|
|
|
ColorOverlay {
|
|
|
|
id: loadingOverlay
|
2020-11-11 14:46:13 +00:00
|
|
|
visible: loadingIndicator.active
|
2020-08-25 12:24:18 +00:00
|
|
|
anchors.fill: loadingIndicator
|
|
|
|
source: loadingIndicator
|
2020-08-28 11:39:23 +00:00
|
|
|
color: control.size === "medium" || control.size === "small" ?
|
2020-08-25 12:24:18 +00:00
|
|
|
Style.current.roundedButtonSecondaryDisabledForegroundColor :
|
|
|
|
Style.current.roundedButtonDisabledForegroundColor
|
|
|
|
antialiasing: true
|
2020-08-25 11:15:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea {
|
2021-01-27 08:32:18 +00:00
|
|
|
hoverEnabled: true
|
2020-08-25 11:15:18 +00:00
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
anchors.fill: parent
|
|
|
|
onPressed: mouse.accepted = false
|
|
|
|
}
|
|
|
|
}
|