fixed the leftdock to allow reordering and better dnd
This commit is contained in:
parent
f14be71572
commit
8d07c7355d
7 changed files with 190 additions and 67 deletions
|
@ -3,6 +3,7 @@ import QtQuick.Dialogs 1.0
|
|||
import QtQuick.Controls 2.0 as Controls
|
||||
import QtQuick.Window 2.13
|
||||
import QtQuick.Layouts 1.2
|
||||
import QtQml.Models 2.12
|
||||
import QtMultimedia 5.15
|
||||
import QtAudioEngine 1.15
|
||||
import org.kde.kirigami 2.13 as Kirigami
|
||||
|
@ -47,13 +48,14 @@ ColumnLayout {
|
|||
ListView {
|
||||
id: serviceItemList
|
||||
anchors.fill: parent
|
||||
model: serviceItemModel
|
||||
delegate: Kirigami.DelegateRecycler {
|
||||
width: serviceItemList.width
|
||||
sourceComponent: itemDelegate
|
||||
}
|
||||
/* model: serviceItemModel */
|
||||
/* delegate: Kirigami.DelegateRecycler { */
|
||||
/* width: serviceItemList.width */
|
||||
/* sourceComponent: itemDelegate */
|
||||
/* } */
|
||||
clip: true
|
||||
spacing: 3
|
||||
property int dragItemIndex
|
||||
|
||||
addDisplaced: Transition {
|
||||
NumberAnimation {properties: "x, y"; duration: 100}
|
||||
|
@ -74,54 +76,160 @@ ColumnLayout {
|
|||
NumberAnimation {properties: "x, y"; duration: 100}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: itemDelegate
|
||||
Item {
|
||||
id: serviceItem
|
||||
model: DelegateModel {
|
||||
id: visualModel
|
||||
model: serviceItemModel
|
||||
delegate: DropArea {
|
||||
id: serviceDrop
|
||||
implicitWidth: serviceItemList.width
|
||||
height: 50
|
||||
onEntered: (drag) => {
|
||||
/* dropPlacement(drag); */
|
||||
const from = (drag.source as visServiceItem)
|
||||
visualModel.items.move(dragItemIndex, index);
|
||||
}
|
||||
onDropped: (drag) => {
|
||||
print("DROPPED IN ITEM AREA: " + drag.keys);
|
||||
print(dragItemIndex + " " + index);
|
||||
const hlIndex = serviceItemList.currentIndex;
|
||||
if (drag.keys === ["library"]) {
|
||||
addItem(index,
|
||||
dragItemTitle,
|
||||
dragItemType,
|
||||
dragItemBackground,
|
||||
dragItemBackgroundType,
|
||||
dragItemText,
|
||||
dragItemIndex);
|
||||
} else if (drag.keys === ["serviceitem"]) {
|
||||
moveRequested(dragItemIndex, index);
|
||||
if (hlIndex === dragItemIndex)
|
||||
serviceItemList.currentIndex = index;
|
||||
else if (hlIndex === index)
|
||||
serviceItemList.currentIndex = index + 1;
|
||||
}
|
||||
}
|
||||
keys: ["library","serviceitem"]
|
||||
|
||||
Kirigami.BasicListItem {
|
||||
anchors.fill: parent
|
||||
id: visServiceItem
|
||||
width: serviceDrop.width
|
||||
height: serviceDrop.height
|
||||
anchors {
|
||||
horizontalCenter: parent.horizontalCenter
|
||||
verticalCenter: parent.verticalCenter
|
||||
}
|
||||
label: name
|
||||
subtitle: type
|
||||
hoverEnabled: true
|
||||
hoverEnabled: false
|
||||
supportsMouseEvents: false
|
||||
backgroundColor: {
|
||||
if (parent.ListView.isCurrentItem) {
|
||||
if (serviceItemList.currentIndex === index ||
|
||||
mouseHandler.containsMouse)
|
||||
Kirigami.Theme.highlightColor;
|
||||
/* } else if (serviceDrop.constainsDrag){ */
|
||||
/* Kirigami.Theme.hoverColor; */
|
||||
} else if (mouseHandler.containsMouse){
|
||||
Kirigami.Theme.highlightColor;
|
||||
} else {
|
||||
Kirigami.Theme.backgroundColor;
|
||||
}
|
||||
else
|
||||
Kirigami.Theme.backgroundColor;
|
||||
}
|
||||
textColor: {
|
||||
if (parent.ListView.isCurrentItem || mouseHandler.containsMouse)
|
||||
if (serviceItemList.currentIndex === index ||
|
||||
mouseHandler.containsMouse)
|
||||
activeTextColor;
|
||||
else
|
||||
Kirigami.Theme.textColor;
|
||||
}
|
||||
|
||||
states: [
|
||||
State {
|
||||
when: mouseHandler.drag.active
|
||||
ParentChange {
|
||||
target: visServiceItem
|
||||
parent: serviceItemList
|
||||
}
|
||||
|
||||
PropertyChanges {
|
||||
target: visServiceItem
|
||||
backgroundColor: Kirigami.Theme.backgroundColor
|
||||
textColor: Kirigami.Theme.textColor
|
||||
anchors.verticalCenter: undefined
|
||||
anchors.horizontalCenter: undefined
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
/* Drag.dragType: Drag.Automatic */
|
||||
Drag.active: mouseHandler.drag.active
|
||||
Drag.hotSpot.x: width / 2
|
||||
Drag.hotSpot.y: height / 2
|
||||
Drag.keys: ["serviceitem"]
|
||||
|
||||
MouseArea {
|
||||
id: mouseHandler
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
||||
preventStealing: true
|
||||
|
||||
drag {
|
||||
target: visServiceItem
|
||||
axis: Drag.YAxis
|
||||
/* minimumY: root.y */
|
||||
/* maximumY: serviceItemList.height - serviceDrop.height */
|
||||
smoothed: false
|
||||
}
|
||||
|
||||
drag.onActiveChanged: {
|
||||
if (mouseHandler.drag.active) {
|
||||
dragItemIndex = index;
|
||||
}
|
||||
}
|
||||
|
||||
/* onPositionChanged: { */
|
||||
/* if (!pressed) { */
|
||||
/* return; */
|
||||
/* } */
|
||||
/* mouseArea.arrangeItem(); */
|
||||
/* } */
|
||||
|
||||
onPressed: {
|
||||
serviceItemList.interactive = false;
|
||||
}
|
||||
|
||||
onClicked: {
|
||||
if (mouse.button === Qt.RightButton)
|
||||
rightClickMenu.popup();
|
||||
else {
|
||||
serviceItemList.currentIndex = index;
|
||||
currentServiceItem = index;
|
||||
changeServiceItem(index);
|
||||
}
|
||||
}
|
||||
|
||||
onReleased: {
|
||||
print("should drop");
|
||||
visServiceItem.Drag.drop();
|
||||
}
|
||||
}
|
||||
}
|
||||
Presenter.DragHandle {
|
||||
id: mouseHandler
|
||||
anchors.fill: parent
|
||||
listItem: serviceItem
|
||||
listView: serviceItemList
|
||||
onMoveRequested: {
|
||||
print(oldIndex, newIndex);
|
||||
serviceItemModel.move(oldIndex, newIndex);
|
||||
}
|
||||
onDropped: {
|
||||
}
|
||||
onClicked: {
|
||||
serviceItemList.currentIndex = index;
|
||||
currentServiceItem = index;
|
||||
changeServiceItem(index);
|
||||
}
|
||||
onRightClicked: rightClickMenu.popup()
|
||||
}
|
||||
|
||||
/* Presenter.DragHandle { */
|
||||
/* id: mouseHandler */
|
||||
/* anchors.fill: parent */
|
||||
/* listItem: serviceItem */
|
||||
/* listView: serviceItemList */
|
||||
/* onMoveRequested: { */
|
||||
/* print(oldIndex, newIndex); */
|
||||
/* serviceItemModel.move(oldIndex, newIndex); */
|
||||
/* } */
|
||||
/* onDropped: { */
|
||||
/* } */
|
||||
/* onClicked: { */
|
||||
/* serviceItemList.currentIndex = index; */
|
||||
/* currentServiceItem = index; */
|
||||
/* changeServiceItem(index); */
|
||||
/* } */
|
||||
/* onRightClicked: rightClickMenu.popup() */
|
||||
/* } */
|
||||
|
||||
|
||||
|
||||
Controls.Menu {
|
||||
id: rightClickMenu
|
||||
|
@ -133,23 +241,16 @@ ColumnLayout {
|
|||
}
|
||||
}
|
||||
|
||||
DropArea {
|
||||
id: serviceDrop
|
||||
anchors.fill: parent
|
||||
onDropped: {
|
||||
print("DROPPED IN ITEM AREA");
|
||||
addItem(index,
|
||||
dragItemTitle,
|
||||
dragItemType,
|
||||
dragItemBackground,
|
||||
dragItemBackgroundType,
|
||||
dragItemText,
|
||||
dragItemIndex);
|
||||
}
|
||||
keys: ["library"]
|
||||
function moveRequested(oldIndex, newIndex) {
|
||||
serviceItemModel.move(oldIndex, newIndex);
|
||||
}
|
||||
|
||||
function dropPlacement(drag) {
|
||||
print(drag.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Kirigami.WheelHandler {
|
||||
id: wheelHandler
|
||||
|
@ -164,19 +265,23 @@ ColumnLayout {
|
|||
active: hovered || pressed
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function addItem(index, name, type,
|
||||
background, backgroundType, text, itemID) {
|
||||
const newtext = songsqlmodel.getLyricList(itemID);
|
||||
print("adding: " + name + " of type " + type);
|
||||
serviceItemModel.insertItem(index, name,
|
||||
type, background,
|
||||
backgroundType, newtext);
|
||||
}
|
||||
|
||||
function appendItem(name, type, background, backgroundType, text, itemID) {
|
||||
print("adding: " + name + " of type " + type);
|
||||
let lyrics;
|
||||
if (type === "song") {
|
||||
print(itemID);
|
||||
lyrics = songsqlmodel.getLyricList(itemID);
|
||||
print(lyrics);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue