status-desktop/ui/shared/status/StatusRoundButton.qml

153 lines
4.3 KiB
QML
Raw Normal View History

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 {
property string state: "default"
property string size: "large"
id: control
font.pixelSize: 15
font.weight: Font.Medium
implicitWidth: {
switch(size) {
case "large":
return 44
case "medium":
return 40
case "small":
return 32
default:
return 44
}
}
implicitHeight: implicitWidth
2020-08-25 11:15:18 +00:00
enabled: state === "default"
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
}
}
icon.color: size === "medium" || size === "small" ?
2020-08-25 11:15:18 +00:00
!enabled ?
Style.current.roundedButtonSecondaryDisabledForegroundColor :
Style.current.roundedButtonSecondaryForegroundColor
:
!enabled ?
Style.current.roundedButtonDisabledForegroundColor :
Style.current.roundedButtonForegroundColor
onIconChanged: {
icon.source = icon.name ? "../../app/img/" + icon.name + ".svg" : ""
}
2020-08-25 11:15:18 +00:00
background: Rectangle {
anchors.fill: parent
color: {
if (size === "medium" || size == "small") {
2020-08-25 11:15:18 +00:00
return !enabled ? Style.current.roundedButtonSecondaryDisabledBackgroundColor :
hovered ? Style.current.roundedButtonSecondaryHoveredBackgroundColor :
Style.current.roundedButtonSecondaryBackgroundColor
}
return !enabled ?
Style.current.roundedButtonDisabledBackgroundColor :
hovered ? Qt.darker(Style.current.buttonBackgroundColor, 1.1) : Style.current.roundedButtonBackgroundColor
2020-08-25 11:15:18 +00:00
}
radius: parent.width / 2
}
contentItem: Item {
anchors.fill: parent
2020-08-25 11:15:18 +00:00
SVGImage {
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
}
Component {
id: loadingComponent
LoadingImage {
}
}
Loader {
id: loadingIndicator
active: control.state === "pending"
sourceComponent: loadingComponent
height: size === "small" ? 14 : 18
width: loadingIndicator.height
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
}
ColorOverlay {
anchors.fill: iconImg
visible: control.state === "default"
source: iconImg
color: {
if (size === "medium" || size == "small") {
return !control.enabled ?
Style.current.roundedButtonSecondaryDisabledForegroundColor :
Style.current.roundedButtonSecondaryForegroundColor
}
return !control.enabled ?
Style.current.roundedButtonDisabledForegroundColor :
Style.current.roundedButtonForegroundColor
}
antialiasing: true
}
ColorOverlay {
id: loadingOverlay
visible: control.state === "pending"
anchors.fill: loadingIndicator
source: loadingIndicator
color: control.size === "medium" || control.size === "small" ?
Style.current.roundedButtonSecondaryDisabledForegroundColor :
Style.current.roundedButtonDisabledForegroundColor
antialiasing: true
2020-08-25 11:15:18 +00:00
}
}
MouseArea {
cursorShape: Qt.PointingHandCursor
anchors.fill: parent
onPressed: mouse.accepted = false
}
}