Files
noctalia-shell/Widgets/NToggle.qml
T
ItsLemmy 73267d1d37 Settings + SetupWizard
- Added a Lock screen settings tabs
- Added button in settings/general tab to re-run the setup wizard
- Fixed missing translations
- Fixed bug when matugen not installed in setup wizard
- Added enabled property for NToggle
2025-10-20 13:33:46 -04:00

95 lines
2.1 KiB
QML

import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import qs.Commons
import qs.Services
RowLayout {
id: root
property string label: ""
property string description: ""
property bool enabled: true
property bool checked: false
property bool hovering: false
property int baseSize: Math.round(Style.baseWidgetSize * 0.8 * Style.uiScaleRatio)
signal toggled(bool checked)
signal entered
signal exited
Layout.fillWidth: true
opacity: enabled ? 1.0 : 0.6
NLabel {
label: root.label
description: root.description
}
Rectangle {
id: switcher
implicitWidth: Math.round(root.baseSize * .85) * 2
implicitHeight: Math.round(root.baseSize * .5) * 2
radius: height * 0.5
color: root.checked ? Color.mPrimary : Color.mSurface
border.color: Color.mOutline
border.width: Math.max(1, Style.borderS)
Behavior on color {
ColorAnimation {
duration: Style.animationFast
}
}
Behavior on border.color {
ColorAnimation {
duration: Style.animationFast
}
}
Rectangle {
implicitWidth: Math.round(root.baseSize * 0.4) * 2
implicitHeight: Math.round(root.baseSize * 0.4) * 2
radius: height * 0.5
color: root.checked ? Color.mOnPrimary : Color.mPrimary
border.color: root.checked ? Color.mSurface : Color.mSurface
border.width: Math.max(1, Style.borderM)
anchors.verticalCenter: parent.verticalCenter
anchors.verticalCenterOffset: 0
x: root.checked ? switcher.width - width - 3 : 3
Behavior on x {
NumberAnimation {
duration: Style.animationFast
easing.type: Easing.OutCubic
}
}
}
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
hoverEnabled: true
onEntered: {
if (!enabled)
return
hovering = true
root.entered()
}
onExited: {
if (!enabled)
return
hovering = false
root.exited()
}
onClicked: {
if (!enabled)
return
root.toggled(!root.checked)
}
}
}
}