Files
amnezia-client/client/ui/qml/Controls2/VerticalRadioButton.qml
T

185 lines
4.4 KiB
QML
Raw Normal View History

import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Qt5Compat.GraphicalEffects
2024-07-07 13:42:38 +03:00
import Style 1.0
2023-06-01 11:25:33 +08:00
import "TextTypes"
RadioButton {
id: root
property int textMaximumLineCount: 2
property int textElide: Qt.ElideRight
property string descriptionText
property string hoveredColor: AmneziaStyle.color.barelyTranslucentWhite
2024-07-07 13:42:38 +03:00
property string defaultColor: AmneziaStyle.color.transparent
property string disabledColor: AmneziaStyle.color.transparent
property string selectedColor: AmneziaStyle.color.transparent
property string textColor: AmneziaStyle.color.paleGray
property string selectedTextColor: AmneziaStyle.color.goldenApricot
property string borderFocusedColor: AmneziaStyle.color.paleGray
2024-04-18 17:54:55 +04:00
property int borderFocusedWidth: 1
2023-06-01 11:25:33 +08:00
property string imageSource
property bool showImage
2024-12-31 04:16:52 +01:00
property bool isFocusable: true
Keys.onTabPressed: {
FocusController.nextKeyTabItem()
}
Keys.onBacktabPressed: {
FocusController.previousKeyTabItem()
}
Keys.onUpPressed: {
FocusController.nextKeyUpItem()
}
Keys.onDownPressed: {
FocusController.nextKeyDownItem()
}
Keys.onLeftPressed: {
FocusController.nextKeyLeftItem()
}
Keys.onRightPressed: {
FocusController.nextKeyRightItem()
}
hoverEnabled: true
indicator: Rectangle {
2023-04-26 18:37:56 +03:00
id: background
2023-06-01 11:25:33 +08:00
anchors.verticalCenter: parent.verticalCenter
2024-07-07 13:42:38 +03:00
border.color: root.focus ? root.borderFocusedColor : AmneziaStyle.color.transparent
2024-04-18 17:54:55 +04:00
border.width: root.focus ? root.borderFocusedWidth : 0
implicitWidth: 56
implicitHeight: 56
radius: 16
color: {
if (root.enabled) {
2023-04-26 18:37:56 +03:00
if (root.hovered) {
return hoveredColor
} else if (root.checked) {
return selectedColor
}
return defaultColor
} else {
return disabledColor
}
}
Behavior on color {
PropertyAnimation { duration: 200 }
}
2024-04-18 17:54:55 +04:00
Behavior on border.color {
PropertyAnimation { duration: 200 }
}
2023-06-01 11:25:33 +08:00
Image {
2023-06-13 20:03:20 +09:00
source: {
if (showImage) {
return imageSource
} else if (root.pressed) {
return "qrc:/images/controls/radio-button-inner-circle-pressed.png"
} else if (root.checked) {
return "qrc:/images/controls/radio-button-inner-circle.png"
}
return ""
}
2023-06-01 11:25:33 +08:00
anchors.centerIn: parent
width: 24
height: 24
}
2023-08-18 14:14:45 +05:00
2023-06-13 20:03:20 +09:00
Image {
source: {
if (showImage) {
return ""
} else if (root.pressed || root.checked) {
return "qrc:/images/controls/radio-button-pressed.svg"
} else {
return "qrc:/images/controls/radio-button.svg"
}
}
2023-06-13 20:03:20 +09:00
anchors.centerIn: parent
2023-06-13 20:03:20 +09:00
width: 24
height: 24
}
}
contentItem: Item {
2024-03-25 22:30:44 +05:00
anchors.left: parent.left
anchors.right: parent.right
2023-04-26 18:37:56 +03:00
anchors.leftMargin: 8 + background.width
2024-03-25 22:30:44 +05:00
implicitHeight: content.implicitHeight
ColumnLayout {
id: content
anchors.left: parent.left
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
2023-06-01 11:25:33 +08:00
spacing: 4
ListItemTitleType {
text: root.text
maximumLineCount: root.textMaximumLineCount
elide: root.textElide
color: {
if (root.checked) {
return selectedTextColor
}
return textColor
2023-06-01 11:25:33 +08:00
}
Layout.fillWidth: true
2023-06-01 11:25:33 +08:00
Behavior on color {
PropertyAnimation { duration: 200 }
}
2023-06-01 11:25:33 +08:00
}
CaptionTextType {
id: description
2023-06-01 11:25:33 +08:00
color: AmneziaStyle.color.mutedGray
text: root.descriptionText
visible: root.descriptionText !== ""
Layout.fillWidth: true
}
}
}
MouseArea {
2023-04-26 18:37:56 +03:00
anchors.fill: root
cursorShape: Qt.PointingHandCursor
2023-04-26 18:37:56 +03:00
enabled: false
}
}
2023-04-26 18:37:56 +03:00