Compare commits

...

2 commits

Author SHA1 Message Date
Benjamin Palko
e27dadba0f use styled switch 2025-08-31 11:33:19 -04:00
Benjamin Palko
135446ab82 properly styled switch to not look like ass 2025-08-31 11:29:15 -04:00
4 changed files with 49 additions and 49 deletions

View file

@ -5,39 +5,51 @@ import QtQuick.Controls
Switch { Switch {
id: control id: control
contentItem: Text {
id: text
rightPadding: control.indicator.width + control.spacing
text: control.text
font: control.font
opacity: enabled ? 1.0 : 0.3
color: Theme.palette.basecontent
elide: Text.ElideRight
verticalAlignment: Text.AlignVCenter
}
HoverHandler { HoverHandler {
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
} }
indicator: Item { indicator: Rectangle {
id: indicator
property int padding: 8
implicitWidth: 48 implicitWidth: 48
implicitHeight: 22 implicitHeight: 24
Rectangle { x: control.width - width - control.rightPadding
implicitWidth: parent.width y: parent.height / 2 - height / 2
implicitHeight: parent.height - 4 radius: 16
x: control.leftPadding color: "transparent"
y: parent.height / 2 - height / 2 border.color: control.checked ? Theme.palette.primary : Theme.palette.basecontent
radius: 6 border.width: 2
color: control.checked ? Theme.palette.primary : Theme.palette.base100
Behavior on color {
ColorAnimation {
duration: 150
}
}
}
Rectangle { Rectangle {
x: control.checked ? parent.width - 3 * width / 4 : width / 4 anchors.margins: 4
x: control.checked ? parent.width - width - indicator.padding / 2 : indicator.padding / 2
y: parent.height / 2 - height / 2 y: parent.height / 2 - height / 2
Behavior on x { Behavior on x {
NumberAnimation { NumberAnimation {
duration: 150 duration: 100
} }
} }
width: 22 width: parent.width / 2 - indicator.padding
height: 22 height: parent.height - indicator.padding
radius: 6 radius: 16
color: Theme.palette.basecontent color: control.checked ? Theme.palette.primary : Theme.palette.basecontent
// border.color: control.checked ? (control.down ? "#17a81a" : "#21be2b") : "#999999"
} }
} }
background: undefined
} }

View file

@ -4,7 +4,6 @@ import qs.components
import qs.config import qs.config
import qs.widgets import qs.widgets
import QtQuick import QtQuick
import QtQuick.Controls
import QtQuick.Layouts import QtQuick.Layouts
import Quickshell import Quickshell
import Quickshell.Bluetooth import Quickshell.Bluetooth
@ -22,29 +21,19 @@ StyledPopupWindow {
margin: 16 margin: 16
Layout.fillWidth: true Layout.fillWidth: true
RowLayout { RowLayout {
RowLayout { StyledSwitch {
StyledText { text: "Enabled"
text: "Enabled" checkable: !!Bluetooth.defaultAdapter
} checked: Bluetooth.defaultAdapter?.enabled ?? false
onClicked: Bluetooth.defaultAdapter.enabled = checked
Switch {
checkable: !!Bluetooth.defaultAdapter
checked: Bluetooth.defaultAdapter?.enabled ?? false
onClicked: Bluetooth.defaultAdapter.enabled = checked
}
} }
RowLayout { StyledSwitch {
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
StyledText { text: "Scan"
text: "Scan" checkable: !!Bluetooth.defaultAdapter
} checked: Bluetooth.defaultAdapter?.discovering ?? false
onClicked: Bluetooth.defaultAdapter.discovering = checked
Switch {
checkable: !!Bluetooth.defaultAdapter
checked: Bluetooth.defaultAdapter?.discovering ?? false
onClicked: Bluetooth.defaultAdapter.discovering = checked
}
} }
} }
} }

View file

@ -5,7 +5,6 @@ import qs.config
import qs.services import qs.services
import qs.widgets import qs.widgets
import QtQuick import QtQuick
import QtQuick.Controls
import QtQuick.Layouts import QtQuick.Layouts
StyledPopupWindow { StyledPopupWindow {
@ -20,17 +19,14 @@ StyledPopupWindow {
RowLayout { RowLayout {
Layout.fillWidth: true Layout.fillWidth: true
StyledText {
text: "Enabled"
}
Switch { StyledSwitch {
text: "Enabled"
checked: Notifications.enabled checked: Notifications.enabled
onClicked: Notifications.enabled = checked onClicked: Notifications.enabled = checked
} }
StyledButton { StyledButton {
id: clearButton
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
text: "Clear" text: "Clear"
onClicked: Notifications.clear() onClicked: Notifications.clear()

View file

@ -62,7 +62,10 @@ StyledWindow {
text: "Switch" text: "Switch"
font.pixelSize: 18 font.pixelSize: 18
} }
StyledSwitch {}
StyledSwitch {
text: "Enable"
}
} }
ColumnLayout { ColumnLayout {