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

199 lines
5.3 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
2025-05-02 23:54:36 -07:00
property string textDisabledColor: AmneziaStyle.color.mutedGray
property string selectedTextColor: AmneziaStyle.color.goldenApricot
2025-05-02 23:54:36 -07:00
property string selectedTextDisabledColor: AmneziaStyle.color.burntOrange
property string descriptionColor: AmneziaStyle.color.mutedGray
property string descriptionDisabledColor: AmneziaStyle.color.charcoalGray
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
2025-05-02 23:54:36 -07:00
property string radioButtonInnerCirclePressedSource: "qrc:/images/controls/radio-button-inner-circle-pressed.png"
property string radioButtonInnerCircleSource: "qrc:/images/controls/radio-button-inner-circle.png"
property string radioButtonPressedSource: "qrc:/images/controls/radio-button-pressed.svg"
property string radioButtonDefaultSource: "qrc:/images/controls/radio-button.svg"
2024-12-31 04:16:52 +01:00
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) {
2025-05-02 23:54:36 -07:00
return root.radioButtonInnerCirclePressedSource
2023-06-13 20:03:20 +09:00
} else if (root.checked) {
2025-05-02 23:54:36 -07:00
return root.radioButtonInnerCircleSource
2023-06-13 20:03:20 +09:00
}
return ""
}
2023-06-01 11:25:33 +08:00
2025-05-02 23:54:36 -07:00
opacity: root.enabled ? 1.0 : 0.3
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) {
2025-05-02 23:54:36 -07:00
return root.radioButtonPressedSource
2023-06-13 20:03:20 +09:00
} else {
2025-05-02 23:54:36 -07:00
return root.radioButtonDefaultSource
}
}
2025-05-02 23:54:36 -07:00
opacity: root.enabled ? 1.0 : 0.3
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: {
2025-05-02 23:54:36 -07:00
if (root.enabled) {
return root.checked ? selectedTextColor : textColor
} else {
return root.checked ? selectedTextDisabledColor : textDisabledColor
}
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
2025-05-02 23:54:36 -07:00
color: root.enabled ? root.descriptionColor : root.descriptionDisabledColor
text: root.descriptionText
visible: root.descriptionText !== ""
Layout.fillWidth: true
}
}
}
MouseArea {
2023-04-26 18:37:56 +03:00
anchors.fill: root
cursorShape: Qt.PointingHandCursor
2025-05-03 10:56:50 +04:00
preventStealing: false
2023-04-26 18:37:56 +03:00
enabled: false
}
}
2023-04-26 18:37:56 +03:00