| 1 | import QtQuick |
| 2 | import QtQuick.Layouts |
| 3 | |
| 4 | // A settings row: label (+ optional hint) and glyph's pill toggle on the right; the whole row is clickable. |
| 5 | // The toggle: off = a dark pill with a dim knob on the left, on = the primary fill runs to the right with a dot. |
| 6 | // After glyph-rice (github.com/Nebelung-cloud/glyph-rice, GPL-3.0), prefs/Toggle.qml. |
| 7 | Rectangle { |
| 8 | id: s |
| 9 | property string label: "" |
| 10 | property string hint: "" |
| 11 | property string keywords: "" // synonyms for the settings search (SetIndex reads them from the source) |
| 12 | property bool checked: false |
| 13 | signal toggled(bool on) |
| 14 | |
| 15 | Layout.fillWidth: true |
| 16 | implicitHeight: Math.max(56, txt.implicitHeight + 20) |
| 17 | radius: 28 |
| 18 | color: m.containsMouse ? Theme.s2 : "transparent" |
| 19 | |
| 20 | ColumnLayout { |
| 21 | id: txt |
| 22 | anchors.left: parent.left |
| 23 | anchors.leftMargin: 18 |
| 24 | anchors.right: box.left |
| 25 | anchors.rightMargin: 16 |
| 26 | anchors.verticalCenter: parent.verticalCenter |
| 27 | spacing: 3 |
| 28 | Text { |
| 29 | Layout.fillWidth: true |
| 30 | text: s.label |
| 31 | color: Theme.fg |
| 32 | elide: Text.ElideRight |
| 33 | font.family: Theme.ui |
| 34 | font.pixelSize: 15 |
| 35 | } |
| 36 | Lb { |
| 37 | Layout.fillWidth: true |
| 38 | visible: s.hint !== "" |
| 39 | text: s.hint |
| 40 | wrapMode: Text.WordWrap |
| 41 | px: 10 |
| 42 | } |
| 43 | } |
| 44 | Rectangle { |
| 45 | id: box |
| 46 | anchors.right: parent.right |
| 47 | anchors.rightMargin: 14 |
| 48 | anchors.verticalCenter: parent.verticalCenter |
| 49 | width: 64 |
| 50 | height: 34 |
| 51 | radius: 17 |
| 52 | color: Theme.s3 |
| 53 | Rectangle { |
| 54 | x: 4 |
| 55 | y: 4 |
| 56 | width: s.checked ? parent.width - 8 : height |
| 57 | height: parent.height - 8 |
| 58 | radius: height / 2 |
| 59 | color: s.checked ? Theme.fill : Theme.mute |
| 60 | Behavior on width { enabled: Theme.motion; NumberAnimation { duration: Theme.t; easing.type: Easing.BezierSpline; easing.bezierCurve: Theme.glide } } |
| 61 | Behavior on color { enabled: Theme.motion; ColorAnimation { duration: Theme.t } } |
| 62 | Rectangle { |
| 63 | anchors.right: parent.right |
| 64 | anchors.rightMargin: 8 |
| 65 | anchors.verticalCenter: parent.verticalCenter |
| 66 | visible: s.checked |
| 67 | width: 10 |
| 68 | height: 10 |
| 69 | radius: 5 |
| 70 | color: Theme.fillFg |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | MouseArea { |
| 75 | id: m |
| 76 | anchors.fill: parent |
| 77 | hoverEnabled: true |
| 78 | cursorShape: Qt.PointingHandCursor |
| 79 | onClicked: s.toggled(!s.checked) |
| 80 | } |
| 81 | } |