PlasmaComponents.ListView already provides onClicked and containsMouse

It does not provide onEntered/onExited but we can mimic that with onContainsMouseChanged
This removes the MouseArea which could never occupy the entire highlight area due to theme
margins leading to annoying flickering when moving between items because the one MouseArea
was exited before the next one was entered
wilder-5.14
Kai Uwe Broulik 12 years ago
parent 798721d866
commit d33fc022c8
  1. 307
      applets/clipboard/contents/ui/ClipboardItemDelegate.qml

@ -38,183 +38,184 @@ PlasmaComponents.ListItem {
x: -listMargins.left x: -listMargins.left
MouseArea { enabled: true
anchors.fill: parent
hoverEnabled: true onClicked: menuItem.itemSelected(UuidRole)
onContainsMouseChanged: {
onClicked: menuItem.itemSelected(UuidRole) if (containsMouse) {
menuListView.currentIndex = index
onEntered: menuListView.currentIndex = index } else {
onExited: menuListView.currentIndex = -1 menuListView.currentIndex = -1
}
}
Item { Item {
id: label id: label
height: childrenRect.height height: childrenRect.height
anchors {
left: parent.left
leftMargin: units.gridUnit / 2
right: parent.right
verticalCenter: parent.verticalCenter
}
PlasmaComponents.Label {
anchors { anchors {
left: parent.left left: parent.left
leftMargin: units.gridUnit / 2
right: parent.right right: parent.right
verticalCenter: parent.verticalCenter
} }
PlasmaComponents.Label { maximumLineCount: 3
text: DisplayRole.trim()
visible: TypeRole == 0 // TypeRole: 0: Text, 1: Image, 2: Url
elide: Text.ElideRight
wrapMode: Text.Wrap
textFormat: Text.PlainText
}
KQuickControlsAddons.QPixmapItem {
id: previewPixmap
width: parent.width
height: Math.round(width * (nativeHeight/nativeWidth) + units.smallSpacing * 2)
pixmap: DecorationRole
visible: TypeRole == 1
fillMode: KQuickControlsAddons.QPixmapItem.PreserveAspectFit
}
Item {
id: previewItem
visible: TypeRole == 2
height: visible ? (units.gridUnit * 4 + units.smallSpacing * 2) : 0
width: parent.width
ListView {
id: previewList
model: TypeRole == 2 ? DisplayRole.split(" ", maximumNumberOfPreviews) : 0
property int itemWidth: units.gridUnit * 4
property int itemHeight: units.gridUnit * 4
interactive: contentWidth > width
spacing: units.smallSpacing
orientation: Qt.Horizontal
width: (itemWidth + spacing) * model.length
anchors { anchors {
top: parent.top
left: parent.left left: parent.left
right: parent.right bottom: parent.bottom
} }
maximumLineCount: 3
text: DisplayRole.trim()
visible: TypeRole == 0 // TypeRole: 0: Text, 1: Image, 2: Url
elide: Text.ElideRight
wrapMode: Text.Wrap
textFormat: Text.PlainText
}
KQuickControlsAddons.QPixmapItem {
id: previewPixmap
width: parent.width
height: Math.round(width * (nativeHeight/nativeWidth) + units.smallSpacing * 2)
pixmap: DecorationRole
visible: TypeRole == 1
fillMode: KQuickControlsAddons.QPixmapItem.PreserveAspectFit
}
Item {
id: previewItem
visible: TypeRole == 2
height: visible ? (units.gridUnit * 4 + units.smallSpacing * 2) : 0
width: parent.width
ListView {
id: previewList
model: TypeRole == 2 ? DisplayRole.split(" ", maximumNumberOfPreviews) : 0
property int itemWidth: units.gridUnit * 4
property int itemHeight: units.gridUnit * 4
interactive: contentWidth > width
spacing: units.smallSpacing
orientation: Qt.Horizontal
width: (itemWidth + spacing) * model.length
anchors {
top: parent.top
left: parent.left
bottom: parent.bottom
}
delegate: Item { delegate: Item {
width: previewList.itemWidth width: previewList.itemWidth
height: previewList.itemHeight height: previewList.itemHeight
y: Math.round((parent.height - previewList.itemHeight) / 2) y: Math.round((parent.height - previewList.itemHeight) / 2)
clip: true clip: true
KQuickControlsAddons.QPixmapItem { KQuickControlsAddons.QPixmapItem {
id: previewPixmap id: previewPixmap
anchors.centerIn: parent anchors.centerIn: parent
Component.onCompleted: { Component.onCompleted: {
function result(job) { function result(job) {
if (!job.error) { if (!job.error) {
pixmap = job.result.preview; pixmap = job.result.preview;
previewPixmap.width = job.result.previewWidth previewPixmap.width = job.result.previewWidth
previewPixmap.height = job.result.previewHeight previewPixmap.height = job.result.previewHeight
}
} }
var service = clipboardSource.serviceForSource(UuidRole)
var operation = service.operationDescription("preview");
operation.url = modelData;
// We request a bigger size and then clip out a square in the middle
// so we get uniform delegate sizes without distortion
operation.previewWidth = previewList.itemWidth * 2;
operation.previewHeight = previewList.itemHeight * 2;
var serviceJob = service.startOperationCall(operation);
serviceJob.finished.connect(result);
} }
var service = clipboardSource.serviceForSource(UuidRole)
var operation = service.operationDescription("preview");
operation.url = modelData;
// We request a bigger size and then clip out a square in the middle
// so we get uniform delegate sizes without distortion
operation.previewWidth = previewList.itemWidth * 2;
operation.previewHeight = previewList.itemHeight * 2;
var serviceJob = service.startOperationCall(operation);
serviceJob.finished.connect(result);
} }
Rectangle { }
id: overlay Rectangle {
color: theme.textColor id: overlay
opacity: 0.6 color: theme.textColor
height: units.gridUnit opacity: 0.6
anchors { height: units.gridUnit
left: parent.left anchors {
right: parent.right left: parent.left
bottom: parent.bottom right: parent.right
} bottom: parent.bottom
} }
PlasmaComponents.Label { }
font.pointSize: theme.smallestFont.pointSize PlasmaComponents.Label {
color: theme.backgroundColor font.pointSize: theme.smallestFont.pointSize
maximumLineCount: 1 color: theme.backgroundColor
anchors { maximumLineCount: 1
verticalCenter: overlay.verticalCenter anchors {
left: overlay.left verticalCenter: overlay.verticalCenter
right: overlay.right left: overlay.left
leftMargin: units.smallSpacing right: overlay.right
rightMargin: units.smallSpacing leftMargin: units.smallSpacing
} rightMargin: units.smallSpacing
elide: Text.ElideRight }
horizontalAlignment: Text.AlignHCenter elide: Text.ElideRight
text: { horizontalAlignment: Text.AlignHCenter
var u = modelData.split("/"); text: {
return decodeURIComponent(u[u.length - 1]); var u = modelData.split("/");
} return decodeURIComponent(u[u.length - 1]);
} }
} }
} }
PlasmaComponents.Label { }
property int additionalItems: DisplayRole.split(" ").length - maximumNumberOfPreviews PlasmaComponents.Label {
visible: additionalItems > 0 property int additionalItems: DisplayRole.split(" ").length - maximumNumberOfPreviews
opacity: 0.6 visible: additionalItems > 0
text: i18nc("Indicator that there are more urls in the clipboard than previews shown", "+%1", additionalItems) opacity: 0.6
anchors { text: i18nc("Indicator that there are more urls in the clipboard than previews shown", "+%1", additionalItems)
left: previewList.right anchors {
right: parent.right left: previewList.right
bottom: parent.bottom right: parent.right
margins: units.smallSpacing bottom: parent.bottom
margins: units.smallSpacing
}
verticalAlignment: Text.AlignBottom
horizontalAlignment: Text.AlignCenter
font.pointSize: theme.smallestFont.pointSize
} }
verticalAlignment: Text.AlignBottom
horizontalAlignment: Text.AlignCenter
font.pointSize: theme.smallestFont.pointSize
} }
} }
}
Row { Row {
id: toolButtonsLayout id: toolButtonsLayout
anchors { anchors {
right: label.right right: label.right
verticalCenter: parent.verticalCenter verticalCenter: parent.verticalCenter
} }
visible: menuListView.currentIndex == index visible: menuListView.currentIndex == index
PlasmaComponents.ToolButton { PlasmaComponents.ToolButton {
// TODO: only show for items supporting actions? // TODO: only show for items supporting actions?
iconSource: "system-run" iconSource: "system-run"
flat: false flat: false
tooltip: i18n("Invoke action") tooltip: i18n("Invoke action")
onClicked: menuItem.action(UuidRole) onClicked: menuItem.action(UuidRole)
} }
PlasmaComponents.ToolButton { PlasmaComponents.ToolButton {
id: barcodeToolButton id: barcodeToolButton
iconSource: "view-barcode" iconSource: "view-barcode"
flat: false flat: false
tooltip: i18n("Show barcode") tooltip: i18n("Show barcode")
onClicked: menuItem.barcode(UuidRole) onClicked: menuItem.barcode(UuidRole)
} }
PlasmaComponents.ToolButton { PlasmaComponents.ToolButton {
iconSource: "document-edit" iconSource: "document-edit"
enabled: !clipboardSource.editing enabled: !clipboardSource.editing
flat: false flat: false
visible: TypeRole != 2 visible: TypeRole != 2
tooltip: i18n("Edit contents") tooltip: i18n("Edit contents")
onClicked: menuItem.edit(UuidRole) onClicked: menuItem.edit(UuidRole)
} }
PlasmaComponents.ToolButton { PlasmaComponents.ToolButton {
iconSource: "edit-delete" iconSource: "edit-delete"
flat: false flat: false
tooltip: i18n("Remove from history") tooltip: i18n("Remove from history")
onClicked: menuItem.remove(UuidRole) onClicked: menuItem.remove(UuidRole)
}
} }
} }
} }

Loading…
Cancel
Save