diff --git a/src/qml/presenter/ServiceList.qml b/src/qml/presenter/ServiceList.qml index 6565a8b..a6fcf56 100644 --- a/src/qml/presenter/ServiceList.qml +++ b/src/qml/presenter/ServiceList.qml @@ -91,12 +91,7 @@ Item { id: serviceListItem implicitWidth: serviceItemList.width height: 30 - Kirigami.ListItemDragHandle { - anchors.fill: parent - listItem: serviceListItem - listView: serviceItemList - onMoveRequested: serviceItemModel.move(oldIndex, newIndex, 1) - } + DropArea { id: serviceDrop anchors.fill: parent @@ -127,9 +122,9 @@ Item { dragItemFontSize, dragItemIndex); } else if (drag.keys[0] === "serviceitem") { - serviceItemModel.move(serviceItemList.indexDragged, - serviceItemList.moveToIndex); - serviceItemList.currentIndex = moveToIndex; + /* serviceItemModel.moveRows(serviceItemList.indexDragged, */ + /* serviceItemList.moveToIndex, 1); */ + /* serviceItemList.currentIndex = moveToIndex; */ } dropHighlightLine.visible = false; } @@ -157,12 +152,12 @@ Item { Controls.Label { id: label - anchors.left: parent.left + anchors.left: dragHandle.right anchors.verticalCenter: parent.verticalCenter anchors.leftMargin: 5 text: name elide: Text.ElideRight - width: parent.width - trailing.width - 15 + width: parent.width - trailing.width - dragHandle.width - 15 color: { if (selected || mouseHandler.containsMouse || active) @@ -187,7 +182,7 @@ Item { } } - onYChanged: serviceItemList.updateDrag(Math.round(y)); + /* onYChanged: serviceItemList.updateDrag(Math.round(y)); */ states: [ State { @@ -208,31 +203,31 @@ Item { ] /* Drag.dragType: Drag.Automatic */ - Drag.active: mouseHandler.drag.active - Drag.hotSpot.x: width / 2 - Drag.hotSpot.y: height / 2 - Drag.keys: ["serviceitem"] + /* 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 + /* preventStealing: true */ - drag { - target: visServiceItem - axis: Drag.YAxis - /* minimumY: root.y */ - /* maximumY: serviceItemList.height - serviceDrop.height */ - smoothed: false - } + /* drag { */ + /* target: visServiceItem */ + /* axis: Drag.YAxis */ + /* /\* minimumY: root.y *\/ */ + /* /\* maximumY: serviceItemList.height - serviceDrop.height *\/ */ + /* smoothed: false */ + /* } */ - drag.onActiveChanged: { - if (mouseHandler.drag.active) { - serviceItemList.indexDragged = index; - } - } + /* drag.onActiveChanged: { */ + /* if (mouseHandler.drag.active) { */ + /* serviceItemList.indexDragged = index; */ + /* } */ + /* } */ /* onPositionChanged: { */ /* if (!pressed) { */ @@ -267,6 +262,18 @@ Item { visServiceItem.Drag.drop(); } } + + Kirigami.ListItemDragHandle { + 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 @@ -346,7 +353,7 @@ Item { function moveRequested(oldIndex, newIndex) { print("moveRequested: ", oldIndex, newIndex); - serviceItemModel.move(oldIndex, newIndex); + serviceItemModel.moveRows(oldIndex, newIndex, 1); indexDragged = newIndex; serviceItemList.currentIndex = newIndex; } @@ -439,7 +446,7 @@ Item { const newid = serviceItemList.currentIndex - 1; showPassiveNotification(oldid + " " + newid); showPassiveNotification("Up"); - const ans = serviceItemModel.move(oldid, newid); + const ans = serviceItemModel.moveRows(oldid, newid, 1); if (ans) { serviceItemList.currentIndex = newid; diff --git a/src/serviceitemmodel.cpp b/src/serviceitemmodel.cpp index 79360b0..f6fe73c 100644 --- a/src/serviceitemmodel.cpp +++ b/src/serviceitemmodel.cpp @@ -322,43 +322,32 @@ void ServiceItemModel::removeItem(int index) { endRemoveRows(); } -bool ServiceItemModel::move(int sourceIndex, int destIndex) { +bool ServiceItemModel::moveRows(int sourceIndex, int destIndex, int count) { qDebug() << index(sourceIndex).row(); qDebug() << index(destIndex).row(); - QModelIndex parent = index(sourceIndex).parent(); - if (sourceIndex >= 0 && sourceIndex != destIndex && - destIndex > -1 && destIndex <= rowCount() && - sourceIndex < rowCount()) { - qDebug() << "starting move: " << "source: " << sourceIndex << "dest: " << destIndex; - bool begsuc = beginMoveRows(parent, sourceIndex, - sourceIndex, parent, destIndex); - if (begsuc) { - if (destIndex == -1) - { - qDebug() << "dest was too small, moving to row 0"; - m_items.move(sourceIndex, 0); - } - else - { - qDebug() << "dest was not too small"; - if (destIndex >= m_items.size()) - { - qDebug() << "destIndex too big, moving to end"; - m_items.move(sourceIndex, m_items.size() - 1); - } - else - m_items.move(sourceIndex, destIndex); - } - endMoveRows(); - return true; - } - qDebug() << "Can't move row, not sure why, sourceIndex: " - << sourceIndex << " destIndex: " << destIndex; + + if (sourceIndex < 0 || sourceIndex == destIndex || + destIndex == -1 || destIndex > rowCount() || + sourceIndex >= rowCount()) { + return false; + }; + + const QModelIndex parent = index(sourceIndex).parent(); + const bool isMoveDown = destIndex > sourceIndex; + + + if (!beginMoveRows(parent, sourceIndex, sourceIndex + count - 1, + parent, isMoveDown ? destIndex + 1 : destIndex)) { + qDebug() << "Can't move rows"; return false; } - qDebug() << "Can't move row, invalid options, sourceIndex: " - << sourceIndex << " destIndex: " << destIndex; - return false; + + qDebug() << "starting move: " << "source: " << sourceIndex << "dest: " << destIndex; + + m_items.move(sourceIndex, isMoveDown ? destIndex + 1 : destIndex); + + endMoveRows(); + return true; } bool ServiceItemModel::moveDown(int id) { @@ -388,7 +377,20 @@ bool ServiceItemModel::moveUp(int id) { qDebug() << index(id - 1).row(); QModelIndex parent = index(id).parent(); - + bool begsuc = beginMoveRows(parent, id, + id, parent, id - 1); + if (begsuc) { + int dest = id - 1; + if (dest <= -1) + { + qDebug() << "dest too big, moving to beginning"; + m_items.move(id, 0); + } + else + m_items.move(id, dest); + endMoveRows(); + return true; + } return false; } diff --git a/src/serviceitemmodel.h b/src/serviceitemmodel.h index d696c79..e448411 100644 --- a/src/serviceitemmodel.h +++ b/src/serviceitemmodel.h @@ -82,7 +82,7 @@ public: const QString &backgroundType, const QStringList &text, const QString &audio, const QString &font, const int &fontSize); Q_INVOKABLE void removeItem(int index); - Q_INVOKABLE bool move(int sourceIndex, int destIndex); + Q_INVOKABLE bool moveRows(int sourceIndex, int destIndex, int count); Q_INVOKABLE bool moveDown(int index); Q_INVOKABLE bool moveUp(int index); Q_INVOKABLE bool select(int id);