Beispiel #1
1
        def paintEvent(self, event):
            self.makeCurrent()
            gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
            gl.glUseProgram(self.shaders_program)
            gl.glUniform1i(self.colormap_location, 0)
            gl.glActiveTexture(gl.GL_TEXTURE0 + 0)
            gl.glBindTexture(gl.GL_TEXTURE_1D, self.colormap_id)

            gl.glBegin(gl.GL_QUAD_STRIP)
            bar_start = -1 + self.text_height / self.height() * 2
            bar_height = (1 - 2 * self.text_height / self.height()) * 2
            steps = 40
            for i in range(steps + 1):
                y = i * (1 / steps)
                # gl.glColor(y, 0, 0)
                gl.glVertex(-0.5, (bar_height * y + bar_start), y)
                gl.glVertex(0.5, (bar_height * y + bar_start), y)
            gl.glEnd()
            p = QPainter(self)
            p.drawText((self.width() - self.vmax_width) / 2, self.text_ascent,
                       self.vmax_str)
            p.drawText((self.width() - self.vmin_width) / 2,
                       self.height() - self.text_height + self.text_ascent,
                       self.vmin_str)
            p.end()
Beispiel #2
0
    def paintEvent(self, event):
        super(DragDoubleSpinBoxLine, self).paintEvent(event)
        p = QPainter()
        p.begin(self)

        try:
            v = float(self.text())
        except Exception:
            v = 0.0000001

        try:
            v /= self._max if v > 0 else (self._min * -1)
        except Exception:
            pass
        if self._sup:
            p.fillRect(QRect(0,
                             self.height() - 4, v * self.width(), 4),
                       self._color)
        else:
            p.fillRect(
                QRect(self.width() * 0.5,
                      self.height() - 4,
                      v * self.width() * 0.5, 4),
                self._color if v > 0 else QColor(255, 0, 0))
        p.end()
Beispiel #3
0
 def convert_svg_to_bitmap(source, target):
     svg_renderer = QSvgRenderer(source)
     height = svg_renderer.defaultSize().height()
     width = svg_renderer.defaultSize().width()
     new_image = QImage(width, height, QImage.Format_ARGB32)
     painter = QPainter(new_image)
     svg_renderer.render(painter)
     new_image.save(target)
     painter.end()
Beispiel #4
0
    def paintEvent(self, event):

        painter = QPainter(self)

        if self._is_expanded:
            rect2 = event.rect()
            rect2.setX(15)
            rect2.setWidth(1)
            painter.fillRect(rect2, QBrush(QColor(87, 87, 87)))
Beispiel #5
0
 def render(self, painter: QPainter, rect: QRect) -> None:
     for x in range(self.m_tilesRect.width() + 1):
         for y in range(self.m_tilesRect.height() + 1):
             tp = QPoint(x + self.m_tilesRect.left(),
                         y + self.m_tilesRect.top())
             box = self.tileRect(tp)
             if rect.intersects(box):
                 painter.drawPixmap(
                     box,
                     self.m_tilePixmaps.get(QPointH(tp), self.m_emptyTile))
Beispiel #6
0
    def paintEvent(self, event):
        if self.isVisible() and self.paintLineNum > 0:

            # NOTE 更新绘制
            self.viewport().update()

            block = self.firstVisibleBlock()
            height = self.lineNumberArea.fontMetrics().height()
            number = block.blockNumber()
            painter = QPainter(self.viewport())

            condition = True
            while block.isValid() and condition:
                block_geometry = self.blockBoundingGeometry(block)
                offset = self.contentOffset()
                block_top = block_geometry.translated(offset).top()
                number += 1

                block_rect = QRect(0, block_top, self.width(), height)

                if number == self.paintLineNum:
                    lineColor = QColor(LINE_COLOR).lighter(100)
                    painter.fillRect(block_rect, lineColor)
                    painter.drawRect(block_rect)
                    condition = False

                if block_top > event.rect().bottom():
                    condition = False

                block = block.next()

            painter.end()
        return super(CodeEditor, self).paintEvent(event)
