Commit 603b0d68 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Fix timeline focus issues on drag and drop

parent 7f3bbc4e
Pipeline #154449 passed with stage
in 6 minutes and 29 seconds
......@@ -99,6 +99,11 @@ Rectangle {
}
}
function itemHeight() {
return clipRoot.height
}
function boundValue(min, val, max) {
return Math.max(min, Math.min(val, max))
}
......@@ -597,7 +602,7 @@ Rectangle {
height: parent.height
width: root.baseUnit / 2
visible: root.activeTool === ProjectTool.SelectTool || (root.activeTool === ProjectTool.RippleTool && clipRoot.mixDuration <= 0 && !controller.hasClipEndMix(clipRoot.clipId))
enabled: !isLocked && (pressed || clipRoot.width > 3 * width)
enabled: !isLocked && (pressed || clipRoot.width > 3 * width) && clipRoot.clipId == dragProxy.draggedItem
hoverEnabled: true
drag.target: trimInMouseArea
drag.axis: Drag.XAxis
......@@ -733,7 +738,7 @@ Rectangle {
width: root.baseUnit / 2
hoverEnabled: true
visible: root.activeTool === ProjectTool.SelectTool || (root.activeTool === ProjectTool.RippleTool && clipRoot.mixDuration <= 0)
enabled: !isLocked && (pressed || clipRoot.width > 3 * width)
enabled: !isLocked && (pressed || clipRoot.width > 3 * width) && clipRoot.clipId == dragProxy.draggedItem
property bool shiftTrim: false
property bool controlTrim: false
property bool sizeChanged: false
......
......@@ -49,6 +49,10 @@ Item {
property bool hideCompoViews: scrollStart > (clipDuration * timeline.scaleFactor) || scrollStart + scrollView.width < 0 || width < root.minClipWidthForViews
property int scrollStart: scrollView.contentX - modelStart * timeline.scaleFactor
property int mouseXPos: mouseArea.mouseX
// We set coordinates to ensure the item can be found using childAt in timeline.qml getItemAtPosq
property int trackOffset: 5
y: trackOffset
height: 5
signal moved(var clip)
signal dragged(var clip, var mouse)
......@@ -83,6 +87,10 @@ Item {
}
}
function itemHeight() {
return displayRect.height
}
function grabItem() {
compositionRoot.forceActiveFocus()
mouseArea.focus = true
......@@ -133,7 +141,7 @@ Item {
anchors.top: compositionRoot.top
anchors.right: compositionRoot.right
anchors.left: compositionRoot.left
anchors.topMargin: displayHeight
anchors.topMargin: displayHeight - compositionRoot.trackOffset
height: parentTrack.height - displayHeight
color: Qt.darker('mediumpurple')
border.color: grouped ? root.groupColor : mouseArea.containsMouse ? activePalette.highlight : borderColor
......
......@@ -325,19 +325,37 @@ Rectangle {
var currentMouseTrack = Logic.getTrackIdFromPos(mousePos.y - ruler.height - subtitleTrack.height + scrollView.contentY)
// Try to find correct item
//console.log('checking item on TK: ', currentMouseTrack, ' AT: XPOS', (mousePos.x - trackHeaders.width), ', SCROLL:', scrollView.contentX, ', RES: ', ((mousePos.x - trackHeaders.width + scrollView.contentX) / root.timeScale), ' SCROLL POS: ', (mousePos.y - ruler.height - subtitleTrack.height + scrollView.contentY))
var tentativeClip = getItemAtPos(currentMouseTrack, mousePos.x - trackHeaders.width + scrollView.contentX, dragProxy.isComposition)
var sourceTrack = Logic.getTrackById(currentMouseTrack)
var mouseYPos = (mousePos.y - ruler.height - subtitleTrack.height + scrollView.contentY) - sourceTrack.y
var allowComposition = mouseYPos > sourceTrack.height / 2
var tentativeClip = undefined
if (allowComposition) {
tentativeClip = getItemAtPos(currentMouseTrack, mousePos.x - trackHeaders.width + scrollView.contentX, true)
if (tentativeClip) {
// Ensure mouse is really over the composition
if (mouseYPos < tentativeClip.displayHeight) {
tentativeClip = undefined
}
}
}
if (!tentativeClip) {
tentativeClip = getItemAtPos(currentMouseTrack, mousePos.x - trackHeaders.width + scrollView.contentX, false)
}
if (tentativeClip && tentativeClip.clipId) {
dragProxy.draggedItem = tentativeClip.clipId
var tk = controller.getItemTrackId(tentativeClip.clipId)
dragProxy.x = tentativeClip.x
dragProxy.y = tentativeClip.y + Logic.getTrackYFromId(tk)
dragProxy.y = sourceTrack.y + (tentativeClip.isComposition ? tentativeClip.displayHeight : tentativeClip.y)
//+ Logic.getTrackYFromId(tk)
dragProxy.width = tentativeClip.width
dragProxy.height = tentativeClip.height
dragProxy.height = tentativeClip.itemHeight()
dragProxy.masterObject = tentativeClip
dragProxy.sourceTrack = tk
dragProxy.sourceFrame = tentativeClip.modelStart
dragProxy.isComposition = tentativeClip.isComposition
console.log('missing item', tentativeClip.clipId, ', COORDS: ', tentativeClip.x, 'x', tentativeClip.y, ', TK id: ', tk, ', TKY: ', Logic.getTrackYFromId(tk),' STARTFRM: ', dragProxy.sourceFrame)
dragProxy.verticalOffset = tentativeClip.isComposition ? tentativeClip.displayHeight : 0
//console.log('missing item', tentativeClip.clipId, ', COORDS: ', dragProxy.x, 'x', dragProxy.y,'-',dragProxy.width,'x',dragProxy.height, ', TK id: ', tk, ', TKY: ', Logic.getTrackYFromId(tk),' STARTFRM: ', dragProxy.sourceFrame)
} else {
console.log('item not found')
if (dragProxy.draggedItem > -1) {
......@@ -356,7 +374,7 @@ Rectangle {
return audioCount;
}
function getItemAtPos(tk, posx, isComposition) {
function getItemAtPos(tk, posx, compositionWanted) {
var track = Logic.getTrackById(tk)
if (track == undefined || track.children == undefined) {
return undefined
......@@ -367,8 +385,8 @@ Rectangle {
if (container.children[i].children.length === 0 || container.children[i].children[0].children.length === 0) {
continue
}
tentativeClip = container.children[i].children[0].childAt(posx, 1)
if (tentativeClip && tentativeClip.clipId && (tentativeClip.isComposition === isComposition)) {
tentativeClip = container.children[i].children[0].childAt(posx, compositionWanted ? 5 : 0)
if (tentativeClip && tentativeClip.clipId && (tentativeClip.isComposition === compositionWanted)) {
break
}
}
......@@ -608,6 +626,7 @@ Rectangle {
}
}
clearDropData()
regainFocus(Qt.point(drag.x + trackHeaders.width, drag.y + ruler.height))
}
}
DropArea {
......@@ -772,6 +791,7 @@ Rectangle {
}
onDropped: {
processDrop()
regainFocus(Qt.point(drag.x + trackHeaders.width, drag.y + ruler.height))
}
}
DropArea { //Drop area for urls (direct drop from file manager)
......@@ -1722,12 +1742,13 @@ Rectangle {
clickAccepted = true
dragProxy.draggedItem = tentativeClip.clipId
dragProxy.x = tentativeClip.x
//dragProxy.y = tentativeClip.y
dragProxy.y = currentMouseTrack.y + tentativeClip.isComposition ? tentativeClip.displayHeight : tentativeClip.y
dragProxy.height = tentativeClip.itemHeight()
dragProxy.width = tentativeClip.width
dragProxy.height = tentativeClip.height
dragProxy.masterObject = tentativeClip
dragProxy.sourceTrack = tk
dragProxy.isComposition = tentativeClip.isComposition
dragProxy.verticalOffset = tentativeClip.isComposition ? tentativeClip.displayHeight : 0
} else {
console.log('item not found')
clickAccepted = false
......
......@@ -497,7 +497,6 @@ bool TimelineWidget::eventFilter(QObject *object, QEvent *event)
void TimelineWidget::regainFocus()
{
qDebug()<<"=== REG FOCUS: "<<underMouse();
if (underMouse() && rootObject()) {
QPoint mousePos = mapFromGlobal(QCursor::pos());
QMetaObject::invokeMethod(rootObject(), "regainFocus", Qt::DirectConnection, Q_ARG(QVariant, mousePos));
......
......@@ -63,6 +63,7 @@ public slots:
void endDrag();
/** @brief Show menu to switch track target audio stream */
void showTargetMenu(int tid = -1);
/** @brief Focus qml item under mouse in timeline, for example after app looses focus or a menu showed up*/
void regainFocus();
private slots:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment