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,195 +88,170 @@ activeAction = actionsRepeater.count - 1 } - width: listItem.implicitWidth - height: listItem.implicitHeight + KQuickControlsAddons.MouseEventListener { + anchors.fill: parent + hoverEnabled: true - acceptedButtons: Qt.LeftButton - hoverEnabled: true - onPressed: { - __pressed = true; - __pressX = mouse.x; - __pressY = mouse.y; - } + property int pressX: -1 + property int pressY: -1 - onReleased: { - if (__pressed) { + onPressed: { + mouse.accepted = false + pressX = mouse.x + pressY = mouse.y + } + + onClicked: { listView.currentIndex = model.index listView.runCurrentIndex() } - __pressed = false; - __pressX = -1; - __pressY = -1; - } + onPositionChanged: { + if (pressed && pressX >= 0 && typeof dragHelper !== "undefined" && dragHelper.isDrag(pressX, pressY, mouse.x, mouse.y)) { + var resultsModel = resultDelegate.ListView.view.model; + var mimeData = resultsModel.getMimeData(resultsModel.index(index, 0)) + if (mimeData) { + dragHelper.startDrag(root, mimeData, model.decoration); + pressX = -1 + pressY = -1 + } + } - onPositionChanged: { - if (__pressX != -1 && typeof dragHelper !== "undefined" && dragHelper.isDrag(__pressX, __pressY, mouse.x, mouse.y)) { - var resultsModel = ListView.view.model; - var mimeData = resultsModel.getMimeData(resultsModel.index(index, 0)); - if (mimeData) { - dragHelper.startDrag(resultDelegate, mimeData, model.decoration); - __pressed = false; - __pressX = -1; - __pressY = -1; + if (!listView.moved && listView.mouseMovedGlobally()) { + listView.moved = true + listView.currentIndex = index } } + } - if (!listView.moved && listView.mouseMovedGlobally()) { + onHoveredChanged: { + if (listView.moved) { + listView.currentIndex = index + } else if (listView.mouseMovedGlobally()) { listView.moved = true listView.currentIndex = index } } - onContainsMouseChanged: { - if (!containsMouse) { - __pressed = false; - __pressX = -1; - __pressY = -1; - } else { - if (listView.moved) { - listView.currentIndex = index - } else if (listView.mouseMovedGlobally()) { - listView.moved = true - listView.currentIndex = index - } - } - } - - PlasmaComponents.Label { - id: typeText - text: resultDelegate.typeText - color: theme.textColor - opacity: 0.5 + readonly property int indexModifier: reversed ? 0 : 1 + width: parent.width - horizontalAlignment: Text.AlignRight - verticalAlignment: Text.AlignVCenter - elide: Text.ElideRight - textFormat: Text.PlainText + highlighted: ListView.isCurrentItem + // fake pressed look + checked: resultDelegate.pressed - width: resultDelegate.categoryWidth - units.largeSpacing + PlasmaCore.SvgItem { + svg: PlasmaCore.Svg {imagePath: "widgets/listitem"} + elementId: "separator" anchors { left: parent.left - verticalCenter: listItem.verticalCenter + right: parent.right + top: parent.top } + height: naturalSize.height + visible: resultDelegate.sectionHasChanged + && !resultDelegate.isCurrent + && (index === 0 || resultDelegate.ListView.view.currentIndex !== (index - indexModifier)) } - PlasmaComponents.ListItem { - id: listItem - - readonly property int indexModifier: reversed ? 0 : 1 - - // fake pressed look - checked: resultDelegate.pressed - separatorVisible: resultDelegate.sectionHasChanged - && !resultDelegate.isCurrent - && (index === 0 || resultDelegate.ListView.view.currentIndex !== (index - indexModifier)) - - Item { - id: labelWrapper - anchors { - left: parent.left - right: parent.right - leftMargin: resultDelegate.categoryWidth - } - height: Math.max(typePixmap.height, displayLabel.height, subtextLabel.height) + RowLayout { + id: contents + anchors { + fill: parent + rightMargin: units.smallSpacing + } - RowLayout { - anchors { - left: parent.left - right: actionsRow.left - rightMargin: units.smallSpacing - } + PlasmaComponents.Label { + id: typeLabel + text: sectionHasChanged ? resultDelegate.ListView.section : "" + color: theme.textColor + opacity: 0.7 - PlasmaCore.IconItem { - id: typePixmap - Layout.preferredWidth: units.iconSizes.small - Layout.preferredHeight: units.iconSizes.small - Layout.fillHeight: true - source: model.decoration - usesPlasmaTheme: false - animated: false - } + horizontalAlignment: Text.AlignRight + verticalAlignment: Text.AlignVCenter + elide: Text.ElideRight + textFormat: Text.PlainText - PlasmaComponents.Label { - id: displayLabel - text: String(typeof modelData !== "undefined" ? modelData : model.display) + Layout.minimumWidth: resultDelegate.categoryWidth - units.largeSpacing + Layout.maximumWidth: Layout.minimumWidth + Layout.rightMargin: units.largeSpacing + } - height: undefined + PlasmaCore.IconItem { + id: typePixmap + Layout.preferredWidth: units.iconSizes.small + Layout.preferredHeight: units.iconSizes.small + Layout.fillHeight: true + source: model.decoration + usesPlasmaTheme: false + animated: false + } - elide: Text.ElideMiddle - wrapMode: Text.NoWrap - maximumLineCount: 1 - verticalAlignment: Text.AlignVCenter - textFormat: Text.PlainText + PlasmaComponents.Label { + id: displayLabel + text: String(typeof modelData !== "undefined" ? modelData : model.display) - Layout.maximumWidth: labelWrapper.width - typePixmap.width - actionsRow.width - } + height: undefined - PlasmaComponents.Label { - id: subtextLabel + elide: Text.ElideMiddle + wrapMode: Text.NoWrap + maximumLineCount: 1 + verticalAlignment: Text.AlignVCenter + textFormat: Text.PlainText + } - // SourcesModel returns number of duplicates in this property - // ResultsModel just has it as a boolean as you would expect from the name of the property - text: model.isDuplicate === true || model.isDuplicate > 1 || resultDelegate.isCurrent ? String(model.subtext || "") : "" + PlasmaComponents.Label { + id: subtextLabel + // SourcesModel returns number of duplicates in this property + // ResultsModel just has it as a boolean as you would expect from the name of the property + text: model.isDuplicate === true || 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 + height: undefined - height: undefined + opacity: width > 0 ? 0.3 : 0 + 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.delay: units.toolTipDelay + 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) } } } diff --git a/lib/qml/ResultsView.qml b/lib/qml/ResultsView.qml --- a/lib/qml/ResultsView.qml +++ b/lib/qml/ResultsView.qml @@ -22,7 +22,6 @@ import QtQuick 2.1 -import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.milou 0.3 as Milou @@ -41,7 +40,6 @@ // NOTE this also flips increment/decrementCurrentIndex (Bug 360789) verticalLayoutDirection: reversed ? ListView.BottomToTop : ListView.TopToBottom keyNavigationWraps: true - highlight: PlasmaComponents.Highlight {} highlightMoveDuration: 0 activeFocusOnTab: true Accessible.role: Accessible.List