Exemplo n.º 1
0
    def wheelEvent(self, event: QWheelEvent):
        if self.capturing_data:
            return

        delta = event.angleDelta().y()
        zoom_factor = 1.001**delta
        p0scene = self.mapToScene(event.pos())
        w = self.view_rect().width()
        zooming_in = zoom_factor > 1
        if zooming_in and w / zoom_factor < self.min_width:
            return

        max_width = self.max_width
        if self.max_width == "auto":
            max_width = self.sceneRect().width()
        if not zooming_in and w / zoom_factor > max_width:
            self.update()
            return

        self.scale(zoom_factor, 1)
        p1mouse = self.mapFromScene(p0scene)
        move = p1mouse - event.pos()
        self.horizontalScrollBar().setValue(move.x() +
                                            self.horizontalScrollBar().value())
        self.zoomed.emit(zoom_factor)
Exemplo n.º 2
0
    def wheelEvent(self, event: QtGui.QWheelEvent):
        delta_x = 0
        delta_y = 0

        if platform == "linux" or platform == "linux2":
            delta_x = event.angleDelta().x()
            delta_y = event.angleDelta().y()
        elif platform == "darwin":
            delta_x = event.pixelDelta().x()
            delta_y = event.pixelDelta().y()
        elif platform == "win32":
            delta_x = event.angleDelta().x()
            delta_y = event.angleDelta().y()

        self.trans.moving_x(delta_x)
        self.trans.moving_range(delta_y)

        plot: QGraphicsItem = self.scene().items()[0]
        trans = plot.transform()
        trans.translate(delta_x, 0)
        scale_x, scale_y = trans.m11(), trans.m22()
        print(scale_x, scale_y)
        trans.scale(1 + delta_y / scale_x / 100, 1 + delta_y / scale_y / 100)
        plot.setTransform(trans)

        print(trans.m11(), trans.m12(), trans.m13())
        print(trans.m21(), trans.m22(), trans.m23())
        print(trans.m31(), trans.m32(), trans.m33())

        super().wheelEvent(event)
Exemplo n.º 3
0
def wheelEvent(self, event: QWheelEvent):
    """
        WheelEvent is the callback for wheel events of the operating system.
        Dependent on the OS, this can be a trackpad or a mouse wheel
    """

    if not (self.imageOpened):
        return

    # Disable wheel if x position is leaving image compartment
    if (event.x() > self.ui.verticalScrollBar.pos().x()):
        return

    if (event.source() == Qt.MouseEventSynthesizedBySystem):
        # touch pad geasture - use direct scrolling, not zooming
        # this is usually indicative for Mac OS
        subs = np.asarray(
            [float(event.pixelDelta().x()),
             float(event.pixelDelta().y())]) / 32000.0 * self.getZoomValue()
        self.relativeCoords -= subs
        if (self.relativeCoords[0] < -0.5):
            self.relativeCoords[0] = -0.5

        if (self.relativeCoords[1] < -0.5):
            self.relativeCoords[1] = -0.5

    else:  # mouse wheel - use scrolling
        inc = 1
        if (event.angleDelta().y() > 0):
            inc = -1
        self.setZoomValue(self.getZoomValue() * np.power(1.25, -inc))

    self.showImage()
    self.updateScrollbars()
Exemplo n.º 4
0
    def wheelEvent(self, a0: QtGui.QWheelEvent) -> None:
        if self.selector.labels and self.pressHoldSel:
            return super().wheelEvent(a0)

        if a0.modifiers() & QtCore.Qt.KeyboardModifier.ShiftModifier:
            c = self.hover.cats()
            if len(c) == 1:
                v = a0.angleDelta().y() or a0.angleDelta().x()
                self.hover.incr() if v > 0 else self.hover.decr()
                self.repaint()
            return super().wheelEvent(a0)

        lastScale = self.scale
        if a0.angleDelta().y() > 0:
            self.scale = min(
                self.scale < 1 and self.scale + 0.125 or self.scale + 1, 32)
        else:
            self.scale = max(
                self.scale <= 1 and self.scale - 0.125 or self.scale - 1, 0.25)

        c = a0.pos()
        self.viewOrigin[0] = int((self.viewOrigin[0] - c.x()) * self.scale /
                                 lastScale + c.x())
        self.viewOrigin[1] = int((self.viewOrigin[1] - c.y()) * self.scale /
                                 lastScale + c.y())
        self.pan(0, 0)
        return super().wheelEvent(a0)
