fixing serviceListItem:

Need to remember that list delegates need a component not a real item,
so the wrapper is necessary
This commit is contained in:
Chris Cochrun 2024-09-14 06:31:28 -05:00
parent 146f2df0c3
commit c2a56cd24b

View file

@ -77,222 +77,207 @@ Item {
}
}
Item {
Component {
id: serviceListItem
implicitWidth: serviceItemList.width
height: Kirigami.Units.gridUnit * 2
Component.onCompleted: Utils.dbg("HELLLLLOOOOOO: " + ServiceItemModel.getItem(0).name)
Item {
implicitWidth: serviceItemList.width
height: Kirigami.Units.gridUnit * 2
Component.onCompleted: Utils.dbg("HELLLLLOOOOOO: " + ServiceItemModel.getItem(0).name)
property var selectedItems
property var selectedItems
DropArea {
id: serviceDrop
anchors.fill: parent
DropArea {
id: serviceDrop
anchors.fill: parent
onEntered: (drag) => {
if (drag.keys[0] === "library") {
dropHighlightLine.visible = true;
dropHighlightLine.y = serviceDrop.mapToItem(
serviceItemList,0,0).y - 2;
}
}
onDropped: (drag) => {
loadingItem.visible = true;
console.log("DROPPED IN ITEM AREA: " + drag.keys);
console.log(dragItemIndex + " " + index);
const hlIndex = serviceItemList.currentIndex;
if (drag.keys[0] === "library") {
addItem(index,
dragItemType,
dragItemIndex);
} else if (drag.keys[0] === "serviceitem") {
/* ServiceItemModel.moveRows(serviceItemList.indexDragged, */
/* serviceItemList.moveToIndex, 1); */
/* serviceItemList.currentIndex = moveToIndex; */
}
dropHighlightLine.visible = false;
loadingItem.visible = false;
}
keys: ["library","serviceitem"]
Rectangle {
id: visServiceItem
width: serviceDrop.width
height: serviceDrop.height
anchors {
horizontalCenter: parent.horizontalCenter
verticalCenter: parent.verticalCenter
}
color: {
if (active)
Kirigami.Theme.highlightColor;
else if (selected)
Kirigami.Theme.focusColor;
else if (mouseHandler.containsMouse)
Kirigami.Theme.hoverColor;
else
Kirigami.Theme.backgroundColor;
}
Controls.Label {
id: label
anchors.left: dragHandle.right
anchors.verticalCenter: parent.verticalCenter
anchors.leftMargin: 5
text: name
elide: Text.ElideRight
width: parent.width - trailing.width - dragHandle.width - 25
color: {
if (selected ||
mouseHandler.containsMouse || active)
Kirigami.Theme.highlightedTextColor;
else
Kirigami.Theme.textColor;
onEntered: (drag) => {
if (drag.keys[0] === "library") {
dropHighlightLine.visible = true;
dropHighlightLine.y = serviceDrop.mapToItem(
serviceItemList,0,0).y - 2;
}
Component.onCompleted: Utils.dbg("SERVICEMODEL: " + name)
}
Kirigami.Icon {
id: trailing
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
anchors.rightMargin: 5
implicitWidth: Kirigami.Units.gridUnit
source: {
switch (ty) {
case 'image': return "folder-pictures-symbolic";
case 'video': return "folder-videos-symbolic";
case 'song': return "folder-music-symbolic";
case 'presentation': return "x-office-presentation-symbolic";
default: return "slideshow-plugin";
}
onDropped: (drag) => {
loadingItem.visible = true;
console.log("DROPPED IN ITEM AREA: " + drag.keys);
console.log(dragItemIndex + " " + index);
const hlIndex = serviceItemList.currentIndex;
if (drag.keys[0] === "library") {
addItem(index,
dragItemType,
dragItemIndex);
} else if (drag.keys[0] === "serviceitem") {
/* ServiceItemModel.moveRows(serviceItemList.indexDragged, */
/* serviceItemList.moveToIndex, 1); */
/* serviceItemList.currentIndex = moveToIndex; */
}
dropHighlightLine.visible = false;
loadingItem.visible = false;
}
keys: ["library","serviceitem"]
Rectangle {
id: visServiceItem
width: serviceDrop.width
height: serviceDrop.height
anchors {
horizontalCenter: parent.horizontalCenter
verticalCenter: parent.verticalCenter
}
color: {
if (selected ||
mouseHandler.containsMouse || active)
Kirigami.Theme.highlightedTextColor;
if (active)
Kirigami.Theme.highlightColor;
else if (selected)
Kirigami.Theme.focusColor;
else if (mouseHandler.containsMouse)
Kirigami.Theme.hoverColor;
else
Kirigami.Theme.textColor;
Kirigami.Theme.backgroundColor;
}
}
/* onYChanged: serviceItemList.updateDrag(Math.round(y)); */
states: [
State {
when: mouseHandler.drag.active
ParentChange {
target: visServiceItem
parent: serviceItemList
Controls.Label {
id: label
anchors.left: dragHandle.right
anchors.verticalCenter: parent.verticalCenter
anchors.leftMargin: 5
text: name
elide: Text.ElideRight
width: parent.width - trailing.width - dragHandle.width - 25
color: {
if (selected ||
mouseHandler.containsMouse || active)
Kirigami.Theme.highlightedTextColor;
else
Kirigami.Theme.textColor;
}
Component.onCompleted: Utils.dbg("SERVICEMODEL: " + name)
}
PropertyChanges {
target: visServiceItem
/* backgroundColor: Kirigami.Theme.backgroundColor */
/* textColor: Kirigami.Theme.textColor */
anchors.verticalCenter: undefined
anchors.horizontalCenter: undefined
Kirigami.Icon {
id: trailing
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
anchors.rightMargin: 5
implicitWidth: Kirigami.Units.gridUnit
source: {
switch (ty) {
case 'image': return "folder-pictures-symbolic";
case 'video': return "folder-videos-symbolic";
case 'song': return "folder-music-symbolic";
case 'presentation': return "x-office-presentation-symbolic";
default: return "slideshow-plugin";
}
}
color: {
if (selected ||
mouseHandler.containsMouse || active)
Kirigami.Theme.highlightedTextColor;
else
Kirigami.Theme.textColor;
}
}
]
/* Drag.dragType: Drag.Automatic */
/* Drag.active: mouseHandler.drag.active */
/* Drag.hotSpot.x: width / 2 */
/* Drag.hotSpot.y: height / 2 */
/* Drag.keys: ["serviceitem"] */
/* onYChanged: serviceItemList.updateDrag(Math.round(y)); */
MouseArea {
id: mouseHandler
anchors.fill: parent
hoverEnabled: true
acceptedButtons: Qt.LeftButton | Qt.RightButton
states: [
State {
when: mouseHandler.drag.active
ParentChange {
target: visServiceItem
parent: serviceItemList
}
/* drag { */
/* target: visServiceItem */
/* axis: Drag.YAxis */
/* /\* minimumY: root.y *\/ */
/* /\* maximumY: serviceItemList.height - serviceDrop.height *\/ */
/* smoothed: false */
/* } */
PropertyChanges {
target: visServiceItem
/* backgroundColor: Kirigami.Theme.backgroundColor */
/* textColor: Kirigami.Theme.textColor */
anchors.verticalCenter: undefined
anchors.horizontalCenter: undefined
}
}
]
/* drag.onActiveChanged: { */
/* if (mouseHandler.drag.active) { */
/* serviceItemList.indexDragged = index; */
/* } */
/* } */
/* Drag.dragType: Drag.Automatic */
/* Drag.active: mouseHandler.drag.active */
/* Drag.hotSpot.x: width / 2 */
/* Drag.hotSpot.y: height / 2 */
/* Drag.keys: ["serviceitem"] */
/* onPositionChanged: { */
/* if (!pressed) { */
/* return; */
/* } */
/* mouseArea.arrangeItem(); */
/* } */
MouseArea {
id: mouseHandler
anchors.fill: parent
hoverEnabled: true
acceptedButtons: Qt.LeftButton | Qt.RightButton
onPressed: {
serviceItemList.interactive = false;
}
/* drag { */
/* target: visServiceItem */
/* axis: Drag.YAxis */
/* /\* minimumY: root.y *\/ */
/* /\* maximumY: serviceItemList.height - serviceDrop.height *\/ */
/* smoothed: false */
/* } */
onClicked: {
if (mouse.button === Qt.RightButton) {
if (!selected) {
/* drag.onActiveChanged: { */
/* if (mouseHandler.drag.active) { */
/* serviceItemList.indexDragged = index; */
/* } */
/* } */
/* onPositionChanged: { */
/* if (!pressed) { */
/* return; */
/* } */
/* mouseArea.arrangeItem(); */
/* } */
onPressed: {
serviceItemList.interactive = false;
}
onClicked: {
if (mouse.button === Qt.RightButton) {
if (!selected) {
serviceItemList.currentIndex = index;
ServiceItemModel.select(index);
}
rightClickMenu.popup(mouse);
}
else if ((mouse.button === Qt.LeftButton) &&
(mouse.modifiers === Qt.ShiftModifier)) {
ServiceItemModel.selectItems(index);
} else {
serviceItemList.currentIndex = index;
ServiceItemModel.select(index);
}
rightClickMenu.popup(mouse);
refocusPresentation();
}
else if ((mouse.button === Qt.LeftButton) &&
(mouse.modifiers === Qt.ShiftModifier)) {
ServiceItemModel.selectItems(index);
} else {
serviceItemList.currentIndex = index;
ServiceItemModel.select(index);
onDoubleClicked: {
changeServiceItem(index);
}
onReleased: {
console.log("should drop");
visServiceItem.Drag.drop();
}
refocusPresentation();
}
onDoubleClicked: {
changeServiceItem(index);
Presenter.DragHandle {
id: dragHandle
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
anchors.leftMargin: 5
/* width: 20 */
listItem: serviceListItem
listView: serviceItemList
onMoveRequested: ServiceItemModel.moveRows(oldIndex,
newIndex,
1)
}
onReleased: {
console.log("should drop");
visServiceItem.Drag.drop();
}
}
Presenter.DragHandle {
id: dragHandle
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
anchors.leftMargin: 5
/* width: 20 */
listItem: serviceListItem
listView: serviceItemList
onMoveRequested: ServiceItemModel.moveRows(oldIndex,
newIndex,
1)
}
}
Controls.Menu {
id: rightClickMenu
Kirigami.Action {
text: "Copy"
}
Kirigami.Action {
text: "Paste"
}
Kirigami.Action {
text: "Delete"
onTriggered: removeItem(index)
}
Controls.MenuSeparator {}
Controls.Menu {
id: rightClickMenu
Kirigami.Action {
@ -303,7 +288,7 @@ Item {
}
Kirigami.Action {
text: "Delete"
onTriggered: removeItems()
onTriggered: removeItem(index)
}
Controls.MenuSeparator {}
@ -322,15 +307,15 @@ Item {
ObsModel.setScene(modelData);
}
}
onObjectAdded: obsMenu.insertAction(index, object)
onObjectRemoved: obsMenu.removeAction(object)
}
onObjectAdded: obsMenu.insertAction(index, object)
onObjectRemoved: obsMenu.removeAction(object)
}
}
}
}
}
}
ListView {
id: serviceItemList
anchors.top: parent.top