2020-12-29 15:31:26 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtGraphicalEffects 1.12
|
|
|
|
import "../../imports"
|
|
|
|
import ".."
|
|
|
|
|
|
|
|
Item {
|
|
|
|
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"
|
|
|
|
property bool isEnabled: true
|
2020-12-29 15:31:26 +00:00
|
|
|
signal clicked(bool checked)
|
|
|
|
|
|
|
|
id: root
|
|
|
|
height: textItem.height
|
|
|
|
width: parent.width
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
id: textItem
|
|
|
|
text: root.text
|
|
|
|
font.pixelSize: 15
|
2021-01-15 19:21:19 +00:00
|
|
|
color: !root.isEnabled ? Style.current.darkGrey : 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
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
radius: 9
|
|
|
|
color: Style.current.blue
|
|
|
|
width: 18
|
|
|
|
height: 18
|
|
|
|
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
|
|
|
|
anchors.verticalCenter: textItem.verticalCenter
|
|
|
|
source: "../../app/img/caret.svg"
|
|
|
|
width: 13
|
|
|
|
height: 7
|
|
|
|
rotation: -90
|
|
|
|
ColorOverlay {
|
|
|
|
anchors.fill: caret
|
|
|
|
source: caret
|
|
|
|
color: Style.current.darkGrey
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
2021-01-15 19:21:19 +00:00
|
|
|
enabled: root.isEnabled
|
2020-12-29 15:31:26 +00:00
|
|
|
onClicked: {
|
|
|
|
root.clicked(!root.switchChecked)
|
|
|
|
}
|
|
|
|
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
}
|
|
|
|
}
|