Exemple #1
0
class TableTopWidget(QWidget):
    MARGIN = 6
    trump_selected = Signal(int)

    def __init__(self, resource_path, parent=None):
        super(TableTopWidget, self).__init__(parent)

        self.width = CARD_WIDTH * 3 + self.MARGIN * 2
        self.height = CARD_HEIGHT * 3 + self.MARGIN * 2
        self.setFixedSize(self.width, self.height)

        self.cards = []
        self.cards.append(TableTopCard(resource_path, 
                QPoint(CARD_WIDTH + self.MARGIN, 0), self))
        self.cards.append(TableTopCard(resource_path, 
                QPoint(CARD_WIDTH  * 2 + self.MARGIN * 2,
                CARD_HEIGHT + self.MARGIN), self))
        self.cards.append(TableTopCard(resource_path,
                QPoint(CARD_WIDTH + self.MARGIN,
                CARD_HEIGHT * 2+ self.MARGIN * 2), self))
        self.cards.append(TableTopCard(resource_path,
                QPoint(0, CARD_HEIGHT + self.MARGIN), self))

        self.trump_select = TrumpWidget(resource_path, self)
        self.trump_select.setAutoFillBackground(True)
        self.trump_select.selected.connect(self.trump_selected)

        rect = self.trump_select.frameGeometry()
        mid_point = self.geometry().center()
        rect.moveCenter(mid_point)
        self.trump_select.move(rect.topLeft())
        self.trump_select.hide()

    def clear_sweep(self, pos):
        group = QParallelAnimationGroup()
        end_pos = self.cards[pos].card_widget.geometry()
        for card in self.cards:
            widget = card.pop()
            widget.raise_()
            ani = QPropertyAnimation(widget, "geometry")
            ani.setDuration(750)
            ani.setEndValue(end_pos)
            ani.finished.connect(partial(widget.setParent, None))
            group.addAnimation(ani)
        group.start()
        self.ani_group = group # Save to keep from being cleaned up

    def clear(self):
        self.hide_trump_select()
        for card in self.cards:
            card.set_card(None)

    def show_card(self, position, card):
        self.cards[position].set_card(card)

    def show_trump_select(self):
        for card in self.cards:
            card.hide()
        self.trump_select.show()

    def hide_trump_select(self):
        self.trump_select.hide()
        for card in self.cards:
            card.show()

    def sizeHint(self):
        return self.minimumSizeHint()

    def minimumSizeHint(self):
        return QSize(self.width, self.height)