2018-03-26 22:56:55 +02:00
|
|
|
// Based on PlasmaComponents.ListItem from Plasma 5.44.0
|
2017-08-29 23:58:49 +02:00
|
|
|
import QtQuick 2.7
|
2023-05-21 20:14:24 +02:00
|
|
|
import org.kde.ksvg 1.0 as KSvg
|
|
|
|
import org.kde.kirigami 2.20 as Kirigami
|
2017-08-29 23:58:49 +02:00
|
|
|
|
2018-03-26 22:56:55 +02:00
|
|
|
Item {
|
|
|
|
id: listItem
|
|
|
|
default property alias content: paddingItem.data
|
2023-11-21 23:31:03 +01:00
|
|
|
property bool expanded: false
|
2018-03-26 22:56:55 +02:00
|
|
|
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
|
|
|
|
|
2023-11-21 23:31:03 +01:00
|
|
|
function activate() {
|
|
|
|
view.activate(index)
|
2018-03-26 22:56:55 +02:00
|
|
|
}
|
|
|
|
|
2023-05-21 20:14:24 +02:00
|
|
|
KSvg.FrameSvgItem {
|
2018-03-26 22:56:55 +02:00
|
|
|
id: background
|
|
|
|
imagePath: "widgets/listitem"
|
2023-11-21 23:31:03 +01:00
|
|
|
prefix: "normal"
|
2018-03-26 22:56:55 +02:00
|
|
|
anchors.fill: parent
|
|
|
|
visible: listItem.ListView.view ? listItem.ListView.view.highlight === null : true
|
|
|
|
Behavior on opacity {
|
|
|
|
NumberAnimation {
|
2023-05-21 20:14:24 +02:00
|
|
|
duration: Kirigami.Units.longDuration
|
2018-03-26 22:56:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-05-21 20:14:24 +02:00
|
|
|
KSvg.SvgItem {
|
|
|
|
svg: KSvg.Svg {
|
2018-03-26 22:56:55 +02:00
|
|
|
imagePath: "widgets/listitem"
|
|
|
|
}
|
|
|
|
elementId: "separator"
|
|
|
|
anchors {
|
|
|
|
left: parent.left
|
|
|
|
right: parent.right
|
|
|
|
top: parent.top
|
|
|
|
}
|
|
|
|
height: naturalSize.height
|
2023-11-21 23:31:03 +01:00
|
|
|
visible: separatorVisible && (index !== undefined
|
|
|
|
&& index > 0 && !listItem.checked
|
|
|
|
&& !itemMouse.pressed)
|
2018-03-26 22:56:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
id: itemMouse
|
|
|
|
property bool changeBackgroundOnPress: !listItem.checked
|
|
|
|
anchors.fill: background
|
|
|
|
hoverEnabled: true
|
|
|
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
2023-11-21 23:31:03 +01:00
|
|
|
onEntered: listItem.activate()
|
2023-05-21 20:14:24 +02:00
|
|
|
onClicked: function(mouse) {
|
2018-03-26 22:56:55 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2017-08-29 23:58:49 +02:00
|
|
|
}
|