panel: Rework panel layout, and refactoring

This commit is contained in:
Devin Lin 2021-10-12 13:50:36 +00:00
parent 957e5126a8
commit 7df05e09be
14 changed files with 229 additions and 172 deletions

View file

@ -0,0 +1,15 @@
/*
* SPDX-FileCopyrightText: 2021 Devin Lin <devin@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQuick 2.12
import org.kde.plasma.core 2.0 as PlasmaCore
pragma Singleton
QtObject {
id: root
property real panelHeight: PlasmaCore.Units.gridUnit // set and updated in panel containment
}

View file

@ -1,3 +1,4 @@
module org.kde.plasma.private.mobileshell module org.kde.plasma.private.mobileshell
singleton HomeScreenControls 1.0 HomeScreenControls.qml singleton HomeScreenControls 1.0 HomeScreenControls.qml
singleton TopPanelControls 1.0 TopPanelControls.qml

View file

@ -7,6 +7,7 @@
import QtQuick 2.12 import QtQuick 2.12
import QtQuick.Controls 2.12 as Controls
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
import QtQml.Models 2.12 import QtQml.Models 2.12
import QtGraphicalEffects 1.12 import QtGraphicalEffects 1.12
@ -28,13 +29,17 @@ import "indicators" as Indicators
Item { Item {
id: indicatorsRow id: indicatorsRow
required property var colorGroup required property var colorGroup
required property bool showGradientBackground
required property bool showDropShadow required property bool showDropShadow
required property color backgroundColor required property color backgroundColor
property bool showSecondRow: false // show extra row with date and mobile provider
property alias colorScopeColor: icons.backgroundColor property alias colorScopeColor: icons.backgroundColor
property alias applets: appletIconsRow property alias applets: appletIconsRow
property real textPixelSize: PlasmaCore.Units.gridUnit * 0.6
property real elementSpacing: PlasmaCore.Units.smallSpacing * 1.5
PlasmaCore.DataSource { PlasmaCore.DataSource {
id: timeSource id: timeSource
engine: "time" engine: "time"
@ -48,9 +53,9 @@ Item {
cached: true cached: true
horizontalOffset: 0 horizontalOffset: 0
verticalOffset: 1 verticalOffset: 1
radius: 4.0 radius: 6.0
samples: 17 samples: 17
color: Qt.rgba(0,0,0,0.8) color: Qt.rgba(0,0,0,0.6)
source: icons source: icons
} }
@ -61,40 +66,51 @@ Item {
colorGroup: indicatorsRow.colorGroup colorGroup: indicatorsRow.colorGroup
anchors.fill: parent anchors.fill: parent
// background Controls.Control {
Rectangle { id: control
topPadding: PlasmaCore.Units.smallSpacing
bottomPadding: PlasmaCore.Units.smallSpacing
rightPadding: PlasmaCore.Units.smallSpacing * 3
leftPadding: PlasmaCore.Units.smallSpacing * 3
anchors.fill: parent anchors.fill: parent
background: Rectangle {
color: backgroundColor color: backgroundColor
} }
Rectangle {
visible: showGradientBackground contentItem: ColumnLayout {
anchors.fill: parent spacing: PlasmaCore.Units.smallSpacing / 2
gradient: Gradient {
GradientStop { RowLayout {
position: 1.0 id: row
color: "transparent" Layout.fillWidth: true
} Layout.maximumHeight: MobileShell.TopPanelControls.panelHeight - control.topPadding - control.bottomPadding
GradientStop { spacing: 0
position: 0.0
color: Qt.rgba(0, 0, 0, 0.1) // clock
PlasmaComponents.Label {
id: clock
property bool is24HourTime: plasmoid.nativeInterface.isSystem24HourFormat
Layout.fillHeight: true
text: Qt.formatTime(timeSource.data.Local.DateTime, is24HourTime ? "h:mm" : "h:mm ap")
color: PlasmaCore.ColorScope.textColor
verticalAlignment: Qt.AlignVCenter
font.pixelSize: textPixelSize
TapHandler {
onTapped: {
plasmoid.nativeInterface.launchApp("org.kde.kclock");
} }
} }
} }
Loader { // spacing in the middle
id: strengthLoader Item {
height: parent.height Layout.fillWidth: true
width: item ? item.width : 0
active: signalStrengthProvider
sourceComponent: Indicators.SignalStrength {
provider: signalStrengthProvider
}
} }
Row { // system tray
id: statusNotifierIndicatorsRow
anchors.left: strengthLoader.right
height: parent.height
Repeater { Repeater {
id: statusNotifierRepeater id: statusNotifierRepeater
model: PlasmaCore.SortFilterModel { model: PlasmaCore.SortFilterModel {
@ -105,49 +121,72 @@ Item {
} }
} }
delegate: TaskWidget {} delegate: TaskWidget {
} Layout.leftMargin: indicatorsRow.elementSpacing
}
PlasmaComponents.Label {
id: clock
property bool is24HourTime: plasmoid.nativeInterface.isSystem24HourFormat
anchors.fill: parent
text: Qt.formatTime(timeSource.data.Local.DateTime, is24HourTime ? "h:mm" : "h:mm ap")
color: PlasmaCore.ColorScope.textColor
horizontalAlignment: Qt.AlignHCenter
verticalAlignment: Qt.AlignVCenter
font.pixelSize: height / 2
TapHandler {
onTapped: {
plasmoid.nativeInterface.launchApp("org.kde.kclock");
}
} }
} }
// applet indicators
RowLayout { RowLayout {
id: appletIconsRow id: appletIconsRow
anchors { Layout.leftMargin: indicatorsRow.elementSpacing
bottom: parent.bottom Layout.fillHeight: true
right: simpleIndicatorsLayout.left spacing: indicatorsRow.elementSpacing
} visible: children.length > 0
height: parent.height
} }
// system indicators
RowLayout { RowLayout {
id: simpleIndicatorsLayout id: indicators
anchors { Layout.leftMargin: PlasmaCore.Units.smallSpacing // applets have different spacing needs
top: parent.top Layout.fillHeight: true
bottom: parent.bottom spacing: indicatorsRow.elementSpacing
right: parent.right
rightMargin: PlasmaCore.Units.smallSpacing Indicators.SignalStrength {
provider: signalStrengthProvider
Layout.fillHeight: true
}
Indicators.Bluetooth {
provider: bluetoothProvider
Layout.fillHeight: true
}
Indicators.Wifi {
provider: wifiProvider
Layout.fillHeight: true
}
Indicators.Volume {
provider: volumeProvider
Layout.fillHeight: true
}
Indicators.Battery {
provider: batteryProvider
spacing: indicatorsRow.elementSpacing
labelHeight: textPixelSize
Layout.fillHeight: true
}
}
}
// extra row with date and mobile provider (for quicksettings panel)
RowLayout {
spacing: 0
visible: indicatorsRow.showSecondRow
Layout.fillWidth: true
PlasmaComponents.Label {
text: Qt.formatDate(timeSource.data.Local.DateTime, "ddd. MMMM d")
color: PlasmaCore.ColorScope.disabledTextColor
font.pixelSize: indicatorsRow.textPixelSize * 0.8
}
Item { Layout.fillWidth: true }
PlasmaComponents.Label {
text: signalStrengthProvider.label
color: PlasmaCore.ColorScope.disabledTextColor
font.pixelSize: indicatorsRow.textPixelSize * 0.8
horizontalAlignment: Qt.AlignRight
}
}
} }
Indicators.Bluetooth { provider: bluetoothProvider }
Indicators.Wifi { provider: wifiProvider }
Indicators.Volume { provider: volumeProvider }
Indicators.Battery { provider: batteryProvider }
} }
} }
} }

View file

@ -23,6 +23,7 @@ Item {
} }
PlasmaCore.IconItem { PlasmaCore.IconItem {
id: icon
source: IconName ? IconName : Icon source: IconName ? IconName : Icon
width: Math.min(parent.width, parent.height) width: Math.min(parent.width, parent.height)
height: width height: width

View file

@ -16,6 +16,7 @@ import "providers"
RowLayout { RowLayout {
required property BatteryProvider provider required property BatteryProvider provider
property real labelHeight
visible: provider.isVisible visible: provider.isVisible
PW.BatteryIcon { PW.BatteryIcon {
@ -36,6 +37,6 @@ RowLayout {
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
color: PlasmaCore.ColorScope.textColor color: PlasmaCore.ColorScope.textColor
font.pixelSize: parent.height / 2 font.pixelSize: labelHeight
} }
} }

View file

@ -17,8 +17,8 @@ import "providers"
Item { Item {
required property QtObject provider required property QtObject provider
width: strengthIcon.height + strengthLabel.width width: strengthIcon.height
Layout.minimumWidth: strengthIcon.height + strengthLabel.width Layout.minimumWidth: strengthIcon.height
PlasmaCore.IconItem { PlasmaCore.IconItem {
id: strengthIcon id: strengthIcon
@ -30,14 +30,4 @@ Item {
source: provider.icon source: provider.icon
} }
PlasmaComponents.Label {
id: label
anchors.left: strengthIcon.right
anchors.verticalCenter: parent.verticalCenter
text: provider.label
color: PlasmaCore.ColorScope.textColor
font.pixelSize: parent.height / 2
}
} }

View file

@ -32,7 +32,21 @@ import "indicators/providers" as IndicatorProviders
Item { Item {
id: root id: root
width: 480 width: 480
height: 30 height: PlasmaCore.Units.gridUnit
// set height binding to top panel API
Binding {
target: MobileShell.TopPanelControls
property: "panelHeight"
value: root.height
}
// set height binding to top panel API
Binding {
target: MobileShell.TopPanelControls
property: "panelHeight"
value: root.height
}
Plasmoid.backgroundHints: showingApp ? PlasmaCore.Types.StandardBackground : PlasmaCore.Types.NoBackground Plasmoid.backgroundHints: showingApp ? PlasmaCore.Types.StandardBackground : PlasmaCore.Types.NoBackground
@ -179,7 +193,6 @@ Item {
z: 1 z: 1
colorGroup: showingApp ? PlasmaCore.Theme.HeaderColorGroup : PlasmaCore.Theme.ComplementaryColorGroup colorGroup: showingApp ? PlasmaCore.Theme.HeaderColorGroup : PlasmaCore.Theme.ComplementaryColorGroup
backgroundColor: !showingApp ? "transparent" : root.backgroundColor backgroundColor: !showingApp ? "transparent" : root.backgroundColor
showGradientBackground: !showingApp
showDropShadow: !showingApp showDropShadow: !showingApp
} }

View file

@ -101,11 +101,15 @@ Item {
IndicatorsRow { IndicatorsRow {
id: indicatorsRow id: indicatorsRow
z: 1 z: 1
Layout.leftMargin: -Kirigami.Units.largeSpacing
Layout.rightMargin: -Kirigami.Units.largeSpacing
Layout.fillWidth: true Layout.fillWidth: true
Layout.preferredHeight: parentSlidingPanel.topPanelHeight Layout.preferredHeight: parentSlidingPanel.topPanelHeight + PlasmaCore.Units.smallSpacing * 2
showSecondRow: true
colorGroup: PlasmaCore.Theme.NormalColorGroup colorGroup: PlasmaCore.Theme.NormalColorGroup
backgroundColor: "transparent" backgroundColor: "transparent"
showGradientBackground: false
showDropShadow: false showDropShadow: false
} }

View file

@ -255,7 +255,7 @@ PlasmaCore.ColorScope {
Window.window.offset = Qt.binding(() => { Window.window.offset = Qt.binding(() => {
// FIXME: find a more precise way to determine the top panel height // FIXME: find a more precise way to determine the top panel height
return plasmoid.formFactor === PlasmaCore.Types.Vertical ? PlasmaCore.Units.gridUnit : 0 return plasmoid.formFactor === PlasmaCore.Types.Vertical ? MobileShell.TopPanelControls.panelHeight : 0
}); });
} }

View file

@ -6,6 +6,7 @@
*/ */
import QtQuick 2.12 import QtQuick 2.12
import QtQuick.Controls 2.15 as Controls
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
import QtGraphicalEffects 1.12 import QtGraphicalEffects 1.12
@ -14,89 +15,73 @@ import org.kde.plasma.components 3.0 as PlasmaComponents
import org.kde.plasma.workspace.components 2.0 as PW import org.kde.plasma.workspace.components 2.0 as PW
import "indicators" as Indicators import "indicators" as Indicators
import "indicators/providers" as Providers
// a simple version of the task panel // a simple version of the task panel
// in the future, it should share components with the existing task panel // in the future, it should share components with the existing task panel
PlasmaCore.ColorScope { PlasmaCore.ColorScope {
colorGroup: PlasmaCore.Theme.ComplementaryColorGroup colorGroup: PlasmaCore.Theme.ComplementaryColorGroup
property real textPixelSize: PlasmaCore.Units.gridUnit * 0.6
layer.enabled: true layer.enabled: true
layer.effect: DropShadow { layer.effect: DropShadow {
visible: true visible: true
cached: true cached: true
horizontalOffset: 0 horizontalOffset: 0
verticalOffset: 1 verticalOffset: 1
radius: 4.0 radius: 6.0
samples: 17 samples: 17
color: Qt.rgba(0,0,0,0.8) color: Qt.rgba(0,0,0,0.6)
} }
PlasmaCore.DataSource { Providers.SignalStrengthProvider {
id: timeSource
engine: "time"
connectedSources: ["Local"]
interval: 60 * 1000
}
Rectangle {
anchors.fill: parent
gradient: Gradient {
GradientStop {
position: 1.0
color: "transparent"
}
GradientStop {
position: 0.0
color: Qt.rgba(0, 0, 0, 0.1)
}
}
}
Loader {
id: strengthLoader
height: parent.height
width: item ? item.width : 0
active: signalStrengthProviderLoader.item
sourceComponent: Indicators.SignalStrength {
provider: signalStrengthProviderLoader.item
}
}
Loader {
id: signalStrengthProviderLoader id: signalStrengthProviderLoader
source: Qt.resolvedUrl("indicators/providers/SignalStrengthProvider.qml")
} }
PlasmaComponents.Label { Controls.Control {
id: clock topPadding: PlasmaCore.Units.smallSpacing
bottomPadding: PlasmaCore.Units.smallSpacing
rightPadding: PlasmaCore.Units.smallSpacing * 3
leftPadding: PlasmaCore.Units.smallSpacing * 3
anchors.fill: parent anchors.fill: parent
text: Qt.formatTime(timeSource.data.Local.DateTime, root.is24HourTime ? "h:mm" : "h:mm ap")
color: PlasmaCore.ColorScope.textColor contentItem: RowLayout {
horizontalAlignment: Qt.AlignHCenter id: row
verticalAlignment: Qt.AlignVCenter spacing: 0
font.pixelSize: height / 2
Indicators.SignalStrength {
provider: signalStrengthProviderLoader
labelPixelSize: textPixelSize
Layout.fillHeight: true
}
// spacing in the middle
Item {
Layout.fillWidth: true
} }
RowLayout { RowLayout {
id: appletIconsRow id: indicators
anchors { spacing: PlasmaCore.Units.smallSpacing * 1.5
bottom: parent.bottom Layout.fillHeight: true
right: simpleIndicatorsLayout.left
}
height: parent.height
}
RowLayout { Indicators.Bluetooth {
id: simpleIndicatorsLayout Layout.fillHeight: true
anchors { }
top: parent.top Indicators.Wifi {
bottom: parent.bottom Layout.fillHeight: true
right: parent.right }
rightMargin: PlasmaCore.Units.smallSpacing Indicators.Volume {
Layout.fillHeight: true
}
Indicators.Battery {
spacing: PlasmaCore.Units.smallSpacing * 1.5
labelPixelSize: textPixelSize
Layout.fillHeight: true
}
}
} }
Indicators.Bluetooth {}
Indicators.Wifi {}
Indicators.Volume {}
Indicators.Battery {}
} }
} }

