[vlc-commits] [Git][videolan/vlc][master] 3 commits: qml: do not let dragging on the same location in playqueue
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Sat Oct 2 09:45:17 UTC 2021
Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
1d194c79 by Fatih Uzunoglu at 2021-10-02T09:26:52+00:00
qml: do not let dragging on the same location in playqueue
- - - - -
b569412c by Fatih Uzunoglu at 2021-10-02T09:26:52+00:00
qml: simplify drag handling in playqueue
- - - - -
1f7c0703 by Fatih Uzunoglu at 2021-10-02T09:26:52+00:00
qml: correct playqueue list fade color
- - - - -
2 changed files:
- modules/gui/qt/playlist/qml/PlaylistDelegate.qml
- modules/gui/qt/playlist/qml/PlaylistListView.qml
Changes:
=====================================
modules/gui/qt/playlist/qml/PlaylistDelegate.qml
=====================================
@@ -69,7 +69,7 @@ Control {
onSetItemDropIndicatorVisible: {
if (index === model.index) {
- topDropIndicator.visible = Qt.binding(function() { return visible || higherDropArea.containsDragItem; })
+ topDropIndicator.visible = Qt.binding(function() { return visible || higherDropArea.containsDrag; })
}
}
}
@@ -213,7 +213,7 @@ Control {
top: parent.top
}
- visible: higherDropArea.containsDragItem
+ visible: higherDropArea.containsDrag
height: VLCStyle.dp(1, VLCStyle.scale)
@@ -284,7 +284,13 @@ Control {
root.model.setSelection([index])
}
- dragItem.index = index
+ if (contains(mapFromItem(dragItem.parent, dragItem.x, dragItem.y))) {
+ // Force trigger entered signal in drop areas
+ // so that containsDrag work properly
+ dragItem.x = -1
+ dragItem.y = -1
+ }
+
dragItem.Drag.active = drag.active
}
else {
@@ -294,8 +300,10 @@ Control {
onPositionChanged: {
if (drag.active) {
- var pos = drag.target.parent.mapFromItem(mouseArea, mouseX, mouseY)
- dragItem.updatePos(pos)
+ // FIXME: Override dragItem's position
+ var pos = mapToItem(dragItem.parent, mouseX, mouseY)
+ dragItem.x = pos.x + VLCStyle.dp(15)
+ dragItem.y = pos.y // y should be changed after x
}
}
}
@@ -310,24 +318,15 @@ Control {
Layout.fillWidth: true
Layout.fillHeight: true
- property bool containsDragItem: false
-
onEntered: {
- if (!isDropAcceptable(drag, index))
+ if (!isDropAcceptable(drag, index)) {
+ drag.accepted = false
return
-
- containsDragItem = true
- }
- onExited: {
- containsDragItem = false
+ }
}
- onDropped: {
- if (!isDropAcceptable(drop, index))
- return
+ onDropped: {
root.acceptDrop(index, drop)
-
- containsDragItem = false
}
}
@@ -345,20 +344,20 @@ Control {
}
onEntered: {
- if (!isDropAcceptable(drag, index + 1))
+ if (!isDropAcceptable(drag, index + 1)) {
+ drag.accepted = false
return
+ }
handleDropIndicators(true)
}
+
onExited: {
handleDropIndicators(false)
}
- onDropped: {
- if(!isDropAcceptable(drop, index + 1))
- return
+ onDropped: {
root.acceptDrop(index + 1, drop)
-
handleDropIndicators(false)
}
}
=====================================
modules/gui/qt/playlist/qml/PlaylistListView.qml
=====================================
@@ -53,8 +53,32 @@ Control {
}
function isDropAcceptable(drop, index) {
- return drop.hasUrls || // external drop (i.e. from filesystem)
- (Helpers.isValidInstanceOf(drop.source, Widgets.DragItem)) // internal drop (inter-view or intra-playlist)
+ if (drop.hasUrls)
+ return true // external drop (i.e. from filesystem)
+
+ if (Helpers.isValidInstanceOf(drop.source, Widgets.DragItem)) {
+ // internal drop (inter-view or intra-playlist)
+ var selection = drop.source.selection
+ if (!!selection) {
+ var length = selection.length
+ var firstIndex = selection[0]
+ var lastIndex = selection[length - 1]
+ var consecutive = true
+ if (length > 1) {
+ for (var i = 0; i < length - 1; ++i) {
+ if (selection[i + 1] - selection[i] !== 1) {
+ consecutive = false
+ break
+ }
+ }
+ }
+ return !consecutive || (index > lastIndex + 1 || index < firstIndex)
+ } else {
+ return true
+ }
+ }
+
+ return false
}
function acceptDrop(index, drop) {
@@ -115,13 +139,13 @@ Control {
parent: (typeof g_mainDisplay !== 'undefined') ? g_mainDisplay : root
- property int index: -1
+ property var selection: null
colors: root.colors
function updateComponents(maxCovers) {
var count = root.model.selectedCount
- var selection = root.model.getSelection().slice(0, maxCovers)
+ selection = root.model.getSelection().slice(0, maxCovers)
var title = selection.map(function (index){
return root.model.itemAt(index).title
@@ -139,36 +163,26 @@ Control {
return model.getItemsForIndexes(model.getSelection())
}
- property point _pos
property int _scrollingDirection: 0
- function updatePos(pos) {
- dragItem.x = pos.x + VLCStyle.dp(15)
- dragItem.y = pos.y // y should be same otherwise dropIndicator will not be shown correctly (DropArea cares about itemY not mouseY)
-
- // since we override position update during dragging with updatePos(),
- // we have to track the final position:
- _pos = pos
- }
-
- on_PosChanged: {
- var dragItemY = dragItem._pos.y
+ onYChanged: {
+ var dragItemY = dragItem.y
var viewY = root.mapFromItem(listView, listView.x, listView.y).y
- var topDiff = (viewY + VLCStyle.dp(20, VLCStyle.scale)) - dragItemY
- var bottomDiff = dragItemY - (viewY + listView.height - toolbar.height - VLCStyle.dp(20, VLCStyle.scale))
+ var margin = VLCStyle.dp(20, VLCStyle.scale)
- if(!listView.listView.atYBeginning && topDiff > 0) {
+ var topDiff = (viewY + margin) - dragItemY
+ var bottomDiff = dragItemY - (viewY + listView.height - toolbar.height - margin)
+
+ if (!listView.listView.atYBeginning && topDiff > 0) {
_scrollingDirection = -1
listView.fadeRectTopHovered = true
- }
- else if( !listView.listView.atYEnd && bottomDiff > 0) {
+ } else if (!listView.listView.atYEnd && bottomDiff > 0) {
_scrollingDirection = 1
listView.fadeRectBottomHovered = true
- }
- else {
+ } else {
_scrollingDirection = 0
listView.fadeRectTopHovered = false
@@ -323,7 +337,8 @@ Control {
playlistId: mainctx.playlist
}
- fadeColor: background.color
+ fadeColor: background.usingAcrylic ? undefined
+ : background.alternativeColor
property int shiftIndex: -1
property int mode: PlaylistListView.Mode.Normal
@@ -371,7 +386,7 @@ Control {
property alias firstItemIndicatorVisible: firstItemIndicator.visible
function setDropIndicatorVisible(visible) {
- dropIndicator.visible = Qt.binding(function() { return (visible || dropArea.containsDragItem); })
+ dropIndicator.visible = Qt.binding(function() { return (visible || dropArea.containsDrag); })
}
MouseArea {
@@ -399,7 +414,7 @@ Control {
height: VLCStyle.dp(1)
anchors.top: parent.top
- visible: dropArea.containsDragItem
+ visible: (root.model.count > 0 && dropArea.containsDrag)
color: colors.accent
}
@@ -414,7 +429,7 @@ Control {
color: "transparent"
- visible: false
+ visible: (root.model.count === 0 && dropArea.containsDrag)
opacity: 0.8
@@ -435,33 +450,15 @@ Control {
anchors.fill: parent
- property bool containsDragItem: false
-
onEntered: {
- if(!root.isDropAcceptable(drag, root.model.count))
+ if(!root.isDropAcceptable(drag, root.model.count)) {
+ drag.accepted = false
return
-
- if (root.model.count === 0)
- firstItemIndicator.visible = true
- else
- containsDragItem = true
- }
- onExited: {
- if (root.model.count === 0)
- firstItemIndicator.visible = false
- else
- containsDragItem = false
+ }
}
- onDropped: {
- if(!root.isDropAcceptable(drop, root.model.count))
- return
+ onDropped: {
root.acceptDrop(root.model.count, drop)
-
- if (root.model.count === 0)
- firstItemIndicator.visible = false
- else
- containsDragItem = false
}
}
}
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/fd8a4fd89fd1428f659fce3ce2090d02352ea52c...1f7c0703c86c44982319a94259a9cdc0cdd380ce
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/fd8a4fd89fd1428f659fce3ce2090d02352ea52c...1f7c0703c86c44982319a94259a9cdc0cdd380ce
You're receiving this email because of your account on code.videolan.org.
More information about the vlc-commits
mailing list