Closed Zren closed 3 months ago
Fudge, plasmoid.editMode
is a containment property, aka panel.editMode
, not widget.editMode
. So I don't think I can access it...
Was thinking I might be able to check if plasmoid.action("edit mode")
exists to detect Plasma 5.18, but that appears to be null
.
https://github.com/KDE/plasma-framework/blob/master/src/plasma/corona.cpp#L375
I've managed to get some code that works... usually.
Item {
id: widget
//--- containment.editMode detector
property var containmentInterface: null
readonly property bool editMode: containmentInterface ? containmentInterface.editMode : false
onParentChanged: {
if (parent) {
for (var obj = widget, depth = 0; !!obj; obj = obj.parent, depth++) {
console.log('depth', depth, 'obj', obj)
if (obj.toString().startsWith('ContainmentInterface')) {
// desktop containment / plasmoidviewer
// Note: This doesn't always work. FolderViewDropArea may not yet have
// ContainmentInterface as a parent when this loop runs.
if (typeof obj['editMode'] === 'boolean') {
console.log('\t', 'obj.editMode', obj.editMode, typeof obj['editMode'])
widget.containmentInterface = obj
break
}
} else if (obj.toString().startsWith('DeclarativeDropArea')) {
// panel containment
if (typeof obj['Plasmoid'] !== 'undefined' && obj['Plasmoid'].toString().startsWith('ContainmentInterface')) {
if (typeof obj['Plasmoid']['editMode'] === 'boolean') {
console.log('\t', 'obj.Plasmoid', obj.Plasmoid, typeof obj['Plasmoid']) // ContainmentInterface
console.log('\t', 'obj.Plasmoid.editMode', obj.Plasmoid.editMode, typeof obj['Plasmoid']['editMode'])
widget.containmentInterface = obj.Plasmoid
break
}
}
}
}
}
}
//---
}
The problem is that a desktop widget sometimes doesn't have ContainmentInterface
as a parent of FolderViewDropArea
. It hasn't been attached yet probably, just like how we need to wait for main.qml
/ widget
to get attached to it's parent
.
qml: depth 0 obj QQuickItem_QML_252(0x56388f22b590)
qml: depth 1 obj AppletInterface(0x56388eaa1420)
qml: depth 2 obj BasicAppletContainer_QMLTYPE_290(0x56388fbb91c0)
qml: depth 3 obj AppletsLayout(0x56388f2d06e0)
qml: depth 4 obj FolderViewDropArea_QMLTYPE_281_QML_293(0x56388f2edde0, "folder")
Though it might detect it:
qml: depth 0 obj QQuickItem_QML_252(0x55e0c3a6d6d0)
qml: depth 1 obj AppletInterface(0x55e0c3d20890)
qml: depth 2 obj BasicAppletContainer_QMLTYPE_289(0x55e0bfe34020)
qml: depth 3 obj AppletsLayout(0x55e0bef3e0c0)
qml: depth 4 obj FolderViewDropArea_QMLTYPE_292_QML_293(0x55e0bef4c7e0, "folder")
qml: depth 5 obj ContainmentInterface(0x55e0be5ac220)
qml: obj.editMode true boolean
A panel will usually detect it though.
qml: depth 0 obj QQuickItem_QML_252(0x56389027d260)
qml: depth 1 obj AppletInterface(0x56388e9f0ca0)
qml: depth 2 obj QQuickLoader_QML_760(0x563891cfbb30)
qml: depth 3 obj QQuickGridLayout_QML_762(0x56389198e250)
qml: depth 4 obj DeclarativeDropArea_QML_758(0x56389198b770)
qml: obj.Plasmoid ContainmentInterface(0x56388e97d9a0) object
qml: obj.Plasmoid.editMode false boolean
Plasma 6 exposes the applet containement and corona objects to read/write their properties.
After a user unlocks widgets in Plasma 5.18, the widget is permanently in "mutable mode". We'll need to check if
plasmoid
has theplasmoid.editMode
property.