View file

@ -15,6 +15,8 @@ import org.kde.plasma.workspace.components 2.0 as PW
RowLayout { RowLayout {
visible: pmSource.data["Battery"]["Has Cumulative"] visible: pmSource.data["Battery"]["Has Cumulative"]
property real labelPixelSize
PW.BatteryIcon { PW.BatteryIcon {
id: battery id: battery
Layout.preferredWidth: height Layout.preferredWidth: height
@ -39,6 +41,6 @@ RowLayout {
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
color: PlasmaCore.ColorScope.textColor color: PlasmaCore.ColorScope.textColor
font.pixelSize: parent.height / 2 font.pixelSize: labelPixelSize
} }
} }

View file

@ -16,8 +16,10 @@ import "providers"
Item { Item {
required property QtObject provider required property QtObject provider
width: strengthIcon.height + strengthLabel.width property real labelPixelSize
Layout.minimumWidth: strengthIcon.height + strengthLabel.width
width: strengthIcon.height + label.width
Layout.minimumWidth: strengthIcon.height + label.width
PlasmaCore.IconItem { PlasmaCore.IconItem {
id: strengthIcon id: strengthIcon
@ -32,11 +34,12 @@ Item {
PlasmaComponents.Label { PlasmaComponents.Label {
id: label id: label
anchors.leftMargin: PlasmaCore.Units.smallSpacing
anchors.left: strengthIcon.right anchors.left: strengthIcon.right
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
text: provider.label text: provider.label
color: PlasmaCore.ColorScope.textColor color: PlasmaCore.ColorScope.textColor
font.pixelSize: parent.height / 2 font.pixelSize: labelPixelSize
} }
} }

View file

@ -3,12 +3,14 @@ for (var j = 0; j < desktopsArray.length; j++) {
desktopsArray[j].wallpaperPlugin = "org.kde.image"; desktopsArray[j].wallpaperPlugin = "org.kde.image";
} }
desktopsArray[0].addWidget("org.kde.phone.krunner", 0, 0, screenGeometry(0).width, 20) desktopsArray[0].addWidget("org.kde.phone.krunner", 0, 0, screenGeometry(0).width, 20)
// keep this list in sync with shell/contents/updates/panelsfix.js // keep this list in sync with shell/contents/updates/panelsfix.js
var panel = new Panel("org.kde.phone.panel"); var panel = new Panel("org.kde.phone.panel");
panel.location = "top"; panel.location = "top";
panel.addWidget("org.kde.plasma.notifications"); panel.addWidget("org.kde.plasma.notifications");
panel.addWidget("org.kde.plasma.mediacontroller"); panel.addWidget("org.kde.plasma.mediacontroller");
panel.height = 1 * gridUnit; panel.height = 1.25 * gridUnit; // HACK: supposed to be gridUnit + smallSpacing, but it doesn't seem to give the correct number
var bottomPanel = new Panel("org.kde.phone.taskpanel") var bottomPanel = new Panel("org.kde.phone.taskpanel")
bottomPanel.location = "bottom"; bottomPanel.location = "bottom";
bottomPanel.height = 2 * gridUnit;

View file

@ -16,6 +16,7 @@ if (!topFound) {
topPanel.addWidget("org.kde.plasma.notifications"); topPanel.addWidget("org.kde.plasma.notifications");
topPanel.addWidget("org.kde.plasma.mediacontroller"); topPanel.addWidget("org.kde.plasma.mediacontroller");
topPanel.location = "top"; topPanel.location = "top";
topPanel.height = 1.25 * gridUnit;
} }
if (!bottomFound) { if (!bottomFound) {
let bottomPanel = new Panel("org.kde.phone.taskpanel") let bottomPanel = new Panel("org.kde.phone.taskpanel")