summaryrefslogtreecommitdiff
path: root/src/main/python/utils/graphics.py
blob: aed7eedae7c7af7869c74b89ac385d3277c8a9bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QGraphicsView

class customView(QGraphicsView):
    
    def __init__(self, scene = None, parent=None):
        if scene is not None:
            super(customView, self).__init__(scene, parent)
        else:
            super(customView, self).__init__(parent)
        self.zoom = 1
        self.setDragMode(True)
        
    def wheelEvent(self, QWheelEvent):
        if Qt.ControlModifier:
            temp = self.zoom
            if QWheelEvent.source() == Qt.MouseEventNotSynthesized:
                if self.zoom + QWheelEvent.angleDelta().y()/2880 > 0.1:
                    self.zoom += QWheelEvent.angleDelta().y()/2880
            else:
                if self.zoom + QWheelEvent.pixelDelta().y() > 0.1:
                    self.zoom += QWheelEvent.angleDelta().y()
            self.scale(self.zoom / temp, self.zoom / temp)
            QWheelEvent.accept()
        else:
            return super().wheelEvent(self, QWheelEvent)