2020-12-29 15:31:26 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtGraphicalEffects 1.12
|
2021-09-28 15:04:06 +00:00
|
|
|
|
|
|
|
import utils 1.0
|
2020-12-29 15:31:26 +00:00
|
|
|
import ".."
|
|
|
|
|
2021-01-19 19:26:59 +00:00
|
|
|
Rectangle {
|
2020-12-29 15:31:26 +00:00
|
|
|
property string text
|
|
|
|
property bool isSwitch: false
|
|
|
|
property bool switchChecked: false
|
|
|
|
property string currentValue
|
2021-01-15 19:21:19 +00:00
|
|
|
property bool isBadge: false
|
|
|
|
property string badgeText: "1"
|
2021-03-16 15:12:28 +00:00
|
|
|
property int badgeRadius: 9
|
2021-01-15 19:21:19 +00:00
|
|
|
property bool isEnabled: true
|
2020-12-29 15:31:26 +00:00
|
|
|
signal clicked(bool checked)
|
2021-01-19 19:26:59 +00:00
|
|
|
property bool isHovered: false
|
2021-03-16 15:12:28 +00:00
|
|
|
property int badgeSize: 18
|
2021-05-25 19:38:18 +00:00
|
|
|
property url iconSource
|
2020-12-29 15:31:26 +00:00
|
|
|
|
|
|
|
id: root
|
2021-05-25 19:38:18 +00:00
|
|
|
implicitHeight: 52
|
2021-01-19 19:26:59 +00:00
|
|
|
color: isHovered ? Style.current.backgroundHover : Style.current.transparent
|
|
|
|
radius: Style.current.radius
|
|
|
|
border.width: 0
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.leftMargin: -Style.current.padding
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: -Style.current.padding
|
2020-12-29 15:31:26 +00:00
|
|
|
|
2021-05-25 19:38:18 +00:00
|
|
|
RoundedIcon {
|
|
|
|
id: pinImage
|
|
|
|
visible: !!root.iconSource.toString()
|
|
|
|
source: root.iconSource
|
|
|
|
iconColor: Style.current.primary
|
|
|
|
color: Style.current.secondaryBackground
|
|
|
|
width: 40
|
|
|
|
height: 40
|
|
|
|
iconWidth: 24
|
|
|
|
iconHeight: 24
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.leftMargin: Style.current.padding
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
}
|
|
|
|
|
2020-12-29 15:31:26 +00:00
|
|
|
StyledText {
|
|
|
|
id: textItem
|
2021-05-25 19:38:18 +00:00
|
|
|
anchors.left: pinImage.visible ? pinImage.right : parent.left
|
2021-01-19 19:26:59 +00:00
|
|
|
anchors.leftMargin: Style.current.padding
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
2020-12-29 15:31:26 +00:00
|
|
|
text: root.text
|
|
|
|
font.pixelSize: 15
|
2021-03-26 21:33:23 +00:00
|
|
|
color: !root.isEnabled ? Style.current.secondaryText : Style.current.textColor
|
2020-12-29 15:31:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
id: valueText
|
|
|
|
visible: !!root.currentValue
|
|
|
|
text: root.currentValue
|
2021-01-04 20:34:46 +00:00
|
|
|
elide: Text.ElideRight
|
2020-12-29 15:31:26 +00:00
|
|
|
font.pixelSize: 15
|
2021-01-04 20:34:46 +00:00
|
|
|
horizontalAlignment: Text.AlignRight
|
2020-12-29 15:31:26 +00:00
|
|
|
color: Style.current.secondaryText
|
2021-01-04 20:34:46 +00:00
|
|
|
anchors.left: textItem.right
|
|
|
|
anchors.leftMargin: Style.current.padding
|
2020-12-29 15:31:26 +00:00
|
|
|
anchors.right: root.isSwitch ? switchItem.left : caret.left
|
|
|
|
anchors.rightMargin: Style.current.padding
|
|
|
|
anchors.verticalCenter: textItem.verticalCenter
|
2021-01-19 19:26:59 +00:00
|
|
|
|
2020-12-29 15:31:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StatusSwitch {
|
|
|
|
id: switchItem
|
2021-01-15 19:21:19 +00:00
|
|
|
enabled: root.isEnabled
|
2020-12-29 15:31:26 +00:00
|
|
|
visible: root.isSwitch
|
|
|
|
checked: root.switchChecked
|
|
|
|
anchors.right: parent.right
|
2021-01-19 19:26:59 +00:00
|
|
|
anchors.rightMargin: Style.current.padding
|
2020-12-29 15:31:26 +00:00
|
|
|
anchors.verticalCenter: textItem.verticalCenter
|
|
|
|
}
|
|
|
|
|
2021-01-15 19:21:19 +00:00
|
|
|
Rectangle {
|
|
|
|
id: badge
|
|
|
|
visible: root.isBadge & !root.isSwitch
|
|
|
|
anchors.right: root.isSwitch ? switchItem.left : caret.left
|
|
|
|
anchors.rightMargin: Style.current.padding
|
|
|
|
anchors.verticalCenter: textItem.verticalCenter
|
2021-03-16 15:12:28 +00:00
|
|
|
radius: root.badgeRadius
|
2021-01-15 19:21:19 +00:00
|
|
|
color: Style.current.blue
|
2021-03-16 15:12:28 +00:00
|
|
|
width: root.badgeSize
|
|
|
|
height: root.badgeSize
|
2021-01-15 19:21:19 +00:00
|
|
|
Text {
|
|
|
|
font.pixelSize: 12
|
|
|
|
color: Style.current.white
|
|
|
|
anchors.centerIn: parent
|
|
|
|
text: root.badgeText
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-29 15:31:26 +00:00
|
|
|
SVGImage {
|
|
|
|
id: caret
|
|
|
|
visible: !root.isSwitch
|
|
|
|
anchors.right: parent.right
|
2021-01-19 19:26:59 +00:00
|
|
|
anchors.rightMargin: Style.current.padding
|
2020-12-29 15:31:26 +00:00
|
|
|
anchors.verticalCenter: textItem.verticalCenter
|
2021-09-28 15:04:06 +00:00
|
|
|
source: Style.svg("caret")
|
2020-12-29 15:31:26 +00:00
|
|
|
width: 13
|
|
|
|
height: 7
|
|
|
|
rotation: -90
|
|
|
|
ColorOverlay {
|
|
|
|
anchors.fill: caret
|
|
|
|
source: caret
|
2021-02-18 19:07:23 +00:00
|
|
|
color: Style.current.secondaryText
|
2020-12-29 15:31:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
2021-01-15 19:21:19 +00:00
|
|
|
enabled: root.isEnabled
|
2021-01-19 19:26:59 +00:00
|
|
|
hoverEnabled: true
|
|
|
|
onEntered: root.isHovered = true
|
|
|
|
onExited: root.isHovered = false
|
2020-12-29 15:31:26 +00:00
|
|
|
onClicked: {
|
|
|
|
root.clicked(!root.switchChecked)
|
|
|
|
}
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
}
|
|
|
|
}
|