Skip to content

dragnavigator

Classes:

DragNavigator

DragNavigator(main: MainWindow, graphics_view: GraphicsView)

Bases: QWidget

Methods:

Attributes:

Source code
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
def __init__(self, main: MainWindow, graphics_view: GraphicsView) -> None:
    from ..abstracts import Timer

    super().__init__(graphics_view)

    self.main = main
    self.graphics_view = graphics_view
    self.graphics_view.dragEvent.connect(self.on_drag)
    self.setAttribute(Qt.WidgetAttribute.WA_NoSystemBackground)
    self.setAttribute(Qt.WidgetAttribute.WA_TransparentForMouseEvents)
    rate = self.main.settings.base_ppi / 96
    self.setGeometry(round(10 * rate), round(10 * rate), round(120 * rate), round(120 * rate))
    self.repaint_timer = Timer(
        timeout=self.repaint_timeout, timerType=Qt.TimerType.PreciseTimer,
        interval=self.main.settings.dragnavigator_timeout
    )
    self.graphics_view.verticalScrollBar().valueChanged.connect(partial(self.on_drag, DragEventType.repaint))
    self.graphics_view.horizontalScrollBar().valueChanged.connect(partial(self.on_drag, DragEventType.repaint))

contentsH class-attribute instance-attribute

contentsH = 0

contentsW class-attribute instance-attribute

contentsW = 0

graphics_view instance-attribute

graphics_view = graphics_view

is_tracking class-attribute instance-attribute

is_tracking = False

main instance-attribute

main = main

repaint_timer instance-attribute

repaint_timer = Timer(
    timeout=repaint_timeout,
    timerType=PreciseTimer,
    interval=dragnavigator_timeout,
)

viewportH class-attribute instance-attribute

viewportH = 0

viewportW class-attribute instance-attribute

viewportW = 0

viewportX class-attribute instance-attribute

viewportX = 0

viewportY class-attribute instance-attribute

viewportY = 0

draw

draw(
    contentsW: int,
    contentsH: int,
    viewportX: int,
    viewportY: int,
    viewportW: int,
    viewportH: int,
) -> None
Source code
80
81
82
83
84
85
86
87
88
89
90
def draw(
    self, contentsW: int, contentsH: int, viewportX: int, viewportY: int, viewportW: int, viewportH: int
) -> None:
    self.contentsW = contentsW
    self.contentsH = contentsH
    self.viewportW = min(viewportW, contentsW)
    self.viewportH = min(viewportH, contentsH)
    self.viewportX = min(viewportX, contentsW)
    self.viewportY = min(viewportY, contentsH)

    self.repaint()

on_drag

on_drag(event_type: DragEventType) -> None
Source code
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
def on_drag(self, event_type: DragEventType) -> None:
    # while reloading and moving mouse
    if not hasattr(self.main, 'current_output') or not self.main.current_output:
        return

    if event_type == DragEventType.repaint:
        self.repaint_timer.stop()
        self.repaint_timer.start()
    elif event_type == DragEventType.move and not self.is_tracking:
        return
    elif event_type == DragEventType.start:
        self.is_tracking = True
    elif event_type == DragEventType.stop:
        self.is_tracking = False
        self.setVisible(False)
        return

    scrollbarW = self.graphics_view.horizontalScrollBar()
    scrollbarH = self.graphics_view.verticalScrollBar()

    if not any({scrollbarW.isVisible(), scrollbarH.isVisible()}):
        return self.hide()

    self.setVisible(True)
    self.draw(
        self.main.current_output.width,
        self.main.current_output.height,
        int(scrollbarW.value() / self.graphics_view.currentZoom),
        int(scrollbarH.value() / self.graphics_view.currentZoom),
        int(self.graphics_view.width() / self.graphics_view.currentZoom),
        int(self.graphics_view.height() / self.graphics_view.currentZoom)
    )

paintEvent

paintEvent(event: QPaintEvent) -> None
Source code
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
def paintEvent(self, event: QPaintEvent) -> None:
    if (self.contentsW == 0) or (self.contentsH == 0) or (self.viewportW == 0) or \
            (self.viewportH == 0) or (self.viewportX >= self.contentsW) or (self.viewportY >= self.contentsH):
        event.ignore()
        return

    norm = 100.0 / max(self.contentsW, self.contentsH, self.viewportW, self.viewportH)

    normContentsWidth, normContentsHeight = round(self.contentsW * norm), round(self.contentsH * norm)
    normViewportWidth, normViewportHeight = round(self.viewportW * norm), round(self.viewportH * norm)
    normVieportX = min(round(self.viewportX * norm), normContentsWidth - normViewportWidth)
    normViwportY = min(round(self.viewportY * norm), normContentsHeight - normViewportHeight)

    cX1 = cY1 = 0
    cX2, cY2 = normContentsWidth - 1, normContentsHeight - 1

    vX1, vY1 = normVieportX, normViwportY
    vX2, vY2 = normVieportX + normViewportWidth - 1, normViwportY + normViewportHeight - 1

    painter = QPainter(self)

    painter.setPen(QColor(255, 0, 255))
    painter.drawLine(cX1, cY1, cX2, cY1)
    painter.drawLine(cX2, cY1, cX2, cY2)
    painter.drawLine(cX2, cY2, cX1, cY2)
    painter.drawLine(cX1, cY2, cX1, cY1)

    painter.setPen(QColor(0, 255, 0))
    painter.drawLine(vX1, vY1, vX2, vY1)
    painter.drawLine(vX2, vY1, vX2, vY2)
    painter.drawLine(vX2, vY2, vX1, vY2)
    painter.drawLine(vX1, vY2, vX1, vY1)

    event.accept()

repaint_timeout

repaint_timeout() -> None
Source code
92
93
94
def repaint_timeout(self) -> None:
    self.hide()
    self.repaint_timer.stop()