Example #1
0
    def __init__(self,
                 x=0,
                 y=10,
                 x1=0,
                 y1=0,
                 colour='green',
                 icon='images/pacman.ico'):
        QGraphicsItem.__init__(self)

        self.key = 0
        self.oldkey = 0
        self.pom = 0

        self.pocetak = 0
        self.game_over = False
        self.brojacZaSilu = 0
        self.colour = colour
        self.i = QImage(icon)
        self.i2 = QImage(icon)
        self.i3 = QImage('images/pacman2.png')
        self.img = QImage('images/pacman5.png')
        self.img2 = QImage('images/pacman6.png')

        self.pojeosilu = False
        self.way1 = 0
        self.poeni = 0
        self.zivot = 3
        self.x = x
        self.y = y
        self.x1 = x1
        self.y1 = y1
        self.konacno = x, y
Example #2
0
 def __init__(self, xy=(75, 75), colour='black', radius=28):
     QGraphicsItem.__init__(self)
     self.colour = colour
     self.xy = xy
     self.dx = xy[0]
     self.dy = xy[1]
     self._radius = radius
Example #3
0
 def mouseReleaseEvent(self, event):
     if self.model_bounds:
         parent = self.parentItem()
         xTL, yTL, xBR, yBR = self.model_bounds
         ct = self.corner_type
         epos = event.scenePos()
         new_pos = self.item_start + epos - self.event_start_position
         new_x = new_pos.x()
         new_y = new_pos.y()
         hwidth = self.half_width
         if ct == TOP_LEFT:
             new_x_TL = xTL - hwidth if new_x + hwidth > xTL else new_x
             new_y_TL = yTL - hwidth if new_y + hwidth > yTL else new_y
             tl, _ = parent.reconfigureRect(
                 (new_x_TL + hwidth, new_y_TL + hwidth), (), do_grid=True)
             self.alignPos(*tl)
         elif ct == BOTTOM_RIGHT:
             new_x_BR = xBR + hwidth if new_x + hwidth < xBR else new_x
             new_y_BR = yBR + hwidth if new_y + hwidth < yBR else new_y
             _, br = parent.reconfigureRect(
                 (), (new_x_BR + hwidth, new_y_BR + hwidth), do_grid=True)
             self.alignPos(*br)
         else:
             raise NotImplementedError("corner_type %d not supported" %
                                       (ct))
         self.model_bounds = ()
     if self.is_grabbing:
         self.is_grabbing = False
         parent = self.parentItem()
         parent.setMovable(False)
         QGraphicsItem.mouseReleaseEvent(parent, event)
         parent.finishDrag()
Example #4
0
 def mousePressEvent(self, event):
     if self.m_mouse_down:
         self.handleMouseRelease()
     self.m_hover_item = None
     self.m_mouse_down = bool(event.button() == Qt.LeftButton)
     self.m_cursor_moving = False
     QGraphicsItem.mousePressEvent(self, event)
    def mousePressEvent(self, event):
        """Handler for user mouse press.

        Args:
            event (QGraphicsSceneMouseEvent): Contains item, scene, and screen
            coordinates of the the event, and previous event.

        Args:
            event (QMouseEvent): contains parameters that describe a mouse event.
        """
        if event.button() == Qt.RightButton:
            return
        part = self._model_part
        part.setSelected(True)
        if self.isMovable():
            return QGraphicsItem.mousePressEvent(self, event)
        tool = self._getActiveTool()
        if tool.FILTER_NAME not in part.document().filter_set:
            return
        tool_method_name = tool.methodPrefix() + "MousePress"
        if tool_method_name == 'createToolMousePress':
            return
        elif hasattr(self, tool_method_name):
            getattr(self, tool_method_name)(tool, event)
        else:
            event.setaccepted(False)
            QGraphicsItem.mousePressEvent(self, event)
Example #6
0
    def append_item(self, item: QGraphicsItem) -> None:
        self.items.append(item)

        col = self.next_col
        row = self.next_row

        x = col * (self.style.tile_width +
                   self.style.spacing_x) + self.style.padding_x
        y = row * (self.style.tile_height +
                   self.style.spacing_y) + self.style.padding_y

        item.setPos(self.x + x + self.center_x_off, self.y + y)

        bottom_y = y + self.style.tile_height + self.style.padding_y

        # calculate next items position
        if self.style.arrangement == TileStyle.Arrangement.ROWS:
            col += 1
            if col == self.columns:
                col = 0
                row += 1
        else:
            row += 1
            if row == self.rows:
                row = 0
                col += 1

        self.next_col = col
        self.next_row = row
        self.height = bottom_y
Example #7
0
    def __init__(
            self,
            text='S',
            startp=Point(x=0.0, y=0.0),
    ):
        """
        Initialisation of the class.
        """
        QGraphicsItem.__init__(self)

        self.setFlag(QGraphicsItem.ItemIsSelectable, False)

        self.text = text
        self.sc = 1.0
        self.startp = QtCore.QPointF(startp.x, -startp.y)

        pencolor = QColor(0, 200, 255)
        self.brush = QColor(0, 100, 255)

        self.pen = QPen(pencolor, 1, QtCore.Qt.SolidLine)
        self.pen.setCosmetic(True)

        self.path = QPainterPath()
        self.path.addText(QtCore.QPointF(0, 0), QFont("Arial", 10 / self.sc),
                          self.text)
    def __init__(self, axis, posModel):
        QGraphicsItem.__init__(self)
        self.setFlag(QGraphicsItem.ItemHasNoContents)

        self.axis = axis
        self.posModel = posModel

        self._width = 0
        self._height = 0

        self.thick_penX = QPen(Qt.red, self.thick_width)
        self.thick_penX.setCosmetic(True)

        self.thick_penY = QPen(Qt.green, self.thick_width)
        self.thick_penY.setCosmetic(True)

        self.thin_penX = QPen(Qt.red, self.thin_width)
        self.thin_penX.setCosmetic(True)

        self.thin_penY = QPen(Qt.green, self.thin_width)
        self.thin_penY.setCosmetic(True)

        self.x = 0
        self.y = 0

        # These child items do most of the work.
        self._horizontal_marker = SliceMarkerLine(self, "horizontal")
        self._vertical_marker = SliceMarkerLine(self, "vertical")
Example #9
0
    def mouseMoveEvent(self, event):
        """
        All mouseMoveEvents are passed to the group if it's in a group

        Args:
            event (TYPE): Description
        """
        MOVE_THRESHOLD = 0.01  # ignore small moves
        selection_group = self.group()
        if selection_group is not None:
            selection_group.mousePressEvent(event)
        elif self._right_mouse_move:
            new_pos = event.scenePos()
            delta = new_pos - self.drag_last_position
            dx = int(floor(delta.x() / _BASE_WIDTH)) * _BASE_WIDTH
            x = self.handle_start.x() + dx
            if abs(dx) > MOVE_THRESHOLD or dx == 0.0:
                old_x = self.x()
                self.setX(x)
                self._virtual_helix_item.setX(x + _VH_XOFFSET)
                self._part_item.updateXoverItems(self._virtual_helix_item)
                dz = self._part_item.convertToModelZ(x - old_x)
                self._model_part.translateVirtualHelices([self.idNum()],
                                                         0,
                                                         0,
                                                         dz,
                                                         False,
                                                         use_undostack=False)
        else:
            QGraphicsItem.mouseMoveEvent(self, event)
Example #10
0
 def mouseDoubleClickEvent(self, event):
     if event.button(
     ) == Qt.LeftButton and event.modifiers() & Qt.ShiftModifier:
         event.accept()
         self.scene().removeItem(self)
     else:
         QGraphicsItem.mouseDoubleClickEvent(self, event)
Example #11
0
 def mousePressEvent(self, event):
     if self.flag_points_wall:
         if event.button() == Qt.LeftButton:
             calc = self.tree.rootItem.childItems[1].itemData[0][1]
             text = calc.lineEdit_points_wall.text()
             if text:
                 if self.name not in text:
                     calc.lineEdit_points_wall.setText(f'{text}, {self.name}')
                     calc.points_wall_list.append(self)
             else:
                 calc.lineEdit_points_wall.setText(self.name)
                 calc.points_wall_list.append(self)
         QGraphicsItem.mousePressEvent(self, event)
     elif self.flag_points_geom_barell:
         if event.button() == Qt.LeftButton:
             calc = self.tree.rootItem.childItems[1].itemData[0][1]
             text = calc.lineEdit_points_geom_barell.text()
             if text:
                 if self.name not in text:
                     calc.lineEdit_points_geom_barell.setText(f'{text}, {self.name}')
                     calc.points_geom_barell_list.append(self)
             else:
                 calc.lineEdit_points_geom_barell.setText(self.name)
                 calc.points_geom_barell_list.append(self)
         QGraphicsItem.mousePressEvent(self, event)
Example #12
0
    def mouseReleaseEvent(self, event):
        if event.button() == Qt.LeftButton:
            if self.m_mouse_down:

                for line_mov in self.m_line_mov_list:
                    item = line_mov
                    canvas.scene.removeItem(item)
                    del item
                self.m_line_mov_list.clear()

                for connection in canvas.connection_list:
                    if CanvasConnectionConcerns(connection, self.m_group_id,
                                                self.m_port_id_list):
                        connection.widget.setLocked(False)

                if self.m_hover_item:
                    if (self.m_last_rclick_item != self.m_hover_item
                            and time.time() > self.m_r_click_time + 0.3):
                        self.ConnectToHover()
                    canvas.scene.clearSelection()

                elif self.m_last_rclick_item:
                    canvas.scene.clearSelection()

            if self.m_cursor_moving:
                self.setCursor(QCursor(Qt.ArrowCursor))

            self.m_hover_item = None
            self.m_mouse_down = False
            self.m_cursor_moving = False
            canvas.is_line_mov = False
        QGraphicsItem.mouseReleaseEvent(self, event)
Example #13
0
 def mouseMoveEvent(self, event):
     if self.m_mouse_down:
         if not self.m_cursor_moving:
             self.setCursor(QCursor(Qt.SizeAllCursor))
             self.m_cursor_moving = True
         self.repaintLines()
     QGraphicsItem.mouseMoveEvent(self, event)
Example #14
0
    def __init__(self, axis, crop_extents_model, editable=True):

        self._cropColor = Qt.white

        QGraphicsItem.__init__(self)
        self.setFlag(QGraphicsItem.ItemHasNoContents)
        self.setAcceptHoverEvents(True)
        self.axis = axis
        self.crop_extents_model = crop_extents_model

        self._width = 0
        self._height = 0

        # Add shading item first so crop lines are drawn on top.
        self._shading_item = ExcludedRegionShading(self, self.crop_extents_model)

        self._horizontal0 = CropLine(self, "horizontal", 0)
        self._horizontal1 = CropLine(self, "horizontal", 1)
        self._vertical0 = CropLine(self, "vertical", 0)
        self._vertical1 = CropLine(self, "vertical", 1)

        self.crop_extents_model.changed.connect(self.onExtentsChanged)
        self.crop_extents_model.colorChanged.connect(self.onColorChanged)

        # keeping track which line started mouse move
        self._mouseMoveStartH = -1
        self._mouseMoveStartV = -1
        self._fractionOfDistance = 1
