Ejemplo n.º 1
0
    def eventFilter(self, watched, event: QtGui.QMouseEvent) -> bool:
        if isinstance(watched, CellWidget):
            if event.type() == QtCore.QEvent.MouseButtonPress:
                if event.buttons() == QtCore.Qt.LeftButton:
                    # start drag if it is possible
                    if self.dragAndDrop and watched.getPiece() \
                            and watched.getPiece().color == self.board.turn:
                        self._dragWidget = _DragWidget(self)
                        self._dragWidget.setAutoFillBackground(True)
                        self._dragWidget.setFixedSize(watched.size())
                        self._dragWidget.setScaledContents(True)
                        self._dragWidget.setStyleSheet(
                            "background: transparent;")
                        self._dragWidget.setPixmap(
                            QtGui.QPixmap(
                                f":/images/{'_'.join(watched.objectName().split('_')[1:])}.png"
                            ))

                        rect = self._dragWidget.geometry()
                        rect.moveCenter(QtGui.QCursor.pos())
                        self._dragWidget.setGeometry(rect)

                        watched.setChecked(not watched.isChecked())
                        return True

                elif event.buttons() == QtCore.Qt.RightButton:
                    # mark cell if it is possible
                    if self.accessibleSides != NO_SIDE:
                        watched.setMarked(not watched.marked)

        return watched.event(event)
 def __cloneMouseEvent(self, e: QMouseEvent):
     event_type = e.type()
     local_pos = e.localPos()
     button = e.button()
     buttons = e.buttons()
     modifiers = e.modifiers()
     clone = QMouseEvent(event_type, local_pos, button, buttons, modifiers)
     clone.ignore()
     return clone
    def mousePressEvent(self, event: QMouseEvent):
        if event.type() == QEvent.MouseButtonPress:
            if self.locked:
                return
            if self.mode == 'hidden':
                if event.button() == Qt.LeftButton:
                    if not self.grid.in_progress:
                        self.grid.start_game()

                    self.mode = 'revealed'
                    if self.content == 'bomb':
                        self.grid.clicked_bomb(self.index)

                    if self.content == '0':
                        self.propagate_click()

                    self.update()

            if event.button() == Qt.RightButton:
                if self.mode in ['flag', 'hidden']:
                    self.grid.flag_update(self.index)
                    self.update()