Esempio n. 1
0
    def testFunctionUnit(self):
        r = QRegion(0, 0, 10, 10)
        r2 = QRegion(5, 5, 10, 10)

        ru = r.united(r2)
        self.assertTrue(ru.contains(QPoint(0,0)))
        self.assertTrue(ru.contains(QPoint(5,5)))
        self.assertTrue(ru.contains(QPoint(10,10)))
        self.assertTrue(ru.contains(QPoint(14,14)))
Esempio n. 2
0
    def testFunctionUnit(self):
        r = QRegion(0, 0, 10, 10)
        r2 = QRegion(5, 5, 10, 10)
 
        ru = r.united(r2)
        self.assert_(ru.contains(QPoint(0,0)))
        self.assert_(ru.contains(QPoint(5,5)))
        self.assert_(ru.contains(QPoint(10,10)))
        self.assert_(ru.contains(QPoint(14,14)))
Esempio n. 3
0
    def print_pdf(self) -> None:
        pix = QPixmap(self.rect().size())
        self.render(pix, QPoint(), QRegion(self.rect()))

        dlg = CustomPrinterDialog(pix)
        if dlg.exec_():
            dlg.save_plan()
Esempio n. 4
0
    def capture(
        self,
        region=None,
        selector=None,
        format=None,
    ):
        """Returns snapshot as QImage.

        :param region: An optional tuple containing region as pixel
            coodinates.
        :param selector: A selector targeted the element to crop on.
        :param format: The output image format.
        """

        if format is None:
            format = QImage.Format_ARGB32_Premultiplied

        self.main_frame.setScrollBarPolicy(
            Qt.Vertical,
            Qt.ScrollBarAlwaysOff,
        )
        self.main_frame.setScrollBarPolicy(
            Qt.Horizontal,
            Qt.ScrollBarAlwaysOff,
        )
        frame_size = self.main_frame.contentsSize()
        max_size = 23170 * 23170
        if frame_size.height() * frame_size.width() > max_size:
            self.logger.warning("Frame size is too large.")
            default_size = self.page.viewportSize()
            if default_size.height() * default_size.width() > max_size:
                return None
        else:
            self.page.setViewportSize(self.main_frame.contentsSize())

        self.logger.info("Frame size -> %s", str(self.page.viewportSize()))

        image = QImage(self.page.viewportSize(), format)
        painter = QPainter(image)

        if region is None and selector is not None:
            region = self.region_for_selector(selector)

        if region:
            x1, y1, x2, y2 = region
            w, h = (x2 - x1), (y2 - y1)
            reg = QRegion(x1, y1, w, h)
            self.main_frame.render(painter, reg)
        else:
            self.main_frame.render(painter)

        painter.end()

        if region:
            x1, y1, x2, y2 = region
            w, h = (x2 - x1), (y2 - y1)
            image = image.copy(x1, y1, w, h)

        return image
Esempio n. 5
0
    def event(self, event):
        if event.type() == QEvent.Resize:
            self.backingStore.resize(self.size())
            self.render()
        elif event.type() == QEvent.UpdateRequest or event.type() == QEvent.Expose:
            self.backingStore.flush(QRegion(QRect(QPoint(0, 0), self.size())))

        return QWindow.event(self, event)
Esempio n. 6
0
    def updateMask(self):
        # get the *whole* window geometry, including its titlebar and borders
        frameRect = self.frameGeometry()

        # get the grabWidget geometry and remap it to global coordinates
        grabGeometry = self.grabWidget.geometry()
        grabGeometry.moveTopLeft(self.grabWidget.mapToGlobal(QPoint(0, 0)))

        self.update_position_lock.acquire()
        #Sends info to the input queue
        x1 = grabGeometry.getRect()[0]
        y1 = grabGeometry.getRect()[1]
        width = grabGeometry.getRect()[2]
        height = grabGeometry.getRect()[3]
        message = f"UPDATE {x1} {y1} {width} {height}"
        # if not self.update_position_queue.empty():
        #     _ = self.update_position_queue.get()
        #     self.update_position_queue.put(message)
        # else:
        #     self.update_position_queue.put(message)

        self.inputs_queue.put(message)

        self.update_position_lock.release()

        # get the actual margins between the grabWidget and the window margins
        left = frameRect.left() - grabGeometry.left()
        top = frameRect.top() - grabGeometry.top()
        right = frameRect.right() - grabGeometry.right()
        bottom = frameRect.bottom() - grabGeometry.bottom()

        # reset the geometries to get "0-point" rectangles for the mask
        frameRect.moveTopLeft(QPoint(0, 0))
        grabGeometry.moveTopLeft(QPoint(0, 0))

        # create the base mask region, adjusted to the margins between the
        # grabWidget and the window as computed above
        region = QRegion(frameRect.adjusted(left, top, right, bottom))
        # "subtract" the grabWidget rectangle to get a mask that only contains
        # the window titlebar, margins and panel
        region -= QRegion(grabGeometry)
        self.setMask(region)
Esempio n. 7
0
 def __init__(self, *args, length=30, **kwargs):
     super(ChessPieces, self).__init__(*args, **kwargs)
     self.can = set()
     self.length = length
     self.radius = length * 5 / 6
     self.area = self.radius ** 2
     self.diam = self.radius * 2
     self.center = length * (10 + 1 / 6), length * (9 + 1 / 6)
     self.resize(self.diam, self.diam)
     self.move(self.length / 6, self.length / 6)
     mask = QRegion(-1, -1, self.diam + 1, self.diam + 1, QRegion.Ellipse)
     self.setMask(mask)
