Browse Source

fix block drag and drop

master
Nils 3 years ago
parent
commit
57c047ef86
  1. 7
      qtgui/musicstructures.py
  2. 17
      qtgui/scorescene.py

7
qtgui/musicstructures.py

@ -53,7 +53,7 @@ class GuiBlockHandle(QtWidgets.QGraphicsRectItem):
which is just a color and stays in place.
"""
def __init__(self, parent, staticExportItem, x, y, w, h):
super().__init__(x, y, w, h)
super().__init__(x, y, w, h) #x and y are coordinates relative to its parent block. Y will always be a fixed value. At the moment of writing -14.
#self.setFlag(QtWidgets.QGraphicsItem.ItemHasNoContents, True) #only child items. Without this we get notImplementedError: QGraphicsItem.paint() is abstract and must be overridden
#self.setFlag(QtWidgets.QGraphicsItem.ItemContainsChildrenInShape, True)
self.parent = parent #GuiTrack instance
@ -120,6 +120,9 @@ class GuiBlockHandle(QtWidgets.QGraphicsRectItem):
self.endLabel.hide()
super().mousePressEvent(event)
#Mouse Move Event, as in dragging the blocks around, in in scorescene.py
#because we need to drag blocks into another track.
def mouseReleaseEventCustom(self, event):
"""Not a qt-override. This is called directly by GuiScore
if you click-release on a block"""
@ -175,7 +178,7 @@ class GuiTrack(QtWidgets.QGraphicsItem):
def __init__(self, parentScore, staticExportItem):
super().__init__()
self.setFlag(QtWidgets.QGraphicsItem.ItemHasNoContents, True) #only child items. Without this we get notImplementedError: QGraphicsItem.paint() is abstract and must be overridden
self.setFlag(QtWidgets.QGraphicsItem.ItemContainsChildrenInShape, True)
#self.setFlag(QtWidgets.QGraphicsItem.ItemContainsChildrenInShape, True) #Do not use! If we activate this a block will not be able to cross over into another track with drag and drop
self.parentScore = parentScore
self.staticExportItem = staticExportItem #This is not the notes but the track meta data. The notes are called staticRepresentationList

17
qtgui/scorescene.py

@ -348,6 +348,7 @@ class GuiScore(QtWidgets.QGraphicsScene):
if modifiers == QtCore.Qt.NoModifier:
block = self.blockAt(event.scenePos())
if block: #works for note blocks and conductor blocks
#block is type GuiBlockHandle
block.staticExportItem["guiPosStart"] = block.pos() #without shame we hijack the backend-dict.
self.duringBlockDragAndDrop = block
block.mousePressEventCustom(event)
@ -367,7 +368,9 @@ class GuiScore(QtWidgets.QGraphicsScene):
"""Catches certain mouse events for moving tracks and blocks.
Otherwise the event is propagated to the real QGraphicsItem.
Don't forget that an item needs to have the flag movable or selectable or else
it will not get mouseRelease or mouseMove events. MousePress always works."""
it will not get mouseRelease or mouseMove events. MousePress always works.
"""
super().mouseMoveEvent(event)
if self.duringTrackDragAndDrop:
#X is locked for tracks.
@ -375,10 +378,16 @@ class GuiScore(QtWidgets.QGraphicsScene):
y = event.scenePos().y()
self.duringTrackDragAndDrop.setPos(x, y)
elif self.duringBlockDragAndDrop:
self.duringBlockDragAndDrop.setPos(event.scenePos())
#self.duringBlockDragAndDrop.mouseMoveEventCustom(event)
#GuiBlockHandles are children of a Track. Their Y position will be offset by the track when we move them around with the mouse.
#Which is the same the distance to the first track is on top. We need to substract that for a good look and feel.
#The actual later dropping of the block is handled with the mouse cursor coordinates, the moving colored block is just eyecandy.
x = event.scenePos().x()
y = event.scenePos().y() - self.duringBlockDragAndDrop.parent.y()
self.duringBlockDragAndDrop.setPos(x, y)
#else:
# #this happens EVERY mouse move. Just idle mouse movement over the window.
super().mouseMoveEvent(event)
def mouseReleaseEvent(self, event):
"""Catches certain mouse events for moving tracks and blocks.

Loading…
Cancel
Save