Пример #1
0
class MTestComponent(MShape):
    def __init__(self):
        MShape.__init__(self)
        self.max_width = 100
        self.max_height = 100
        self.width = 100
        self.height = 100
        self.__color = MColors.PRIMARY_COLOR
        self.__pen = QPen(self.__color, 0)
        self.__painter = QPainter()
        self.__reveal = MCircularReveal()
        self.__reveal.duration = 1000
        self.__reveal.add_target(self)
        self.margin_start = 10
        self.margin_top = 15
        self.__bounding_rect = QRect(self.margin_start, self.margin_top, self.width, self.height)

    def paintEvent(self, event):
        self.__painter.begin(self)
        self.__painter.setRenderHint(QPainter.Antialiasing)
        self.__painter.setPen(self.__pen)
        self.__painter.setBrush(self.__color)
        if self.clip is not None:
            self.__painter.setClipPath(self.clip)
        self.__painter.drawRect(self.__bounding_rect)
        self.__painter.end()

    def mousePressEvent(self, event):
        self.__reveal.start()

    def trigger_cancel(self):
        self.__reveal.cancel()
Пример #2
0
class MRadioButton(MShape):
    def __init__(self):
        MShape.__init__(self)

        self.max_height = 20
        self.max_width = 20
        self.width = self.max_width
        self.height = self.max_height
        self.setFixedSize(self.width, self.height)
        self.innerCircle = None
        self.outerRing = OuterRing()
        self.add_layout_item(self.outerRing, 0, 0)
        self.setLayout(self.layout)
        self.__checked = False
        self.__reveal = MCircularReveal()
        self.__reveal.duration = 300
        self.__fade = MFadeOut()
        self.__fade.duration = 200
        self.__bounding_rect = QRect(self.x() + self.margin_x / 2, self.y() + self.margin_y / 2,
                                     self.width - self.margin_x, self.height - self.margin_y)

    def mousePressEvent(self, event):
        if self.__checked:
            self.__reveal.remove_target(self.innerCircle)
            self.__fade.add_target(self.innerCircle)
            self.__fade.end_signal.connect(self.on_fade_end)
            self.__fade.start()
        else:
            self.innerCircle = InnerCircle()
            self.add_layout_item(self.innerCircle, 0, 0)
            self.__reveal.add_target(self.innerCircle)
            self.__reveal.start()
            self.__checked = True

    def on_fade_end(self):
        self.__fade.remove_target(self.innerCircle)
        self.__fade.end_signal.disconnect(self.on_fade_end)
        self.remove_layout_item(self.innerCircle)
        self.__checked = False
Пример #3
0
class MCheckBox(MShape):
    def __init__(self):
        MShape.__init__(self)

        self.max_height = 20
        self.max_width = 20
        self.width = self.max_width
        self.height = self.max_height
        self.setFixedSize(self.width, self.height)
        self.__border = CheckboxBorder()
        self.__area = None
        self.add_layout_item(self.__border, 0, 0)
        self.__reveal = MCircularReveal()
        self.__reveal.duration = 300
        self.__fade = MFadeOut()
        self.__fade.duration = 200
        self.setLayout(self.layout)
        self.__checked = False

    def mousePressEvent(self, event):
        if self.__checked:
            self.__reveal.remove_target(self.__area)
            self.__fade.add_target(self.__area)
            self.__fade.end_signal.connect(self.on_fade_end)
            self.__fade.start()
        else:
            self.__area = CheckboxArea()
            self.add_layout_item(self.__area, 0, 0)
            self.__reveal.add_target(self.__area)
            self.__reveal.start()
            self.__checked = True

    def on_fade_end(self):
        self.__fade.remove_target(self.__area)
        self.__fade.end_signal.disconnect(self.on_fade_end)
        self.remove_layout_item(self.__area)
        self.__checked = False