Exemplo n.º 5
0
    def wheelEvent(self, event: QWheelEvent) -> None:
        if Town.isPointInRect(
                event.pos(),
            (QPoint(0,
                    self.height() * .8), QSize(self.width(),
                                               self.height() * .2))):
            if self.menu_mode == 1:
                types = Town.BuildingTypes
            elif self.menu_mode == 2:
                types = Town.RoadTypes
            delta = event.pixelDelta()
            if delta is None:
                delta = -event.angleDelta().y() / 2
            else:
                delta = -delta.x() / 2
            max_scroll = (3 * len(types.sorted_names) +
                          1) / 15 * self.height() - self.width() - 4
            if Town.isPointInRect(
                    event.pos(),
                (QPoint(self.height() / 15 - 4,
                        self.height() * .8),
                 QSize(self.width(),
                       self.height() *
                       .2))) and (delta > 0 and max_scroll > self.scrollAmount
                                  or delta < 0 and self.scrollAmount > 0):
                self.scrollAmount += delta
                if max_scroll < self.scrollAmount:
                    self.scrollAmount = max_scroll
                elif self.scrollAmount < 0:
                    self.scrollAmount = 0

        elif self.mode != Modes.Instructions:
            self.town.scaleByEvent(event)
Exemplo n.º 6
0
    def wheelEvent(self, event: QtGui.QWheelEvent):
        """ ChartView's wheel event handler

        Handle mouse wheel event.
        This method must handle :
            1. Change range of model by y-axis
            2. Change translate of model by x-axis

        Parameters
        ----------
        event : QtGui.QWheelEvent
            QGraphicsView's wheel event.

        """
        if self.open_file_finished:
            if platform == "darwin":
                delta_x = event.pixelDelta().x()
                delta_y = event.pixelDelta().y()
            else:
                delta_x = event.angleDelta().x()
                delta_y = event.angleDelta().y()

            self.model.change_x_range(delta_y)

        super().wheelEvent(event)
Exemplo n.º 7
0
 def wheelEvent(self, event: QtGui.QWheelEvent) -> None:
     event.accept()
     if isinstance(self._current_circle, CircleSeedNp):
         self._current_circle.set_radius(
             self._current_circle.radius +
             (1 if event.angleDelta().y() > 0 else -1), self._cv_image)
         self.update()
Exemplo n.º 8
0
 def wheelEvent(self, e: QWheelEvent):
     """ 实现平滑滚动效果 """
     if self.smoothMode == SmoothMode.NO_SMOOTH:
         super().wheelEvent(e)
         return
     # 将当前时间点插入队尾
     now = QDateTime.currentDateTime().toMSecsSinceEpoch()
     self.scrollStamps.append(now)
     while now - self.scrollStamps[0] > 500:
         self.scrollStamps.popleft()
     # 根据未处理完的事件调整移动速率增益
     accerationRatio = min(len(self.scrollStamps) / 15, 1)
     if not self.lastWheelEvent:
         self.lastWheelEvent = QWheelEvent(e)
     else:
         self.lastWheelEvent = e
     # 计算步数
     self.stepsTotal = self.fps * self.duration / 1000
     # 计算每一个事件对应的移动距离
     delta = e.angleDelta().y() * self.stepRatio
     if self.acceleration > 0:
         delta += delta * self.acceleration * accerationRatio
     # 将移动距离和步数组成列表,插入队列等待处理
     self.stepsLeftQueue.append([delta, self.stepsTotal])
     # 定时器的溢出时间t=1000ms/帧数
     self.smoothMoveTimer.start(1000 / self.fps)
Exemplo n.º 9
0
    def wheelEvent(self, event: QWheelEvent):
        """
        Zoom in or out of the view.
        """
        if event.modifiers() & Qt.ControlModifier or event.modifiers(
        ) & Qt.MetaModifier:
            zoomInFactor = 1.25
            zoomOutFactor = 1 / zoomInFactor

            # Save the scene pos
            oldPos = self.mapToScene(event.pos())

            # Zoom
            if event.angleDelta().y() > 0:
                zoomFactor = zoomInFactor
            else:
                zoomFactor = zoomOutFactor
            self.scale(zoomFactor, zoomFactor)

            # Get the new position
            newPos = self.mapToScene(event.pos())

            # Move scene to old position
            delta = newPos - oldPos
            self.translate(delta.x(), delta.y())