Beispiel #7
0
def overlay_pixmap(pixmap, over_pixmap, overlay_color, align=Qt.AlignCenter):
    """
    Overlays one pixmap over the other
    :param pixmap:
    :param over_pixmap:
    :param overlay_color:
    :param align:
    :return:
    """

    if isinstance(overlay_color, str):
        overlay_color = color.Color.from_string(overlay_color)

    if overlay_color is not None:
        over_pixmap = colorize_pixmap(over_pixmap, overlay_color)

    painter = QPainter(pixmap)
    painter.setCompositionMode(QPainter.CompositionMode_SourceOver)

    x = 0
    y = 0
    if align is Qt.AlignCenter:
        x = pixmap.width() / 2 - over_pixmap.width() / 2
        y = pixmap.height() / 2 - over_pixmap.height() / 2
    elif align is None:
        x = 0
        y = 0

    painter.drawPixmap(x, y, over_pixmap.width(), over_pixmap.height(), over_pixmap)
    painter.end()
Beispiel #8
0
    def _render_svg(self, svg_path, replace_color=None):
        if issubclass(self._cls, QIcon) and not replace_color:
            return QIcon(svg_path)

        with open(svg_path, 'r+') as f:
            data_content = f.read()
            if replace_color is not None:
                data_content = data_content.replace('#555555', replace_color)
                self._render.load(QByteArray(data_content))
                pix = QPixmap(128, 128)
                pix.fill(Qt.transparent)
                painter = QPainter(pix)
                self._render.render(painter)
                painter.end()
                if issubclass(self._cls, QPixmap):
                    return pix
                else:
                    return self._cls(pix)
Beispiel #9
0
    def printDocument(self, printer):
        loop = QEventLoop()
        result = False

        def printPreview(success):
            nonlocal result
            result = success
            loop.quit()

        self.m_page.print(printer, printPreview)
        loop.exec_()
        if not result:
            painter = QPainter()
            if painter.begin(printer):
                font = painter.font()
                font.setPixelSize(20)
                painter.setFont(font)
                painter.drawText(QPointF(10, 25), "Could not generate print preview.")
                painter.end()
Beispiel #10
0
def overlay_image(front_image, back_image, x, y):
    """
    Overlays front image on top of given background image
    :param front_image: QImage
    :param back_image: QImage
    :param x: int
    :param y: int
    """

    painter = QPainter(back_image)
    painter.setRenderHint(QPainter.Antialiasing)
    painter.drawImage(x, y, front_image)
    painter.end()
Beispiel #11
0
 def paintEvent(self, event):
     QMainWindow.paintEvent(self, event)
     if not self.line.isNull():
         painter = QPainter(self)
         pen = QPen(Qt.red, 3)
         painter.setPen(pen)
         painter.drawLine(self.line)
    def _create_pixmap(self, path, color):
        """
        Internal function that creates a new item pixmap from the given path
        :param path: str
        :param color: str or QColor
        :return: QPixmap
        """

        if not path:
            return QPixmap()

        dpi = self.treeWidget().dpi()
        key = path + color + 'DPI-' + str(dpi)
        item_pixmap = self._PIXMAP_CACHE.get(key)
        if not item_pixmap:
            width = 20 * dpi
            height = 18 * dpi
            if '/' not in path and '\\' not in path:
                path = resources.get('icons', path)
            if not path or not os.path.exists(path):
                path = self.default_icon_path()
            pixmap2 = pixmap.Pixmap(path)
            pixmap2.set_color(color)
            pixmap2 = pixmap2.scaled(16 * dpi, 16 * dpi, Qt.KeepAspectRatio, Qt.SmoothTransformation)
            x = (width - pixmap2.width()) / 2
            y = (height - pixmap2.height()) / 2
            item_pixmap = QPixmap(QSize(width, height))
            item_pixmap.fill(Qt.transparent)
            painter = QPainter(item_pixmap)
            painter.drawPixmap(x, y, pixmap2)
            painter.end()
            self._PIXMAP_CACHE[key] = item_pixmap

        return item_pixmap
