C++ / fmt (pull_request) Successful in 7s
JS/TS / lint (pull_request) Successful in 21s
JS/TS / fmt (pull_request) Successful in 20s
Python / lint (pull_request) Successful in 31s
Python / fmt (pull_request) Successful in 33s
Python / typecheck (pull_request) Failing after 1m4s
Python / test (pull_request) Successful in 1m7s
C++ / build (pull_request) Successful in 1m48s
Rust / fmt (pull_request) Successful in 37s
Rust / build (pull_request) Successful in 1m42s
Python / buildcheck (pull_request) Successful in 2m33s
Rust / clippy (pull_request) Successful in 1m32s
C++ / clang-tidy (pull_request) Successful in 3m35s
88 lines
2.3 KiB
QML
88 lines
2.3 KiB
QML
import QtQuick
|
|
import qs.Config
|
|
|
|
CustomRect {
|
|
id: root
|
|
|
|
enum ButtonType {
|
|
Filled,
|
|
Tonal,
|
|
Text
|
|
}
|
|
|
|
property color activeColor
|
|
property color activeOnColor
|
|
property bool checked
|
|
property real checkedRadius: Appearance.rounding.medium
|
|
property real defaultRadius: Appearance.rounding.large
|
|
property color disabledColor: Qt.alpha(DynamicColors.palette.m3onSurface, 0.1)
|
|
property color disabledOnColor: Qt.alpha(DynamicColors.palette.m3onSurface, 0.38)
|
|
property bool fillWidth
|
|
property font font: ({
|
|
family: Appearance.font.family.sans,
|
|
pointSize: Appearance.font.size.larger,
|
|
bold: false
|
|
})
|
|
property real horizontalPadding: padding
|
|
readonly property alias hovered: stateLayer.containsMouse
|
|
required implicitHeight
|
|
required implicitWidth
|
|
property color inactiveColor
|
|
property color inactiveOnColor
|
|
property bool internalChecked
|
|
property bool isRound
|
|
property bool isToggle
|
|
readonly property color onColor: !enabled ? disabledOnColor : internalChecked ? activeOnColor : inactiveOnColor
|
|
property real padding
|
|
readonly property alias pressed: stateLayer.pressed
|
|
property real pressedRadius: Appearance.rounding.smallest
|
|
readonly property alias radiusAnim: radiusAnim
|
|
property bool radiusMorph: true
|
|
property alias shapeMorph: stateLayer.shapeMorph
|
|
property real shapeMorphExpansion: shapeMorph && pressed ? 24 : 0
|
|
readonly property alias stateLayer: stateLayer
|
|
property int type: ButtonBase.Filled
|
|
property real verticalPadding: padding
|
|
|
|
signal clicked
|
|
|
|
color: type === ButtonBase.Text ? "transparent" : !enabled ? disabledColor : internalChecked ? activeColor : inactiveColor
|
|
radius: {
|
|
if (radiusMorph && pressed)
|
|
return pressedRadius;
|
|
if (internalChecked)
|
|
return checkedRadius;
|
|
if (isRound)
|
|
return (height || implicitHeight) / 2 * Math.min(1, Appearance.rounding.scale);
|
|
return defaultRadius;
|
|
}
|
|
|
|
Behavior on radius {
|
|
Anim {
|
|
id: radiusAnim
|
|
|
|
type: Anim.DefaultEffects
|
|
}
|
|
}
|
|
Behavior on shapeMorphExpansion {
|
|
Anim {
|
|
type: Anim.FastSpatial
|
|
}
|
|
}
|
|
|
|
onCheckedChanged: internalChecked = checked
|
|
|
|
StateLayer {
|
|
id: stateLayer
|
|
|
|
color: root.internalChecked ? root.activeOnColor : root.inactiveOnColor
|
|
enabled: root.enabled
|
|
|
|
onClicked: {
|
|
if (root.isToggle)
|
|
root.internalChecked = !root.internalChecked;
|
|
root.clicked();
|
|
}
|
|
}
|
|
}
|