Exemplo n.º 10
0
    def wheelEvent(self, event):
        if self.control_scheme.wheel_zooms:
            dy = event.angleDelta().y()
            # Filter out horizontal wheel motion. We don't support this yet.
            if dy == 0:
                event.ignore()
                return
            self.zoom_camera(dy)
        else:
            if event.modifiers() & Qt.ShiftModifier:
                event = QWheelEvent(event.posF(),
                                    event.globalPosF(),
                                    event.pixelDelta(),
                                    event.angleDelta(),

                                    # Value magically chosen to approximate
                                    # what is happening on nirvana using
                                    # a steelseries mouse...
                                    event.angleDelta().y() / 8,

                                    Qt.Horizontal,  # Qt4 crap
                                    event.buttons(),
                                    event.modifiers(),
                                    event.phase())
            super().wheelEvent(event)
Exemplo n.º 11
0
 def wheelEvent(self, event: QtGui.QWheelEvent):
     try:
         zoom = super().page().mainFrame().zoomFactor()
         if self.ctrlOn is True:
             event.accept()
             if event.angleDelta().y() > 0:
                 zoom += 0.2
             else:
                 zoom -= 0.2
             if zoom <= 0.2: zoom = 0.2
             if zoom >= 3: zoom = 3
             print('zoom = {}'.format(zoom))
             super().page().mainFrame().setZoomFactor(zoom)
         # super().page().repaint()
         else:
             if self.mode.value == QwwMode.CBZ.value:
                 super().page().mainFrame().setZoomFactor(1)
                 event.accept()
                 passed = 0
                 if event.angleDelta().y() < 0: passed = 1
                 elif event.angleDelta().y() > 0: passed = -1
                 self.updatePositionCbz(passed)
             else:
                 self.updatePositionEpub(event.angleDelta().y() * -1)
                 event.ignore()
     except Exception:
         traceback.print_exc()
Exemplo n.º 12
0
 def wheelEvent(self, a0: QWheelEvent) -> None:
     if a0.modifiers() & Qt.ControlModifier:
         # ctrl press + scroll
         delta = a0.angleDelta().y()
         self.ctrlWheelScrolled.emit(delta)
     else:
         super(BasicTreeView, self).wheelEvent(a0)
Exemplo n.º 13
0
 def on_wheel_turn(self, event: QtGui.QWheelEvent) -> None:
     if event.modifiers() & PAN_X_MODIFIER:
         self._api.video.view.pan_x += event.angleDelta().y() / 15 / 100
     elif event.modifiers() & PAN_Y_MODIFIER:
         self._api.video.view.pan_y += event.angleDelta().y() / 15 / 100
     else:
         self._api.video.view.zoom += event.angleDelta().y() / 15 / 100
Exemplo n.º 14
0
 def wheelEvent(self, event: QWheelEvent) -> None:
     if self.parent.mediaAvailable:
         if event.angleDelta().y() > 0:
             self.parent.mpvWidget.frameBackStep()
         else:
             self.parent.mpvWidget.frameStep()
         event.accept()
Exemplo n.º 15
0
 def wheelEvent(self, event: QWheelEvent):
     """Zooms in or out the SVG image, depending on which direction
     the mouse wheel is being spun, and how far since the last
     wheel spin event.
     """
     factor = pow(1.2, event.angleDelta().y() / 240.0)
     self.zoom(factor)
     event.accept()
Exemplo n.º 16
0
 def wheelEvent(self, event: QWheelEvent) -> None:
     step = event.angleDelta().y() / 8 / 150  # one step, 0.1
     pos = event.position()
     print('鼠标滚轮滚动, X: %s, Y: %s, Step: %s' % (pos.x(), pos.y(), step))
     if step > 0:
         self.zoomIn(pos=pos, p=abs(step))
     else:
         self.zoomOut(pos=pos, p=abs(step))
Exemplo n.º 17
0
 def _emit_wheel_event(self):
     ev = QWheelEvent(*self._saved_wheel_event_info)
     if ev.delta() >= 0:
         self._Iren.MouseWheelForwardEvent()
     else:
         self._Iren.MouseWheelBackwardEvent()
     self.wheel_timer.stop()
     self.wheel_accumulator = 0
Exemplo n.º 18
0
 def eventFilter(self, watched: QtCore.QObject, event: QtCore.QEvent) -> bool:
     if event.type() == QtCore.QEvent.Wheel:
         scroll = QScrollArea(watched)
         wheel = QWheelEvent(event)
         scrollbar = scroll.horizontalScrollBar()
         scrollbar.setValue(int(scrollbar.value() - wheel.angleDelta().y() / 5))
         return True
     return super(TTScroller, self).eventFilter(watched, event)