Esempio n. 8
0
    def _adapt_size(self):
        top_spacing = round(self.parent.frameGeometry().height() * self.y_offset_factor) + self.header_height
        left_spacing = round(self.parent.frameGeometry().width() * self.x_offset_factor)

        self.left_space_widget.setMinimumWidth(left_spacing)
        self.top_space_widget.setMinimumHeight(top_spacing)
        self.resize(self.parent.size())

        # Mask out invisible areas to -not- grab mouse events from that region
        reg = QRegion(self.parent.frameGeometry())
        reg -= self.frameGeometry()
        reg += self.overlay_grp.frameGeometry()
        self.setMask(reg)
Esempio n. 9
0
 def paint(
     self, painter: QPainter, option: QStyleOptionViewItem, index: QModelIndex
 ):
     model = index.model()
     value = model.data(index, Qt.DisplayRole)
     frame = self.get_frame(value)
     frame.setFixedSize(option.rect.size())
     ratio = self.parent().devicePixelRatioF()
     pixmap = QPixmap(frame.size() * ratio)
     pixmap.setDevicePixelRatio(ratio)
     frame.render(pixmap, QPoint(), QRegion())
     painter.drawPixmap(option.rect, pixmap)
     if index in self.parent().selectedIndexes():
         fill_selection(option, painter)
Esempio n. 10
0
 def __init__(self, *args, pos=(0, 0), length=30, **kwargs):
     super(RootPieces, self).__init__(*args, **kwargs)
     # self.setAttribute(Qt.WA_TransparentForMouseEvents, True)
     self.length = length
     self.radius = length * 5 / 6
     self.area = self.radius ** 2
     self.diam = self.radius * 2
     self.center = length * (10 + 1 / 6), length * (9 + 1 / 6)
     self.resize(self.diam, self.diam)
     x, y = pos
     self.move(x, y)
     # self.move(self.length / 6, self.length / 6)
     mask = QRegion(-1, -1, self.diam + 1, self.diam + 1, QRegion.Ellipse)
     self.setMask(mask)
Esempio n. 11
0
 def resizeEvent(self, r: QResizeEvent) -> None:
     """
     Qt Resize Event - does two things:
     1) applies rounded corners if window transparency has been disabled
     2) ensures resizer widgets and titlebar buttons stay in place
     TODO: the 'rounded_corner_px' value is harcoded. It relates to in '.TitleTabBar::tab' in
           widgetstyle/tabwidget_titlebar.py (border-width and border-image QSS attribute).
           Action: investigate a way so that this value doesn't have to be hard-coded.
     """
     # if transparency is turned off, set a mask for some basic rounded corners:
     if not self.__transparent_window and self.__style.window.WINDOW_CORNER_RADIUS_PX > 0:
         path = QPainterPath()
         path.addRoundedRect(
             QRectF(self.rect()),
             self.__style.window.WINDOW_CORNER_RADIUS_PX +
             1,  # add 1 to avoid drawing artifacts
             self.__style.window.WINDOW_CORNER_RADIUS_PX + 1)
         reg = QRegion(path.toFillPolygon().toPolygon())
         self.setMask(reg)
     # adjust window button positions
     if not isinstance(self.__window, QDIALOG_TYPES):
         self.resizer_bl.adjust_resizers(self.geometry(
         ))  # adjusting one resizer adjusts all other resizers too
     if self.__window_buttons_position == WINDOW_BUTTONS_RIGHT:
         self.__move_window_buttons()
     # if a titlebar tab widget is set, mask it so that the empty area can be used to drag the window
     if self.__tab_widget is not None:
         width = 0
         tab_bar = self.__tab_widget.tabBar()
         for i in range(0,
                        tab_bar.count() -
                        1):  # don't count invisible tab at end
             if tab_bar.isTabVisible(i):
                 width += tab_bar.tabRect(i).width()
         rounder_corner_px = 8  # TODO  # related to hardcoded border-image value in widgetstyle/tabwidget_titlebar.py
         r = QRect(0, 0, width + rounder_corner_px, self.__titlebar_height)
         self.__tab_widget.tabBar().setMask(r)
Esempio n. 12
0
    def setupUI(self):
        currentFilePath = os.path.dirname(__file__)

        # .uiファイルを読み込み
        loader = QUiLoader()
        uiFilePath = os.path.join(currentFilePath,
                                  'kkDisplayVertexColorSeparatelyGUI.ui')
        self.uiFIle = loader.load(uiFilePath)
        self.setCentralWidget(self.uiFIle)

        # scriptJobのparent設定のためにオブジェクト名を設定
        self.setObjectName("kkDisplayVertexColorSeparatelyWindow")

        # ウインドウのタイトルを指定
        self.setWindowTitle("kkDisplayVertexColorSeparately")

        # ウインドウのサイズを指定
        self.resize(200, 300)

        # UI要素にシグナルを追加
        self.setSignals()

        # SelectedNameに選択オブジェクト名を表示
        self.uiFIle.lineEdit_SelObj.setText(self.targetObj.name())

        # 内蔵のpaintVertexColourツールアイコンをセットする
        self.uiFIle.btn_PaintTool.setIcon(QIcon(':/paintVertexColour.png'))

        # フレームレスにする
        self.setWindowFlags(Qt.Window | Qt.FramelessWindowHint)

        # ウィンドウ自体の角を丸くする
        path = QPainterPath()
        path.addRoundedRect(self.rect(), 10, 10)
        region = QRegion(path.toFillPolygon().toPolygon())
        self.setMask(region)