Beispiel #13
0
    def mousePressEvent(self, event):
        """
        Override the behaviour when the mouse is pressed
        """

        self._drag_initiated = False
        self._drag_dropped_pos = QPoint()

        if event.button() == Qt.LeftButton and event.modifiers(
        ) == Qt.ControlModifier:
            self._drag_start_pos = event.pos()

            # Get mouse position and store the area rectangle of the selected tab
            pos = event.pos()
            self._select_tab_index = self.tabAt(pos)
            rect = self.tabRect(self._select_tab_index)

            # Store a pixmap of the selected tab and a pixmap of the close hand cursor image
            # After that we draw the tab and also the hand cursor in the middle of the tab
            pixmap = QPixmap.grabWidget(self, rect)
            painter = QPainter(pixmap)
            cursor_pm = QPixmap(':/icons/close_hand_cursor.png')
            cursor_pos = QPoint(*map(lambda x, y: (x - y) * 0.5,
                                     rect.size().toTuple(),
                                     cursor_pm.size().toTuple()))
            painter.drawPixmap(cursor_pos, cursor_pm)
            painter.end()

            # Update cursor
            cursor = QCursor(pixmap)
            self.setCursor(cursor)

        super(TearOffTabBar, self).mousePressEvent(event)
Beispiel #14
0
def tint_pixmap(pixmap, tint_color=(255, 255, 255, 100), composition_mode=QPainter.CompositionMode_Plus):
    """
    Composite one pixmap on top of another
    :param pixmap:
    :param tint_color:
    :param composition_mode:
    :return:
    """

    tint_color = QColor(*tint_color)
    over_pixmap = QPixmap(pixmap.width(), pixmap.height())
    over_pixmap.fill(tint_color)
    over_pixmap.setMask(pixmap.mask())
    painter = QPainter(pixmap)
    painter.setCompositionMode(composition_mode)
    painter.drawPixmap(0, 0, over_pixmap.width(), over_pixmap.height(), over_pixmap)
    painter.end()
Beispiel #15
0
    def paintEvent(self, event):
        """
        Overrides base QFrame paintEvent function
        Override to make mouse events work in transparent widgets
        :param event: QPaintEvent
        """

        painter = QPainter(self)
        painter.fillRect(self.rect(), QColor(255, 255, 255, 1))
        painter.end()
 def cdMapper(self,*args):
     global cdR, cdG, cdB
     
     temp2 = QPixmap(cd_pix2)
     mask = QPixmap(cd_pix2_alpha)
     
     mult = 255
     R = cdR * mult
     G = cdG *mult
     B = cdB * mult
     colour = QColor(R,G,B)
     #print("R:" + str(cdR) + " G:" + str(cdG) + " B:" + str(cdB))
     
     #Paint Lines
     painter2 = QPainter(temp2)
     painter2.setCompositionMode(painter2.CompositionMode_Overlay)
     painter2.fillRect(temp2.rect(), colour)
     painter2.end()
      
     #Update Image
     self.main_widget.lbl_LGTC_PRV.setPixmap(temp2)
Beispiel #17
0
    def paintEvent(self, event):

        # If we call super paintEvent function without an style, the icon will be draw twice
        if self._style:
            super(IconButton, self).paintEvent(event)

        painter = QPainter()
        painter.begin(self)
        opt = QStyleOptionButton()
        self.initStyleOption(opt)
        rect = opt.rect
        icon_size = max(
            min(rect.height(), rect.width()) - 2 * self._pad, self._minSize)
        opt.iconSize = QSize(icon_size, icon_size)
        self.style().drawControl(QStyle.CE_PushButton, opt, painter, self)
        painter.end()
