Esempio n. 1
0
    def paintEvent(self, arg__1: QPaintEvent):
        # super(Push, self).paintEvent(arg__1)
        # lightgrey
        painter = QPainter()
        painter.begin(self)
        pen = QPen(QColor(162, 181, 205), 2, Qt.SolidLine)
        painter.setBrush(QBrush(QColor(255, 255, 255)))
        painter.setPen(pen)
        painter.setRenderHint(QPainter.Antialiasing, True)
        rect = QRect()
        rect.moveTo(1, 10)
        rect.setWidth(140)
        rect.setHeight(140)
        painter.drawRoundedRect(rect, 5, 5)
        painter.drawConvexPolygon(
            [QPoint(60, 10), QPoint(80, 10),
             QPoint(70, 1)])

        pen.setColor(QColor(255, 255, 255))
        painter.setPen(pen)
        painter.drawLine(63, 10, 77, 10)
        pen.setWidth(1)
        painter.setPen(pen)
        painter.drawPoints([QPoint(61, 10), QPoint(78, 10)])
        painter.end()
Esempio n. 2
0
    def __init__(self, id: str, pos: QtCore.QRect, *content_args, img="", height_from_width=False, **extra_args):
        super().__init__()
        # satisfy RenameableMixin abstract property
        self.id = id
        self._lo = QtWidgets.QVBoxLayout()
        self._lo.setMargin(0)
        self.z_index = 0
        self._header = PageItemHeader(id)
        self._header.setAlignment(QtCore.Qt.AlignCenter)
        # if img was provided, don't set the content as text, but as a label
        if img != "":
            self._contents = PageImageItem(self, img, pos.width(), *content_args, **extra_args)
            if height_from_width:
                # Make the widget big enough to contain the image
                pos.setHeight(self._contents.height + self._non_content_height())
            try:
                # Let the user customize how often a resize of the image is done when resizing the item container
                timeout = settings.img_resize_interval
            except ValueError:
                timeout = 0.05
            self._resize_debouncer = Debouncer(timeout=timeout)
            self._resize_debouncer.action = self._resize_image
            self._type = "image"
        else:
            self._contents = PageTextEdit()
            self._html_contents = ""  # stores item contents in a thread-safe way for saving
            self._contents.textChanged.connect(self._set_html_contents)
            self._type = "text"

        self._resizeArrow = PageItemResizeLabel()
        self._resizeArrow.setAlignment(QtCore.Qt.AlignRight)
        self._lo.addWidget(self._header)
        self._lo.addWidget(self._contents)
        self._lo.addWidget(self._resizeArrow)
        self._lo.setSpacing(0)
        self.setLayout(self._lo)
        self.setGeometry(pos)
        self._connect_signals()
Esempio n. 3
0
    def _locate_win_result(self, target_rect: QRect):
        if target_rect.width() < 2 or target_rect.height() < 2:
            return
        # Trigger a resize to regular size if previous size was fitted to a window
        self.img_view.change_viewer_size()

        if self.locate_btn.key_modifier == 0 and self.img_view.height() > 0:
            # No Key Modifier tries to keep aspect ratio
            height_factor: float = self.img_view.height() / self.img_view.width()
            height: int = round(target_rect.width() * height_factor)
            target_rect.setHeight(height)
            LOGGER.debug('Trying to keep aspect ratio at %s height factor. %s %s',
                         height_factor, target_rect.width(), height)
        elif self.locate_btn.key_modifier == Qt.ControlModifier:
            # Ctrl Key only moves window
            self.img_view.move(target_rect.topLeft())
            return
        elif self.locate_btn.key_modifier == Qt.ShiftModifier:
            # Shift/Any Key Modifier fits to window without respecting aspect ratio of image
            pass

        self.img_view.resize(target_rect.size())
        self.img_view.move(target_rect.topLeft())
Esempio n. 4
0
    def mouseMoveEvent(self, event: QMouseEvent) -> None:
        """Qt Mouse-Move Event"""
        def get_top_resize_values() -> Tuple[int, int]:
            """calculates vertial position and height"""
            py: int = (event.globalPos() - self.__mouse_pos).y()
            if self.__window_geometry_height - py < self.__parent.minimumSize(
            ).height():
                height: int = self.__parent.minimumSize().height()
                pos_y: int = self.__window_pos_y + self.__window_geometry_height - height
            else:
                height = self.__window_geometry_height - py
                pos_y = self.__window_pos_y + py
            return pos_y, height

        def get_left_resize_values() -> Tuple[int, int]:
            """calculates horizontal position and width"""
            px: int = (event.globalPos() - self.__mouse_pos).x()
            if self.__window_geometry_width - px < self.__parent.minimumSize(
            ).width():
                width: int = self.__parent.minimumSize().width()
                pos_x: int = self.__window_pos_x + self.__window_geometry_width - width
            else:
                width = self.__window_geometry_width - px
                pos_x = self.__window_pos_x + px
            return pos_x, width

        if self.__mouse_pressed:
            if self.__type == self.BOTTOM:
                py = (event.globalPos() - self.__mouse_pos).y()
                geometry = QRect(self.__window_geometry_x,
                                 self.__window_geometry_y,
                                 self.__window_geometry_width,
                                 self.__window_geometry_height + py)
            elif self.__type == self.RIGHT:
                px = (event.globalPos() - self.__mouse_pos).x()
                geometry = QRect(self.__window_geometry_x,
                                 self.__window_geometry_y,
                                 self.__window_geometry_width + px,
                                 self.__window_geometry_height)
            elif self.__type == self.TOP:
                pos_y, height = get_top_resize_values()
                geometry = QRect(self.__window_geometry_x, pos_y,
                                 self.__window_geometry_width, height)
            elif self.__type == self.LEFT:
                pos_x, width = get_left_resize_values()
                geometry = QRect(pos_x, self.__window_geometry_y, width,
                                 self.__window_geometry_height)
            elif self.__type == self.TOP_LEFT:
                pos_x, width = get_left_resize_values()
                pos_y, height = get_top_resize_values()
                geometry = QRect(pos_x, pos_y, width, height)
            elif self.__type == self.TOP_RIGHT:
                px = (event.globalPos() - self.__mouse_pos).x()
                pos_y, height = get_top_resize_values()
                geometry = QRect(self.__window_pos_x, pos_y,
                                 self.__window_geometry_width + px, height)
            elif self.__type == self.BOTTOM_LEFT:
                pos_x, width = get_left_resize_values()
                py = (event.globalPos() - self.__mouse_pos).y()
                geometry = QRect(pos_x, self.__window_pos_y, width,
                                 self.__window_geometry_height + py)
            elif self.__type == self.BOTTOM_RIGHT:
                px = (event.globalPos() - self.__mouse_pos).x()
                py = (event.globalPos() - self.__mouse_pos).y()
                geometry = QRect(self.__window_geometry_x,
                                 self.__window_geometry_y,
                                 self.__window_geometry_width + px,
                                 self.__window_geometry_height + py)
            if geometry.width() < self.__parent.minimumSize().width():
                geometry.setWidth(self.__parent.minimumSize().width())
            if geometry.height() < self.__parent.minimumSize().height():
                geometry.setHeight(self.__parent.minimumSize().height())
            self.__parent.setGeometry(geometry)
            self.adjust_resizers(geometry)