Fix weird highlighting behavior of list items in Plasma 6 version of Plasmoid
* Simplify `TopLevelItem` to what is actually needed to make it easier to understand * Use `onEntered` instead of `onContainsMouseChanged` which apparently works better (with `onContainsMouseChanged` the selection/highlighting did not always work reliably)
This commit is contained in:
parent
fe20167e5b
commit
e80200f7df
|
@ -1,55 +1,27 @@
|
||||||
// Based on PlasmaComponents.ListItem from Plasma 5.44.0
|
// 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 2.7
|
||||||
import QtQuick.Layouts 1.1
|
|
||||||
import org.kde.ksvg 1.0 as KSvg
|
import org.kde.ksvg 1.0 as KSvg
|
||||||
import org.kde.kirigami 2.20 as Kirigami
|
import org.kde.kirigami 2.20 as Kirigami
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
id: listItem
|
id: listItem
|
||||||
property bool expanded: false
|
|
||||||
default property alias content: paddingItem.data
|
default property alias content: paddingItem.data
|
||||||
|
property bool expanded: false
|
||||||
/**
|
|
||||||
* 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
|
property bool separatorVisible: true
|
||||||
|
|
||||||
width: parent ? parent.width : childrenRect.width
|
width: parent ? parent.width : childrenRect.width
|
||||||
height: paddingItem.childrenRect.height + background.margins.top + background.margins.bottom
|
height: paddingItem.childrenRect.height + background.margins.top + background.margins.bottom
|
||||||
|
|
||||||
implicitHeight: paddingItem.childrenRect.height + background.margins.top
|
implicitHeight: paddingItem.childrenRect.height + background.margins.top
|
||||||
+ background.margins.bottom
|
+ background.margins.bottom
|
||||||
|
|
||||||
function activate(containsMouse) {
|
function activate() {
|
||||||
view.activate(containsMouse ? index : -1)
|
view.activate(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
KSvg.FrameSvgItem {
|
KSvg.FrameSvgItem {
|
||||||
id: background
|
id: background
|
||||||
imagePath: "widgets/listitem"
|
imagePath: "widgets/listitem"
|
||||||
prefix: (listItem.sectionDelegate ? "section" : (itemMouse.pressed
|
prefix: "normal"
|
||||||
|| listItem.checked) ? "pressed" : "normal")
|
|
||||||
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
visible: listItem.ListView.view ? listItem.ListView.view.highlight === null : true
|
visible: listItem.ListView.view ? listItem.ListView.view.highlight === null : true
|
||||||
Behavior on opacity {
|
Behavior on opacity {
|
||||||
|
@ -69,20 +41,18 @@ Item {
|
||||||
top: parent.top
|
top: parent.top
|
||||||
}
|
}
|
||||||
height: naturalSize.height
|
height: naturalSize.height
|
||||||
visible: separatorVisible && (listItem.sectionDelegate
|
visible: separatorVisible && (index !== undefined
|
||||||
|| (typeof (index) != "undefined"
|
|
||||||
&& index > 0 && !listItem.checked
|
&& index > 0 && !listItem.checked
|
||||||
&& !itemMouse.pressed))
|
&& !itemMouse.pressed)
|
||||||
}
|
}
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
id: itemMouse
|
id: itemMouse
|
||||||
property bool changeBackgroundOnPress: !listItem.checked
|
property bool changeBackgroundOnPress: !listItem.checked
|
||||||
&& !listItem.sectionDelegate
|
|
||||||
anchors.fill: background
|
anchors.fill: background
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
||||||
|
onEntered: listItem.activate()
|
||||||
onClicked: function(mouse) {
|
onClicked: function(mouse) {
|
||||||
switch (mouse.button) {
|
switch (mouse.button) {
|
||||||
case Qt.LeftButton:
|
case Qt.LeftButton:
|
||||||
|
@ -96,10 +66,6 @@ Item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onContainsMouseChanged: {
|
|
||||||
listItem.activate(containsMouse)
|
|
||||||
}
|
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
id: paddingItem
|
id: paddingItem
|
||||||
anchors {
|
anchors {
|
||||||
|
|
Loading…
Reference in New Issue