shift-shell/components/mobileshell/qml/actiondrawer/quicksettings/QuickSettings.qml

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

316 lines
10 KiB
QML
Raw Normal View History

/*
* SPDX-FileCopyrightText: 2014 Marco Martin <notmart@gmail.com>
* SPDX-FileCopyrightText: 2021 Devin Lin <devin@kde.org>
*
* SPDX-License-Identifier: LGPL-2.0-or-later
*/
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.1
import QtQuick.Window 2.2
import org.kde.plasma.private.mobileshell as MobileShell
2022-05-12 13:20:39 +00:00
import org.kde.plasma.components 3.0 as PlasmaComponents
import org.kde.plasma.private.mobileshell.quicksettingsplugin as QS
import org.kde.kirigami 2.20 as Kirigami
/**
* Quick settings elements layout, change the height to clip.
*/
Item {
id: root
clip: true
2024-07-27 03:47:44 +00:00
required property var actionDrawer
required property int mode
enum Mode {
Pages,
ScrollView
}
readonly property real columns: Math.round(Math.min(6, Math.max(3, width / intendedColumnWidth)))
readonly property real columnWidth: Math.floor(width / columns)
readonly property int minimizedColumns: Math.round(Math.min(8, Math.max(5, width / intendedMinimizedColumnWidth)))
readonly property real minimizedColumnWidth: Math.floor(width / minimizedColumns)
2024-07-27 03:47:44 +00:00
readonly property real rowHeight: columnWidth * 0.7
readonly property real fullHeight: fullView.implicitHeight
2024-07-27 03:47:44 +00:00
readonly property real intendedColumnWidth: Kirigami.Units.gridUnit * 7
readonly property real intendedMinimizedColumnWidth: Kirigami.Units.gridUnit * 4 + Kirigami.Units.smallSpacing
readonly property real minimizedRowHeight: Kirigami.Units.gridUnit * 4 + Kirigami.Units.smallSpacing
2024-07-27 03:47:44 +00:00
property real minimizedViewProgress: 0
property real fullViewProgress: 1
2022-05-07 17:10:02 +00:00
readonly property QS.QuickSettingsModel quickSettingsModel: QS.QuickSettingsModel {}
2024-07-27 03:47:44 +00:00
2022-05-07 21:19:56 +00:00
readonly property int columnCount: Math.floor(width/columnWidth)
readonly property int rowCount: {
let totalRows = Math.ceil(quickSettingsCount / columnCount);
if (root.mode === QuickSettings.Pages) {
// portrait orientation
let maxRows = 5; // more than 5 is just disorienting
let targetRows = Math.floor(Window.height * 0.65 / rowHeight);
return Math.min(maxRows, Math.min(totalRows, targetRows));
2024-07-27 03:47:44 +00:00
} else if (root.mode === QuickSettings.ScrollView) {
// horizontal orientation
let targetRows = Math.floor(Window.height * 0.8 / rowHeight);
return Math.min(totalRows, targetRows);
}
}
2024-07-27 03:47:44 +00:00
2022-05-07 21:19:56 +00:00
readonly property int pageSize: rowCount * columnCount
readonly property int quickSettingsCount: quickSettingsModel.count
2024-07-27 03:47:44 +00:00
2022-05-07 17:10:02 +00:00
function resetSwipeView() {
if (root.mode === QuickSettings.Pages) {
pageLoader.item.view.currentIndex = 0;
}
2022-05-07 17:10:02 +00:00
}
// return to the first page when the action drawer is closed
Connections {
target: actionDrawer
function onOpenedChanged() {
if (!actionDrawer.opened) {
2022-05-07 17:10:02 +00:00
resetSwipeView();
}
}
}
2024-07-27 03:47:44 +00:00
// view when fully open
ColumnLayout {
id: fullView
opacity: root.fullViewProgress
visible: opacity !== 0
transform: Translate { y: (1 - fullView.opacity) * root.rowHeight }
2024-07-27 03:47:44 +00:00
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
2024-07-27 03:47:44 +00:00
// Dynamically loads the appropriate view
2022-05-07 21:19:56 +00:00
Loader {
id: pageLoader
2024-07-27 03:47:44 +00:00
Layout.fillWidth: true
2022-05-12 13:20:39 +00:00
Layout.minimumHeight: rowCount * rowHeight
asynchronous: true
sourceComponent: root.mode === QuickSettings.Pages ? swipeViewComponent : scrollViewComponent
2022-05-07 17:10:02 +00:00
}
2024-07-27 03:47:44 +00:00
BrightnessItem {
id: brightnessItem
Layout.bottomMargin: Kirigami.Units.smallSpacing * 2
Layout.leftMargin: Kirigami.Units.smallSpacing
Layout.rightMargin: Kirigami.Units.smallSpacing
Layout.fillWidth: true
}
}
2024-07-27 03:47:44 +00:00
// view when in minimized mode
RowLayout {
id: minimizedView
spacing: 0
opacity: root.minimizedViewProgress
visible: opacity !== 0
transform: Translate { y: (1 - minimizedView.opacity) * -root.rowHeight }
2024-07-27 03:47:44 +00:00
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
2024-07-27 03:47:44 +00:00
Repeater {
model: QS.PaginateModel {
2022-05-07 17:10:02 +00:00
sourceModel: quickSettingsModel
pageSize: minimizedColumns
}
delegate: MobileShell.BaseItem {
required property var modelData
2024-07-27 03:47:44 +00:00
implicitHeight: root.minimizedRowHeight
implicitWidth: root.minimizedColumnWidth
horizontalPadding: (width - Kirigami.Units.gridUnit * 3) / 2
verticalPadding: (height - Kirigami.Units.gridUnit * 3) / 2
2024-07-27 03:47:44 +00:00
contentItem: QuickSettingsMinimizedDelegate {
restrictedPermissions: actionDrawer.restrictedPermissions
2024-07-27 03:47:44 +00:00
text: modelData.text
status: modelData.status
icon: modelData.icon
enabled: modelData.enabled
settingsCommand: modelData.settingsCommand
toggleFunction: modelData.toggle
2024-07-27 03:47:44 +00:00
onCloseRequested: {
actionDrawer.close();
}
}
}
}
}
2024-07-27 03:47:44 +00:00
2022-05-12 13:20:39 +00:00
// Loads portrait quick settings view
Component {
id: swipeViewComponent
2024-07-27 03:47:44 +00:00
ColumnLayout {
readonly property var view: swipeView
2024-07-27 03:47:44 +00:00
SwipeView {
id: swipeView
2024-07-27 03:47:44 +00:00
Layout.fillWidth: true
Layout.preferredHeight: rowCount * rowHeight
2024-07-27 03:47:44 +00:00
Repeater {
model: Math.ceil(quickSettingsCount / pageSize)
delegate: Flow {
id: flow
spacing: 0
2024-07-27 03:47:44 +00:00
required property int index
2024-07-27 03:47:44 +00:00
Repeater {
model: QS.PaginateModel {
sourceModel: quickSettingsModel
pageSize: root.pageSize
firstItem: pageSize * flow.index
}
delegate: Loader {
required property var modelData
2024-07-27 03:47:44 +00:00
asynchronous: true
2024-07-27 03:47:44 +00:00
sourceComponent: quickSettingComponent
}
}
}
}
}
2024-07-27 03:47:44 +00:00
Loader {
id: indicatorLoader
2024-07-27 03:47:44 +00:00
Layout.alignment: Qt.AlignCenter
Layout.topMargin: Kirigami.Units.smallSpacing
Layout.leftMargin: Kirigami.Units.smallSpacing
Layout.rightMargin: Kirigami.Units.smallSpacing
2024-07-27 03:47:44 +00:00
// Avoid wasting space when not loaded
Layout.maximumHeight: active ? item.implicitHeight : 0
2024-07-27 03:47:44 +00:00
active: swipeView.count > 1 ? true: false
asynchronous: true
2024-07-27 03:47:44 +00:00
sourceComponent: PageIndicator {
count: swipeView.count
currentIndex: swipeView.currentIndex
2024-07-27 03:47:44 +00:00
delegate: Rectangle {
implicitWidth: 8
implicitHeight: count > 1 ? 8 : 0
radius: parent.width / 2
color: Kirigami.Theme.disabledTextColor
opacity: index === currentIndex ? 0.95 : 0.45
}
}
}
}
}
2024-07-27 03:47:44 +00:00
2022-05-12 13:20:39 +00:00
// Loads landscape quick settings view
Component {
id: scrollViewComponent
2024-07-27 03:47:44 +00:00
2022-05-12 13:20:39 +00:00
Item {
width: parent.width
height: rowCount * rowHeight
2024-07-27 03:47:44 +00:00
2022-05-12 13:20:39 +00:00
Flickable {
id: flickable
anchors.fill: parent
contentWidth: width
contentHeight: flow.height
2024-07-27 03:47:44 +00:00
2022-05-12 13:20:39 +00:00
clip: true
2024-07-27 03:47:44 +00:00
2022-05-12 13:20:39 +00:00
ScrollIndicator.vertical: ScrollIndicator {
id: scrollIndicator
2022-05-12 13:20:39 +00:00
visible: quickSettingsCount > pageSize ? true : false
position: 0.1
2024-07-27 03:47:44 +00:00
contentItem: Item {
implicitWidth: Kirigami.Units.smallSpacing / 4
Rectangle {
// shift over the indicator a bit to the right
anchors.fill: parent
anchors.leftMargin: 2
anchors.rightMargin: -2
2024-07-27 03:47:44 +00:00
color: Kirigami.Theme.textColor
opacity: scrollIndicator.active ? 0.5 : 0
2024-07-27 03:47:44 +00:00
Behavior on opacity { NumberAnimation {} }
}
2022-05-12 13:20:39 +00:00
}
}
2024-07-27 03:47:44 +00:00
2022-05-12 13:20:39 +00:00
Flow {
id: flow
width: parent.width
height: Math.ceil(quickSettingsCount / columnCount) * rowHeight
spacing: 0
2024-07-27 03:47:44 +00:00
2022-05-12 13:20:39 +00:00
Repeater {
model: quickSettingsModel
delegate: Loader {
required property var modelData
2024-07-27 03:47:44 +00:00
2022-05-12 13:20:39 +00:00
asynchronous: true
2024-07-27 03:47:44 +00:00
2022-05-12 13:20:39 +00:00
sourceComponent: quickSettingComponent
}
}
}
}
}
}
2024-07-27 03:47:44 +00:00
// Quick setting component
Component {
id: quickSettingComponent
2024-07-27 03:47:44 +00:00
MobileShell.BaseItem {
height: root.rowHeight
width: root.columnWidth
padding: Kirigami.Units.smallSpacing
contentItem: QuickSettingsFullDelegate {
restrictedPermissions: actionDrawer.restrictedPermissions
2024-07-27 03:47:44 +00:00
text: modelData.text
status: modelData.status
icon: modelData.icon
enabled: modelData.enabled
settingsCommand: modelData.settingsCommand
toggleFunction: modelData.toggle
2024-07-27 03:47:44 +00:00
onCloseRequested: {
actionDrawer.close();
}
}
}
}
}