Browse Source

fix block context menu

master
Nils 3 years ago
parent
commit
e387cd64d2
  1. 8
      qtgui/musicstructures.py
  2. 52
      qtgui/scorescene.py

8
qtgui/musicstructures.py

@ -94,8 +94,6 @@ class GuiBlockHandle(QtWidgets.QGraphicsRectItem):
self.endLabel.setPos(self.rect().width() - self.endLabel.boundingRect().width(), constantsAndConfigs.stafflineGap)
self.endLabel.setFlags(QtWidgets.QGraphicsItem.ItemIgnoresParentOpacity)
def stretchXCoordinates(self, factor):
"""Reposition the items on the X axis.
Call goes through all parents/children, starting from ScoreView._stretchXCoordinates.
@ -133,7 +131,9 @@ class GuiBlockHandle(QtWidgets.QGraphicsRectItem):
self.endLabel.show()
super().mouseReleaseEvent(event)
def contextMenuEvent(self, event):
def contextMenuEventCustom(self):
"""The original context menu was too unreliable. We now call it
directly in Track."""
if self.startLabel.isVisible():
listOfLabelsAndFunctions = [
(translate("musicstructures", "edit properties"), lambda: BlockPropertiesEdit(self.scene().parentView.mainWindow, staticExportItem = self.staticExportItem)),
@ -149,8 +149,6 @@ class GuiBlockHandle(QtWidgets.QGraphicsRectItem):
(translate("musicstructures", "append block at the end"), lambda: api.appendBlock(self.parent.staticExportItem["id"])),
]
callContextMenu(listOfLabelsAndFunctions)
else:
super().contextMenuEvent(event)
class GuiTrack(QtWidgets.QGraphicsItem):
"""In opposite to tracks and block(backgrounds and handles) tracks never get recreated.

52
qtgui/scorescene.py

@ -341,28 +341,42 @@ class GuiScore(QtWidgets.QGraphicsScene):
and drop. We make the mouse cursor invisible so the user
can see where the object is moving
"""
if event.button() == QtCore.Qt.LeftButton and self.parentView.mode() in ("block", "cc"):
modifiers = QtWidgets.QApplication.keyboardModifiers()
super().mousePressEvent(event)
if self.parentView.mode() in ("block", "cc"):
if event.button() == QtCore.Qt.LeftButton:
modifiers = QtWidgets.QApplication.keyboardModifiers()
#Block Move
if modifiers == QtCore.Qt.NoModifier:
#Block Move
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)
#Track Move
elif (modifiers == QtCore.Qt.AltModifier or modifiers == QtCore.Qt.ShiftModifier ) and self.parentView.mode() == "block":
track = self.trackAt(event.scenePos())
if track and not track is self.conductor:
self.parentView.setCursor(QtCore.Qt.BlankCursor)
self.cursor.hide()
track.staticExportItem["guiPosStart"] = track.pos()
self.duringTrackDragAndDrop = track
elif event.button() == QtCore.Qt.RightButton:
"""Fake context menu event. The built-in one never got
the correct detection. Yes, this will hardcode the
context menu to right mouse button, which is not really
the only way to trigger a context menu. However, too
much time has been spent to get this right already.
Good enough is better than good."""
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)
#Track Move
elif (modifiers == QtCore.Qt.AltModifier or modifiers == QtCore.Qt.ShiftModifier ) and self.parentView.mode() == "block":
track = self.trackAt(event.scenePos())
if track and not track is self.conductor:
self.parentView.setCursor(QtCore.Qt.BlankCursor)
self.cursor.hide()
track.staticExportItem["guiPosStart"] = track.pos()
self.duringTrackDragAndDrop = track
block.contextMenuEventCustom()
super().mousePressEvent(event)
def mouseMoveEvent(self, event):
"""Catches certain mouse events for moving tracks and blocks.
@ -395,7 +409,7 @@ class GuiScore(QtWidgets.QGraphicsScene):
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."""
self.parentView.unsetCursor() #While moving stuff the mouse-cursor is hidden. Reset.
#self.parentView.unsetCursor() #While moving stuff the mouse-cursor is hidden. Reset.
#self.cursor.show() #Our own position cursor #TODO: why was that in here? It shows the cursor after a mouseclick, even in CC mode (it should not)
tempBlockDragAndDrop = self.duringBlockDragAndDrop

Loading…
Cancel
Save