Quick GUI: Make entry icon clickable, show menu on right/long click

This commit is contained in:
Martchus 2018-09-02 19:09:16 +02:00
parent a8681e6af1
commit a16021ca9a
1 changed files with 54 additions and 15 deletions

View File

@ -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)
}
}
}
}