Browse Source

Remove grid completely. It was just not worth the effort

master
Nils 4 years ago
parent
commit
6375495f5e
  1. 15
      qtgui/cursor.py
  2. 28
      qtgui/grid.py
  3. 3
      qtgui/mainwindow.py
  4. 16
      qtgui/menu.py
  5. 14
      qtgui/scorescene.py
  6. 13
      qtgui/scoreview.py

15
qtgui/cursor.py

@ -201,13 +201,14 @@ class Playhead(QtWidgets.QGraphicsLineItem):
api.seek(p * constantsAndConfigs.ticksToPixelRatio)
event.accept()
def mouseReleaseEvent(self, event):
if constantsAndConfigs.snapToGrid:
x = event.scenePos().x() * constantsAndConfigs.ticksToPixelRatio
p = round(x / constantsAndConfigs.gridRhythm) * constantsAndConfigs.gridRhythm
if p < 0:
p = 0
api.seek(p)
#TODO: grid does not exist anymore
#def mouseReleaseEvent(self, event):
# if constantsAndConfigs.snapToGrid:
# x = event.scenePos().x() * constantsAndConfigs.ticksToPixelRatio
# p = round(x / constantsAndConfigs.gridRhythm) * constantsAndConfigs.gridRhythm
# if p < 0:
# p = 0
# api.seek(p)
#def hoverEnterEvent(self, event):
# self.setCursor(QtCore.Qt.SizeHorCursor)

28
qtgui/grid.py