Example #15
0
 def __init__(self, parent=None):
     QGraphicsItem.__init__(self, parent)
     self.setFlag(QGraphicsItem.ItemIgnoresTransformations, True)
     self.setAcceptedMouseButtons(
         Qt.NoButton
     )  # is selectable but only by explicit flag setting; no mouseclick here
     self.setFlag(QGraphicsItem.ItemIsSelectable, True)
    def mouseMoveEvent(self, event):
        """
        All mouseMoveEvents are passed to the group if it's in a group

        Args:
            event (TYPE): Description
        """
        MOVE_THRESHOLD = 0.01   # ignore small moves
        selection_group = self.group()
        if selection_group is not None:
            selection_group.mousePressEvent(event)
        elif self._right_mouse_move:
            new_pos = event.scenePos()
            delta = new_pos - self.drag_last_position
            dx = int(floor(delta.x() / _BASE_WIDTH))*_BASE_WIDTH
            x = self.handle_start.x() + dx
            if abs(dx) > MOVE_THRESHOLD or dx == 0.0:
                old_x = self.x()
                self.setX(x)
                self._virtual_helix_item.setX(x + _VH_XOFFSET)
                self._part_item.updateXoverItems(self._virtual_helix_item)
                dz = self._part_item.convertToModelZ(x - old_x)
                self._model_part.translateVirtualHelices([self.idNum()],
                                                         0, 0, dz, False,
                                                         use_undostack=False)
        else:
            QGraphicsItem.mouseMoveEvent(self, event)
Example #17
0
 def keyPressEvent(self, event):
     factor = PointSize / 4
     changed = False
     if event.modifiers() & Qt.ShiftModifier:
         if event.key() == Qt.Key_Left:
             self.boundingRect().setRight(self.boundingRect().right() -
                                          factor)
             changed = True
         elif event.key() == Qt.Key_Right:
             self.boundingRect().setRight(self.boundingRect().right() +
                                          factor)
             changed = True
         elif event.key() == Qt.Key_Up:
             self.boundingRect().setBottom(self.boundingRect().bottom() -
                                           factor)
             changed = True
         elif event.key() == Qt.Key_Down:
             self.boundingRect().setBottom(self.boundingRect().bottom() +
                                           factor)
             changed = True
     if changed:
         self.update()
         global Dirty
         Dirty = True
     else:
         QGraphicsItem.keyPressEvent(self, event)
Example #18
0
 def mouseMoveEvent(self, event: 'QGraphicsSceneMouseEvent') -> None:
     """
     :param event:
     :return:
     """
     self.is_left_mouse_move = self.is_left_mouse_press
     QGraphicsItem.mouseMoveEvent(self, event)
Example #19
0
 def __init__(self, xy=(75, 75), dimensionality=9, radius=30):
     self.dimensionality = dimensionality
     QGraphicsItem.__init__(self)
     self.colour = QColor(155, 88, 19)
     self.dx = xy[0]
     self.dy = xy[1]
     self._radius = radius
Example #20
0
 def keyPressEvent(self, event):
     # ?????????????????????????/为什么没效果?????????????????????????????
     factor = PointSize / 4  # 移动精度
     changed = False
     if event.modifiers() & Qt.ShiftModifier:
         if event.key() == Qt.Key_Left:
             self.rect.setRight(self.rect.right() - factor)
             # void QRect::setRight(int x) Sets the right edge of the rectangle to the given x coordinate
             # May change the width, but will never change the left edge of the rectangle.
             # moveRight() Moves the rectangle horizontally, leaving the rectangle's right edge at the given x coordinate. The rectangle's size is unchanged.
             changed = True
         elif event.key() == Qt.Key_Right:
             self.rect.setRight(self.rect.right() + factor)
             changed = True
         elif event.key() == Qt.Key_Up:
             self.rect.setBottom(self.rect.bottom() - factor)
             changed = True
         elif event.key() == Qt.Key_Down:
             self.rect.setBottom(self.rect.bottom() + factor)
             changed = True
     if changed:
         self.update()
         global Dirty
         Dirty = True
     else:
         QGraphicsItem.keyPressEvent(self, event)
	def __init__(self, ad_data, physical_index):
		QGraphicsItem.__init__(self, parent=None)
		self.physical_location = ad_data.navpoint.code
		self.physical_runway_index = physical_index
		self.base_rwy, self.opposite_runway = ad_data.physicalRunway(physical_index)
		width_metres, surface = ad_data.physicalRunwayData(physical_index)
		self.width = m2NM * width_metres
		self.paved = is_paved_surface(surface)
		self.occupation_indication = 0
		thr = self.base_rwy.threshold().toRadarCoords()
		self.length = thr.distanceTo(self.opposite_runway.threshold().toRadarCoords())
		item_rot = self.base_rwy.orientation().trueAngle()
		self.label1 = RunwayNameItem(self.base_rwy.name, item_rot, self)
		self.label2 = RunwayNameItem(self.opposite_runway.name, item_rot + 180, self)
		self.label1.setPos(0, 0)
		self.label2.setPos(0, -self.length)
		self.LOC_item1 = LocaliserItem(self.base_rwy, self) # CAUTION: accessed from outside of class
		self.LOC_item2 = LocaliserItem(self.opposite_runway, self) # CAUTION: accessed from outside of class
		self.LOC_item2.setPos(0, -self.length)
		if self.base_rwy.LOC_bearing != None:
			self.LOC_item1.setRotation(self.base_rwy.LOC_bearing.trueAngle() - item_rot)
		if self.opposite_runway.LOC_bearing == None:
			self.LOC_item2.setRotation(180)
		else:
			self.LOC_item2.setRotation(self.opposite_runway.LOC_bearing.trueAngle() - item_rot)
		self.rect = QRectF(-self.width / 2, -self.length, self.width, self.length)
		self.setPos(thr.toQPointF())
		self.setRotation(item_rot)
		self.setAcceptHoverEvents(True)
