Browse Source

repair CC blocks

master
Nils 3 years ago
parent
commit
f424b3737d
  1. 1
      qtgui/conductor.py
  2. 14
      qtgui/graphs.py
  3. 1
      qtgui/musicstructures.py
  4. 23
      qtgui/scorescene.py

1
qtgui/conductor.py

@ -200,6 +200,7 @@ class ConductorTransparentBlock(QtWidgets.QGraphicsRectItem):
self.setFlags(QtWidgets.QGraphicsItem.ItemDoesntPropagateOpacityToChildren|QtWidgets.QGraphicsItem.ItemIsMovable) #no mouseReleaseEvent without selection or movable.
self.setAcceptHoverEvents(True)
self.parent = parent #Conductor instance
self.parentGuiTrack = parent #redundant, but specifically for block movement. see ScoreScene
self.color = stringToColor(staticExportItem["name"])
self.trans = QtGui.QColor("transparent")
self.setPen(self.trans)

14
qtgui/graphs.py

@ -237,13 +237,17 @@ class CCGraphTransparentBlock(QtWidgets.QGraphicsRectItem):
super().__init__(x, y, w, h)
#self.setFlags(QtWidgets.QGraphicsItem.ItemDoesntPropagateOpacityToChildren|QtWidgets.QGraphicsItem.ItemIsMovable) #no mouseReleaseEvent without selection or movable.
self.setFlags(QtWidgets.QGraphicsItem.ItemDoesntPropagateOpacityToChildren) #no mouseReleaseEvent without selection or movable.
self.parent = parent # CCPath instance
self.parentCCPath = parent
self.parent = parent #for compatibility with block movement to the appending positon.
self.parentGuiTrack = parent.parentGuiTrack #redundant, but specifically for block movement. see ScoreScene
self.color = stringToColor(staticExportItem["name"])
self.setBrush(self.color)
self.trans = QtGui.QColor("transparent")
self.setPen(self.trans)
self.setBrush(self.trans)
self.setOpacity(0.2) #mimic background behaviour
self.setOpacity(0.9) #only visible during drag and move
self.staticExportItem = staticExportItem
self.blockEndMarker = CCGraphBlockEndMarker(self, staticExportItem)
@ -280,8 +284,8 @@ class CCGraphTransparentBlock(QtWidgets.QGraphicsRectItem):
#self.setPos(self.mapToItem(self, event.scenePos()))
#self.setPos(self.mapFromScene(event.scenePos()))
#posGlobal = QtGui.QCursor.pos()
#posView = self.parent.parentScore.parentView.mapFromGlobal(posGlobal) #a widget
#posScene = self.parent.parentScore.parentView.mapToScene(posView)
#posView = self.parentCCPath.parentScore.parentView.mapFromGlobal(posGlobal) #a widget
#posScene = self.parentCCPath.parentScore.parentView.mapToScene(posView)
#print (posGlobal, posView, posScene, event.scenePos())
@ -331,7 +335,7 @@ class CCGraphTransparentBlock(QtWidgets.QGraphicsRectItem):
("join with next block", lambda: api.mergeWithNextGraphBlock(self.staticExportItem["id"])),
("delete block", lambda: api.deleteCCBlock(self.staticExportItem["id"])),
("separator", None),
("append block at the end", lambda ccNum = self.parent.getCCNumber(): api.appendGraphBlock(self.parent.parentDataTrackId, ccNum)),
("append block at the end", lambda ccNum = self.parentCCPath.getCCNumber(): api.appendGraphBlock(self.parentCCPath.parentDataTrackId, ccNum)),
]
callContextMenu(listOfLabelsAndFunctions)

1
qtgui/musicstructures.py

@ -57,6 +57,7 @@ class GuiBlockHandle(QtWidgets.QGraphicsRectItem):
#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
self.parentGuiTrack = parent #redundant, but specifically for block movement. see ScoreScene
self.color = None #QColor inserted by the creating function in GuiTrack. Used during dragging, then reset to transparent.
self.trans = QtGui.QColor("transparent")
self.setPen(self.trans)

23
qtgui/scorescene.py

@ -341,9 +341,7 @@ class GuiScore(QtWidgets.QGraphicsScene):
and drop. We make the mouse cursor invisible so the user
can see where the object is moving
"""
super().mousePressEvent(event)
if self.parentView.mode() in ("block"): #CC Block Moving is done in its own if clause below.
if self.parentView.mode() == "block": #CC Block Moving is done in its own if clause below.
if event.button() == QtCore.Qt.LeftButton:
modifiers = QtWidgets.QApplication.keyboardModifiers()
@ -351,7 +349,6 @@ 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)
@ -376,7 +373,23 @@ class GuiScore(QtWidgets.QGraphicsScene):
if block: #works for note blocks and conductor blocks
block.contextMenuEventCustom(event)
event.accept() #eat it
return
#CC is a special case because we need to handle points and block movement at the same time.
#Hence the alt/shift key is mandatory here. That was also the reason why everything was with the middle mouse button AND shortcuts once,
#but that was too inconvenient overall. This system is not 100% straightforward but easy enough to remember. And more robust against accidents.
elif self.parentView.mode() == "cc" and event.button() == QtCore.Qt.LeftButton:
modifiers = QtWidgets.QApplication.keyboardModifiers()
if (modifiers == QtCore.Qt.AltModifier or modifiers == QtCore.Qt.ShiftModifier):
block = self.blockAt(event.scenePos())
if block and type(block) is CCGraphTransparentBlock:
block.staticExportItem["guiPosStart"] = block.pos() #without shame we hijack the backend-dict.
self.duringBlockDragAndDrop = block
block.mousePressEventCustom(event)
event.accept() #eat it
return
super().mousePressEvent(event)
def mouseMoveEvent(self, event):
@ -397,7 +410,7 @@ class GuiScore(QtWidgets.QGraphicsScene):
#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()
y = event.scenePos().y() - self.duringBlockDragAndDrop.parentGuiTrack.y()
self.duringBlockDragAndDrop.setPos(x, y)
#else:
# #this happens EVERY mouse move. Just idle mouse movement over the window.

Loading…
Cancel
Save