Exemplo n.º 19
0
 def _emit_wheel_event(self):
     ev = QWheelEvent(*self._saved_wheel_event_info)
     if ev.delta() >= 0:
         self._Iren.MouseWheelForwardEvent()
     else:
         self._Iren.MouseWheelBackwardEvent()
     self.wheel_timer.stop()
     self.__wheelDelta = 0
Exemplo n.º 20
0
 def process_viewport_wheel_event(self, event: QWheelEvent):
     # print("size when wheeling: ", self.view.viewport().size())
     zoom_in = self.zoom_step
     zoom_out = 1 / zoom_in
     zoom_ = zoom_in if event.angleDelta().y() > 0 else zoom_out
     self.update_scale(event.pos(), zoom_)
     event.accept()
     self.on_view_changed()
     return True
Exemplo n.º 21
0
 def wheelEvent(self, event: QtGui.QWheelEvent) -> None:
     event.accept()
     if self._current_item_index != -1:
         current_seed_item = self._circle_seed_items[
             self._current_item_index]  # type: CircleSeedItem
         if current_seed_item.change_able:
             current_seed_item.radius += (1 if event.angleDelta().y() > 0
                                          else -1)
             self.update()
Exemplo n.º 22
0
    def wheelEvent(self, event: QtGui.QWheelEvent):
        x, y = self.translate(event.pos().x(), event.pos().y())

        new_zoom = self.zoom + event.angleDelta().y() / 400
        if new_zoom < self.min_scale and event.angleDelta().y() < 0:
            new_zoom = self.min_scale
        self.offset_x = ((new_zoom - self.zoom) * x + self.zoom * self.offset_x) / new_zoom
        self.offset_y = ((new_zoom - self.zoom) * y + self.zoom * self.offset_y) / new_zoom
        self.zoom = new_zoom
Exemplo n.º 23
0
    def wheelEvent(self, e: QWheelEvent):
        if e.modifiers() and Qt.ControlModifier:
            if e.angleDelta().y() > 0:
                self.view.zoomIn(6)
            else:
                self.view.zoomOut(6)

        else:
            super().wheelEvent(e)
Exemplo n.º 24
0
    def wheel_callback(self, event: QtGui.QWheelEvent):
        self.zoom_level += (event.angleDelta().y()) / (abs(
            event.angleDelta().y())) * 0.05
        if self.zoom_level < 0.05:
            self.zoom_level = 0.05

        if self.zoom_level > 10:
            self.zoom_level = 10

        self.update_zoom_level()
Exemplo n.º 25
0
 def wheelEvent(self, event: QtGui.QWheelEvent):
     """Translate Qt wheelEvent to MPL scroll_event"""
     pxDelta = event.pixelDelta()
     # See QWheelEvent::pixelDelta docs
     if not pxDelta.isNull():
         step = pxDelta.y()
     else:
         step = event.angleDelta().y() / 120
     if step:
         self.scroll_event(*self.mapToFigure(event.pos()), step, event)
Exemplo n.º 26
0
 def wheelEvent(self, event: QWheelEvent) -> None:
     # print(click_descriptor(event, 'scroll'))
     # Zoom on Ctrl-scroll
     if with_control_key(event) and event.angleDelta().y():
         if event.angleDelta().y() > 0:
             self.zoom_in()
         else:
             self.zoom_out()
     else:
         super().wheelEvent(event)
Exemplo n.º 27
0
 def wheelEvent(self, event: QWheelEvent):
     if event.modifiers() == QtCore.Qt.ControlModifier:
         self.font_size = self.font_size + event.angleDelta().y() / 15
         if self.font_size < 5:
             self.font_size = 5
         #fnt = self.ui.CsvVisualizer.font()
         #fnt.setPointSize(self.font_size)
         #self.ui.CsvVisualizer.setFont(fnt)
     else:
         event.ignore()
Exemplo n.º 28
0
    def wheelEvent(self, event: QWheelEvent) -> None:
        y_delta = event.angleDelta().y()
        if y_delta:
            notches = ceil(y_delta / 120)
            self._v_scrollbar.setValue(self._v_scrollbar.value() - notches)

        x_delta = event.angleDelta().x()
        if x_delta:
            notches = ceil(x_delta / 120)
            self._h_scrollbar.setValue(self._h_scrollbar.value() - notches)
