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
|
@ -56,12 +56,15 @@ Item {
|
||||||
property int mouseDownY
|
property int mouseDownY
|
||||||
property Item originalParent
|
property Item originalParent
|
||||||
property int autoScrollThreshold: (listView.contentHeight > listView.height) ? listItem.height * 3 : 0
|
property int autoScrollThreshold: (listView.contentHeight > listView.height) ? listItem.height * 3 : 0
|
||||||
opacity: mouseArea.pressed || (!Kirigami.Settings.tabletMode && listItem.hovered) ? 1 : 0.6
|
|
||||||
|
|
||||||
function arrangeItem() {
|
function arrangeItem() {
|
||||||
var newIndex = listView.indexAt(1, listView.contentItem.mapFromItem(listItem, 0, 0).y + mouseArea.mouseDownY);
|
var newIndex = listView.indexAt(1,
|
||||||
|
listView.contentItem.mapFromItem(listItem, 0, 0).y +
|
||||||
|
mouseArea.mouseDownY);
|
||||||
|
|
||||||
if (Math.abs(listItem.y - mouseArea.startY) > height && newIndex > -1 && newIndex !== index) {
|
if (Math.abs(listItem.y - mouseArea.startY) > height && newIndex > -1 &&
|
||||||
|
newIndex !== index) {
|
||||||
|
print("old index is: " + index + " and new index is: " + newIndex);
|
||||||
root.moveRequested(index, newIndex);
|
root.moveRequested(index, newIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ Item {
|
||||||
implicitWidth: 300
|
implicitWidth: 300
|
||||||
editable: true
|
editable: true
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
onCurrentTextChanged: showPassiveNotification(currentText)
|
/* onCurrentTextChanged: showPassiveNotification(currentText) */
|
||||||
}
|
}
|
||||||
Controls.SpinBox {
|
Controls.SpinBox {
|
||||||
editable: true
|
editable: true
|
||||||
|
|
|
@ -3,6 +3,7 @@ import QtQuick.Dialogs 1.0
|
||||||
import QtQuick.Controls 2.0 as Controls
|
import QtQuick.Controls 2.0 as Controls
|
||||||
import QtQuick.Window 2.13
|
import QtQuick.Window 2.13
|
||||||
import QtQuick.Layouts 1.2
|
import QtQuick.Layouts 1.2
|
||||||
|
import QtQml.Models 2.12
|
||||||
import QtMultimedia 5.15
|
import QtMultimedia 5.15
|
||||||
import QtAudioEngine 1.15
|
import QtAudioEngine 1.15
|
||||||
import org.kde.kirigami 2.13 as Kirigami
|
import org.kde.kirigami 2.13 as Kirigami
|
||||||
|
@ -47,13 +48,14 @@ ColumnLayout {
|
||||||
ListView {
|
ListView {
|
||||||
id: serviceItemList
|
id: serviceItemList
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
model: serviceItemModel
|
/* model: serviceItemModel */
|
||||||
delegate: Kirigami.DelegateRecycler {
|
/* delegate: Kirigami.DelegateRecycler { */
|
||||||
width: serviceItemList.width
|
/* width: serviceItemList.width */
|
||||||
sourceComponent: itemDelegate
|
/* sourceComponent: itemDelegate */
|
||||||
}
|
/* } */
|
||||||
clip: true
|
clip: true
|
||||||
spacing: 3
|
spacing: 3
|
||||||
|
property int dragItemIndex
|
||||||
|
|
||||||
addDisplaced: Transition {
|
addDisplaced: Transition {
|
||||||
NumberAnimation {properties: "x, y"; duration: 100}
|
NumberAnimation {properties: "x, y"; duration: 100}
|
||||||
|
@ -74,54 +76,160 @@ ColumnLayout {
|
||||||
NumberAnimation {properties: "x, y"; duration: 100}
|
NumberAnimation {properties: "x, y"; duration: 100}
|
||||||
}
|
}
|
||||||
|
|
||||||
Component {
|
model: DelegateModel {
|
||||||
id: itemDelegate
|
id: visualModel
|
||||||
Item {
|
model: serviceItemModel
|
||||||
id: serviceItem
|
delegate: DropArea {
|
||||||
|
id: serviceDrop
|
||||||
implicitWidth: serviceItemList.width
|
implicitWidth: serviceItemList.width
|
||||||
height: 50
|
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 {
|
Kirigami.BasicListItem {
|
||||||
anchors.fill: parent
|
id: visServiceItem
|
||||||
|
width: serviceDrop.width
|
||||||
|
height: serviceDrop.height
|
||||||
|
anchors {
|
||||||
|
horizontalCenter: parent.horizontalCenter
|
||||||
|
verticalCenter: parent.verticalCenter
|
||||||
|
}
|
||||||
label: name
|
label: name
|
||||||
subtitle: type
|
subtitle: type
|
||||||
hoverEnabled: true
|
hoverEnabled: false
|
||||||
supportsMouseEvents: false
|
supportsMouseEvents: false
|
||||||
backgroundColor: {
|
backgroundColor: {
|
||||||
if (parent.ListView.isCurrentItem) {
|
if (serviceItemList.currentIndex === index ||
|
||||||
|
mouseHandler.containsMouse)
|
||||||
Kirigami.Theme.highlightColor;
|
Kirigami.Theme.highlightColor;
|
||||||
/* } else if (serviceDrop.constainsDrag){ */
|
else
|
||||||
/* Kirigami.Theme.hoverColor; */
|
Kirigami.Theme.backgroundColor;
|
||||||
} else if (mouseHandler.containsMouse){
|
|
||||||
Kirigami.Theme.highlightColor;
|
|
||||||
} else {
|
|
||||||
Kirigami.Theme.backgroundColor;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
textColor: {
|
textColor: {
|
||||||
if (parent.ListView.isCurrentItem || mouseHandler.containsMouse)
|
if (serviceItemList.currentIndex === index ||
|
||||||
|
mouseHandler.containsMouse)
|
||||||
activeTextColor;
|
activeTextColor;
|
||||||
else
|
else
|
||||||
Kirigami.Theme.textColor;
|
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
|
/* Presenter.DragHandle { */
|
||||||
anchors.fill: parent
|
/* id: mouseHandler */
|
||||||
listItem: serviceItem
|
/* anchors.fill: parent */
|
||||||
listView: serviceItemList
|
/* listItem: serviceItem */
|
||||||
onMoveRequested: {
|
/* listView: serviceItemList */
|
||||||
print(oldIndex, newIndex);
|
/* onMoveRequested: { */
|
||||||
serviceItemModel.move(oldIndex, newIndex);
|
/* print(oldIndex, newIndex); */
|
||||||
}
|
/* serviceItemModel.move(oldIndex, newIndex); */
|
||||||
onDropped: {
|
/* } */
|
||||||
}
|
/* onDropped: { */
|
||||||
onClicked: {
|
/* } */
|
||||||
serviceItemList.currentIndex = index;
|
/* onClicked: { */
|
||||||
currentServiceItem = index;
|
/* serviceItemList.currentIndex = index; */
|
||||||
changeServiceItem(index);
|
/* currentServiceItem = index; */
|
||||||
}
|
/* changeServiceItem(index); */
|
||||||
onRightClicked: rightClickMenu.popup()
|
/* } */
|
||||||
}
|
/* onRightClicked: rightClickMenu.popup() */
|
||||||
|
/* } */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Controls.Menu {
|
Controls.Menu {
|
||||||
id: rightClickMenu
|
id: rightClickMenu
|
||||||
|
@ -133,24 +241,17 @@ ColumnLayout {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DropArea {
|
function moveRequested(oldIndex, newIndex) {
|
||||||
id: serviceDrop
|
serviceItemModel.move(oldIndex, newIndex);
|
||||||
anchors.fill: parent
|
}
|
||||||
onDropped: {
|
|
||||||
print("DROPPED IN ITEM AREA");
|
function dropPlacement(drag) {
|
||||||
addItem(index,
|
print(drag.y);
|
||||||
dragItemTitle,
|
|
||||||
dragItemType,
|
|
||||||
dragItemBackground,
|
|
||||||
dragItemBackgroundType,
|
|
||||||
dragItemText,
|
|
||||||
dragItemIndex);
|
|
||||||
}
|
|
||||||
keys: ["library"]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Kirigami.WheelHandler {
|
Kirigami.WheelHandler {
|
||||||
id: wheelHandler
|
id: wheelHandler
|
||||||
target: serviceItemList
|
target: serviceItemList
|
||||||
|
@ -166,17 +267,21 @@ ColumnLayout {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function addItem(index, name, type,
|
function addItem(index, name, type,
|
||||||
background, backgroundType, text, itemID) {
|
background, backgroundType, text, itemID) {
|
||||||
const newtext = songsqlmodel.getLyricList(itemID);
|
const newtext = songsqlmodel.getLyricList(itemID);
|
||||||
|
print("adding: " + name + " of type " + type);
|
||||||
serviceItemModel.insertItem(index, name,
|
serviceItemModel.insertItem(index, name,
|
||||||
type, background,
|
type, background,
|
||||||
backgroundType, newtext);
|
backgroundType, newtext);
|
||||||
}
|
}
|
||||||
|
|
||||||
function appendItem(name, type, background, backgroundType, text, itemID) {
|
function appendItem(name, type, background, backgroundType, text, itemID) {
|
||||||
|
print("adding: " + name + " of type " + type);
|
||||||
let lyrics;
|
let lyrics;
|
||||||
if (type === "song") {
|
if (type === "song") {
|
||||||
|
print(itemID);
|
||||||
lyrics = songsqlmodel.getLyricList(itemID);
|
lyrics = songsqlmodel.getLyricList(itemID);
|
||||||
print(lyrics);
|
print(lyrics);
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ Item {
|
||||||
implicitWidth: 300
|
implicitWidth: 300
|
||||||
editable: true
|
editable: true
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
onCurrentTextChanged: showPassiveNotification(currentText)
|
/* onCurrentTextChanged: showPassiveNotification(currentText) */
|
||||||
}
|
}
|
||||||
Controls.SpinBox {
|
Controls.SpinBox {
|
||||||
editable: true
|
editable: true
|
||||||
|
|
|
@ -32,7 +32,7 @@ Item {
|
||||||
implicitWidth: 300
|
implicitWidth: 300
|
||||||
editable: true
|
editable: true
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
onCurrentTextChanged: showPassiveNotification(currentText)
|
/* onCurrentTextChanged: showPassiveNotification(currentText) */
|
||||||
}
|
}
|
||||||
Controls.SpinBox {
|
Controls.SpinBox {
|
||||||
editable: true
|
editable: true
|
||||||
|
|
|
@ -116,7 +116,7 @@ Qt::ItemFlags ServiceItemModel::flags(const QModelIndex &index) const {
|
||||||
|
|
||||||
void ServiceItemModel::addItem(ServiceItem *item) {
|
void ServiceItemModel::addItem(ServiceItem *item) {
|
||||||
const int index = m_items.size();
|
const int index = m_items.size();
|
||||||
// qDebug() << index;
|
qDebug() << index;
|
||||||
// foreach (item, m_items) {
|
// foreach (item, m_items) {
|
||||||
// qDebug() << item;
|
// qDebug() << item;
|
||||||
// }
|
// }
|
||||||
|
@ -179,15 +179,19 @@ void ServiceItemModel::removeItem(int index) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServiceItemModel::move(int sourceIndex, int destIndex) {
|
bool ServiceItemModel::move(int sourceIndex, int destIndex) {
|
||||||
qDebug() << "starting move of: " << "source: " << sourceIndex << "dest: " << destIndex;
|
|
||||||
qDebug() << index(sourceIndex).row();
|
qDebug() << index(sourceIndex).row();
|
||||||
qDebug() << index(destIndex).row();
|
qDebug() << index(destIndex).row();
|
||||||
// QModelIndex parent = index(sourceIndex).parent();
|
// beginResetModel();
|
||||||
// bool begsuc = beginMoveRows(parent, sourceIndex, sourceIndex, parent, destIndex);
|
QModelIndex parent = index(sourceIndex).parent();
|
||||||
beginResetModel();
|
if (sourceIndex >= 0 && sourceIndex != destIndex && destIndex >= 0 && destIndex < rowCount() && sourceIndex < rowCount()) {
|
||||||
m_items.move(sourceIndex, destIndex);
|
qDebug() << "starting move of: " << "source: " << sourceIndex << "dest: " << destIndex;
|
||||||
// endMoveRows();
|
bool begsuc = beginMoveRows(QModelIndex(), sourceIndex, sourceIndex, QModelIndex(), destIndex);
|
||||||
endResetModel();
|
if (begsuc)
|
||||||
|
m_items.move(sourceIndex, destIndex);
|
||||||
|
endMoveRows();
|
||||||
|
}
|
||||||
|
// endResetModel();
|
||||||
|
// emit dataChanged(index(sourceIndex), QModelIndex());
|
||||||
// qDebug() << success;
|
// qDebug() << success;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,6 +190,7 @@ QStringList SongSqlModel::getLyricList(const int &row) {
|
||||||
|
|
||||||
// This first function pulls out each verse into our verses map
|
// This first function pulls out each verse into our verses map
|
||||||
foreach (line, rawLyrics) {
|
foreach (line, rawLyrics) {
|
||||||
|
qDebug() << line;
|
||||||
if (firstItem) {
|
if (firstItem) {
|
||||||
if (keywords.contains(line)) {
|
if (keywords.contains(line)) {
|
||||||
recordVerse = true;
|
recordVerse = true;
|
||||||
|
@ -213,6 +214,16 @@ QStringList SongSqlModel::getLyricList(const int &row) {
|
||||||
}
|
}
|
||||||
qDebug() << verses;
|
qDebug() << verses;
|
||||||
|
|
||||||
|
// let's check to see if there is a verse order, if not return the list given
|
||||||
|
if (vorder.first().isEmpty()) {
|
||||||
|
qDebug() << "NO VORDER";
|
||||||
|
foreach (verse, verses) {
|
||||||
|
qDebug() << verse;
|
||||||
|
lyrics.append(verse);
|
||||||
|
}
|
||||||
|
qDebug() << lyrics;
|
||||||
|
return lyrics;
|
||||||
|
}
|
||||||
// this function appends the verse that matches the verse order from the map
|
// this function appends the verse that matches the verse order from the map
|
||||||
foreach (const QString &vstr, vorder) {
|
foreach (const QString &vstr, vorder) {
|
||||||
foreach (line, rawLyrics) {
|
foreach (line, rawLyrics) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue