Verified Commit 74c88b77 authored by Carl Schwan's avatar Carl Schwan 🚴
Browse files

Port PlasmaExtras.ScrollArea to ScrollView

This also introduce a consistent scrollbar with Kickoff and other KDE
apps.
parent 1189bd44
Pipeline #122080 passed with stage
in 44 seconds
......@@ -16,11 +16,13 @@ import org.kde.plasma.private.bluetooth 1.0 as PlasmaBt
import "logic.js" as Logic
PlasmaComponents3.Page {
PlasmaExtras.Representation {
implicitWidth: PlasmaCore.Units.gridUnit * 24
implicitHeight: PlasmaCore.Units.gridUnit * 24
collapseMarginsHint: true
Action {
id: addBluetoothDeviceAction
......@@ -31,6 +33,7 @@ PlasmaComponents3.Page {
onTriggered: plasmoid.action("addNewDevice").trigger()
}
Action {
id: enableBluetoothAction
......@@ -49,99 +52,91 @@ PlasmaComponents3.Page {
visible: btManager.adapters.length > 0
}
FocusScope {
PlasmaComponents3.ScrollView {
id: scrollView
anchors.fill: parent
anchors.topMargin: PlasmaCore.Units.smallSpacing
focus: true
PlasmaBt.DevicesProxyModel {
id: devicesModel
sourceModel: BluezQt.DevicesModel { }
}
// HACK: workaround for https://bugreports.qt.io/browse/QTBUG-83890
PlasmaComponents3.ScrollBar.horizontal.policy: PlasmaComponents3.ScrollBar.AlwaysOff
PlasmaExtras.ScrollArea {
id: scrollView
anchors.fill: parent
visible: btManager.adapters.length > 0 && !btManager.bluetoothBlocked
ListView {
id: listView
anchors.fill: parent
clip: true
model: devicesModel
currentIndex: -1
enabled: btManager.bluetoothOperational
boundsBehavior: Flickable.StopAtBounds
section.property: "Section"
// We want to hide the section delegate for the "Connected"
// group because it's unnecessary; all we want to do here is
// separate the connected devices from the available ones
section.delegate: Loader {
active: section != "Connected" && Logic.conectedDevicesCount() > 0
// Need to manually set the height or else the loader takes up
// space after the first time it unloads a previously-loaded item
height: active ? PlasmaCore.Units.gridUnit : 0
sourceComponent: Item {
width: listView.width
height: PlasmaCore.Units.gridUnit
PlasmaCore.SvgItem {
width: parent.width - PlasmaCore.Units.gridUnit * 2
anchors.centerIn: parent
id: separatorLine
svg: PlasmaCore.Svg {
imagePath: "widgets/line"
}
elementId: "horizontal-line"
contentItem: ListView {
id: listView
readonly property var devicesModel: PlasmaBt.DevicesProxyModel {
id: devicesModel
sourceModel: BluezQt.DevicesModel { }
}
model: btManager.adapters.length > 0 && !btManager.bluetoothBlocked ? devicesModel : null
currentIndex: -1
boundsBehavior: Flickable.StopAtBounds
topMargin: PlasmaCore.Units.smallSpacing * 2
bottomMargin: PlasmaCore.Units.smallSpacing * 2
leftMargin: PlasmaCore.Units.smallSpacing * 2
rightMargin: PlasmaCore.Units.smallSpacing * 2
spacing: PlasmaCore.Units.smallSpacing
section.property: "Section"
// We want to hide the section delegate for the "Connected"
// group because it's unnecessary; all we want to do here is
// separate the connected devices from the available ones
section.delegate: Loader {
active: section != "Connected" && Logic.conectedDevicesCount() > 0
// Need to manually set the height or else the loader takes up
// space after the first time it unloads a previously-loaded item
height: active ? PlasmaCore.Units.gridUnit : 0
sourceComponent: Item {
width: listView.width - PlasmaCore.Units.smallSpacing * 4
height: PlasmaCore.Units.gridUnit
PlasmaCore.SvgItem {
width: parent.width - PlasmaCore.Units.gridUnit * 2
anchors.centerIn: parent
id: separatorLine
svg: PlasmaCore.Svg {
imagePath: "widgets/line"
}
elementId: "horizontal-line"
}
}
highlight: PlasmaComponents.Highlight { }
highlightMoveDuration: 0
highlightResizeDuration: 0
delegate: DeviceItem {
width: listView.width
}
}
}
highlight: PlasmaComponents.Highlight { }
highlightMoveDuration: 0
highlightResizeDuration: 0
delegate: DeviceItem {
width: listView.width - (scrollView.PlasmaComponents3.ScrollBar.vertical.visible ? PlasmaCore.Units.smallSpacing * 4 : 0)
}
// Not inside the ListView because we want the listview to be hidden
// when Bluetooth is disabled, yet still show an "Enable Bluetooth"
// message
PlasmaExtras.PlaceholderMessage {
anchors.centerIn: parent
anchors.left: parent.left
anchors.right: parent.right
anchors.margins: PlasmaCore.Units.largeSpacing
visible: text.length > 0
text: {
// We cannot use the adapter count here because that can be zero when
// bluetooth is disabled even when there are physical devices
if (BluezQt.Manager.rfkill.state === BluezQt.Rfkill.Unknown) {
return i18n("No Bluetooth Adapters Available")
} else if (btManager.bluetoothBlocked) {
return i18n("Bluetooth is Disabled")
} else if (btManager.devices.length === 0) {
return i18n("No Devices Found")
PlasmaExtras.PlaceholderMessage {
anchors.centerIn: parent
anchors.left: parent.left
anchors.right: parent.right
anchors.margins: PlasmaCore.Units.largeSpacing
visible: text.length > 0
text: {
// We cannot use the adapter count here because that can be zero when
// bluetooth is disabled even when there are physical devices
if (BluezQt.Manager.rfkill.state === BluezQt.Rfkill.Unknown) {
return i18n("No Bluetooth Adapters Available")
} else if (btManager.bluetoothBlocked) {
return i18n("Bluetooth is Disabled")
} else if (btManager.devices.length === 0) {
return i18n("No Devices Found")
}
return ""
}
return ""
}
helpfulAction: {
if (BluezQt.Manager.rfkill.state === BluezQt.Rfkill.Unknown) {
helpfulAction: {
if (BluezQt.Manager.rfkill.state === BluezQt.Rfkill.Unknown) {
return null
} else if (btManager.bluetoothBlocked) {
return enableBluetoothAction
} else if (btManager.devices.length === 0) {
return addBluetoothDeviceAction
}
return null
} else if (btManager.bluetoothBlocked) {
return enableBluetoothAction
} else if (btManager.devices.length === 0) {
return addBluetoothDeviceAction
}
return null
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment