Example #1
0
    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):

        movingItem = self.itemAt(event.scenePos(), self.view.transform())
        if movingItem is None and event.button() is Qt.MouseButton.RightButton:
            self.popMenu.exec_(event.screenPos())
        if movingItem is not None and event.button(
        ) is Qt.MouseButton.LeftButton:
            self.oldPos = movingItem.pos()
        self.clearSelection()
        super(Scene, self).mousePressEvent(event)
Example #2
0
 def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
     if self.isEnabled():
         self.setZValue(1)
         if event.button() is Qt.MouseButton.LeftButton:
             pass
             # self.posmouseinItem = event.scenePos() - self.pos()
             # items = self.scene().selectedItems()
             # if self not in items:
             #     self.scene().clearSelection()
             # if self.DialogVar is not None:
             #     self.DialogVar.close()
         if event.button() is Qt.MouseButton.RightButton:
             self.popMenu.exec_(event.screenPos())
Example #3
0
    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
        """Implementation.

    A left-click places a tile on a grid space, while a right-click removes a
    tile.
    """

        editor = self._editor
        pos = event.buttonDownScenePos(event.button())
        if editor.validGridPos(pos, scene=True):
            self.lastTilePos = editor.sceneToGrid(pos)
            if event.button() is Qt.LeftButton:
                return self.handleLeftButton(pos)
            elif event.button() is Qt.RightButton:
                return self.handleRightButton(pos)
Example #4
0
 def mouseReleaseEvent(self, event: QGraphicsSceneMouseEvent):
     if self.m_Item is not None and event.button() == Qt.LeftButton:
         self.itemLock.emit(self.m_Item)
         if self.m_oldPos != self.m_Item.pos():
             self.itemMoveSignal.emit(self.m_Item, self.m_oldPos)
         self.m_Item = None
     super(GraphicsScene, self).mouseReleaseEvent(event)
Example #5
0
    def mouseReleaseEvent(self,
                          event: QtWidgets.QGraphicsSceneMouseEvent) -> None:
        if not event.button() & QtCore.Qt.LeftButton:
            return
        modes = list(self.modifierModes(event.modifiers()))
        pixel = self.pixelSize()

        array = polygonf_to_array(self.poly)
        # Get start and end points of area
        x1, x2 = np.amin(array[:, 0]), np.amax(array[:, 0])
        y1, y2 = np.amin(array[:, 1]), np.amax(array[:, 1])
        # Bound to image area
        x1, y1 = max(x1, 0.0), max(y1, 0.0)
        x2 = min(x2, self.rect.width() - pixel.width() / 2.0)
        y2 = min(y2, self.rect.height() - pixel.height() / 2.0)
        # Generate pixel centers
        xs = np.arange(x1, x2, pixel.width()) + pixel.width() / 2.0
        ys = np.arange(y1, y2, pixel.height()) + pixel.height() / 2.0
        X, Y = np.meshgrid(xs, ys)
        pixels = np.stack((X.flat, Y.flat), axis=1)

        # Get mask of selected area
        mask = np.zeros(self.image_shape, dtype=bool)
        polymask = polygonf_contains_points(self.poly,
                                            pixels).reshape(ys.size, xs.size)
        # Insert
        ix, iy = int(x1 / pixel.width()), int(y1 / pixel.height())
        mask[iy:iy + ys.size, ix:ix + xs.size] = polymask

        # self.poly.append(self.poly.first())
        self.poly.clear()
        self.prepareGeometryChange()

        self.selectionChanged.emit(mask, modes)
Example #6
0
 def mousePressEvent(self,
                     event: QtWidgets.QGraphicsSceneMouseEvent) -> None:
     if not event.button() & QtCore.Qt.LeftButton:
         return
     self._rect.setTopLeft(event.pos())
     self._rect.setBottomRight(event.pos())
     self.prepareGeometryChange()
Example #7
0
 def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
     if event.button() == Qt.LeftButton and QApplication.keyboardModifiers() in (Qt.NoModifier, Qt.ControlModifier):
         # toggle selection
         self.infodock.toggle_instruction_selection(
             self.addr,
             insn_pos=self.scenePos(),
             unique=QApplication.keyboardModifiers() != Qt.ControlModifier)
         event.accept()
     elif event.button() == Qt.RightButton and QApplication.keyboardModifiers() == Qt.NoModifier:
         if self.addr not in self.infodock.selected_insns:
             self.infodock.toggle_instruction_selection(self.addr, insn_pos=self.scenePos(), unique=True)
         self.disasm_view.instruction_context_menu(self.insn, QCursor.pos())
         event.accept()
     elif self.workspace.plugins.handle_click_insn(self, event):
         event.accept()
     else:
         super().mousePressEvent(event)
