diff --git a/lib/qml/ResultDelegate.qml b/lib/qml/ResultDelegate.qml --- a/lib/qml/ResultDelegate.qml +++ b/lib/qml/ResultDelegate.qml @@ -23,14 +23,18 @@ import QtQuick 2.1 import QtQuick.Layouts 1.1 +import QtQuick.Controls 2.1 +import org.kde.kquickcontrolsaddons 2.0 as KQuickControlsAddons import org.kde.plasma.core 2.0 as PlasmaCore -import org.kde.plasma.components 2.0 as PlasmaComponents +import org.kde.plasma.components 3.0 as PlasmaComponents -MouseArea { +PlasmaComponents.ItemDelegate +{ id: resultDelegate property variant theModel: model + property alias typeText: typeLabel.text readonly property bool isCurrent: ListView.isCurrentItem // cannot properly Connect {} to this readonly property bool sectionHasChanged: typeof reversed !== "undefined" && ( @@ -40,7 +44,6 @@ property int activeAction: -1 - property string typeText: sectionHasChanged ? ListView.section : "" property var additionalActions: typeof actions !== "undefined" ? actions : [] property int categoryWidth: units.gridUnit * 10 @@ -59,10 +62,6 @@ } } - property bool __pressed: false - property int __pressX: -1 - property int __pressY: -1 - onIsCurrentChanged: { if (!isCurrent) { activeAction = -1 @@ -89,191 +88,169 @@ activeAction = actionsRepeater.count - 1 } - width: listItem.implicitWidth - height: listItem.implicitHeight - - acceptedButtons: Qt.LeftButton - hoverEnabled: true - onPressed: { - __pressed = true; - __pressX = mouse.x; - __pressY = mouse.y; + onClicked: { + listView.currentIndex = model.index + listView.runCurrentIndex() } - onReleased: { - if (__pressed) { - listView.currentIndex = model.index - listView.runCurrentIndex() - } + KQuickControlsAddons.MouseEventListener { + anchors.fill: parent + hoverEnabled: true - __pressed = false; - __pressX = -1; - __pressY = -1; - } + property int pressX: -1 + property int pressY: -1 - onPositionChanged: { - if (__pressX != -1 && typeof dragHelper !== "undefined" && dragHelper.isDrag(__pressX, __pressY, mouse.x, mouse.y)) { - var mimeData = ListView.view.model.getMimeData(index); - if (mimeData) { - dragHelper.startDrag(root, mimeData, model.decoration); - __pressed = false; - __pressX = -1; - __pressY = -1; - } - } - if (!listView.moved && listView.mouseMovedGlobally()) { - listView.moved = true - listView.currentIndex = index + onPressed: { + pressX = mouse.x + pressY = mouse.y } - } - onContainsMouseChanged: { - if (!containsMouse) { - __pressed = false; - __pressX = -1; - __pressY = -1; - } else { - if (listView.moved) { - listView.currentIndex = index - } else if (listView.mouseMovedGlobally()) { + onPositionChanged: { + if (pressed && pressX >= 0 && typeof dragHelper !== "undefined" && dragHelper.isDrag(pressX, pressY, mouse.x, mouse.y)) { + var mimeData = resultDelegate.ListView.view.model.getMimeData(index); + if (mimeData) { + dragHelper.startDrag(root, mimeData, model.decoration); + pressX = -1 + pressY = -1 + } + } + + if (!listView.moved && listView.mouseMovedGlobally()) { listView.moved = true listView.currentIndex = index } } } - PlasmaComponents.Label { - id: typeText - text: resultDelegate.typeText - color: theme.textColor - opacity: 0.5 + onHoveredChanged: { + if (listView.moved) { + listView.currentIndex = index + } else if (listView.mouseMovedGlobally()) { + listView.moved = true + listView.currentIndex = index + } + } - horizontalAlignment: Text.AlignRight - verticalAlignment: Text.AlignVCenter - elide: Text.ElideRight - textFormat: Text.PlainText + readonly property int indexModifier: reversed ? 0 : 1 + width: parent.width - width: resultDelegate.categoryWidth - units.largeSpacing + // fake pressed look + checked: resultDelegate.pressed + + Rectangle { //Separator anchors { left: parent.left - verticalCenter: listItem.verticalCenter + right: parent.right } + height: Math.floor(units.devicePixelRatio) + Layout.preferredWidth: Math.floor(units.devicePixelRatio) + Layout.preferredHeight: Math.floor(units.devicePixelRatio) + color: Qt.tint(theme.textColor, Qt.rgba(theme.backgroundColor.r, theme.backgroundColor.g, theme.backgroundColor.b, 0.7)) + + visible: resultDelegate.sectionHasChanged + && !resultDelegate.isCurrent + && (index === 0 || resultDelegate.ListView.view.currentIndex !== (index - indexModifier)) } - PlasmaComponents.ListItem { - id: listItem - - readonly property int indexModifier: reversed ? 0 : 1 + RowLayout { + id: contents + anchors { + fill: parent + rightMargin: units.smallSpacing + } - // fake pressed look - checked: resultDelegate.pressed - separatorVisible: resultDelegate.sectionHasChanged - && !resultDelegate.isCurrent - && (index === 0 || resultDelegate.ListView.view.currentIndex !== (index - indexModifier)) + PlasmaComponents.Label { + id: typeLabel + text: sectionHasChanged ? resultDelegate.ListView.section : "" + color: theme.textColor + opacity: 0.5 - Item { - id: labelWrapper - anchors { - left: parent.left - right: parent.right - leftMargin: resultDelegate.categoryWidth - } - height: Math.max(typePixmap.height, displayLabel.height, subtextLabel.height) + horizontalAlignment: Text.AlignRight + verticalAlignment: Text.AlignVCenter + elide: Text.ElideRight + textFormat: Text.PlainText - RowLayout { - anchors { - left: parent.left - right: actionsRow.left - rightMargin: units.smallSpacing - } + Layout.minimumWidth: resultDelegate.categoryWidth - units.largeSpacing + Layout.rightMargin: units.largeSpacing + } - PlasmaCore.IconItem { - id: typePixmap - Layout.preferredWidth: units.iconSizes.small - Layout.preferredHeight: units.iconSizes.small - Layout.fillHeight: true - source: model.decoration - usesPlasmaTheme: false - animated: false - } + PlasmaCore.IconItem { + id: typePixmap + Layout.preferredWidth: units.iconSizes.small + Layout.preferredHeight: units.iconSizes.small + Layout.fillHeight: true + source: model.decoration + usesPlasmaTheme: false + animated: false + } - PlasmaComponents.Label { - id: displayLabel - text: String(typeof modelData !== "undefined" ? modelData : model.display) + PlasmaComponents.Label { + id: displayLabel + text: String(typeof modelData !== "undefined" ? modelData : model.display) - height: undefined + height: undefined - elide: Text.ElideMiddle - wrapMode: Text.NoWrap - maximumLineCount: 1 - verticalAlignment: Text.AlignVCenter - textFormat: Text.PlainText + elide: Text.ElideMiddle + wrapMode: Text.NoWrap + maximumLineCount: 1 + verticalAlignment: Text.AlignVCenter + textFormat: Text.PlainText + } - Layout.maximumWidth: labelWrapper.width - typePixmap.width - actionsRow.width - } + PlasmaComponents.Label { + id: subtextLabel + text: model.isDuplicate > 1 || resultDelegate.isCurrent ? String(model.subtext || "") : "" - PlasmaComponents.Label { - id: subtextLabel - text: model.isDuplicate > 1 || resultDelegate.isCurrent ? String(model.subtext || "") : "" + color: theme.textColor + // HACK If displayLabel is too long it will shift this label outside boundaries + // but still render the text leading to it overlapping the action buttons looking horrible + opacity: width > 0 ? 0.3 : 0 - color: theme.textColor - // HACK If displayLabel is too long it will shift this label outside boundaries - // but still render the text leading to it overlapping the action buttons looking horrible - opacity: width > 0 ? 0.3 : 0 + height: undefined - height: undefined + elide: Text.ElideMiddle + wrapMode: Text.NoWrap + maximumLineCount: 1 + verticalAlignment: Text.AlignVCenter + textFormat: Text.PlainText - elide: Text.ElideMiddle - wrapMode: Text.NoWrap - maximumLineCount: 1 - verticalAlignment: Text.AlignVCenter - textFormat: Text.PlainText + Layout.fillWidth: true + } - Layout.fillWidth: true + Repeater { + id: actionsRepeater + model: resultDelegate.additionalActions + + PlasmaComponents.ToolButton { + visible: resultDelegate.isCurrent && modelData.visible !== false + Layout.fillHeight: true + Layout.preferredWidth: height + enabled: modelData.enabled !== false + ToolTip.visible: hovered && ToolTip.text.length > 0 + ToolTip.text: { + var text = modelData.text || "" + if (index === 0) { // Shift+Return will invoke first action + text = i18ndc("milou", "placeholder is action e.g. run in terminal, in parenthesis is shortcut", "%1 (Shift+Return)", text) + } + return text } - } + Accessible.role: Accessible.Button + Accessible.name: modelData.text + checkable: checked + checked: resultDelegate.activeAction === index + focus: resultDelegate.activeAction === index - Row { - id: actionsRow - anchors.right: parent.right - anchors.verticalCenter: parent.verticalCenter - visible: resultDelegate.isCurrent - - Repeater { - id: actionsRepeater - model: resultDelegate.additionalActions - - PlasmaComponents.ToolButton { - width: height - height: listItem.height - visible: modelData.visible || true - enabled: modelData.enabled || true - tooltip: { - var text = modelData.text || "" - if (index === 0) { // Shift+Return will invoke first action - text = i18ndc("milou", "placeholder is action e.g. run in terminal, in parenthesis is shortcut", "%1 (Shift+Return)", text) - } - return text - } - Accessible.role: Accessible.Button - Accessible.name: modelData.text - checkable: checked - checked: resultDelegate.activeAction === index - focus: resultDelegate.activeAction === index - - PlasmaCore.IconItem { - anchors.centerIn: parent - width: units.iconSizes.small - height: units.iconSizes.small - // ToolButton cannot cope with QIcon - source: modelData.icon || "" - active: parent.hovered || parent.checked - } - - onClicked: resultDelegate.ListView.view.runAction(index) - } + PlasmaCore.IconItem { + anchors.centerIn: parent + width: units.iconSizes.small + height: units.iconSizes.small + // ToolButton cannot cope with QIcon + source: modelData.icon || "" + active: parent.hovered || parent.checked } + + onClicked: resultDelegate.ListView.view.runAction(index) } } }