Martchus
912dca1564
* Split QML part into distinct versions for Plasma 5 and 6 as there are too many differences and `#ifdef` is not possible * Change API usage according to https://develop.kde.org/docs/plasma/widget/porting_kf6 * Port "contextualActions" to API documented on https://invent.kde.org/frameworks/plasma-framework/-/blob/master/src/plasma/applet.h * Document testing * Add FIXMEs/notes for remaining problems; there are likely many more, though
117 lines
3.7 KiB
QML
117 lines
3.7 KiB
QML
// Based on PlasmaComponents.ListItem from Plasma 5.44.0
|
|
// (Can't use PlasmaComponents.ListItem itself because creating a MouseArea filling
|
|
// the entire entire item for detecting right-mouse-click is not possible due to binding
|
|
// loop of width and height properties.)
|
|
import QtQuick 2.7
|
|
import QtQuick.Layouts 1.1
|
|
import org.kde.ksvg 1.0 as KSvg
|
|
import org.kde.kirigami 2.20 as Kirigami
|
|
|
|
Item {
|
|
id: listItem
|
|
property bool expanded: false
|
|
default property alias content: paddingItem.data
|
|
|
|
/**
|
|
* If true makes the list item look as checked or pressed. It has to be set
|
|
* from the code, it won't change by itself.
|
|
*/
|
|
//plasma extension
|
|
//always look pressed?
|
|
property bool checked: false
|
|
|
|
/**
|
|
* If true the item will be a delegate for a section, so will look like a
|
|
* "title" for the otems under it.
|
|
*/
|
|
//is this to be used as section delegate?
|
|
property bool sectionDelegate: false
|
|
|
|
/**
|
|
* type: bool
|
|
* True if the separator between items is visible
|
|
* default: true
|
|
*/
|
|
property bool separatorVisible: true
|
|
|
|
width: parent ? parent.width : childrenRect.width
|
|
height: paddingItem.childrenRect.height + background.margins.top + background.margins.bottom
|
|
|
|
implicitHeight: paddingItem.childrenRect.height + background.margins.top
|
|
+ background.margins.bottom
|
|
|
|
function activate(containsMouse) {
|
|
view.activate(containsMouse ? index : -1)
|
|
}
|
|
|
|
KSvg.FrameSvgItem {
|
|
id: background
|
|
imagePath: "widgets/listitem"
|
|
prefix: (listItem.sectionDelegate ? "section" : (itemMouse.pressed
|
|
|| listItem.checked) ? "pressed" : "normal")
|
|
|
|
anchors.fill: parent
|
|
visible: listItem.ListView.view ? listItem.ListView.view.highlight === null : true
|
|
Behavior on opacity {
|
|
NumberAnimation {
|
|
duration: Kirigami.Units.longDuration
|
|
}
|
|
}
|
|
}
|
|
KSvg.SvgItem {
|
|
svg: KSvg.Svg {
|
|
imagePath: "widgets/listitem"
|
|
}
|
|
elementId: "separator"
|
|
anchors {
|
|
left: parent.left
|
|
right: parent.right
|
|
top: parent.top
|
|
}
|
|
height: naturalSize.height
|
|
visible: separatorVisible && (listItem.sectionDelegate
|
|
|| (typeof (index) != "undefined"
|
|
&& index > 0 && !listItem.checked
|
|
&& !itemMouse.pressed))
|
|
}
|
|
|
|
MouseArea {
|
|
id: itemMouse
|
|
property bool changeBackgroundOnPress: !listItem.checked
|
|
&& !listItem.sectionDelegate
|
|
anchors.fill: background
|
|
hoverEnabled: true
|
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
|
|
|
onClicked: function(mouse) {
|
|
switch (mouse.button) {
|
|
case Qt.LeftButton:
|
|
expanded = !expanded
|
|
break
|
|
case Qt.RightButton:
|
|
var view = listItem.ListView.view
|
|
var coordinates = mapToItem(view, mouseX, mouseY)
|
|
view.showContextMenu(listItem, coordinates.x, coordinates.y)
|
|
break
|
|
}
|
|
}
|
|
|
|
onContainsMouseChanged: {
|
|
listItem.activate(containsMouse)
|
|
}
|
|
|
|
Item {
|
|
id: paddingItem
|
|
anchors {
|
|
fill: parent
|
|
leftMargin: background.margins.left
|
|
topMargin: background.margins.top
|
|
rightMargin: background.margins.right
|
|
bottomMargin: background.margins.bottom
|
|
}
|
|
}
|
|
}
|
|
|
|
Accessible.role: Accessible.ListItem
|
|
}
|