Beispiel #18
0
    def _setup_general_tab(self):
        general_widget = QWidget()
        general_layout = layouts.VerticalLayout(spacing=2,
                                                margins=(2, 2, 2, 2))
        general_widget.setLayout(general_layout)

        self._themes_combobox = combobox.BaseComboBox(parent=self)
        all_themes = resources.get_all_resources_of_type(
            resources.ResourceTypes.THEME)

        for i, theme in enumerate(all_themes):
            accent_color_hex = theme.accent_color
            accent_color = color.Color.hex_to_qcolor(
                accent_color_hex[1:] if accent_color_hex.
                startswith('#') else accent_color_hex)
            background_color_hex = theme.background_color
            background_color = color.Color.hex_to_qcolor(
                background_color_hex[1:] if accent_color_hex.
                startswith('#') else background_color_hex)
            accent_color_pixmap = QPixmap(25, 25)
            background_color_pixmap = QPixmap(25, 25)
            accent_color_pixmap.fill(accent_color)
            background_color_pixmap.fill(background_color)
            color_pixmap = QPixmap(50, 25)
            painter = QPainter(color_pixmap)
            painter.drawPixmap(0, 0, 25, 25, accent_color_pixmap)
            painter.drawPixmap(25, 0, 25, 25, background_color_pixmap)
            painter.end()

            color_icon = QIcon(color_pixmap)
            self._themes_combobox.addItem(color_icon, theme.name())

        general_layout.addWidget(self._themes_combobox)
        general_layout.addStretch()

        return general_widget
Beispiel #19
0
    def renderNow(self) -> None:
        if not self.isExposed():
            return

        rect = QRect(0, 0, self.width(), self.height())
        self.m_backingStore.beginPaint(QRegion(rect))

        device: QPaintDevice = self.m_backingStore.paintDevice()
        painter = QPainter(device)

        painter.fillRect(0, 0, self.width(), self.height(),
                         QGradient.NightFade)
        self.render(painter)
        painter.end()

        self.m_backingStore.endPaint()
        self.m_backingStore.flush(QRegion(rect))
Beispiel #20
0
    def thumbnail_icon(self):
        """
        Returns the thumbnail icon
        :return: QIcon
        """

        # custom_path = self.custom_icon_path()
        # if custom_path and '/' not in custom_path and '\\' not in custom_path:
        #     custom_path = resources.icon('icons/{}'.format(self.theme().style()), custom_path)
        # if not custom_path or not os.path.isfile(custom_path):
        #     return super(FolderItemView, self).thumbnail_icon()

        return super(FolderItemView, self).thumbnail_icon()

        color = self.icon_color()
        if not color:
            color = consts.DEFAULT_FOLDER_ICON_COLOR

        icon_key = custom_path + color

        icon = self._THUMBNAIL_ICON_CACHE.get(icon_key)
        if not icon:
            color1 = qt_color.Color.from_string(color)
            color2 = qt_color.Color.from_string('rgb(255, 255, 255, 150)')
            pixmap1 = qt_pixmap.Pixmap(self.THUMBNAIL_PATH)
            pixmap2 = qt_pixmap.Pixmap(custom_path)
            pixmap1.set_color(color1)
            pixmap2.set_color(color2)
            pixmap1 = pixmap1.scaled(128, 128, Qt.KeepAspectRatio,
                                     Qt.SmoothTransformation)
            pixmap2 = pixmap2.scaled(64, 64, Qt.KeepAspectRatio,
                                     Qt.SmoothTransformation)
            x = (128 - pixmap2.width()) / 2
            y = (128 - pixmap2.width()) / 2
            painter = QPainter(pixmap1)
            painter.drawPixmap(x, y + 5, pixmap2)
            painter.end()
            icon = qt_icon.Icon(pixmap1)
            self._THUMBNAIL_ICON_CACHE[icon_key] = icon

        return self._THUMBNAIL_ICON_CACHE.get(icon_key)
Beispiel #21
0
    def _line_number_paint(self, event):
        paint = QPainter(self._line_numbers)
        if not dcc.is_maya():
            paint.fillRect(event.rect(), Qt.lightGray)
        else:
            paint.fillRect(event.rect(), Qt.black)

        block = self.firstVisibleBlock()
        block_number = block.blockNumber()
        top = int(
            self.blockBoundingGeometry(block).translated(
                self.contentOffset()).top())
        bottom = int(top + self.blockBoundingGeometry(block).height())
        while block.isValid() and top <= event.rect().bottom():
            if block.isVisible() and bottom >= event.rect().top():
                number = block_number + 1
                if dcc.is_maya():
                    paint.setPen(Qt.lightGray)
                else:
                    paint.setPen(Qt.black)
                paint.drawText(0, top, self._line_numbers.width(),
                               self.fontMetrics().height(), Qt.AlignRight,
                               str(number))
            block = block.next()
            top = bottom
            bottom = top + self.blockBoundingRect(block).height()
            block_number += 1
