From a16021ca9af3c87a3cf146c34e74c117818449fc Mon Sep 17 00:00:00 2001 From: Martchus Date: Sun, 2 Sep 2018 19:09:16 +0200 Subject: [PATCH] Quick GUI: Make entry icon clickable, show menu on right/long click --- qml/EntriesPage.qml | 69 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 15 deletions(-) diff --git a/qml/EntriesPage.qml b/qml/EntriesPage.qml index 2d4056d..bff0b04 100644 --- a/qml/EntriesPage.qml +++ b/qml/EntriesPage.qml @@ -1,7 +1,7 @@ import QtQuick 2.4 import QtQuick.Layouts 1.2 import QtQml.Models 2.2 -import QtQuick.Controls 2.1 as Controls +import QtQuick.Controls 2.4 as Controls import org.kde.kirigami 2.5 as Kirigami Kirigami.ScrollablePage { @@ -235,24 +235,63 @@ Kirigami.ScrollablePage { rootIndex, oldIndex, 1, rootIndex, oldIndex < newIndex ? newIndex + 1 : newIndex) } - Kirigami.Icon { - width: Kirigami.Units.iconSizes.smallMedium - height: Kirigami.Units.iconSizes.smallMedium - Layout.fillHeight: true - source: delegateModel.isNode( - index) ? "folder-symbolic" : "story-editor" - } - Controls.Label { + Item { Layout.fillWidth: true Layout.fillHeight: true - height: Math.max(implicitHeight, - Kirigami.Units.iconSizes.smallMedium) - text: model.name - + RowLayout { + anchors.fill: parent + Kirigami.Icon { + width: Kirigami.Units.iconSizes.smallMedium + height: Kirigami.Units.iconSizes.smallMedium + Layout.fillHeight: true + source: delegateModel.isNode( + index) ? "folder-symbolic" : "story-editor" + } + Controls.Label { + Layout.fillWidth: true + Layout.fillHeight: true + height: Math.max( + implicitHeight, + Kirigami.Units.iconSizes.smallMedium) + text: model.name + } + } MouseArea { anchors.fill: parent - onClicked: delegateModel.handleEntryClicked(index, - model.name) + acceptedButtons: Qt.LeftButton | Qt.RightButton + onClicked: { + if (mouse.button === Qt.RightButton) { + entryContextMenu.popup() + return + } + delegateModel.handleEntryClicked(index, model.name) + } + onPressAndHold: entryContextMenu.popup() + } + Controls.Menu { + id: entryContextMenu + Controls.MenuItem { + icon.name: "edit-cut" + text: qsTr("Cut") + onTriggered: { + nativeInterface.cutEntry( + entryModel.index(index, 0, + rootIndex)) + showPassiveNotification(text + " " + model.name) + } + } + Controls.MenuItem { + icon.name: "edit-delete" + text: qsTr("Delete") + onTriggered: confirmDeletionDialog.confirmDeletion( + model.name, index) + } + Controls.MenuItem { + icon.name: "edit-rename" + text: qsTr("Rename") + onTriggered: renameDialog.renameEntry(model.name, + index) + } } } }