Example #22
0
    def mousePressEvent(self, event):
        """Event handler for when the mouse button is pressed inside
        this item. If a tool-specific mouse press method is defined, it will be
        called for the currently active tool. Otherwise, the default
        QGraphicsItem.mousePressEvent will be called.

        Note:
            Only applies the event if the clicked item is in the part
            item's active filter set.

        Args:
            event (QMouseEvent): contains parameters that describe the mouse event.
        """
        if self.FILTER_NAME not in self._part_item.getFilterSet():
            self._doc_controller.showFilterHints(True,
                                                 filter_name=self.FILTER_NAME)
            return
        if event.button() == Qt.RightButton:
            return
        part_item = self._part_item
        tool = part_item._getActiveTool()
        tool_method_name = tool.methodPrefix() + "MousePress"
        if hasattr(self, tool_method_name):
            getattr(self, tool_method_name)(tool, part_item, event)
        else:
            QGraphicsItem.mousePressEvent(self, event)
Example #23
0
    def mouseMoveEvent(self, event):
        #pos = self.mapFromGlobal(event.globalPos())
        self.graphics_view._is_cursor_moved = True
        QGraphicsItem.mouseMoveEvent(self, event)
        if event.buttons() == Qt.LeftButton:
            max_y_pos = self._minimap_height - self.height()
            # fix vertical
            self.setX(0)
            if self.y() < 0:
                self.setY(0)
            elif self.y() > max_y_pos and max_y_pos < 0:
                self.setY(0)
            elif self.y() > max_y_pos and max_y_pos > 0:
                self.setY(max_y_pos)

            # move textedit's scrollbar
            elif self.pos_ratio > 0:
                print("self.y()", self.y())
                print("self.pos_ratio", self.pos_ratio)
                print("/", int(self.y() / self.pos_ratio))
                cursor_ratio = self.y() / self._minimap_height
                print("cursor_ratio", cursor_ratio)
                r = self.y() + self.height() * cursor_ratio
                print("r", r)
                self.graphics_view._change_scrollbar_value(
                    int(r / self.pos_ratio))
Example #24
0
 def mouseReleaseEvent(self, event):
     if self.m_cursor_moving:
         self.unsetCursor()
         QTimer.singleShot(0, self.fixPos)
     self.m_mouse_down = False
     self.m_cursor_moving = False
     QGraphicsItem.mouseReleaseEvent(self, event)
 def __init__(self):
     QGraphicsItem.__init__(self, None)
     self.setFlag(QGraphicsItem.ItemIgnoresTransformations, True)
     self.setVisible(False)
     self.timer = QTimer(self.scene())
     self.timer.setSingleShot(True)
     self.timer.timeout.connect(lambda: self.setVisible(False))
    def mouseMoveEvent(self, event):
        #pos = self.mapFromGlobal(event.globalPos())
        if self.graphics_view == None:
            return
        self.graphics_view._is_cursor_moved = True
        QGraphicsItem.mouseMoveEvent(self, event)
        if event.buttons() == Qt.LeftButton:
            max_y_pos = self._minimap_height - self.height()
            # fix vertical
            self.setX(0)
            if self.y() < 0:
                self.setY(0)
            elif self.y() > max_y_pos and max_y_pos < 0:
                self.setY(0)
            elif self.y() > max_y_pos and max_y_pos > 0:
                self.setY(max_y_pos)

            # move textedit's scrollbar
            elif self.pos_ratio > 0:
                print("self.y()", self.y())
                print("self.pos_ratio", self.pos_ratio)
                print("/", int(self.y() / self.pos_ratio))
                cursor_ratio = self.y() / self._minimap_height
                print("cursor_ratio", cursor_ratio)
                r = self.y() + self.height() * cursor_ratio
                print("r", r)
                self.graphics_view._change_scrollbar_value(
                    int(r / self.pos_ratio))
Example #27
0
 def hoverEnterEvent(self, event: QGraphicsSceneHoverEvent):
     if event.modifiers() & Qt.ShiftModifier:
         self.setCursor(Qt.OpenHandCursor)
     else:
         self.setCursor(Qt.ArrowCursor)
     self._part_item.updateStatusBar("{}–{}".format(self._idx_low, self._idx_high))
     QGraphicsItem.hoverEnterEvent(self, event)
Example #28
0
    def mousePressEvent(self, event):
        canvas.last_z_value += 1
        self.setZValue(canvas.last_z_value)
        self.resetLinesZValue()
        self.m_cursor_moving = False

        if event.button() == Qt.RightButton:
            event.accept()
            canvas.scene.clearSelection()
            self.setSelected(True)
            self.m_mouse_down = False
            return

        elif event.button() == Qt.LeftButton:
            if self.sceneBoundingRect().contains(event.scenePos()):
                self.m_mouse_down = True
            else:
                # FIXME: Check if still valid: Fix a weird Qt behaviour with right-click mouseMove
                self.m_mouse_down = False
                event.ignore()
                return

        else:
            self.m_mouse_down = False

        QGraphicsItem.mousePressEvent(self, event)
    def mouseReleaseEvent(self, event):
        """
        Called when mouse button is released.
        Resets selected handle and mouse press pos
        """
        self.setCursor(Qt.OpenHandCursor)

        self.set_pixmap()

        # update clip position if changed
        if self.x_pos != self.mouse_press_start_pos:
            if self.group_id is None:
                self.__controller.move_timeable(self.view_id,
                                                self.mouse_press_start_pos,
                                                self.x_pos)
            else:
                diff = self.x_pos - self.mouse_press_start_pos
                self.__controller.group_move_operation(self.group_id, diff)

        # trim start or end if resize happened
        if (self.resizable_right != self.infos_on_click["resizable_right"] or
                self.resizable_left != self.infos_on_click["resizable_left"]):
            self.__controller.resize_timeable(self.infos_on_click,
                                              self.get_info_dict())

        self.mouse_press_pos = 0
        self.handle_selected = None
        self.mouse_press_rect = None

        QGraphicsItem.mouseReleaseEvent(self, event)
