quicksettings: fix landscape view

This commit is contained in:
Yari Polla 2022-05-12 15:20:39 +02:00 committed by Devin Lin
parent ee951627b3
commit ed0030eea3
2 changed files with 65 additions and 38 deletions

View file

@ -11,6 +11,7 @@ import QtQuick.Layouts 1.1
import QtQuick.Window 2.2 import QtQuick.Window 2.2
import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 3.0 as PlasmaComponents
import org.kde.plasma.private.mobileshell 1.0 as MobileShell import org.kde.plasma.private.mobileshell 1.0 as MobileShell
import "../../components" as Components import "../../components" as Components
@ -42,8 +43,7 @@ Item {
readonly property MobileShell.QuickSettingsModel quickSettingsModel: MobileShell.QuickSettingsModel {} readonly property MobileShell.QuickSettingsModel quickSettingsModel: MobileShell.QuickSettingsModel {}
readonly property real pageHeight: (Window.height * 60/100) readonly property int rowCount: Math.floor(Window.height * 65/100 / rowHeight)
readonly property int rowCount: Math.floor(pageHeight / rowHeight)
readonly property int columnCount: Math.floor(width/columnWidth) readonly property int columnCount: Math.floor(width/columnWidth)
readonly property int pageSize: rowCount * columnCount readonly property int pageSize: rowCount * columnCount
readonly property int quickSettingsCount: quickSettingsModel.count readonly property int quickSettingsCount: quickSettingsModel.count
@ -82,7 +82,8 @@ Item {
id: pageLoader id: pageLoader
Layout.fillWidth: true Layout.fillWidth: true
Layout.minimumHeight: rowCount * rowHeight
asynchronous: true asynchronous: true
sourceComponent: MobileShell.Shell.orientation === MobileShell.Shell.Portrait ? swipeViewComponent : scrollViewComponent sourceComponent: MobileShell.Shell.orientation === MobileShell.Shell.Portrait ? swipeViewComponent : scrollViewComponent
} }
@ -139,7 +140,7 @@ Item {
} }
} }
// Loaded when in portrait mode // Loads portrait quick settings view
Component { Component {
id: swipeViewComponent id: swipeViewComponent
@ -210,32 +211,64 @@ Item {
} }
} }
// Loaded when in landscape mode // Loads landscape quick settings view
Component { Component {
id: scrollViewComponent id: scrollViewComponent
Flickable { Item {
clip: true width: parent.width
height: pageHeight height: rowCount * rowHeight
contentWidth: parent.width PlasmaComponents.ScrollView {
contentHeight: quickSettingsCount / columnCount * rowHeight enabled: pageSize <= quickSettingsCount
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
ScrollBar.vertical.policy: ScrollBar.AlwaysOff
ScrollBar.vertical.interactive:false
anchors.fill: parent
contentWidth: width
contentHeight: height
contentItem: flickable
}
Flow { Flickable {
width: parent.width id: flickable
anchors.fill: parent
contentWidth: width
contentHeight: flow.height
height: quickSettingsCount / columnCount * rowHeight clip: true
spacing: 0 ScrollIndicator.vertical: ScrollIndicator {
active: true
Repeater {
model: quickSettingsModel visible: quickSettingsCount > pageSize ? true : false
delegate: Loader {
required property var modelData position: 0.1
asynchronous: true contentItem: Rectangle {
implicitWidth: PlasmaCore.Units.smallSpacing/4
sourceComponent: quickSettingComponent color: PlasmaCore.Theme.textColor
opacity: 0.5
}
}
Flow {
id: flow
width: parent.width
height: Math.ceil(quickSettingsCount / columnCount) * rowHeight
spacing: 0
Repeater {
model: quickSettingsModel
delegate: Loader {
required property var modelData
asynchronous: true
sourceComponent: quickSettingComponent
}
} }
} }
} }

View file

@ -13,7 +13,6 @@ import QtGraphicalEffects 1.12
import org.kde.kirigami 2.12 as Kirigami import org.kde.kirigami 2.12 as Kirigami
import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 3.0 as PlasmaComponents
import org.kde.plasma.private.mobileshell 1.0 as MobileShell import org.kde.plasma.private.mobileshell 1.0 as MobileShell
import "../../statusbar" as StatusBar import "../../statusbar" as StatusBar
@ -82,25 +81,20 @@ Components.BaseItem {
disableSystemTray: actionDrawer.restrictedPermissions disableSystemTray: actionDrawer.restrictedPermissions
} }
PlasmaComponents.ScrollView { QuickSettings {
id: scrollView id: quickSettings
width: column.width
implicitHeight: quickSettings.fullHeight
Layout.alignment: Qt.AlignTop Layout.alignment: Qt.AlignTop
Layout.fillWidth: true Layout.fillWidth: true
Layout.maximumHeight: root.fullHeight - root.topPadding - root.bottomPadding - statusBar.height - mediaWidget.fullHeight - PlasmaCore.Units.smallSpacing Layout.maximumHeight: root.fullHeight - root.topPadding - root.bottomPadding - statusBar.height - mediaWidget.fullHeight - PlasmaCore.Units.smallSpacing
Layout.maximumWidth: column.width Layout.maximumWidth: column.width
QQC2.ScrollBar.horizontal.policy: QQC2.ScrollBar.AlwaysOff actionDrawer: root.actionDrawer
clip: true minimizedViewProgress: 0
fullViewProgress: 1
QuickSettings {
id: quickSettings
width: column.width
implicitHeight: quickSettings.fullHeight
actionDrawer: root.actionDrawer
minimizedViewProgress: 0
fullViewProgress: 1
}
} }
Item { Layout.fillHeight: true } Item { Layout.fillHeight: true }