Ejemplo n.º 1
0
    def event(self, event):
        ''' Event handling for input events. '''
        if event.type() == QEvent.Wheel:
            # For mice we zoom with control/command and the scrolwheel
            if event.modifiers() & Qt.ControlModifier:
                origin = (event.pos().x(), event.pos().y())
                zoom = 1.0
                try:
                    if event.pixelDelta():
                        # High resolution scroll
                        zoom *= (1.0 + 0.01 * event.pixelDelta().y())
                    else:
                        # Low resolution scroll
                        zoom *= (1.0 + 0.001 * event.angleDelta().y())
                except AttributeError:
                    zoom *= (1.0 + 0.001 * event.delta())
                self.panzoomchanged = True
                return self.panzoom(zoom=zoom, origin=origin)

            # For touchpad scroll (2D) is used for panning
            else:
                try:
                    dlat = 0.01 * event.pixelDelta().y() / (self.zoom * self.ar)
                    dlon = -0.01 * event.pixelDelta().x() / (self.zoom * self.flat_earth)
                    self.panzoomchanged = True
                    return self.panzoom(pan=(dlat, dlon))
                except AttributeError:
                    pass

        # For touchpad, pinch gesture is used for zoom
        elif event.type() == QEvent.Gesture:
            pan = zoom = None
            dlat = dlon = 0.0
            for g in event.gestures():
                if g.gestureType() == Qt.PinchGesture:
                    zoom = g.scaleFactor() * (zoom or 1.0)
                    if CORRECT_PINCH:
                        zoom /= g.lastScaleFactor()
                elif g.gestureType() == Qt.PanGesture:
                    if abs(g.delta().y() + g.delta().x()) > 1e-1:
                        dlat += 0.005 * g.delta().y() / (self.zoom * self.ar)
                        dlon -= 0.005 * g.delta().x() / (self.zoom * self.flat_earth)
                        pan = (dlat, dlon)
            if pan is not None or zoom is not None:
                self.panzoomchanged = True
                return self.panzoom(pan, zoom, self.mousepos)

        elif event.type() == QEvent.MouseButtonPress and event.button() & Qt.LeftButton:
            self.mousedragged = False
            # For mice we pan with control/command and mouse movement.
            # Mouse button press marks the beginning of a pan
            self.prevmousepos = (event.x(), event.y())

        elif event.type() == QEvent.MouseButtonRelease and \
             event.button() & Qt.LeftButton and not self.mousedragged:
            lat, lon = self.pixelCoordsToLatLon(event.x(), event.y())
            # TODO: acdata en routedata
            tostack, tocmdline = radarclick(console.get_cmdline(), lat, lon,
                                            self.acdata, self.routedata)
            if '\n' not in tocmdline:
                console.append_cmdline(tocmdline)
            if tostack:
                console.stack(tostack)

        elif event.type() == QEvent.MouseMove:
            self.mousedragged = True
            self.mousepos = (event.x(), event.y())
            if event.buttons() & Qt.LeftButton:
                dlat = 0.003 * (event.y() - self.prevmousepos[1]) / (self.zoom * self.ar)
                dlon = 0.003 * (self.prevmousepos[0] - event.x()) / (self.zoom * self.flat_earth)
                self.prevmousepos = (event.x(), event.y())
                self.panzoomchanged = True
                return self.panzoom(pan=(dlat, dlon))

        # Update pan/zoom to simulation thread only when the pan/zoom gesture is finished
        elif (event.type() == QEvent.MouseButtonRelease or
              event.type() == QEvent.TouchEnd) and self.panzoomchanged:
            self.panzoomchanged = False
            bs.net.send_event(b'PANZOOM', dict(pan=(self.panlat, self.panlon),
                                           zoom=self.zoom, ar=self.ar, absolute=True))

        # If this is a mouse move event, check if we are updating a preview poly
        if self.mousepos != self.prevmousepos:
            cmd = console.get_cmd()
            nargs = len(console.get_args())
            if cmd in ['AREA', 'BOX', 'POLY','POLYLINE',
                       'POLYALT', 'POLYGON', 'CIRCLE', 'LINE'] and nargs >= 2:
                self.prevmousepos = self.mousepos
                try:
                    # get the largest even number of points
                    start = 0 if cmd == 'AREA' else 3 if cmd == 'POLYALT' else 1
                    end = ((nargs - start) // 2) * 2 + start
                    data = [float(v) for v in console.get_args()[start:end]]
                    data += self.pixelCoordsToLatLon(*self.mousepos)
                    self.previewpoly(cmd, data)

                except ValueError:
                    pass

        # For all other events call base class event handling
        return super(RadarWidget, self).event(event)
Ejemplo n.º 2
0
    def event(self, event):
        ''' Event handling for input events. '''
        if event.type() == QEvent.Wheel:
            # For mice we zoom with control/command and the scrolwheel
            if event.modifiers() & Qt.ControlModifier:
                origin = (event.pos().x(), event.pos().y())
                zoom = 1.0
                try:
                    if event.pixelDelta():
                        # High resolution scroll
                        zoom *= (1.0 + 0.01 * event.pixelDelta().y())
                    else:
                        # Low resolution scroll
                        zoom *= (1.0 + 0.001 * event.angleDelta().y())
                except AttributeError:
                    zoom *= (1.0 + 0.001 * event.delta())
                self.panzoomchanged = True
                return self.panzoom(zoom=zoom, origin=origin)

            # For touchpad scroll (2D) is used for panning
            else:
                try:
                    dlat = 0.01 * event.pixelDelta().y() / (self.zoom *
                                                            self.ar)
                    dlon = -0.01 * event.pixelDelta().x() / (self.zoom *
                                                             self.flat_earth)
                    self.panzoomchanged = True
                    return self.panzoom(pan=(dlat, dlon))
                except AttributeError:
                    pass

        # For touchpad, pinch gesture is used for zoom
        elif event.type() == QEvent.Gesture:
            pan = zoom = None
            dlat = dlon = 0.0
            for g in event.gestures():
                if g.gestureType() == Qt.PinchGesture:
                    zoom = g.scaleFactor() * (zoom or 1.0)
                    if CORRECT_PINCH:
                        zoom /= g.lastScaleFactor()
                elif g.gestureType() == Qt.PanGesture:
                    if abs(g.delta().y() + g.delta().x()) > 1e-1:
                        dlat += 0.005 * g.delta().y() / (self.zoom * self.ar)
                        dlon -= 0.005 * g.delta().x() / (self.zoom *
                                                         self.flat_earth)
                        pan = (dlat, dlon)
            if pan is not None or zoom is not None:
                self.panzoomchanged = True
                return self.panzoom(pan, zoom, self.mousepos)

        elif event.type(
        ) == QEvent.MouseButtonPress and event.button() & Qt.LeftButton:
            self.mousedragged = False
            # For mice we pan with control/command and mouse movement.
            # Mouse button press marks the beginning of a pan
            self.prevmousepos = (event.x(), event.y())

        elif event.type() == QEvent.MouseButtonRelease and \
             event.button() & Qt.LeftButton and not self.mousedragged:
            lat, lon = self.pixelCoordsToLatLon(event.x(), event.y())
            # TODO: acdata en routedata
            tostack, tocmdline = radarclick(console.get_cmdline(), lat, lon,
                                            self.acdata, self.routedata)
            if '\n' not in tocmdline:
                console.append_cmdline(tocmdline)
            if tostack:
                console.stack(tostack)

        elif event.type() == QEvent.MouseMove:
            self.mousedragged = True
            self.mousepos = (event.x(), event.y())
            if event.buttons() & Qt.LeftButton:
                dlat = 0.003 * (event.y() -
                                self.prevmousepos[1]) / (self.zoom * self.ar)
                dlon = 0.003 * (self.prevmousepos[0] -
                                event.x()) / (self.zoom * self.flat_earth)
                self.prevmousepos = (event.x(), event.y())
                self.panzoomchanged = True
                return self.panzoom(pan=(dlat, dlon))

        # Update pan/zoom to simulation thread only when the pan/zoom gesture is finished
        elif (event.type() == QEvent.MouseButtonRelease
              or event.type() == QEvent.TouchEnd) and self.panzoomchanged:
            self.panzoomchanged = False
            bs.net.send_event(
                b'PANZOOM',
                dict(pan=(self.panlat, self.panlon),
                     zoom=self.zoom,
                     ar=self.ar,
                     absolute=True))

        # If this is a mouse move event, check if we are updating a preview poly
        if self.mousepos != self.prevmousepos:
            cmd = console.get_cmd()
            nargs = len(console.get_args())
            if cmd in [
                    'AREA', 'BOX', 'POLY', 'POLYLINE', 'POLYALT', 'POLYGON',
                    'CIRCLE', 'LINE'
            ] and nargs >= 2:
                self.prevmousepos = self.mousepos
                try:
                    # get the largest even number of points
                    start = 0 if cmd == 'AREA' else 3 if cmd == 'POLYALT' else 1
                    end = ((nargs - start) // 2) * 2 + start
                    data = [float(v) for v in console.get_args()[start:end]]
                    data += self.pixelCoordsToLatLon(*self.mousepos)
                    self.previewpoly(cmd, data)

                except ValueError:
                    pass

        # For all other events call base class event handling
        return super(RadarWidget, self).event(event)
Ejemplo n.º 3
0
    def event(self, event):
        ''' Event handling for input events. '''
        if event.type() == QEvent.Type.Wheel:
            # For mice we zoom with control/command and the scrolwheel
            if event.modifiers() & Qt.KeyboardModifier.ControlModifier:
                origin = (event.pos().x(), event.pos().y())
                zoom = 1.0
                try:
                    if event.pixelDelta():
                        # High resolution scroll
                        zoom *= (1.0 + 0.01 * event.pixelDelta().y())
                    else:
                        # Low resolution scroll
                        zoom *= (1.0 + 0.001 * event.angleDelta().y())
                except AttributeError:
                    zoom *= (1.0 + 0.001 * event.delta())
                self.panzoomchanged = True
                return self.panzoom(zoom=zoom, origin=origin)

            # For touchpad scroll (2D) is used for panning
            else:
                try:
                    dlat = 0.01 * event.pixelDelta().y() / (self.zoom *
                                                            self.ar)
                    dlon = -0.01 * event.pixelDelta().x() / (self.zoom *
                                                             self.flat_earth)
                    self.panzoomchanged = True
                    return self.panzoom(pan=(dlat, dlon))
                except AttributeError:
                    pass

        # For touchpad, pinch gesture is used for zoom
        elif event.type() == QEvent.Type.Gesture:
            pan = zoom = None
            dlat = dlon = 0.0
            for g in event.gestures():
                if g.gestureType() == Qt.GestureType.PinchGesture:
                    event.accept(g)
                    zoom = g.scaleFactor() * (zoom or 1.0)
                    if CORRECT_PINCH:
                        zoom /= g.lastScaleFactor()
                elif g.gestureType() == Qt.GestureType.PanGesture:
                    event.accept(g)
                    if abs(g.delta().y() + g.delta().x()) > 1e-1:
                        dlat += 0.005 * g.delta().y() / (self.zoom * self.ar)
                        dlon -= 0.005 * g.delta().x() / (self.zoom *
                                                         self.flat_earth)
                        pan = (dlat, dlon)
            if pan is not None or zoom is not None:
                self.panzoomchanged = True
                return self.panzoom(pan, zoom, self.mousepos)

        elif event.type() == QEvent.Type.MouseButtonPress and event.button(
        ) & Qt.MouseButton.LeftButton:
            self.mousedragged = False
            # For mice we pan with control/command and mouse movement.
            # Mouse button press marks the beginning of a pan
            self.prevmousepos = (event.pos().x(), event.pos().y())

        elif event.type() == QEvent.Type.MouseButtonRelease and \
                event.button() & Qt.MouseButton.LeftButton and not self.mousedragged:
            lat, lon = self.pixelCoordsToLatLon(event.pos().x(),
                                                event.pos().y())
            actdata = bs.net.get_nodedata()
            tostack, tocmdline = radarclick(console.get_cmdline(), lat, lon,
                                            actdata.acdata, actdata.routedata)

            console.process_cmdline((tostack + '\n' +
                                     tocmdline) if tostack else tocmdline)

        elif event.type() == QEvent.Type.MouseMove:
            self.mousedragged = True
            self.mousepos = (event.pos().x(), event.pos().y())
            if event.buttons() & Qt.MouseButton.LeftButton:
                dlat = 0.003 * \
                    (event.pos().y() - self.prevmousepos[1]) / (self.zoom * self.ar)
                dlon = 0.003 * \
                    (self.prevmousepos[0] - event.pos().x()) / \
                    (self.zoom * self.flat_earth)
                self.prevmousepos = (event.pos().x(), event.pos().y())
                self.panzoomchanged = True
                return self.panzoom(pan=(dlat, dlon))

        elif event.type() == QEvent.Type.TouchBegin:
            # Accept touch start to enable reception of follow-on touch update and touch end events
            event.accept()

        # Update pan/zoom to simulation thread only when the pan/zoom gesture is finished
        elif (event.type() == QEvent.Type.MouseButtonRelease
              or event.type() == QEvent.Type.TouchEnd) and self.panzoomchanged:
            self.panzoomchanged = False
            bs.net.send_event(
                b'PANZOOM',
                dict(pan=(self.panlat, self.panlon),
                     zoom=self.zoom,
                     ar=self.ar,
                     absolute=True))
            self.panzoom_event.emit(True)
        else:
            return super().event(event)

        # If we get here, the event was a mouse/trackpad event. Emit it to interested children
        self.mouse_event.emit(event)

        # For all other events call base class event handling
        return True