Example #30
0
    def mousePressEvent(self, event):
        if canvas.scene.get_zoom_scale() <= 0.4:
            # prefer move box if zoom is too low
            event.ignore()
            return

        if event.button() == Qt.LeftButton:
            self.m_hover_item = None
            self.m_mouse_down = True
            self.m_cursor_moving = False

            for connection in canvas.connection_list:
                if CanvasConnectionConcerns(connection, self.m_group_id,
                                            self.m_port_id_list):
                    self.m_has_connections = True
                    break
            else:
                self.m_has_connections = False

        elif event.button() == Qt.RightButton:
            if canvas.is_line_mov:
                if self.m_hover_item:
                    self.ConnectToHover()
                    self.m_last_rclick_item = self.m_hover_item
                    self.m_r_click_time = time.time()

                    for line_mov in self.m_line_mov_list:
                        line_mov.toggleReadyToDisc()
                        line_mov.updateLinePos(event.scenePos())
        QGraphicsItem.mousePressEvent(self, event)
Example #31
0
 def mouseReleaseEvent(self, event):
     if self.model_bounds:
         parent = self.parentItem()
         xTL, yTL, xBR, yBR = self.model_bounds
         ct = self.corner_type
         epos = event.scenePos()
         new_pos = self.item_start + epos - self.event_start_position
         new_x = new_pos.x()
         new_y = new_pos.y()
         hwidth = self.half_width
         if ct == TOP_LEFT:
             new_x_TL = xTL - hwidth if new_x + hwidth > xTL else new_x
             new_y_TL = yTL - hwidth if new_y + hwidth > yTL else new_y
             tl, _ = parent.reconfigureRect((new_x_TL + hwidth, new_y_TL + hwidth), (), do_grid=True)
             self.alignPos(*tl)
         elif ct == BOTTOM_RIGHT:
             new_x_BR = xBR + hwidth if new_x + hwidth < xBR else new_x
             new_y_BR = yBR + hwidth if new_y + hwidth < yBR else new_y
             _, br = parent.reconfigureRect((), (new_x_BR + hwidth, new_y_BR + hwidth), do_grid=True)
             self.alignPos(*br)
         elif ct == TOP_RIGHT:
             pass
         elif ct == BOTTOM_LEFT:
             pass
         else:
             raise NotImplementedError("corner_type %d not supported" % (ct))
         self.model_bounds = ()
     if self.is_grabbing:
         self.is_grabbing = False
         parent = self.parentItem()
         parent.setMovable(False)
         QGraphicsItem.mouseReleaseEvent(parent, event)
         parent.finishDrag()
Example #32
0
 def __init__(self, parent=None):
     QGraphicsItem.__init__(self, parent)
     self.display_distance = True
     self.setVisible(False)
     self.info_box = ToolTextItem(self)
     self.setCursor(Qt.CrossCursor)
     self.mousePos = self.pos()  # dummy
Example #33
0
    def __init__(self, group_id, port_id, port_name, port_mode, port_type,
                 is_alternate, parent):
        QGraphicsItem.__init__(self)
        self.setParentItem(parent)

        # Save Variables, useful for later
        self.m_group_id = group_id
        self.m_port_id = port_id
        self.m_port_mode = port_mode
        self.m_port_type = port_type
        self.m_port_name = port_name
        self.m_is_alternate = is_alternate

        # Base Variables
        self.m_port_width = 15
        self.m_port_height = canvas.theme.port_height
        self.m_port_font = QFont()
        self.m_port_font.setFamily(canvas.theme.port_font_name)
        self.m_port_font.setPixelSize(canvas.theme.port_font_size)
        self.m_port_font.setWeight(canvas.theme.port_font_state)

        self.m_line_mov = None
        self.m_hover_item = None

        self.m_mouse_down = False
        self.m_cursor_moving = False

        self.setFlags(QGraphicsItem.ItemIsSelectable)

        if options.auto_select_items:
            self.setAcceptHoverEvents(True)
Example #34
0
 def __init__(self, src, title, draw_sections):
     QGraphicsItem.__init__(self, None)
     self.source_file = src
     self.title = title
     self.bounding_rect = QRectF()
     self.line_paths = []
     self.single_points = []
     self.text_labels = []
     for colour, points in draw_sections:
         for coords, txt in points:
             if txt != None:
                 label_item = BgHandDrawingLabelItem(colour, txt, self)
                 self.text_labels.append(label_item)
                 label_item.setPos(self.qpoint_rebound(coords))
         if len(points) == 1:
             point_item = BgHandDrawingPointItem(colour, self)
             self.single_points.append(point_item)
             point_item.setPos(self.qpoint_rebound(points[0][0]))
         else:
             path = QPainterPath()
             path.moveTo(self.qpoint_rebound(points[0][0]))
             for p, txt in points[1:]:
                 path.lineTo(self.qpoint_rebound(p))
             self.line_paths.append((colour, path))
     self.setVisible(False)
Example #35
0
    def append_item(self, item: QGraphicsItem) -> None:
        self.items.append(item)

        col = self.next_col
        row = self.next_row

        x = col * (self.style.tile_width + self.style.spacing_x) + self.style.padding_x
        y = row * (self.style.tile_height + self.style.spacing_y) + self.style.padding_y

        item.setPos(self.x + x + self.center_x_off,
                    self.y + y)

        bottom_y = y + self.style.tile_height + self.style.padding_y

        # calculate next items position
        if self.style.arrangement == TileStyle.Arrangement.ROWS:
            col += 1
            if col == self.columns:
                col = 0
                row += 1
        else:
            row += 1
            if row == self.rows:
                row = 0
                col += 1

        self.next_col = col
        self.next_row = row
        self.height = bottom_y
