From a121fd492239b6c54001295327db8651b21406a7 Mon Sep 17 00:00:00 2001 From: Nils <> Date: Sun, 19 Jul 2020 11:06:30 +0200 Subject: [PATCH] bounding rects and paint for conductor --- qtgui/conductor.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/qtgui/conductor.py b/qtgui/conductor.py index 8e9755a..2f7236a 100644 --- a/qtgui/conductor.py +++ b/qtgui/conductor.py @@ -42,6 +42,7 @@ class Conductor(QtWidgets.QGraphicsItem): def __init__(self, parentView): 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.parentView = parentView self.totalHeight = 71 @@ -50,8 +51,6 @@ class Conductor(QtWidgets.QGraphicsItem): self.staticBlocks = None #Cached Block Data list self.staticMeta = None #Cached track meta data dict. - self.setFlag(QtWidgets.QGraphicsItem.ItemHasNoContents, True) #only child items. Without this we get notImplementedError: QGraphicsItem.paint() is abstract and must be overridden - self.staffLine = QtWidgets.QGraphicsLineItem(0,0,10,0) #x1, y1, x2, y2 self.staffLine.setParentItem(self) self.staffLine.setPos(0,0) @@ -64,7 +63,7 @@ class Conductor(QtWidgets.QGraphicsItem): api.callbacks.updateTempoTrack.append(self.createGraphicItemsFromData) api.callbacks.updateTempoTrackMeta.append(self.updateMetaData) - def boundingRect(self, *args): + def boundingRect(self): """The tempo track extends above the real tracks""" return QtCore.QRectF(0, -1*self.totalHeight, 20000, 1.2*self.totalHeight) #x,y,w,h @@ -433,6 +432,9 @@ class TempoPoint(QtWidgets.QGraphicsItem): self.setZValue(0) #avoid hovering conflict with block handle self.ungrabMouse = api.nothing #to surpress a warning from the context menu + #Set this flag after setFlags above + self.setFlag(QtWidgets.QGraphicsItem.ItemHasNoContents, True) #only child items. Without this we get notImplementedError: QGraphicsItem.paint() is abstract and must be overridden + self.note = QtWidgets.QGraphicsTextItem("") self.note.setParentItem(self) self.note.setFont(constantsAndConfigs.musicFont) @@ -457,14 +459,10 @@ class TempoPoint(QtWidgets.QGraphicsItem): self.wheelEventChangedValue = 0 #resetted in hoverEnterEvent. But we still need it for new items that appear directly under the mouse cursor - def paint(self, painter, options, widget=None): - #painter.drawRect(self.boundingRect()) #uncomment to show the bounding rect - pass - def boundingRect(self): + """We could return self.childrenBoundingRect() but we want the clickable area to be bigger""" return QtCore.QRectF(0,0,25,50) #x, y, w, h - def mouseMoveEvent(self, event): if self.staticExportItem["positionInBlock"] == 0: #First in block can't be moved @@ -570,15 +568,13 @@ class TimeLine(QtWidgets.QGraphicsItem): def __init__(self, parent): 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.parent = parent # self.gridInSeconds = 10 api.callbacks.updateTempoTrackBlocks.append(self.redraw) #no redraw on init. self.parent.staticPoints is not set yet. - def paint(self, *args): - pass - - def boundingRect(self, *args): + def boundingRect(self): return self.parent.boundingRect() def redraw(self, staticRepresentationList):