summaryrefslogtreecommitdiff
path: root/tropical/qt/eventdrawer.py
diff options
context:
space:
mode:
Diffstat (limited to 'tropical/qt/eventdrawer.py')
-rw-r--r--tropical/qt/eventdrawer.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/tropical/qt/eventdrawer.py b/tropical/qt/eventdrawer.py
new file mode 100644
index 0000000..4afcf55
--- /dev/null
+++ b/tropical/qt/eventdrawer.py
@@ -0,0 +1,61 @@
+
+from PyQt6.QtWidgets import QGraphicsScene, QGraphicsView, QSizePolicy
+from PyQt6 import uic, QtGui, QtCore
+from PyQt6.QtCore import Qt, QRect
+import math
+#https://forum.qt.io/topic/93327/how-can-i-use-qpainter-to-paint-on-qgraphicsview/5
+#https://www.pythonguis.com/tutorials/pyqt6-bitmap-graphics/#qpainter
+
+# to solve the fit problem: https://stackoverflow.com/questions/61886358/qgraphicsview-fitinview-not-working-as-expected
+
+class EvtQGraphicsView(QGraphicsView):
+ def __init__(self, scene):
+ super().__init__(None)
+ self.setScene(scene)
+
+ def resizeEvent(self, event):
+ self.fitInView(self.sceneRect(), Qt.AspectRatioMode.IgnoreAspectRatio)
+
+
+class EvtDrawerScene(QGraphicsScene):
+ def __init__(self, calState):
+ self.gridWidth=2
+ super().__init__(None)
+ self.calState=calState
+
+ def drawForeground(self, painter, rect):
+ origXF, origYF, widthF, heightF = rect.getRect()
+ origXI, origYI, widthI, heightI = (int(origXF),int(origYF),int(widthF),int(heightF))
+ self.drawEvents(painter,origXI, origYI, widthI, heightI)
+
+
+ def drawEvents(self,painter,x,y,width,height):
+ # Init Pen
+ pen=QtGui.QPen()
+ pen.setWidth(self.gridWidth)
+ pen.setJoinStyle(Qt.PenJoinStyle.MiterJoin)
+ po=int(self.gridWidth/2) # Pen offset
+ painter.setPen(pen)
+
+ painter.drawRect(x+po,y+po,width-po*2,height-po*2)
+
+class EvtDrawer():
+
+ def __init__(self, layout, calState):
+ self.gs=EvtDrawerScene(calState)
+ self.gv=EvtQGraphicsView(self.gs)
+ # Setup propertion
+ spLeft=QSizePolicy(QSizePolicy.Policy.Preferred,QSizePolicy.Policy.Preferred);
+ spLeft.setHorizontalStretch(1);
+ self.gv.setSizePolicy(spLeft);
+
+ # if jean:
+ # spLeft=QSizePolicy(QSizePolicy.Policy.Preferred,QSizePolicy.Policy.Preferred);
+ # spLeft.setHorizontalStretch(2);
+ # self.gv.setSizePolicy(spLeft);
+ # else:
+ # spLeft=QSizePolicy(QSizePolicy.Policy.Preferred,QSizePolicy.Policy.Preferred);
+ # spLeft.setHorizontalStretch(1);
+ # self.gv.setSizePolicy(spLeft);
+ layout.addWidget(self.gv)
+