Beispiel #22
0
    def paintEvent(self, event):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.SmoothPixmapTransform)
        painter.translate(self._loading_pixmap.width() / 2,
                          self._loading_pixmap.height() / 2)
        painter.rotate(self._rotation)
        painter.drawPixmap(-self._loading_pixmap.width() / 2,
                           -self._loading_pixmap.height() / 2,
                           self._loading_pixmap.width(),
                           self._loading_pixmap.height(), self._loading_pixmap)
        painter.end()

        return super(CircleLoading, self).paintEvent(event)
Beispiel #23
0
 def paintEvent(self, event):
     painter = QPainter()
     painter.begin(self)
     painter.setBrush(QColor(192, 192, 192))
     painter.setPen(QColor(64, 64, 64))
     painter.drawPolygon(self._arrow)
     painter.end()
 def paintEvent(self, event):
     super(CommandButton, self).paintEvent(event)
     if self.has_menu:
         painter = QPainter()
         painter.begin(self)
         brush = QBrush(QColor(self.theme().accent_color))
         painter.setRenderHint(painter.Antialiasing)
         painter.setBrush(brush)
         painter.setPen(Qt.NoPen)
         w = self.rect().width() - 1
         h = self.rect().height() - 1
         polygon = QPolygon()
         polygon.append(QPoint(w - 1, h - 8))
         polygon.append(QPoint(w - 8, h - 1))
         polygon.append(QPoint(w - 1, h - 1))
         painter.drawPolygon(polygon)
Beispiel #25
0
 def pixmap(self, size, mode, state):
     pm = QPixmap(size)
     pm.fill(Qt.transparent)
     self.paint(QPainter(pm), QRect(QPoint(0, 0), size), mode, state)
     return pm
Beispiel #26
0
    def create_drop_indicator_pixmap(palette, size, drop_area):
        border_color = palette.color(QPalette.Active, QPalette.Highlight)
        background_color = palette.color(QPalette.Active, QPalette.Base)
        area_background_color = palette.color(QPalette.Active,
                                              QPalette.Highlight).lighter(150)

        pm = QPixmap(size.width(), size.height())
        pm.fill(QColor(0, 0, 0, 0))

        painter = QPainter(pm)
        pen = painter.pen()
        base_rect = QRectF(pm.rect())

        painter.fillRect(base_rect, background_color)

        painter.save()
        area_rect = QRectF()
        area_line = QLineF()
        gradient = QLinearGradient()
        if drop_area == DropArea.TopDropArea:
            area_rect = QRectF(base_rect.x(), base_rect.y(), base_rect.width(),
                               base_rect.height() * 0.5)
            area_line = QLineF(area_rect.bottomLeft(), area_rect.bottomRight())
            gradient.setStart(area_rect.topLeft())
            gradient.setFinalStop(area_rect.bottomLeft())
            gradient.setColorAt(0, area_background_color)
            gradient.setColorAt(1, area_background_color.lighter(120))
        elif drop_area == DropArea.RightDropArea:
            area_rect = QRectF(base_rect.width() * 0.5, base_rect.y(),
                               base_rect.width() * 0.5, base_rect.height())
            area_line = QLineF(area_rect.topLeft(), area_rect.bottomLeft())
            gradient.setStart(area_rect.topLeft())
            gradient.setFinalStop(area_rect.topRight())
            gradient.setColorAt(0, area_background_color.lighter(120))
            gradient.setColorAt(1, area_background_color)
        elif drop_area == DropArea.BottomDropArea:
            area_rect = QRectF(base_rect.x(),
                               base_rect.height() * 0.5, base_rect.width(),
                               base_rect.height() * 0.5)
            area_line = QLineF(area_rect.topLeft(), area_rect.topRight())
            gradient.setStart(area_rect.topLeft())
            gradient.setFinalStop(area_rect.bottomLeft())
            gradient.setColorAt(0, area_background_color.lighter(120))
            gradient.setColorAt(1, area_background_color)
        elif drop_area == DropArea.LeftDropArea:
            area_rect = QRectF(base_rect.x(), base_rect.y(),
                               base_rect.width() * 0.5, base_rect.height())
            area_line = QLineF(area_rect.topRight(), area_rect.bottomRight())
            gradient.setStart(area_rect.topLeft())
            gradient.setFinalStop(area_rect.topRight())
            gradient.setColorAt(0, area_background_color)
            gradient.setColorAt(1, area_background_color.lighter(120))

        if area_rect.isValid():
            painter.fillRect(area_rect, gradient)
            pen = painter.pen()
            pen.setColor(border_color)
            pen.setStyle(Qt.DashLine)
            painter.setPen(pen)
            painter.drawLine(area_line)

        painter.restore()

        painter.save()
        pen = painter.pen()
        pen.setColor(border_color)
        pen.setWidth(1)

        painter.setPen(pen)
        painter.drawRect(base_rect.adjusted(0, 0, -pen.width(), -pen.width()))
        painter.restore()

        return pm