Example #8
0
    def mousePressEvent(self,
                        event: QtWidgets.QGraphicsSceneMouseEvent) -> None:
        if not event.button() & QtCore.Qt.LeftButton:
            return
        self.poly.clear()
        self.poly.append(self.snapPos(event.pos()))

        self.prepareGeometryChange()
Example #9
0
 def mouseReleaseEvent(self, event: QGraphicsSceneMouseEvent):
     if len(self.selectedItems()) is not 0:
         movingItem = self.selectedItems()[0]
     else:
         movingItem = None
     if movingItem is not None and event.button(
     ) is Qt.MouseButton.LeftButton:
         if self.oldPos is not movingItem.pos():
             self.undoStack.push(MoveCommand(movingItem, self.oldPos, self))
     super(Scene, self).mouseReleaseEvent(event)
Example #10
0
    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
        mousePos = QPointF(
            event.buttonDownScenePos(Qt.LeftButton).x(),
            event.buttonDownScenePos(Qt.LeftButton).y())

        itemList = list(self.items(mousePos))
        super(GraphicsScene, self).mousePressEvent(event)

        if event.button() == Qt.LeftButton:
            if len(self.nodeList) <= 2:
                if self.focusItem():
                    self.nodeList.append((self.focusItem(), time()))

        if not self.focusItem():
            self.nodeList.clear()

        if len(itemList) > 0:
            self.m_Item = itemList[0]
            self.itemLock.emit(self.m_Item)
        if self.m_Item is not None and event.button() == Qt.LeftButton:
            self.m_oldPos = self.m_Item.pos()
 def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
     if event.button() == Qt.LeftButton and \
             event.modifiers() & Qt.ControlModifier:
         tabIndex = self.tabWidget.currentIndex()
         tabName = self.tabWidget.tabText(tabIndex)
         rowIndex = self.tabWidget.getCurrentTableModel().rowCount(
             QModelIndex())
         label = self.comboBox.currentText()
         box = QRectF(event.buttonDownScenePos(Qt.LeftButton), QSizeF(1, 1))
         color = self.tabWidget.color_map(tabIndex)[label]
         rect = self.addBox(tabIndex, tabName, rowIndex, self.page, label,
                            box, color)
         rect.handleSelected = 4
         self.signalHandler.boxCreated.emit(rect)
     super().mousePressEvent(event)
Example #12
0
    def mouseReleaseEvent(self,
                          event: QtWidgets.QGraphicsSceneMouseEvent) -> None:
        if not event.button() & QtCore.Qt.LeftButton:
            return
        modes = list(self.modifierModes(event.modifiers()))

        px, py = (
            self.rect.width() / self.image_shape[1],
            self.rect.height() / self.image_shape[0],
        )  # pixel size

        x1, y1, x2, y2 = self._rect.normalized().getCoords()
        x1 = np.round(x1 / px).astype(int)
        x2 = np.round(x2 / px).astype(int)
        y1 = np.round(y1 / py).astype(int)
        y2 = np.round(y2 / py).astype(int)

        mask = np.zeros(self.image_shape, dtype=bool)
        mask[y1:y2, x1:x2] = True

        self._rect = QtCore.QRectF()
        self.prepareGeometryChange()

        self.selectionChanged.emit(mask, modes)
 def mouseDoubleClickEvent(self, event: QtWidgets.QGraphicsSceneMouseEvent) -> None:
     if event.button() == QtCore.Qt.LeftButton:
         if self._node.ins_addr:
             self._workspace.viz(self._node.ins_addr)
Example #14
0
 def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
     if event.button() == Qt.LeftButton:
         self.on_click()
Example #15
0
 def mouseReleaseEvent(self, sceneMouseEvent: QGraphicsSceneMouseEvent):
     if sceneMouseEvent.button() == Qt.LeftButton:
         self.tetris.drop()
     if sceneMouseEvent.button() == Qt.RightButton:
         self.tetris.rotate()
 def mouseDoubleClickEvent(self, event: QGraphicsSceneMouseEvent):
     if event.button() == Qt.LeftButton:
         self.setTextInteractionFlags(Qt.TextEditorInteraction)
Example #17
0
 def mouseReleaseEvent(self, sceneMouseEvent: QGraphicsSceneMouseEvent):
     if sceneMouseEvent.button() == Qt.LeftButton:
         self.tetris.drop()
     if sceneMouseEvent.button() == Qt.RightButton:
         self.tetris.rotate()
Example #18
0
 def mouseReleaseEvent(self, event: QGraphicsSceneMouseEvent):
     item = self.parentItem()
     if event.button() and Qt.LeftButton:
         item.focusOutEvent(event)
         self.scene().update()