@ -29,7 +29,7 @@ import logging; logger = logging.getLogger(__name__); logger.info("import")
from PyQt5 import QtCore, QtGui, QtWidgets
#Our Template Modules
from template.engine.sequencer import MAXIMUM_TICK_DURATION
from template.qtgui.helper import stretchLine
#Client Modules
from .constantsAndConfigs import constantsAndConfigs
@ -150,19 +150,16 @@ class GuiGrid(QtWidgets.QGraphicsItemGroup):
scoreViewWidgetHeight = self.parent.parentView.height()
scoreViewWidgetWidth = self.parent.parentView.width()
if (not self.height) or scoreViewWidgetHeight * 1.1 > self.height:
self.height = scoreViewWidgetHeight * 1.1
if (not self.width) or scoreViewWidgetWidth * 1.1 > self.width:
self.width = scoreViewWidgetWidth * 1.1
if (not self.height) or scoreViewWidgetHeight * 2 > self.height:
self.height = scoreViewWidgetHeight * 2
if (not self.width) or scoreViewWidgetWidth * 2 > self.width:
self.width = scoreViewWidgetWidth * 2
if self.initialGridExists:
assert self.linesHorizontal and self.linesVertical, (self.linesHorizontal, self.linesVertical)
assert self.parent.parentView.isVisible(), self.parent.parentView.isVisible()
self._fillVerticalLines()
self._fillHorizontalLines()
#else:
#reactToresizeEventOrZoom without grid
#self.redrawTickGrid() #this happens only once, on program start. Afterwards it's user triggered by changing the grid rhythm
def _fillVerticalLines(self):
"""Only allowed to get called by reactToresizeEventOrZoom because we need an updated
@ -208,15 +205,22 @@ class GuiGrid(QtWidgets.QGraphicsItemGroup):
"""Reposition the items on the X axis.
Call goes through all parents/children, starting from ScoreView._stretchXCoordinates.
Docstring there."""
self.gapVertical = constantsAndConfigs.gridRhythm / constantsAndConfigs.ticksToPixelRatio #this is necessarry every time after stretching (ticksToPixelRatio) and after changing the gridRhythm
self.gapVertical = constantsAndConfigs.gridRhythm / constantsAndConfigs.ticksToPixelRatio #this is necessary every time after stretching (ticksToPixelRatio) and after changing the gridRhythm
for vline in self.linesVertical:
for vline in self.linesVertical: #rhythm- and barlines
#if vline.x() < 400:
# print(vline.x(), vline.x() * factor)
vline.setX(vline.x() * factor)
self._fillVerticalLines()
#for hline in self.linesHorizontal:
# stretchLine(hline, factor)
for hline in self.linesHorizontal: #pitch helper lines
stretchLine(hline, factor)
self._fillHorizontalLines()
print()
print()
def updateMode(self, nameAsString):
assert nameAsString in constantsAndConfigs.availableEditModes

3
qtgui/mainwindow.py

@ -121,7 +121,8 @@ class MainWindow(TemplateMainWindow):
#Now all tracks and items from a loaded backend-file are created. We can setup the initial editMode and viewPort.
self.scoreView.updateMode() #hide CCs at program start and other stuff
self.scoreView.scoreScene.grid.redrawTickGrid() #Init the grid only after everything got loaded and drawn to prevent a gap in the display. #TODO: which might be a bug. but this here works fine.
#self.scoreView.scoreScene.grid.redrawTickGrid() #Init the grid only after everything got loaded and drawn to prevent a gap in the display. #TODO: which might be a bug. but this here works fine.
#There is so much going on in the engine, we never reach a save status on load.
#Here is the crowbar-method.

16
qtgui/menu.py

@ -177,6 +177,7 @@ class MenuActionDatabase(object):
#...
}
self.mainWindow.ui.actionChange_Grid_Rhythm.setVisible(False)
self.actions = { #always available in the main window. It doesn't matter if you change to CC mode or Note Edit etc.
self.mainWindow.ui.actionToggle_Notehead_Rectangles : self.mainWindow.scoreView.toggleNoteheadsRectangles,
self.mainWindow.ui.actionData_Editor : self.mainWindow.toggleMainView,
@ -187,7 +188,7 @@ class MenuActionDatabase(object):
self.mainWindow.ui.actionBlock_Mode : self.mainWindow.scoreView.updateMode,
self.mainWindow.ui.actionCC_Mode : self.mainWindow.scoreView.updateMode,
self.mainWindow.ui.actionChange_Grid_Rhythm : self.mainWindow.scoreView.changeGridRhythm,
#self.mainWindow.ui.actionChange_Grid_Rhythm : self.mainWindow.scoreView.changeGridRhythm,
self.mainWindow.ui.actionAdd_Track : api.newEmptyTrack,
self.mainWindow.ui.actionDelete_Current_Track : api.deleteCurrentTrack,
self.mainWindow.ui.actionUse_Current_Track_as_Metronome : api.useCurrentTrackAsMetronome,
@ -339,7 +340,7 @@ class MenuActionDatabase(object):
self.mainWindow.ui.actionNotation_Mode,
self.mainWindow.ui.actionBlock_Mode,
self.mainWindow.ui.actionCC_Mode,
self.mainWindow.ui.actionChange_Grid_Rhythm,
#self.mainWindow.ui.actionChange_Grid_Rhythm,
self.mainWindow.ui.actionAdd_Track,
self.mainWindow.ui.actionUndo,
self.mainWindow.ui.actionRedo,
@ -358,16 +359,19 @@ class MenuActionDatabase(object):
#Prepare non-designer widgets. Designer can't put normal widgets in a toolbar, but Qt can.
#Eventhough this is a dict, which has no order, the CREATION has an order. So the first item in the dict will be the first item in the toolBar
self.extraToolBarWidgets = {
"snapToGrid" : self.mainWindow.ui.toolBar.addWidget(ToolBarSnapToGrid(mainWindow=self.mainWindow)),
#"snapToGrid" : self.mainWindow.ui.toolBar.addWidget(ToolBarSnapToGrid(mainWindow=self.mainWindow)),
"metronome" : self.mainWindow.ui.toolBar.addWidget(ToolBarMetronome(mainWindow=self.mainWindow)),
"playbackSpeed" : self.mainWindow.ui.toolBar.addWidget(ToolBarPlaybackSpeed(mainWindow=self.mainWindow)),
"ccType" : self.mainWindow.ui.toolBar.addWidget(ToolBarCCType(mainWindow=self.mainWindow)), #keep this at the end of the toolbar because it toggles visibility
}
self.toolbarContexts = {
"notation" : [self.extraToolBarWidgets["snapToGrid"], self.extraToolBarWidgets["metronome"], self.extraToolBarWidgets["playbackSpeed"], ],
"cc" : [self.extraToolBarWidgets["snapToGrid"], self.extraToolBarWidgets["metronome"], self.extraToolBarWidgets["ccType"], self.extraToolBarWidgets["playbackSpeed"]],
"block": [self.extraToolBarWidgets["snapToGrid"], self.extraToolBarWidgets["metronome"], self.extraToolBarWidgets["playbackSpeed"], ],
#"notation" : [self.extraToolBarWidgets["snapToGrid"], self.extraToolBarWidgets["metronome"], self.extraToolBarWidgets["playbackSpeed"], ],
"notation" : [self.extraToolBarWidgets["metronome"], self.extraToolBarWidgets["playbackSpeed"], ],
#"cc" : [self.extraToolBarWidgets["snapToGrid"], self.extraToolBarWidgets["metronome"], self.extraToolBarWidgets["ccType"], self.extraToolBarWidgets["playbackSpeed"]],
"cc" : [self.extraToolBarWidgets["metronome"], self.extraToolBarWidgets["ccType"], self.extraToolBarWidgets["playbackSpeed"]],
#"block": [self.extraToolBarWidgets["snapToGrid"], self.extraToolBarWidgets["metronome"], self.extraToolBarWidgets["playbackSpeed"], ],
"block": [self.extraToolBarWidgets["metronome"], self.extraToolBarWidgets["playbackSpeed"], ],
}
#Now connect all actions to functions

14
qtgui/scorescene.py

@ -32,7 +32,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets
import engine.api as api
from .constantsAndConfigs import constantsAndConfigs
from .grid import GuiGrid
#from .grid import GuiGrid
from .conductor import Conductor, ConductorTransparentBlock
from .musicstructures import GuiBlockHandle, GuiTrack
from .graphs import CCGraphTransparentBlock
@ -69,10 +69,10 @@ class GuiScore(QtWidgets.QGraphicsScene):
self.backColor.setNamedColor("#fdfdff")
self.setBackgroundBrush(self.backColor)
self.grid = GuiGrid(parentScene=self)
self.addItem(self.grid)
self.grid.setPos(0, -20 * constantsAndConfigs.stafflineGap) #this is more calculation than simply using self.yStart, and might require manual adjustment in the future, but at least it guarantees the grid matches the staffline positions
self.grid.setZValue(-50)
#self.grid = GuiGrid(parentScene=self)
#self.addItem(self.grid)
#self.grid.setPos(0, -20 * constantsAndConfigs.stafflineGap) #this is more calculation than simply using self.yStart, and might require manual adjustment in the future, but at least it guarantees the grid matches the staffline positions
#self.grid.setZValue(-50)
self.cachedSceneHeight = 0 #set in self.redraw. Used by updateTrack to set the sceneRect
@ -100,7 +100,7 @@ class GuiScore(QtWidgets.QGraphicsScene):
for track in self.tracks.values():
track.updateMode(nameAsString)
self.grid.updateMode(nameAsString)
#self.grid.updateMode(nameAsString)
def maxTrackLength(self):
if self.tracks:
@ -310,7 +310,7 @@ class GuiScore(QtWidgets.QGraphicsScene):
Docstring there."""
#The big structures have a fixed position at (0,0) and move its child items, like notes, internally
#Some items, like the cursor, move around, as a whole item, in the scene directly and need no stretchXCoordinates() themselves.
self.grid.stretchXCoordinates(factor)
#self.grid.stretchXCoordinates(factor)
self.conductor.stretchXCoordinates(factor)
self.cursor.setX(self.cursor.pos().x() * factor)
self.playhead.setX(self.playhead.pos().x() * factor)

13
qtgui/scoreview.py

@ -31,7 +31,7 @@ from template.helper import onlyOne
#Our Modules
from .constantsAndConfigs import constantsAndConfigs
from .scorescene import GuiScore
from .submenus import GridRhytmEdit
#from .submenus import GridRhytmEdit
import engine.api as api
class ScoreView(QtWidgets.QGraphicsView):
@ -143,12 +143,13 @@ class ScoreView(QtWidgets.QGraphicsView):
else:
raise ValueError("Edit Mode unknown")
def resizeEvent(self, event):
#self.scoreScene.grid.reactToresizeEventOrZoom()
super().resizeEvent(event)
#Grid is gone
#def resizeEvent(self, event):
# self.scoreScene.grid.reactToresizeEventOrZoom()
# super().resizeEvent(event)
def changeGridRhythm(self):
GridRhytmEdit(mainWindow=self.mainWindow) #handles everything.
#def changeGridRhythm(self):
# GridRhytmEdit(mainWindow=self.mainWindow) #handles everything.
def updateMode(self, *args):
"""Switch through different views for editing:

Loading…
Cancel
Save