Beispiel #27
0
    def paintEvent(self, event):
        painter = QPainter(self)
        area_color = self.palette().color(QPalette.Active, QPalette.Highlight)

        if self._full_area_drop:
            r = self.rect()
            painter.fillRect(r, QBrush(area_color, Qt.Dense4Pattern))
            painter.setBrush(QBrush(area_color))
            painter.drawRect(r)
            return

        r = self.rect()
        drop_area = self.cursor_location()
        if drop_area == DropArea.TopDropArea:
            r.setHeight(r.height() * 0.5)
        elif drop_area == DropArea.RightDropArea:
            r.setX(r.width() * 0.5)
        elif drop_area == DropArea.BottomDropArea:
            r.setY(r.height() * 0.5)
        elif drop_area == DropArea.LeftDropArea:
            r.setWidth(r.width() * 0.5)
        elif drop_area == DropArea.CenterDropArea:
            r = self.rect()

        if not r.isNull():
            painter.fillRect(r, QBrush(area_color, Qt.Dense4Pattern))
            painter.setBrush(QBrush(area_color))
            painter.drawRect(r)
Beispiel #28
0
 def paintEvent(self, e):
     qp = QPainter(self)
     qp.setPen(QColor("#d4d4d4"))
     qp.setBrush(QColor(200, 0, 0))
     qp.drawRect(self.rect)