Exemplo n.º 29
0
    def wheelEvent(self, event: qtgui.QWheelEvent):
        numPixels = event.pixelDelta()
        numDegrees = event.angleDelta() / 8

        if numPixels:
            self.scrollWithPixels(numPixels.y())
        elif numDegrees:
            numSteps = numDegrees / 15
            self.scrollWithDegrees(numSteps.y())

        event.accept()
Exemplo n.º 30
0
 def wheelEvent(self, event: QWheelEvent) -> None:
     if self.mediaPlayer.isVideoAvailable(
     ) or self.mediaPlayer.isAudioAvailable():
         if event.angleDelta().y() > 0:
             newval = self.seekSlider.value() - 1000
         else:
             newval = self.seekSlider.value() + 1000
         self.seekSlider.setValue(newval)
         self.seekSlider.setSliderPosition(newval)
         self.mediaPlayer.setPosition(newval)
     event.accept()
Exemplo n.º 31
0
 def wheelEvent(self, event: QtGui.QWheelEvent):
     """Allow selected item to be scrolled with the mouse wheel."""
     degrees = event.angleDelta().y() // 8  # angle delta is in eighths of a degree
     steps = degrees // 15
     for _ in range(abs(steps)):
         new_index = self.currentRow() + (1 if steps < 0 else -1)
         if -1 < new_index < self.count():  # do not wrap around
             self.setCurrentRow(new_index)
         else:
             break
     event.accept()
Exemplo n.º 32
0
 def _prev_or_next_track(self, event: QtGui.QWheelEvent) -> None:
     with self.exception_guard():
         self._connection.send(
             [
                 "script-message-to",
                 "playlist",
                 "playlist-next"
                 if event.angleDelta().y() > 0
                 else "playlist-prev",
             ]
         )
         self.refresh()
         self.render()
Exemplo n.º 33
0
    def wheelEvent(self, event: QtGui.QWheelEvent):
        if self.hasImage:
            factor=event.angleDelta().y()/120

            if factor>0:
                #self.transform变换,获取放缩后的倍数,在变换的基础上
                s = self.transform().scale(1.1, 1.1).mapRect(QtCore.QRectF(0, 0, 1, 1)).width()
                self.scale(1.1,1.1)

                #print(self.transform().scale(factor*10,factor*10))
            else:
                s = self.transform().scale(0.9,0.9).mapRect(QtCore.QRectF(0, 0, 1, 1)).width()
                self.scale(0.9,0.9)
            self.scale_factor = s
Exemplo n.º 34
0
    def _wheel(self, event: QtGui.QWheelEvent) -> None:
        with self.exception_guard():
            workspace_widgets = list(self._workspace_widgets)
            focused_widget_idx = None
            for i, workspace_widget in enumerate(workspace_widgets):
                workspace = self._widget_to_workspace(workspace_widget)
                if workspace.focused:
                    focused_widget_idx = i
                    break
            if focused_widget_idx is None:
                return

            focused_widget_idx += 1 if event.angleDelta().y() > 0 else -1
            focused_widget_idx %= len(workspace_widgets)
            focused_workspace = self._widget_to_workspace(
                workspace_widgets[focused_widget_idx]
            )
            run(["bspc", "desktop", "-f", focused_workspace.name or "?"])
Exemplo n.º 35
0
    def wheelEvent(self, event: QWheelEvent):
        """
        Zoom in/out on the mouse cursor
        """
        # zoom only when CTRL key pressed
        if (event.modifiers() & Qt.ControlModifier) == Qt.ControlModifier:
            steps = event.angleDelta().y() / 15 / 8

            if steps == 0:
                event.ignore()
                return

            # scale factor 1.25
            sc = pow(1.25, steps)
            self.scale(sc, sc)
            self.centerOn(self.mapToScene(event.pos()))
            event.accept()
        #  act normally on scrollbar
        else:
            # transmit event to parent class wheelevent
            super(QGraphicsView, self).wheelEvent(event)
Exemplo n.º 36
0
 def wheelEvent(self, event: QWheelEvent):
     self.safeScale(event.angleDelta().y())
Exemplo n.º 37
0
 def wheelEvent(self, event: QWheelEvent):
     event.ignore()
Exemplo n.º 38
0
 def wheelEvent(self, event: QWheelEvent):
     zoom_factor = 1.001 ** event.angleDelta().y()
     self.zoom(zoom_factor, cursor_pos=event.pos())