Example #36
0
 def itemChange(self, change, value):
     return QGraphicsItem.itemChange(self, change, value)
     # for selection changes test against QGraphicsItem.ItemSelectedChange
     # intercept the change instead of the has changed to enable features.
     if change == QGraphicsItem.ItemSelectedChange and self.scene():
         active_tool = self._getActiveTool()
         if active_tool.methodPrefix() == "selectTool":
             viewroot = self._viewroot
             current_filter_dict = viewroot.selectionFilterDict()
             selection_group = viewroot.strandItemSelectionGroup()
     
             # only add if the selection_group is not locked out
             is_normal_select = selection_group.isNormalSelect()
             if value == True and (self._filter_name in current_filter_dict or not is_normal_select):
                 if self._strand_filter in current_filter_dict:
                     if self.group() != selection_group:
                         self.setSelectedColor(True)
                         # This should always be the case, but...
                         if is_normal_select:
                             selection_group.pendToAdd(self)
                             selection_group.setSelectionLock(selection_group)
                             selection_group.pendToAdd(self._low_cap)
                             selection_group.pendToAdd(self._high_cap)
                         # this else will capture the error.  Basically, the
                         # strandItem should be member of the group before this
                         # ever gets fired
                         else:
                             selection_group.addToGroup(self)
                     return True
                 else:
                     return False
             # end if
             elif value == True:
                 # Don't select
                 return False
             # end elif
             else:
                 # Deselect
                 # print "Deselecting strand"
                 selection_group.pendToRemove(self)
                 self.setSelectedColor(False)
                 selection_group.pendToRemove(self._low_cap)
                 selection_group.pendToRemove(self._high_cap)
                 return False
             # end else
         # end if
         elif active_tool.methodPrefix() == "paintTool":
             viewroot = self._viewroot
             current_filter_dict = viewroot.selectionFilterDict()
             if self._strand_filter in current_filter_dict:
                 if not active_tool.isMacrod():
                     active_tool.setMacrod()
                 self.paintToolMousePress(None, None)
         # end elif
         return False
     # end if
     return QGraphicsItem.itemChange(self, change, value)
 def mouseMoveEvent(self, event):
     """
     All mouseMoveEvents are passed to the group if it's in a group
     """
     selection_group = self.group()
     if selection_group != None:
         selection_group.mousePressEvent(event)
     else:
         QGraphicsItem.mouseMoveEvent(self, event)
Example #38
0
 def mouseReleaseEvent(self, event):
     if self.model_bounds:
         self.model_bounds = ()
     if self.is_grabbing:
         # print("I am released")
         self.is_grabbing = False
         parent = self.parentItem()
         parent.setMovable(False)
         QGraphicsItem.mouseReleaseEvent(parent, event)
         parent.finishDrag()
Example #39
0
    def mousePressEvent(self, event):
        '''Handle mouse press event.

        Argument(s):
        event (QGraphicsSceneMouseEvent): Graphics scene mouse event
        '''
        QGraphicsItem.mousePressEvent(self, event)

        # Get the focus
        if event.buttons() == Qt.LeftButton:
            self.getFocus(self.id)
Example #40
0
    def __init__(self, nr, closed, parentEntity):
        QGraphicsItem.__init__(self)
        Shape.__init__(self, nr, closed, parentEntity)

        self.setFlag(QGraphicsItem.ItemIsSelectable, True)
        self.setAcceptedMouseButtons(QtCore.Qt.NoButton)

        self.selectionChangedCallback = None
        self.enableDisableCallback = None

        self.starrow = None
        self.enarrow = None
Example #41
0
    def mouseMoveEvent(self, event):
        """Handle mouse move event.

        Argument(s):
        event (QGraphicsSceneMouseEvent): Graphics scene mouse event
        """
        # Only move the node if CTRL button pressed
        if event.modifiers() == Qt.ControlModifier:
            QGraphicsItem.mouseMoveEvent(self, event)

        # Update coordinates of the line
        elif self.semiEdge is not None:
            self.semiEdge.update(event.scenePos())
Example #42
0
    def hoverMoveEvent(self, event: QGraphicsSceneHoverEvent):
        """Summary

        Args:
            event: Description
        """

        tool = self._getActiveTool()
        tool_method_name = tool.methodPrefix() + "HoverMove"
        if hasattr(self, tool_method_name):
            getattr(self, tool_method_name)(tool, event)
        else:
            event.setAccepted(False)
            QGraphicsItem.hoverMoveEvent(self, event)
Example #43
0
    def setSelected(self, flag=True, blockSignals=True):
        """
        Override inherited function to turn off selection of Arrows.
        @param flag: The flag to enable or disable Selection
        """
        self.starrow.setSelected(flag)
        self.enarrow.setSelected(flag)
        self.stmove.setSelected(flag)

        QGraphicsItem.setSelected(self, flag)
        Shape.setSelected(self, flag)

        if self.selectionChangedCallback and not blockSignals:
            self.selectionChangedCallback(self, flag)
Example #44
0
    def __init__(self, parent, direction, index):
        assert isinstance(parent, CroppingMarkers)
        assert direction in ("horizontal", "vertical")

        self._parent = parent
        self._direction = direction
        self._index = index
        QGraphicsItem.__init__(self, parent)
        self.setAcceptHoverEvents(True)
        self._position = 0
        self._line_thickness = 1

        # keeping track which line started mouse move
        self._mouseMoveStartH = -1
        self._mouseMoveStartV = -1
Example #45
0
 def mousePressEvent(self, event):
     """
     Parses a mousePressEvent, calling the approproate tool method as
     necessary. Stores _move_idx for future comparison.
     """
     if event.button() != Qt.LeftButton:
         event.ignore()
         QGraphicsItem.mousePressEvent(self, event)
         return
     self.scene().views()[0].addToPressList(self)
     self._move_idx = int(floor((self.x() + event.pos().x()) / _BASE_WIDTH))
     tool_method_name = self._getActiveTool().methodPrefix() + "MousePress"
     if hasattr(self, tool_method_name):  # if the tool method exists
         modifiers = event.modifiers()
         getattr(self, tool_method_name)(modifiers)  # call tool method
Example #46
0
    def mousePressEvent(self, event):
        """Handle mouse press event.

        Argument(s):
        event (QGraphicsSceneMouseEvent): Graphics scene mouse event
        """
        QGraphicsItem.mousePressEvent(self, event)

        # Create the semi-edge and get the focus
        if event.buttons() == Qt.LeftButton:
            self.getFocus(self.id)
            self.semiEdge = GraphicsSemiEdge(event.scenePos(), self)
            self.scene().addItem(self.semiEdge)
        elif event.buttons() == Qt.RightButton:
            self.contextMenu.popup(event.screenPos())
Example #47
0
	def mouseMoveEvent(self, ev):
		if self.mode == MODE_MOVE:
			return QGraphicsItem.mouseMoveEvent(self, ev)

		center = self.transform().map(self.boundingRect().center())
		origToCenter = self.origin - center
		originScale = vectorLength(origToCenter)
		origAngle = math.atan2(origToCenter.y(), origToCenter.x())

		newPt = self.transform().map(ev.pos())
		newToCenter = newPt - center
		newScale = vectorLength(newToCenter)
		newAngle = math.atan2(newToCenter.y(), newToCenter.x())

		# build transform
		t = QTransform()
		t.translate(center.x(), center.y())
		if self.mode == MODE_ROT:
			self._angle = math.degrees(newAngle - origAngle)
		t.rotate(self._angle)

		if self.mode == MODE_ZOOM:
			self._scale = newScale / originScale
		t.scale(self._scale, self._scale)
		t.translate(-center.x(), -center.y())
		self.setTransform(t)
Example #48
0
 def mouseMoveEvent(self, event):
     parent = self.parentItem()
     if self.model_bounds:
         xTL, yTL, xBR, yBR = self.model_bounds
         ct = self.corner_type
         epos = event.scenePos()
         # print(epos, self.item_start)
         # print(xTL, self.item_start.x())
         new_pos = self.item_start + epos - self.event_start_position
         new_x = new_pos.x()
         new_y = new_pos.y()
         hwidth = self.half_width
         if ct == TOP_LEFT:
             new_x_TL = xTL - hwidth if new_x + hwidth > xTL else new_x
             new_y_TL = yTL - hwidth if new_y + hwidth > yTL else new_y
             tl, _ = parent.reconfigureRect((new_x_TL + hwidth, new_y_TL + hwidth), (), do_grid=True)
             self.alignPos(*tl)
         elif ct == BOTTOM_RIGHT:
             new_x_BR = xBR + hwidth if new_x + hwidth < xBR else new_x
             new_y_BR = yBR + hwidth if new_y + hwidth < yBR else new_y
             _, br = parent.reconfigureRect((), (new_x_BR + hwidth, new_y_BR + hwidth), do_grid=True)
             self.alignPos(*br)
         elif ct == TOP_RIGHT:
             pass
         elif ct == BOTTOM_LEFT:
             pass
         else:
             raise NotImplementedError("corner_type %d not supported" % (ct))
     else:
         res = QGraphicsItem.mouseMoveEvent(parent, event)
         return res
Example #49
0
    def itemChange(self, change, value):
        # Move selected nodes and edges to the front, untill unselected
        if change == QGraphicsItem.ItemSelectedChange:
            if QGraphicsItem.isSelected(self):
            	#Unselected (since the flag is not updated yet)
                self.setZValue(0)
                self.setZValueEdges(1)
            else:
            	#Selected
                self.setZValue(4)
                self.setZValueEdges(5)

        #If the position of the node changes -> calculate position change
        #and move edges with the node
        newPos = value

        if change == QGraphicsItem.ItemPositionChange:
            if self.snappingIsOn:
                newPos = self.snapToGrid(newPos)
            posChange = newPos - self.lastPos
            # Due to the grid snapping, only process when node actually moved 
            if not posChange.isNull():
                self.moveEdges(posChange)
                self.lastPos = newPos
                self.widget.editNodePosition(self.nodeName, newPos)

        return super(Node, self).itemChange(change, newPos)
    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
        """All mousePressEvents are passed to the group if it's in a group

        Args:
            event: Description
        """
        selection_group = self.group()
        if selection_group is not None:
            selection_group.mousePressEvent(event)
        elif event.button() == Qt.RightButton:
            current_filter_set = self._viewroot.selectionFilterSet()
            if self.FILTER_NAME in current_filter_set and self.part().isZEditable():
                self._right_mouse_move = True
                self.drag_last_position = event.scenePos()
                self.handle_start = self.pos()
        else:
            QGraphicsItem.mousePressEvent(self, event)
Example #51
0
 def sceneEvent(self, event):
     """Included for unit testing in order to grab events that are sent
     via QGraphicsScene.sendEvent()."""
     # if self._parent.sliceController.testRecorder:
     #     coord = (self._row, self._col)
     #     self._parent.sliceController.testRecorder.sliceSceneEvent(event, coord)
     if event.type() == QEvent.MouseButtonPress:
         self.mousePressEvent(event)
         return True
     elif event.type() == QEvent.MouseButtonRelease:
         self.mouseReleaseEvent(event)
         return True
     elif event.type() == QEvent.MouseMove:
         self.mouseMoveEvent(event)
         return True
     QGraphicsItem.sceneEvent(self, event)
     return False
Example #52
0
    def mouseMoveEvent(self, event):
        parent = self.parentItem()
        epos = event.scenePos()
        h_w = self.half_width

        if self.model_bounds:
            mTLx, mTLy, mBRx, mBRy = self.model_bounds
            po_rect = parent.outline.rect()
            poTL = po_rect.topLeft()
            poBR = po_rect.bottomRight()
            poTLx, poTLy = poTL.x(), poTL.y()
            poBRx, poBRy = poBR.x(), poBR.y()
            new_pos = self.item_start + epos - self.event_start_position
            new_x = new_pos.x()+h_w
            new_y = new_pos.y()+h_w
            ht = self._handle_type
            if ht == HandleEnum.TOP_LEFT:
                new_x_TL = mTLx if new_x > mTLx else new_x
                new_y_TL = mTLy if new_y > mTLy else new_y
                r = parent.reconfigureRect((new_x_TL, new_y_TL), ())
                self._group.alignHandles(r)
            elif ht == HandleEnum.TOP:
                new_y_TL = mTLy if new_y > mTLy else new_y
                r = parent.reconfigureRect((poTLx, new_y_TL), ())
                self._group.alignHandles(r)
            elif ht == HandleEnum.TOP_RIGHT:
                new_y_TL = mTLy if new_y > mTLy else new_y
                new_x_BR = mBRx if new_x < mBRx else new_x
                r = parent.reconfigureRect((poTLx, new_y_TL), (new_x_BR, poBRy))
                self._group.alignHandles(r)
            elif ht == HandleEnum.RIGHT:
                new_x_BR = mBRx if new_x < mBRx else new_x
                r = parent.reconfigureRect((), (new_x_BR, poBRy))
                self._group.alignHandles(r)
            elif ht == HandleEnum.BOTTOM_RIGHT:
                new_x_BR = mBRx if new_x < mBRx else new_x
                new_y_BR = mBRy if new_y < mBRy else new_y
                r = parent.reconfigureRect((), (new_x_BR, new_y_BR))
                self._group.alignHandles(r)
            elif ht == HandleEnum.BOTTOM:
                new_y_BR = mBRy if new_y < mBRy else new_y
                r = parent.reconfigureRect((), (poBRx, new_y_BR))
                self._group.alignHandles(r)
            elif ht == HandleEnum.BOTTOM_LEFT:
                new_x_TL = mTLx if new_x > mTLx else new_x
                new_y_BR = mBRy if new_y < mBRy else new_y
                r = parent.reconfigureRect((new_x_TL, poTLy), (poBRx, new_y_BR))
                self._group.alignHandles(r)
            elif ht == HandleEnum.LEFT:
                new_x_TL = mTLx if new_x > mTLx else new_x
                r = parent.reconfigureRect((new_x_TL, poTLy), ())
                self._group.alignHandles(r)
            else:
                raise NotImplementedError("handle_type %d not supported" % (ht))
            event.setAccepted(True)
        else:
            res = QGraphicsItem.mouseMoveEvent(parent, event)
            return res
Example #53
0
    def __init__(self):
        QGraphicsItem.__init__(self)

        self._width = 0
        self._height = 0

        self.penDotted = QPen(Qt.red, 2, Qt.DotLine, Qt.RoundCap, Qt.RoundJoin)
        self.penDotted.setCosmetic(True)

        self.penSolid = QPen(Qt.red, 2)
        self.penSolid.setCosmetic(True)

        self.x = 0
        self.y = 0
        self.brushSize = 0

        self.mode = self.modeXYPosition
        self._enabled = True
Example #54
0
    def keyPressEvent(self, event: QKeyEvent):
        """event.key() seems to be capital only?

        Args:
            event (TYPE): Description
        """
        # print("press", ord('g'))
        if event.text() == 'g':
            print("hey het")
        return QGraphicsItem.keyPressEvent(self, event)
Example #55
0
    def createToolHoverMove(self, tool: AbstractGridToolT,
                                event: QGraphicsSceneHoverEvent):
        """Summary

        Args:
            tool: Description
            event: Description
        """
        tool.hoverMoveEvent(self, event)
        return QGraphicsItem.hoverMoveEvent(self, event)
Example #56
0
    def hoverLeaveEvent(self, event: QGraphicsSceneHoverEvent):
        """Summary

        Args:
            event (QGraphicsSceneHoverEvent): the hover event
        """
        self.prexoveritem_manager.updateModelActiveBaseInfo(None)
        self.setActiveHovered(False)
        self.clearFocus()
        self.parentItem().window().statusBar().showMessage("")
        return QGraphicsItem.hoverLeaveEvent(self, event)
Example #57
0
    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
        """Handler for user mouse press.

        Args:
            event: Contains item, scene, and screen coordinates of the event,
                and previous event.
        """
        self._viewroot.clearSelectionsIfActiveTool()
        self.unsetActiveVirtualHelixItem()

        return QGraphicsItem.mousePressEvent(self, event)
Example #58
0
    def hoverMoveEvent(self, event):
        #Don't execute when the nodeBody is selected in order to prevent unselecting the nodeBody
        if not QGraphicsItem.isSelected(self):
            self.mouseIsOnIO(event.pos())

        super().hoverMoveEvent(event)
        self.update()

        #Must be done after super().mousePressEvent(event) in order to
        #flag the node again after clicking on an input/output
        self.setFlag(QGraphicsItem.ItemIsSelectable, True)
        self.setFlag(QGraphicsItem.ItemIsMovable, True)
Example #59
0
    def mouseReleaseEvent(self, event):
        """Handle mouse release event.

        Argument(s):
        event (QGraphicsSceneMouseEvent): Graphics scene mouse event
        """
        QGraphicsItem.mouseReleaseEvent(self, event)

        # Construct edge if a semi edge is built
        if self.semiEdge is not None:
            # Remove the semi edge
            self.scene().removeItem(self.semiEdge)
            self.semiEdge = None

            # Filter item on the mouse and only get GraphicsNode
            items = [
                item for item in self.scene().items(event.scenePos()) if isinstance(item, GraphicsNode) and item != self
            ]
            if items:
                # Create edge
                self.graphicsGraphView.controller.onCreateEdge(self.id, items[0].id)