Beispiel #29
0
 def paintEvent(self, event):
     painter = QPainter()
     painter.begin(self)
     painter.setRenderHint(painter.Antialiasing)
     font = painter.font()
     font.setBold(True)
     painter.setFont(font)
     x = self.rect().x()
     y = self.rect().y()
     w = self.rect().width() - 1
     h = self.rect().height() - 1
     _rect = 8
     if self._rolloutStyle == ExpanderStyles.Rounded:
         painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title())
         self.__drawTriangle(painter, x, y)
         pen = QPen(self.palette().color(QPalette.Light))
         pen.setWidthF(0.6)
         painter.setPen(pen)
         painter.drawRoundedRect(x + 1, y + 1, w - 1, h - 1, _rect, _rect)
         pen.setColor(self.palette().color(QPalette.Shadow))
         painter.setPen(pen)
         painter.drawRoundedRect(x, y, w - 1, h - 1, _rect, _rect)
     if self._rolloutStyle == ExpanderStyles.Square:
         painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title())
         self.__drawTriangle(painter, x, y)
         pen = QPen(self.palette().color(QPalette.Light))
         pen.setWidthF(0.2)
         painter.setPen(pen)
         painter.drawRect(x + 1, y + 1, w - 1, h - 1)
         pen.setColor(self.palette().color(QPalette.Shadow))
         painter.setPen(pen)
         painter.drawRect(x, y, w - 1, h - 1)
     if self._rolloutStyle == ExpanderStyles.Maya:
         painter.drawText(
             x + (45 if self.dragDropMode() == ExpanderDragDropModes.InternalMove else 25),
             y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title())
         painter.setRenderHint(QPainter.Antialiasing, False)
         self.__drawTriangle(painter, x, y)
         header_height = 20
         header_rect = QRect(x + 1, y + 1, w - 1, header_height)
         header_rect_shadow = QRect(x - 1, y - 1, w + 1, header_height + 2)
         pen = QPen(self.palette().color(QPalette.Light))
         pen.setWidthF(0.4)
         # painter.setPen(pen)
         painter.setPen(Qt.NoPen)
         painter.drawRect(header_rect)
         painter.fillRect(header_rect, QColor(255, 255, 255, 18))
         pen.setColor(self.palette().color(QPalette.Dark))
         painter.setPen(pen)
         painter.drawRect(header_rect_shadow)
         if not self.isCollapsed():
             # pen = QPen(self.palette().color(QPalette.Background))
             # painter.setPen(pen)
             offset = header_height + 3
             body_rect = QRect(x, y + offset, w, h - offset)
             # body_rect_shadow = QRect(x + 1, y + offSet, w + 1, h - offSet + 1)
             painter.drawRect(body_rect)
             # pen.setColor(self.palette().color(QPalette.Foreground))
             # pen.setWidthF(0.4)
             # painter.setPen(pen)
             # painter.drawRect(body_rect_shadow)
     elif self._rolloutStyle == ExpanderStyles.Boxed:
         if self.isCollapsed():
             arect = QRect(x + 1, y + 9, w - 1, 4)
             brect = QRect(x, y + 8, w - 1, 4)
             text = '+'
         else:
             arect = QRect(x + 1, y + 9, w - 1, h - 9)
             brect = QRect(x, y + 8, w - 1, h - 9)
             text = '-'
         pen = QPen(self.palette().color(QPalette.Light))
         pen.setWidthF(0.6)
         painter.setPen(pen)
         painter.drawRect(arect)
         pen.setColor(self.palette().color(QPalette.Shadow))
         painter.setPen(pen)
         painter.drawRect(brect)
         painter.setRenderHint(painter.Antialiasing, False)
         painter.setBrush(self.palette().color(QPalette.Window).darker(120))
         painter.drawRect(x + 10, y + 1, w - 20, 16)
         painter.drawText(x + 16, y + 1, w - 32, 16, Qt.AlignLeft | Qt.AlignVCenter, text)
         painter.drawText(x + 10, y + 1, w - 20, 16, Qt.AlignCenter, self.title())
     if self.dragDropMode():
         rect = self.dragDropRect()
         _layout = rect.left()
         _rect = rect.right()
         center_y = rect.center().y()
         pen = QPen(self.palette().color(self.isCollapsed() and QPalette.Shadow or QPalette.Mid))
         painter.setPen(pen)
         for y in (center_y - 3, center_y, center_y + 3):
             painter.drawLine(_layout, y, _rect, y)
     painter.end()
Beispiel #30
0
    def paintEvent(self, event):
        if self.isVisible():
            block = self.editor.firstVisibleBlock()
            height = self.fontMetrics().height()
            number = block.blockNumber()
            painter = QPainter(self)
            painter.fillRect(event.rect(), LINEBAR_COLOR)
            painter.drawRect(event.rect().width() - 1, 0,
                             event.rect().width(),
                             event.rect().height() - 1)
            font = painter.font()
            current_block = self.editor.textCursor().block().blockNumber() + 1

            condition = True
            while block.isValid() and condition:
                block_geometry = self.editor.blockBoundingGeometry(block)
                offset = self.editor.contentOffset()
                block_top = block_geometry.translated(offset).top()
                number += 1

                # NOTE set the linebar breakpoint color
                if self.paintLineNum > 0 and number == self.paintLineNum:
                    font.setBold(True)
                    block_rect = QRect(LINE_MARGIN, block_top,
                                       self.width() - LINE_MARGIN * 2, height)
                    painter.fillRect(block_rect, LINEBAR_BP_COLOR)
                # NOTE set the current line color
                elif number == current_block:
                    font.setBold(True)
                    block_rect = QRect(LINE_MARGIN, block_top,
                                       self.width() - LINE_MARGIN * 2, height)
                    painter.fillRect(block_rect, LINEBAR_NUM_COLOR)
                else:
                    font.setBold(False)

                painter.setFont(font)
                rect = QRect(0, block_top, self.width() - 5, height)
                painter.drawText(rect, Qt.AlignRight, '%i' % number)

                if block_top > event.rect().bottom():
                    condition = False

                block = block.next()

            painter.end()