forked from Shinonome/dots-hyprland
sidebar: android-style quick toggles & sliders (#2217)
Co-Authored-By: Vague Syntax <173799252+vaguesyntax@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,156 @@
|
||||
import qs.services
|
||||
import qs.modules.common
|
||||
import qs.modules.common.widgets
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import Quickshell
|
||||
import Quickshell.Bluetooth
|
||||
|
||||
import "./androidStyle/"
|
||||
|
||||
AbstractQuickPanel {
|
||||
id: root
|
||||
property bool editMode: false
|
||||
Layout.fillWidth: true
|
||||
implicitHeight: (editMode ? contentItem.implicitHeight : usedRows.implicitHeight) + root.padding * 2
|
||||
|
||||
Behavior on implicitHeight {
|
||||
animation: Appearance.animation.elementMove.numberAnimation.createObject(this)
|
||||
}
|
||||
|
||||
property real spacing: 6
|
||||
property real padding: 6
|
||||
|
||||
readonly property list<string> availableToggleTypes: ["network", "bluetooth", "idleInhibitor", "easyEffects", "nightLight", "darkMode", "cloudflareWarp", "gameMode", "screenSnip", "colorPicker", "onScreenKeyboard", "mic", "audio", "notifications", "powerProfile"]
|
||||
readonly property int columns: Config.options.sidebar.quickToggles.android.columns
|
||||
readonly property list<var> toggles: Config.options.sidebar.quickToggles.android.toggles
|
||||
readonly property list<var> toggleRows: toggleRowsForList(toggles)
|
||||
readonly property list<var> unusedToggles: {
|
||||
const types = availableToggleTypes.filter(type => !toggles.some(toggle => (toggle && toggle.type === type)))
|
||||
return types.map(type => { return { type: type, size: 1 } })
|
||||
}
|
||||
readonly property list<var> unusedToggleRows: toggleRowsForList(unusedToggles)
|
||||
readonly property real baseCellWidth: {
|
||||
// This is the wrong calculation, but it looks correct in reality???
|
||||
// (theoretically spacing should be multiplied by 1 column less)
|
||||
const availableWidth = root.width - (root.padding * 2) - (root.spacing * (root.columns))
|
||||
return availableWidth / root.columns
|
||||
}
|
||||
readonly property real baseCellHeight: 56
|
||||
|
||||
function toggleRowsForList(togglesList) {
|
||||
var rows = [];
|
||||
var row = [];
|
||||
var totalSize = 0; // Total cols taken in current row
|
||||
for (var i = 0; i < togglesList.length; i++) {
|
||||
if (!togglesList[i]) continue;
|
||||
if (totalSize + togglesList[i].size > columns) {
|
||||
rows.push(row);
|
||||
row = [];
|
||||
totalSize = 0;
|
||||
}
|
||||
row.push(togglesList[i]);
|
||||
totalSize += togglesList[i].size;
|
||||
}
|
||||
if (row.length > 0) {
|
||||
rows.push(row);
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
Column {
|
||||
id: contentItem
|
||||
anchors {
|
||||
fill: parent
|
||||
margins: root.padding
|
||||
}
|
||||
spacing: 12
|
||||
|
||||
Column {
|
||||
id: usedRows
|
||||
spacing: root.spacing
|
||||
|
||||
Repeater {
|
||||
id: usedRowsRepeater
|
||||
model: ScriptModel {
|
||||
values: root.toggleRows
|
||||
}
|
||||
delegate: ButtonGroup {
|
||||
id: toggleRow
|
||||
required property var modelData
|
||||
required property int index
|
||||
property int startingIndex: {
|
||||
const rows = usedRowsRepeater.model.values;
|
||||
let sum = 0;
|
||||
for (let i = 0; i < index; i++) {
|
||||
sum += rows[i].length;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
spacing: root.spacing
|
||||
|
||||
Repeater {
|
||||
model: ScriptModel {
|
||||
values: toggleRow.modelData
|
||||
}
|
||||
delegate: AndroidToggleDelegateChooser {
|
||||
startingIndex: toggleRow.startingIndex
|
||||
editMode: root.editMode
|
||||
baseCellWidth: root.baseCellWidth
|
||||
baseCellHeight: root.baseCellHeight
|
||||
spacing: root.spacing
|
||||
onOpenWifiDialog: root.openWifiDialog()
|
||||
onOpenBluetoothDialog: root.openBluetoothDialog()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FadeLoader {
|
||||
shown: root.editMode
|
||||
anchors {
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
leftMargin: root.baseCellHeight / 2
|
||||
rightMargin: root.baseCellHeight / 2
|
||||
}
|
||||
sourceComponent: Rectangle {
|
||||
implicitHeight: 1
|
||||
color: Appearance.colors.colOutlineVariant
|
||||
}
|
||||
}
|
||||
|
||||
FadeLoader {
|
||||
shown: root.editMode
|
||||
sourceComponent: Column {
|
||||
id: unusedRows
|
||||
spacing: root.spacing
|
||||
|
||||
Repeater {
|
||||
model: ScriptModel {
|
||||
values: root.unusedToggleRows
|
||||
}
|
||||
delegate: ButtonGroup {
|
||||
id: unusedToggleRow
|
||||
required property var modelData
|
||||
spacing: root.spacing
|
||||
|
||||
Repeater {
|
||||
model: ScriptModel {
|
||||
values: unusedToggleRow.modelData
|
||||
}
|
||||
delegate: AndroidToggleDelegateChooser {
|
||||
startingIndex: -1
|
||||
editMode: root.editMode
|
||||
baseCellWidth: root.baseCellWidth
|
||||
baseCellHeight: root.baseCellHeight
|
||||
spacing: root.spacing
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user