def paintEvent(self,event):
        titleHeight = 40
        bottomHeight = 50
        
        #画标题背景
        painter = QPainter(self)
        painter.save()
        linearGradient = QLinearGradient(0, 0,0,titleHeight)
        linearGradient.setColorAt(0, QColor(60,150,255))
        linearGradient.setColorAt(0.1, QColor(6,88,200)) 
        linearGradient.setColorAt(1, QColor(80,150,255))
        painter.setBrush(QBrush(linearGradient))
        contenRect = QRect(0, 0, self.width(), titleHeight)
        painter.fillRect(contenRect, QBrush(linearGradient))
        painter.restore()
        
        #画标题内容
        painter.save()
        painter.setPen(QPen(QColor(255, 255, 255),1))
        font = painter.font()
        font.setPointSize(12)
        painter.setFont(font)
        painter.drawText(QPoint(10,25), self.title)
        painter.restore()
        
        #画中间白色背景
        painter.save()
        painter.setPen(QPen(QColor(255, 255, 255),1))
        brush = QBrush(QColor(242,242,242))
        painter.setBrush(brush)
        contenRect = QRect(0, titleHeight, self.width()-1, self.height() - titleHeight - bottomHeight)
#         painter.fillRect(contenRect, brush)
        painter.drawRect(contenRect)
        painter.restore()
        
        #画提示信息内容
        painter.save()
        painter.setPen(QPen(QColor(1, 1, 1),1))
        font = painter.font()
        font.setPointSize(15)
        painter.setFont(font)
        fm = QFontMetrics(font)
        infoWidth = fm.width(self.hintInfo)
        painter.drawText(QPoint((self.width() - infoWidth - 10)/2, 150), self.hintInfo)
        painter.restore()
        
        #画底层背景
        painter.save()
        brush = QBrush(QColor(219,234,255))
        painter.setBrush(brush)
        contenRect = QRect(0, self.height() - bottomHeight, self.width(), bottomHeight)
        painter.fillRect(contenRect, brush)
        painter.restore()
        
        
        
        
        
Beispiel #2
0
        def paintEvent(self, event):
            """
            Paint the widget event
            """
            contents_y = self.edit.verticalScrollBar().value()
            page_bottom = contents_y + self.edit.viewport().height()
            font_metrics = self.fontMetrics()
            current_block = self.edit.document().findBlock(
                self.edit.textCursor().position())

            painter = QPainter(self)

            line_count = 0
            # Iterate over all text blocks in the document.
            block = self.edit.document().begin()
            while block.isValid():
                line_count += 1

                # The top left position of the block in the document
                position = self.edit.document().documentLayout(
                ).blockBoundingRect(block).topLeft()

                # Check if the position of the block is out side of the visible
                # area.
                if position.y() > page_bottom:
                    break

                # We want the line number for the selected line to be bold.
                bold = False
                if block == current_block:
                    bold = True
                    font = painter.font()
                    font.setBold(True)
                    painter.setFont(font)

                # Draw the line number right justified at the y position of the
                # line. 3 is a magic padding number. drawText(x, y, text).
                x = self.width() - font_metrics.width(str(line_count)) - 3
                y = round(position.y()) - contents_y + font_metrics.ascent()
                t = str(line_count)

                painter.drawText(x, y, t)

                # Remove the bold style if it was set previously.
                if bold:
                    font = painter.font()
                    font.setBold(False)
                    painter.setFont(font)

                block = block.next()

            self.highest_line = line_count
            painter.end()

            QWidget.paintEvent(self, event)
Beispiel #3
0
        def paintEvent(self, event):
            contents_y = 0
            page_bottom = self.edit.viewport().height()
            font_metrics = QFontMetrics(self.edit.document().defaultFont())
            current_block = self.edit.document().findBlock(
                self.edit.textCursor().position())

            painter = QPainter(self)
            painter.fillRect(self.rect(), Qt.lightGray)

            block = self.edit.firstVisibleBlock()
            viewport_offset = self.edit.contentOffset()
            line_count = block.blockNumber()
            painter.setFont(self.edit.document().defaultFont())
            while block.isValid():
                line_count += 1
                # The top left position of the block in the document
                position = self.edit.blockBoundingGeometry(
                    block).topLeft() + viewport_offset
                # Check if the position of the block is out side of the visible area
                if position.y() > page_bottom:
                    break

                # We want the line number for the selected line to be bold.
                bold = False
                if block == current_block:
                    bold = True
                    font = painter.font()
                    font.setBold(True)
                    painter.setFont(font)

                # Draw the line number right justified at the y position of the
                # line. 3 is a magic padding number. drawText(x, y, text).
                painter.drawText(
                    self.width() - font_metrics.width(str(line_count)) - 3,
                    round(position.y()) + font_metrics.ascent() +
                    font_metrics.descent() - 1, str(line_count))

                # Remove the bold style if it was set previously.
                if bold:
                    font = painter.font()
                    font.setBold(False)
                    painter.setFont(font)

                block = block.next()

            self.highest_line = line_count
            painter.end()

            QWidget.paintEvent(self, event)
Beispiel #4
0
        def paintEvent(self, event):
            contents_y = self.edit.verticalScrollBar().value()
            page_bottom = contents_y + self.edit.viewport().height()
            font_metrics = self.fontMetrics()
            current_block = self.edit.document().findBlock(self.edit.textCursor().position())

            painter = QPainter(self)

            line_count = 0
            # Iterate over all text blocks in the document.
            block = self.edit.document().begin()
            while block.isValid():
                line_count += 1

                # The top left position of the block in the document
                position = self.edit.document().documentLayout().blockBoundingRect(block).topLeft()

                # Check if the position of the block is out side of the visible
                # area.
                if position.y() > page_bottom:
                    break

                # We want the line number for the selected line to be bold.
                bold = False
                if block == current_block:
                    bold = True
                    font = painter.font()
                    font.setBold(True)
                    painter.setFont(font)

                # Draw the line number right justified at the y position of the
                # line. 3 is a magic padding number. drawText(x, y, text).
                painter.drawText(
                    self.width() - font_metrics.width(str(line_count)) - 3,
                    round(position.y()) - contents_y + font_metrics.ascent(),
                    str(line_count),
                )

                # Remove the bold style if it was set previously.
                if bold:
                    font = painter.font()
                    font.setBold(False)
                    painter.setFont(font)

                block = block.next()

            self.highest_line = line_count
            painter.end()

            QWidget.paintEvent(self, event)
Beispiel #5
0
def draw_image(name, q):
  image = QSvgGenerator()
  image.setSize(QSize(IMAGE_SIZE, IMAGE_SIZE))
  image.setFileName(name + ".svg")

  painter = QPainter()
  painter.begin(image)
  painter.setBrush(Qt.white)
  painter.setPen(Qt.NoPen)
  painter.drawEllipse(QPointF(IMAGE_SIZE/2, IMAGE_SIZE/2), IMAGE_SIZE/2, IMAGE_SIZE/2)
  painter.setBrush(QBrush())
  painter.setPen(QPen())
  
  draw_defect(painter, q)
  draw_circle(painter, q)
  
  pen = QPen()
  pen.setWidth(7)
  pen.setColor(Qt.red)
  painter.setPen(pen)
  
  painter.drawLine(IMAGE_SIZE/2 - ARROW_SIZE, IMAGE_SIZE/2, IMAGE_SIZE/2 + ARROW_SIZE, IMAGE_SIZE/2)
  painter.drawLine(IMAGE_SIZE/2 + ARROW_SIZE, IMAGE_SIZE/2, IMAGE_SIZE/2 + ARROW_SIZE - 30, IMAGE_SIZE/2 + 20)
  painter.drawLine(IMAGE_SIZE/2 + ARROW_SIZE, IMAGE_SIZE/2, IMAGE_SIZE/2 + ARROW_SIZE - 30, IMAGE_SIZE/2 - 20)
  
  font = painter.font()
  font.setPixelSize(40)
  font.setBold(True)
  painter.setFont(font)
  painter.drawText(QPointF(IMAGE_SIZE/2 + ARROW_SIZE - 30, IMAGE_SIZE/2 - 30), "E")
  
  painter.end()
Beispiel #6
0
 def _paint_title(self, p: QPainter):
     dpi = Info.dpi
     p.drawLine(OIBlock.padding * dpi, 0.35 * dpi + OIBlock.padding * dpi,
                self.width() - (0.01 + OIBlock.padding) * dpi,
                0.35 * dpi + OIBlock.padding * dpi)
     p.setPen(self._fg_color)
     f = p.font()
     f.setPointSize(10)
     f.setBold(True)
     p.setFont(f)
     p.drawText(
         QRectF((0.04 + OIBlock.padding) * dpi,
                (OIBlock.padding + .01) * dpi,
                self.width() - .12 * dpi, .25 * dpi),
         str(self.__block.name()))
     f.setBold(False)
     f.setPointSize(8)
     p.setPen(
         QColor(self._fg_color.red(), self._fg_color.green(),
                self._fg_color.blue(), 100))
     p.setFont(f)
     p.drawText(
         QRectF((.04 + OIBlock.padding) * dpi,
                (.17 + OIBlock.padding) * dpi,
                self.width() - .12 * dpi, .15 * dpi),
         str(self.__block.type_name()))
Beispiel #7
0
    def _drawMonthFrame(self):
        self.initMonthInfo()
        wi = self.month_info
        painter = QPainter(self)

        pen = painter.pen()
        pen.setWidth(Var.line_width)
        painter.setPen(pen)

        for coord in wi.paint_base_lines:
            painter.drawLine(*coord)

        # Draw selections
        for selection in wi.selections():
            painter.fillRect(*selection)


        # Draw dates
        font = painter.font()
        font.setPointSize(wi.cell_height/8)
        painter.setFont(font)

        for cell_id in range(42):
            x, y = wi.getCoordinate(cell_id)
            x += wi.cell_width * 74/100
            y += wi.cell_height/7
            
            day = wi.getDay(cell_id)

            painter.drawText(QPointF(x, y), QString(str(day)))
Beispiel #8
0
        def paintEvent(self, event):
            contents_y = 0
            page_bottom = self.edit.viewport().height()
            font_metrics = QFontMetrics(self.edit.document().defaultFont())
            current_block = self.edit.document().findBlock(self.edit.textCursor().position())
 
            painter = QPainter(self)
            painter.fillRect(self.rect(), Qt.lightGray)
            
            block = self.edit.firstVisibleBlock()
            viewport_offset = self.edit.contentOffset()
            line_count = block.blockNumber()
            painter.setFont(self.edit.document().defaultFont())
            while block.isValid():
                line_count += 1
                # The top left position of the block in the document
                position = self.edit.blockBoundingGeometry(block).topLeft() + viewport_offset
                # Check if the position of the block is out side of the visible area
                if position.y() > page_bottom:
                    break
 
                # We want the line number for the selected line to be bold.
                bold = False
                if block == current_block:
                    bold = True
                    font = painter.font()
                    font.setBold(True)
                    painter.setFont(font)
 
                # Draw the line number right justified at the y position of the
                # line. 3 is a magic padding number. drawText(x, y, text).
                painter.drawText(self.width() - font_metrics.width(str(line_count)) - 3,
                    round(position.y()) + font_metrics.ascent()+font_metrics.descent()-1,
                    str(line_count))
 
                # Remove the bold style if it was set previously.
                if bold:
                    font = painter.font()
                    font.setBold(False)
                    painter.setFont(font)
 
                block = block.next()
 
            self.highest_line = line_count
            painter.end()
 
            QWidget.paintEvent(self, event)
Beispiel #9
0
 def _paint_title(self, p: QPainter):
     f = p.font()
     f.setBold(True)
     f.setPointSize(8)
     p.setPen(QColor(self._fg_color.red(), self._fg_color.green(), self._fg_color.blue(), 180))
     p.setFont(f)
     title = str(self.name()) + ' : ' + self.type_name()
     p.drawText(QRectF(6 + Block.padding, 25 + Block.padding, self.width() - 12, 15), title)
Beispiel #10
0
    def number_bar_paint(self, number_bar, event):
        font_metrics = self.fontMetrics()
        current_line = self.document().findBlock(self.textCursor().position()).blockNumber() + 1

        block = self.firstVisibleBlock()
        line_count = block.blockNumber()
        painter = QPainter(number_bar)
        # painter.fillRect(event.rect(), Qt.lightGray)#self.palette().base())
        painter.fillRect(event.rect(), QColor(230, 230, 230))
        painter.setPen(QPen(QColor(180, 180, 180)))
        painter.drawLine(event.rect().width() - 1, 0, event.rect().width() - 1, event.rect().height() - 1)

        # Iterate over all visible text blocks in the document.
        while block.isValid():
            line_count += 1
            block_top = self.blockBoundingGeometry(block).translated(self.contentOffset()).top()

            # Check if the position of the block is out side of the visible
            # area.
            if not block.isVisible() or block_top >= event.rect().bottom():
                break

            # We want the line number for the selected line to be bold.
            if line_count == current_line:
                font = painter.font()
                font.setBold(True)
                painter.setFont(font)
                painter.setPen(QColor(160, 100, 160))
            else:
                font = painter.font()
                font.setBold(False)
                painter.setFont(font)
                painter.setPen(QColor(160, 160, 160))

            # Draw the line number right justified at the position of the line.
            # left, top, right, bottom = super(WithLineNumbers, self).get_viewport_margins()
            left = number_bar.width()
            super(WithLineNumbers, self).set_viewport_margins("line_number", (left, 0, 0, 0))
            paint_rect = QRect(0, block_top, number_bar.width() - 3, font_metrics.height())
            painter.drawText(paint_rect, Qt.AlignRight, str(line_count))

            block = block.next()

        painter.end()
Beispiel #11
0
        def numberbarPaint(self, number_bar, event):
            font_metrics = self.fontMetrics()
            current_line = self.document().findBlock(self.textCursor().position()).blockNumber() + 1

            block = self.firstVisibleBlock()
            line_count = block.blockNumber()
            painter = QPainter(number_bar)
            painter.fillRect(event.rect(), self.palette().base())

            # Iterate over all visible text blocks in the document.
            while block.isValid():
                line_count += 1
                block_top = self.blockBoundingGeometry(block).translated(self.contentOffset()).top()

                # Check if the position of the block is out side of the visible
                # area.
                if not block.isVisible() or block_top >= event.rect().bottom():
                    break

                # We want the line number for the selected line to be bold.
                if line_count == current_line:
                    font = painter.font()
                    font.setBold(True)
                    painter.setPen(Qt.black)
                    painter.setFont(font)
                else:
                    font = painter.font()
                    font.setBold(False)
                    painter.setPen(Qt.darkGray)
                    painter.setFont(font)

                if self.instLine is not None and line_count == self.instLine:
                    painter.drawImage(QRect(0, block_top, 16, 16), self.instPtrImage)

                if line_count in self.breakpoints:
                    painter.drawImage(QRect(0, block_top, 16, 16), self.brkpObjImage)

                # Draw the line number right justified at the position of the line.
                paint_rect = QRect(0, block_top, number_bar.width(), font_metrics.height())
                painter.drawText(paint_rect, Qt.AlignRight, unicode(line_count))

                block = block.next()

            painter.end()
Beispiel #12
0
    def paintEvent(self, e):
        qp = QPainter(self)
        qp.fillRect(e.rect(), self.palette().color(QPalette.Window))
        qp.setPen(Qt.black)

        block = self._edistor.firstVisibleBlock()
        block_number = block.blockNumber()
        text_cursor_position = self._edistor.textCursor().position()
        actual_block = self._edistor.document().findBlock(text_cursor_position)
        top = int(
            self._edistor.blockBoundingGeometry(block).translated(
                self._edistor.contentOffset()).top())
        bottom = top + int(self._edistor.blockBoundingRect(block).height())

        while block.isValid() and top <= e.rect().bottom():
            # Set bold current line
            if block == actual_block:
                self._bold = True
                font = qp.font()
                font.setBold(True)
                qp.setFont(font)

            if block.isVisible() and bottom >= e.rect().top():
                number = str(block_number + 1)
                qp.drawText(0, top, self.width(),
                            self._edistor.fontMetrics().height(),
                            Qt.AlignRight, number)

            if self._bold:
                font = qp.font()
                font.setBold(False)
                qp.setFont(font)

            block = block.next()
            boundingRect = self._edistor.blockBoundingRect(block)
            top = bottom
            bottom = top + int(boundingRect.height())
            block_number += 1
Beispiel #13
0
 def _paint_title(self, p: QPainter):
     p.drawLine(Block.padding, 35 + Block.padding, self.width() - Block.padding, 35 + Block.padding)
     p.setPen(self._fg_color)
     f = p.font()
     f.setPointSize(10)
     f.setBold(True)
     p.setFont(f)
     p.drawText(QRectF(4 + Block.padding, Block.padding + 2, self.width() - 12, 25),
                str(self.settings["Name"].value()))
     f.setBold(False)
     f.setPointSize(8)
     p.setPen(QColor(self._fg_color.red(), self._fg_color.green(), self._fg_color.blue(), 100))
     p.setFont(f)
     p.drawText(QRectF(4 + Block.padding, 18 + Block.padding, self.width() - 12, 15), str(self.__type_name))
Beispiel #14
0
    def paintEvent(self, e):
        qp = QPainter(self)
        qp.fillRect(e.rect(), self.palette().color(QPalette.Window))
        qp.setPen(Qt.black)

        block = self._edistor.firstVisibleBlock()
        block_number = block.blockNumber()
        text_cursor_position = self._edistor.textCursor().position()
        actual_block = self._edistor.document().findBlock(text_cursor_position)
        top = int(self._edistor.blockBoundingGeometry(block).translated(
                  self._edistor.contentOffset()).top())
        bottom = top + int(self._edistor.blockBoundingRect(block).height())

        while block.isValid() and top <= e.rect().bottom():
            # Set bold current line
            if block == actual_block:
                self._bold = True
                font = qp.font()
                font.setBold(True)
                qp.setFont(font)

            if block.isVisible() and bottom >= e.rect().top():
                number = str(block_number + 1)
                qp.drawText(0, top, self.width(),
                            self._edistor.fontMetrics().height(),
                            Qt.AlignRight, number)

            if self._bold:
                font = qp.font()
                font.setBold(False)
                qp.setFont(font)

            block = block.next()
            boundingRect = self._edistor.blockBoundingRect(block)
            top = bottom
            bottom = top + int(boundingRect.height())
            block_number += 1
Beispiel #15
0
 def _paint_title(self, p: QPainter):
     dpi = Info.dpi
     p.drawLine(OIBlock.padding * dpi, 0.35 * dpi + OIBlock.padding * dpi,
                self.width() - (0.01 + OIBlock.padding) * dpi,
                0.35 * dpi + OIBlock.padding * dpi)
     p.setPen(self._fg_color)
     f = p.font()
     f.setPointSize(10)
     f.setBold(True)
     p.setFont(f)
     p.drawText(
         QRectF((0.04 + OIBlock.padding) * dpi, (OIBlock.padding + .01) * dpi, self.width() - .12 * dpi, .25 * dpi),
         str(self.__block.name()))
     f.setBold(False)
     f.setPointSize(8)
     p.setPen(QColor(self._fg_color.red(), self._fg_color.green(), self._fg_color.blue(), 100))
     p.setFont(f)
     p.drawText(
         QRectF((.04 + OIBlock.padding) * dpi, (.17 + OIBlock.padding) * dpi, self.width() - .12 * dpi, .15 * dpi),
         str(self.__block.type_name()))
Beispiel #16
0
    def paintEvent(self, event):
        """This method draws a left sidebar

        :param event: QEvent
        """

        bottom = self.editor.viewport().height()
        font_metrics = QFontMetrics(self.editor.document().defaultFont())
        current_line = self.editor.document().findBlock(
            self.editor.textCursor().position()).blockNumber() + 1
        painter = QPainter(self)
        painter.fillRect(self.rect(), QColor("#D0D0D0"))
        block = self.editor.firstVisibleBlock()
        vpoffset = self.editor.contentOffset()
        line = block.blockNumber()
        painter.setFont(self.editor.document().defaultFont())

        while block.isValid():
            line += 1
            pos = self.editor.blockBoundingGeometry(block).topLeft() + vpoffset
            if pos.y() > bottom:
                break

            # Text bold
            font = painter.font()
            if current_line == line:
                font.setBold(True)
            else:
                font.setBold(False)
            painter.setFont(font)

            if block.isVisible():
                fm_ascent = font_metrics.ascent()
                fm_descent = font_metrics.descent()
                painter.drawText(self.width() -
                                 font_metrics.width(str(line)) + 1,
                                 pos.y() + fm_ascent + fm_descent, str(line))

            block = block.next()
        painter.end()
        QFrame.paintEvent(self, event)
Beispiel #17
0
    def paintEvent(self, event):
        page_bottom = self.edit.viewport().height()
        font_metrics = QFontMetrics(self.edit.document().defaultFont())
        current_block = self.edit.document().findBlock(
            self.edit.textCursor().position())

        painter = QPainter(self)
        painter.fillRect(self.rect(), Qt.lightGray)

        block = self.edit.firstVisibleBlock()
        viewport_offset = self.edit.contentOffset()
        line_count = block.blockNumber()
        painter.setFont(self.edit.document().defaultFont())
        while block.isValid():
            line_count += 1
            # The top left position of the block in the document
            position = self.edit.blockBoundingGeometry(block).topLeft() + \
                viewport_offset
            # Check if the position of the block is outside of the visible area
            if position.y() > page_bottom:
                break

            # Set the Painter Pen depending on special lines
            error = False
            if settings.CHECK_STYLE and \
               ((line_count - 1) in self._pep8Lines):
                painter.setPen(Qt.darkYellow)
                font = painter.font()
                font.setItalic(True)
                font.setUnderline(True)
                painter.setFont(font)
                error = True
            elif settings.FIND_ERRORS and \
                 ((line_count - 1) in self._errorsLines):
                painter.setPen(Qt.red)
                font = painter.font()
                font.setItalic(True)
                font.setUnderline(True)
                painter.setFont(font)
                error = True
            else:
                painter.setPen(Qt.black)

            # We want the line number for the selected line to be bold.
            bold = False
            if block == current_block:
                bold = True
                font = painter.font()
                font.setBold(True)
                painter.setFont(font)

            # Draw the line number right justified at the y position of the
            # line. 3 is a magic padding number. drawText(x, y, text).
            if block.isVisible():
                painter.drawText(self.width() - self.foldArea - \
                    font_metrics.width(str(line_count)) - 3,
                    round(position.y()) + font_metrics.ascent() + \
                    font_metrics.descent() - 1,
                    str(line_count))

            # Remove the bold style if it was set previously.
            if bold:
                font = painter.font()
                font.setBold(False)
                painter.setFont(font)
            if error:
                font = painter.font()
                font.setItalic(False)
                font.setUnderline(False)
                painter.setFont(font)

            block = block.next()

        self.highest_line = line_count

        #Code Folding
        xofs = self.width() - self.foldArea
        painter.fillRect(xofs, 0, self.foldArea, self.height(),
                QColor(resources.CUSTOM_SCHEME.get('fold-area',
                resources.COLOR_SCHEME['fold-area'])))
        if self.foldArea != self.rightArrowIcon.width():
            polygon = QPolygonF()

            self.rightArrowIcon = QPixmap(self.foldArea, self.foldArea)
            self.rightArrowIcon.fill(Qt.transparent)
            self.downArrowIcon = QPixmap(self.foldArea, self.foldArea)
            self.downArrowIcon.fill(Qt.transparent)

            polygon.append(QPointF(self.foldArea * 0.4, self.foldArea * 0.25))
            polygon.append(QPointF(self.foldArea * 0.4, self.foldArea * 0.75))
            polygon.append(QPointF(self.foldArea * 0.8, self.foldArea * 0.5))
            iconPainter = QPainter(self.rightArrowIcon)
            iconPainter.setRenderHint(QPainter.Antialiasing)
            iconPainter.setPen(Qt.NoPen)
            iconPainter.setBrush(QColor(
                resources.CUSTOM_SCHEME.get('fold-arrow',
                resources.COLOR_SCHEME['fold-arrow'])))
            iconPainter.drawPolygon(polygon)

            polygon.clear()
            polygon.append(QPointF(self.foldArea * 0.25, self.foldArea * 0.4))
            polygon.append(QPointF(self.foldArea * 0.75, self.foldArea * 0.4))
            polygon.append(QPointF(self.foldArea * 0.5, self.foldArea * 0.8))
            iconPainter = QPainter(self.downArrowIcon)
            iconPainter.setRenderHint(QPainter.Antialiasing)
            iconPainter.setPen(Qt.NoPen)
            iconPainter.setBrush(QColor(
                resources.CUSTOM_SCHEME.get('fold-arrow',
                resources.COLOR_SCHEME['fold-arrow'])))
            iconPainter.drawPolygon(polygon)

        block = self.edit.firstVisibleBlock()
        while block.isValid():
            position = self.edit.blockBoundingGeometry(
                block).topLeft() + viewport_offset
            #Check if the position of the block is outside of the visible area
            if position.y() > page_bottom:
                break

            if self.pat.match(unicode(block.text())) and block.isVisible():
                if block.blockNumber() in self._foldedBlocks:
                    painter.drawPixmap(xofs, round(position.y()),
                        self.rightArrowIcon)
                else:
                    painter.drawPixmap(xofs, round(position.y()),
                        self.downArrowIcon)
            #Add Bookmarks and Breakpoint
            elif block.blockNumber() in self._breakpoints:
                linear_gradient = QLinearGradient(
                    xofs, round(position.y()),
                    xofs + self.foldArea, round(position.y()) + self.foldArea)
                linear_gradient.setColorAt(0, QColor(255, 11, 11))
                linear_gradient.setColorAt(1, QColor(147, 9, 9))
                painter.setRenderHints(QPainter.Antialiasing, True)
                painter.setPen(Qt.NoPen)
                painter.setBrush(QBrush(linear_gradient))
                painter.drawEllipse(
                    xofs + 1,
                    round(position.y()) + 6,
                    self.foldArea - 1, self.foldArea - 1)
            elif block.blockNumber() in self._bookmarks:
                linear_gradient = QLinearGradient(
                    xofs, round(position.y()),
                    xofs + self.foldArea, round(position.y()) + self.foldArea)
                linear_gradient.setColorAt(0, QColor(13, 62, 243))
                linear_gradient.setColorAt(1, QColor(5, 27, 106))
                painter.setRenderHints(QPainter.Antialiasing, True)
                painter.setPen(Qt.NoPen)
                painter.setBrush(QBrush(linear_gradient))
                painter.drawRoundedRect(
                    xofs + 1,
                    round(position.y()) + 6,
                    self.foldArea - 2, self.foldArea - 1,
                    3, 3)

            block = block.next()

        painter.end()
        QWidget.paintEvent(self, event)
Beispiel #18
0
 def paintEvent(self,e):
     painter = QPainter(self)
     painter.fillRect(0, 0, self.width * self.fixed_font_width + 2, self.height * self.fixed_font_height, Qt.black)
     painter.setPen(Qt.gray)
     painter.setRenderHint(QPainter.TextAntialiasing)
     painter.setFont(self.fixed_font)
     painter.setBackgroundMode(Qt.OpaqueMode)
     # Print main window
     l = self.height
     while (l > 0):
         c = 1
         while (c <= self.width):
             y = self.fixed_font_metrics.ascent() + (l - 1) * self.fixed_font_height
             x = 1 + ((c - 1) * self.fixed_font_width)
             #print "**",l,"**",c
             if self.buf[(((self.height - l) * self.width) + c - 1) * 4] == 0:
                 painter.setPen(self.ztoq_color(self.cur_fg))
             else:
                 painter.setPen(self.ztoq_color(self.buf[(((self.height - l) * self.width) + c - 1) * 4]))
             if self.buf[((((self.height - l) * self.width) + c - 1) * 4) + 1] == 0:
                 painter.setBackground(QBrush(self.ztoq_color(self.cur_bg)))
             else:
                 painter.setBackground(QBrush(self.ztoq_color(self.buf[((((self.height - l) * self.width) + c - 1) * 4) + 1])))
             # Set appropriate font style
             if self.buf[((((self.height - l) * self.width) + c - 1) * 4) + 2] == 0:
                 f = painter.font()
                 f.setBold(False)
                 f.setItalic(False)
                 painter.setFont(f)
             if self.buf[((((self.height - l) * self.width) + c - 1) * 4) + 2] & 1: # Reverse video
                 painter.setPen(self.ztoq_color(self.buf[((((self.height - l) * self.width) + c - 1) * 4) + 1]))
                 painter.setBackground(QBrush(self.ztoq_color(self.buf[(((self.height - l) * self.width) + c - 1) * 4])))
             if self.buf[((((self.height - l) * self.width) + c - 1) * 4) + 2] & 2: # Bold
                 f = painter.font()
                 f.setBold(True)
                 painter.setFont(f)
             if self.buf[((((self.height - l) * self.width) + c - 1) * 4) + 2] & 4: # Italic
                 f = painter.font()
                 f.setItalic(True)
                 painter.setFont(f)
             if self.buf[((((self.height - l) * self.width) + c - 1) * 4) + 3] <> 0:
                 painter.drawText(x,y,self.buf[((((self.height - l) * self.width) + c - 1) * 4) + 3])
             c += 1
         l -= 1
         c = 1
     # Print upper window
     if self.upper_buf <> []:
         l = 1
         while (l <= self.upper_buf_height):
             c = 1
             while (c <= self.width):
                 y = self.fixed_font_metrics.ascent() + (l - 1) * self.fixed_font_height
                 x = 1 + ((c - 1) * self.fixed_font_width)
                 #print "**",l,"**",c
                 if self.upper_buf[((((l - 1) * self.width) + c - 1) * 4) + 3] <> 0:
                     painter.setPen(self.ztoq_color(self.upper_buf[(((l - 1) * self.width) + c - 1) * 4]))
                     painter.setBackground(QBrush(self.ztoq_color(self.upper_buf[((((l - 1) * self.width) + c - 1) * 4) + 1])))
                     # Set appropriate font style
                     if self.upper_buf[((((l - 1) * self.width) + c - 1) * 4) + 2] == 0:
                         f = painter.font()
                         f.setBold(False)
                         f.setItalic(False)
                         painter.setFont(f)
                     if self.upper_buf[((((l - 1) * self.width) + c - 1) * 4) + 2] & 1: # Reverse video
                         painter.setPen(self.ztoq_color(self.upper_buf[((((l - 1) * self.width) + c - 1) * 4) + 1]))
                         painter.setBackground(QBrush(self.ztoq_color(self.upper_buf[(((l - 1) * self.width) + c - 1) * 4])))
                     if self.upper_buf[((((l - 1) * self.width) + c - 1) * 4) + 2] & 2: # Bold
                         f = painter.font()
                         f.setBold(True)
                         painter.setFont(f)
                     if self.upper_buf[((((l - 1) * self.width) + c - 1) * 4) + 2] & 4: # Italic
                         f = painter.font()
                         f.setItalic(True)
                         painter.setFont(f)
                     painter.drawText(x,y,self.upper_buf[((((l - 1) * self.width) + c - 1) * 4) + 3])
                 c += 1
             l += 1
     # Print cursor if visible
     if self._cursor_visible:
         self.display_cursor()
    def paintEvent(self, event):

        page_bottom = self.edit.viewport().height()

        font_metrics = QFontMetrics(self.edit.document().defaultFont())
        current_block = self.edit.document().findBlock(
            self.edit.textCursor().position())

        if self._firstPaintEvent is True:
            self.jumpedUP = False
            self.strings = self.edit.toPlainText().split('\n')
            self._originalTotalLine = len(self.strings)
            self.edit.jump_to_line(len(self.strings) - 2)
        elif self.jumpedUP is False:
            self.edit.jump_to_line(1)
            self.edit.verticalScrollBar().setValue(0)
            self.jumpedUP = True
            return

        pattern = self.pat if self.edit.lang == "python" else self.patNotPython

        painter = QPainter(self)
        background = resources.CUSTOM_SCHEME.get(
            'sidebar-background', resources.COLOR_SCHEME['sidebar-background'])
        foreground = resources.CUSTOM_SCHEME.get(
            'sidebar-foreground', resources.COLOR_SCHEME['sidebar-foreground'])
        pep8color = resources.CUSTOM_SCHEME.get(
            'pep8-underline', resources.COLOR_SCHEME['pep8-underline'])
        errorcolor = resources.CUSTOM_SCHEME.get(
            'error-underline', resources.COLOR_SCHEME['error-underline'])
        migrationcolor = resources.CUSTOM_SCHEME.get(
            'migration-underline',
            resources.COLOR_SCHEME['migration-underline'])
        painter.fillRect(self.rect(), QColor(background))
        '''
        if self._firstPaintEvent is True:
            block = self.edit.document().findBlock(0)
        else:
            block = self.edit.firstVisibleBlock()
        '''
        block = self.edit.firstVisibleBlock()
        viewport_offset = self.edit.contentOffset()
        line_count = block.blockNumber()
        painter.setFont(self.edit.document().defaultFont())

        pat = re.compile('\s*#.*AppObject:')
        patAlexaAppImage = re.compile('\s*#.*AppImage:')
        patAlexaAppText = re.compile('\s*#.*AppText:')
        patAlexaLog = re.compile('\s*##.*Alexa Log')

        while block.isValid():
            line_count += 1
            # The top left position of the block in the document
            position = self.edit.blockBoundingGeometry(block).topLeft() + \
                viewport_offset
            # Check if the position of the block is outside of the visible area
            if position.y() > page_bottom:
                break

            # Set the Painter Pen depending on special lines
            error = False
            if settings.CHECK_STYLE and \
               ((line_count - 1) in self._pep8Lines):
                painter.setPen(QColor(pep8color))
                font = painter.font()
                font.setItalic(True)
                font.setUnderline(True)
                painter.setFont(font)
                error = True
            elif settings.FIND_ERRORS and \
                 ((line_count - 1) in self._errorsLines):
                painter.setPen(QColor(errorcolor))
                font = painter.font()
                font.setItalic(True)
                font.setUnderline(True)
                painter.setFont(font)
                error = True
            elif settings.SHOW_MIGRATION_TIPS and \
                 ((line_count - 1) in self._migrationLines):
                painter.setPen(QColor(migrationcolor))
                font = painter.font()
                font.setItalic(True)
                font.setUnderline(True)
                painter.setFont(font)
                error = True
            else:
                painter.setPen(QColor(foreground))

            # We want the line number for the selected line to be bold.
            bold = False
            if block == current_block:
                bold = True
                font = painter.font()
                font.setBold(True)
                painter.setFont(font)

            # Draw the line number right justified at the y position of the
            # line. 3 is a magic padding number. drawText(x, y, text).
            if block.isVisible():
                painter.drawText(
                    self.width() - self.foldArea -
                    font_metrics.width(str(line_count)) - 3,
                    round(position.y()) + font_metrics.ascent() +
                    font_metrics.descent() - 1, str(line_count))

            # Remove the bold style if it was set previously.
            if bold:
                font = painter.font()
                font.setBold(False)
                painter.setFont(font)
            if error:
                font = painter.font()
                font.setItalic(False)
                font.setUnderline(False)
                painter.setFont(font)

            block = block.next()

        self.highest_line = line_count

        #Code Folding
        xofs = self.width() - self.foldArea
        painter.fillRect(
            xofs, 0, self.foldArea, self.height(),
            QColor(
                resources.CUSTOM_SCHEME.get(
                    'fold-area', resources.COLOR_SCHEME['fold-area'])))
        if self.foldArea != self.rightArrowIcon.width():
            polygon = QPolygonF()

            self.rightArrowIcon = QPixmap(self.foldArea, self.foldArea)
            self.rightArrowIcon.fill(Qt.transparent)
            self.downArrowIcon = QPixmap(self.foldArea, self.foldArea)
            self.downArrowIcon.fill(Qt.transparent)

            polygon.append(QPointF(self.foldArea * 0.4, self.foldArea * 0.25))
            polygon.append(QPointF(self.foldArea * 0.4, self.foldArea * 0.75))
            polygon.append(QPointF(self.foldArea * 0.8, self.foldArea * 0.5))
            iconPainter = QPainter(self.rightArrowIcon)
            iconPainter.setRenderHint(QPainter.Antialiasing)
            iconPainter.setPen(Qt.NoPen)
            iconPainter.setBrush(
                QColor(
                    resources.CUSTOM_SCHEME.get(
                        'fold-arrow', resources.COLOR_SCHEME['fold-arrow'])))
            iconPainter.drawPolygon(polygon)

            polygon.clear()
            polygon.append(QPointF(self.foldArea * 0.25, self.foldArea * 0.4))
            polygon.append(QPointF(self.foldArea * 0.75, self.foldArea * 0.4))
            polygon.append(QPointF(self.foldArea * 0.5, self.foldArea * 0.8))
            iconPainter = QPainter(self.downArrowIcon)
            iconPainter.setRenderHint(QPainter.Antialiasing)
            iconPainter.setPen(Qt.NoPen)
            iconPainter.setBrush(
                QColor(
                    resources.CUSTOM_SCHEME.get(
                        'fold-arrow', resources.COLOR_SCHEME['fold-arrow'])))
            iconPainter.drawPolygon(polygon)

        if self._firstPaintEvent is True:
            block = self.edit.document().findBlock(0)
        else:
            block = self.edit.firstVisibleBlock()
        #block = self.edit.firstVisibleBlock()
        line_count = block.blockNumber()
        while block.isValid():
            #while line_count < 5000:
            line_count += 1
            position = self.edit.blockBoundingGeometry(
                block).topLeft() + viewport_offset
            #Check if the position of the block is outside of the visible area
            if position.y() > page_bottom:
                break

            #block.isVisible() and
            if block.isVisible() and pat.match(
                    block.text()) and block not in self._foldedAlexaObject:
                self._fold(line_count)
                self._foldedAlexaObject.append(block)
                self._alexaObjectsPresent = True
            elif block.isVisible() and patAlexaAppImage.match(
                    block.text()) and block not in self._foldedAlexaImage:
                self._fold(line_count)
                self._foldedAlexaImage.append(block)
                self._alexaObjectsPresent = True
            elif block.isVisible() and patAlexaAppText.match(
                    block.text()) and block not in self._foldedAlexaText:
                self._fold(line_count)
                self._foldedAlexaText.append(block)
                self._alexaObjectsPresent = True
            elif block.isVisible() and patAlexaLog.match(
                    block.text()) and block not in self._foldedAlexaLog:
                self._fold(line_count)
                self._foldedAlexaLog.append(block)
                self._alexaObjectsPresent = True
            elif pattern.match(block.text()) and block.isVisible():
                if block.blockNumber() in self._foldedBlocks:
                    painter.drawPixmap(xofs, round(position.y()),
                                       self.rightArrowIcon)
                else:
                    #block.setVisible(True)
                    painter.drawPixmap(xofs, round(position.y()),
                                       self.downArrowIcon)
            #Add Bookmarks and Breakpoint
            elif block.blockNumber() in self._breakpoints:
                linear_gradient = QLinearGradient(
                    xofs, round(position.y()), xofs + self.foldArea,
                    round(position.y()) + self.foldArea)
                linear_gradient.setColorAt(0, QColor(255, 11, 11))
                linear_gradient.setColorAt(1, QColor(147, 9, 9))
                painter.setRenderHints(QPainter.Antialiasing, True)
                painter.setPen(Qt.NoPen)
                painter.setBrush(QBrush(linear_gradient))
                painter.drawEllipse(xofs + 1,
                                    round(position.y()) + 6, self.foldArea - 1,
                                    self.foldArea - 1)
            elif block.blockNumber() in self._bookmarks:
                linear_gradient = QLinearGradient(
                    xofs, round(position.y()), xofs + self.foldArea,
                    round(position.y()) + self.foldArea)
                linear_gradient.setColorAt(0, QColor(13, 62, 243))
                linear_gradient.setColorAt(1, QColor(5, 27, 106))
                painter.setRenderHints(QPainter.Antialiasing, True)
                painter.setPen(Qt.NoPen)
                painter.setBrush(QBrush(linear_gradient))
                painter.drawRoundedRect(xofs + 1,
                                        round(position.y()) + 6,
                                        self.foldArea - 2, self.foldArea - 1,
                                        3, 3)

            block = block.next()

        block = self.edit.document().findBlock(0)
        line_count = 0
        line_hidden = 0
        while block.isValid():
            line_count += 1
            if not block.isVisible():
                line_hidden += 1
            block = block.next()
        endScrollBar = line_count - line_hidden
        self.edit.verticalScrollBar().setRange(0, endScrollBar)

        if self._firstPaintEvent is True:
            self._firstPaintEvent = False

        #self.updateAlexaAppObjCoords()
        #self.updateAlexaLogCoords()
        painter.end()
        '''
        #self.edit.update()
        if self.edit.verticalScrollBar().value() != self._oldVerticalScrollbarPosition and self._alexaObjectsPresent is True:
            self._oldVerticalScrollbarPosition = self.edit.verticalScrollBar().value()
            self.updateAlexaCoords()
            self.edit.update()  # in this way we can refresh alexa icon position

        if self.edit.horizontalScrollBar().value() != self._oldHorizontalScrollbarPosition and self._alexaObjectsPresent is True:
            self._oldHorizontalScrollbarPosition = self.edit.horizontalScrollBar().value()
            self.updateAlexaCoords()
            self.edit.update()  # in this way we can refresh alexa icon position
        '''

        self.strings = self.edit.toPlainText().split('\n')
        self._currentTotalLine = len(self.strings)

        if self._currentTotalLine != self._originalTotalLine:
            self._originalTotalLine = self._currentTotalLine
            self.updateAlexaCoords()
            self.edit.update()
        '''
        if self._returnPressed is True:
            self._returnPressed = False
            self.updateAlexaAppObjCoords()
            self.updateAlexaLogCoords()
            self.edit.update()

        if self._backspacePressed is True:
            self._backspacePressed = False
            self.strings = self.edit.toPlainText().split('\n')
            self._currentTotalLine = len(self.strings)
            if self._currentTotalLine != self._originalTotalLine:
                self.updateAlexaAppObjCoords()
                self.updateAlexaLogCoords()
                self.edit.update()
        '''

        if self.edit._alexaAppObjIconsCoords != self._oldAlexaAppObjIconsCoords:
            self._oldAlexaAppObjIconsCoords = copy.deepcopy(
                self.edit._alexaAppObjIconsCoords)
            self.edit.update()

        if self.edit._alexaAppImgIconsCoords != self._oldAlexaAppImgIconsCoords:
            self._oldAlexaAppImgIconsCoords = copy.deepcopy(
                self.edit._alexaAppImgIconsCoords)
            self.edit.update()

        if self.edit._alexaAppTextIconsCoords != self._oldAlexaAppTextIconsCoords:
            self._oldAlexaAppTextIconsCoords = copy.deepcopy(
                self.edit._alexaAppTextIconsCoords)
            self.edit.update()

        if self.edit._alexaLogIconsCoords != self._oldAlexaLogIconsCoords:
            self._oldAlexaLogIconsCoords = copy.deepcopy(
                self.edit._alexaLogIconsCoords)
            self.edit.update()

        selectedLine = self.edit.textCursor().selectedText()
        textAtCursorPos = self.edit.textCursor().block().text()

        try:
            #tmp = selectedLine.index("#   AppObject")
            if (pat.match(selectedLine) or patAlexaLog.match(selectedLine) or \
            pat.match(textAtCursorPos) or patAlexaLog.match(textAtCursorPos) or \
            patAlexaAppImage.match(selectedLine) or patAlexaAppImage.match(textAtCursorPos) or\
            patAlexaAppText.match(selectedLine) or patAlexaAppText.match(textAtCursorPos)) and \
            self._keypress is True:
                self._keypress = False
                self.updateAlexaCoords()
        except:
            pass

        QWidget.paintEvent(self, event)
        '''
Beispiel #20
0
 def paintEvent(self, event):
     painter = QPainter(self.viewport())
     painter.setRenderHint(QPainter.Antialiasing)
     self.fm = QFontMetrics(painter.font())
     self.paint(painter, event.rect(), self.viewport().rect(), True)
Beispiel #21
0
    def lineNumberAreaPaintEvent(self, event):
		
		#~ QtGui.QPlainTextEdit.paintEvent(self,event)
        painter=QPainter(self.lineNumberArea)
        #~ print "entro aca el joputa"	
        #~ painter.begin(self.lineNumberArea)
        painter.fillRect(event.rect(), Qt.lightGray)
        painter.setPen(QPen(QColor(243, 243, 243)))
        painter.setBrush(QColor(243, 243, 243))
        painter.drawRect(self.lineNumberArea.width()-15,event.rect().top(),self.lineNumberArea.width(),event.rect().bottom())
        
        initialFont = painter.font()
        font = QFont(initialFont)
        font.setWeight(QFont.Bold)
        
        block = self.firstVisibleBlock()
        blockNumber = block.blockNumber();
        top = int(self.blockBoundingGeometry(block).translated(self.contentOffset()).top())
        bottom = top + int(self.blockBoundingRect(block).height())
        
        markers = self.lineNumberArea.markers
        folding = []
        for a in range(blockNumber):
			if self.foldableLines.has_key(a) and blockNumber <= self.foldableLines[a]:
				folding.append(a)
        #~ print "entro",blockNumber,folding
        while block.isValid() and top <= event.rect().bottom():
            
            if block.isVisible() and bottom >= event.rect().top():
				number = blockNumber
				if self.textCursor().blockNumber() == number:
					painter.setFont(font)
				painter.setPen(Qt.black)
				painter.drawText(0, top, self.lineNumberArea.width()-35, 
                    self.fontMetrics().height(),
                    Qt.AlignRight, str(blockNumber+1))
				if self.textCursor().block().blockNumber() == number:
					painter.setFont(initialFont)
				if number in markers:
					self.lineNumberArea.drawMarker(painter,QRect(self.lineNumberArea.width()-30,top,15,self.fontMetrics().height()))
				painter.setPen(Qt.black)
				#~ print folding
				if folding and (number in self.foldableLines.values()):
					painter.drawLine(self.lineNumberArea.width()-7.5,top+(bottom-top)/2,self.lineNumberArea.width(),top+(bottom-top)/2)
					#~ painter.setPen(QtCore.Qt.red)

					painter.drawLine(self.lineNumberArea.width()-7.5,top+(bottom-top)/2,self.lineNumberArea.width()-7.5,top)
					folding.pop()
				if folding and (number > folding[-1]) and (number < self.foldableLines[folding[-1]]):
					#~ painter.setPen(Qt.red)
					painter.drawLine(self.lineNumberArea.width() - 7.5, top, self.lineNumberArea.width() - 7.5, bottom)
					#~ print  number in self.foldableLines.keys()
				if number in self.foldableLines.keys():
					#~ self.updateFoldedLines()
					#~ print self.foldedLines
					if number in self.foldedLines.keys():
						self.lineNumberArea.drawFoldingItem(painter,QRect(self.lineNumberArea.width()-15,self.blockBoundingGeometry(block).translated(self.contentOffset()).top(),15,self.fontMetrics().height()),False)
					else:
						self.lineNumberArea.drawFoldingItem(painter,QRect(self.lineNumberArea.width()-15,self.blockBoundingGeometry(block).translated(self.contentOffset()).top(),15,self.fontMetrics().height()),True)
						folding.append(number)
						#~ print "folding:",folding

            block = block.next()
            top = bottom
            bottom = top + int(self.blockBoundingRect(block).height())
            
            blockNumber+=1
Beispiel #22
0
    def paintEvent(self, event):
        page_bottom = self.edit.viewport().height()
        font_metrics = QFontMetrics(self.edit.document().defaultFont())
        current_block = self.edit.document().findBlock(
            self.edit.textCursor().position())
        pattern = self.pat if self.edit.lang == "python" else self.patNotPython

        painter = QPainter(self)
        background = resources.CUSTOM_SCHEME.get('sidebar-background',
            resources.COLOR_SCHEME['sidebar-background'])
        foreground = resources.CUSTOM_SCHEME.get('sidebar-foreground',
            resources.COLOR_SCHEME['sidebar-foreground'])
        pep8color = resources.CUSTOM_SCHEME.get('pep8-underline',
            resources.COLOR_SCHEME['pep8-underline'])
        errorcolor = resources.CUSTOM_SCHEME.get('error-underline',
            resources.COLOR_SCHEME['error-underline'])
        painter.fillRect(self.rect(), QColor(background))

        block = self.edit.firstVisibleBlock()
        viewport_offset = self.edit.contentOffset()
        line_count = block.blockNumber()
        painter.setFont(self.edit.document().defaultFont())
        while block.isValid():
            line_count += 1
            # The top left position of the block in the document
            position = self.edit.blockBoundingGeometry(block).topLeft() + \
                viewport_offset
            # Check if the position of the block is outside of the visible area
            if position.y() > page_bottom:
                break

            # Set the Painter Pen depending on special lines
            error = False
            if settings.CHECK_STYLE and \
               ((line_count - 1) in self._pep8Lines):
                painter.setPen(QColor(pep8color))
                font = painter.font()
                font.setItalic(True)
                font.setUnderline(True)
                painter.setFont(font)
                error = True
            elif settings.FIND_ERRORS and \
                 ((line_count - 1) in self._errorsLines):
                painter.setPen(QColor(errorcolor))
                font = painter.font()
                font.setItalic(True)
                font.setUnderline(True)
                painter.setFont(font)
                error = True
            else:
                painter.setPen(QColor(foreground))

            # We want the line number for the selected line to be bold.
            bold = False
            if block == current_block:
                bold = True
                font = painter.font()
                font.setBold(True)
                painter.setFont(font)

            # Draw the line number right justified at the y position of the
            # line. 3 is a magic padding number. drawText(x, y, text).
            if block.isVisible():
                painter.drawText(self.width() - self.foldArea -
                    font_metrics.width(str(line_count)) - 3,
                    round(position.y()) + font_metrics.ascent() +
                    font_metrics.descent() - 1,
                    str(line_count))

            # Remove the bold style if it was set previously.
            if bold:
                font = painter.font()
                font.setBold(False)
                painter.setFont(font)
            if error:
                font = painter.font()
                font.setItalic(False)
                font.setUnderline(False)
                painter.setFont(font)

            block = block.next()

        self.highest_line = line_count

        #Code Folding
        xofs = self.width() - self.foldArea
        painter.fillRect(xofs, 0, self.foldArea, self.height(),
                QColor(resources.CUSTOM_SCHEME.get('fold-area',
                resources.COLOR_SCHEME['fold-area'])))
        if self.foldArea != self.rightArrowIcon.width():
            polygon = QPolygonF()

            self.rightArrowIcon = QPixmap(self.foldArea, self.foldArea)
            self.rightArrowIcon.fill(Qt.transparent)
            self.downArrowIcon = QPixmap(self.foldArea, self.foldArea)
            self.downArrowIcon.fill(Qt.transparent)

            polygon.append(QPointF(self.foldArea * 0.4, self.foldArea * 0.25))
            polygon.append(QPointF(self.foldArea * 0.4, self.foldArea * 0.75))
            polygon.append(QPointF(self.foldArea * 0.8, self.foldArea * 0.5))
            iconPainter = QPainter(self.rightArrowIcon)
            iconPainter.setRenderHint(QPainter.Antialiasing)
            iconPainter.setPen(Qt.NoPen)
            iconPainter.setBrush(QColor(
                resources.CUSTOM_SCHEME.get('fold-arrow',
                resources.COLOR_SCHEME['fold-arrow'])))
            iconPainter.drawPolygon(polygon)

            polygon.clear()
            polygon.append(QPointF(self.foldArea * 0.25, self.foldArea * 0.4))
            polygon.append(QPointF(self.foldArea * 0.75, self.foldArea * 0.4))
            polygon.append(QPointF(self.foldArea * 0.5, self.foldArea * 0.8))
            iconPainter = QPainter(self.downArrowIcon)
            iconPainter.setRenderHint(QPainter.Antialiasing)
            iconPainter.setPen(Qt.NoPen)
            iconPainter.setBrush(QColor(
                resources.CUSTOM_SCHEME.get('fold-arrow',
                resources.COLOR_SCHEME['fold-arrow'])))
            iconPainter.drawPolygon(polygon)

        block = self.edit.firstVisibleBlock()
        while block.isValid():
            position = self.edit.blockBoundingGeometry(
                block).topLeft() + viewport_offset
            #Check if the position of the block is outside of the visible area
            if position.y() > page_bottom:
                break

            if pattern.match(block.text()) and block.isVisible():
                if block.blockNumber() in self._foldedBlocks:
                    painter.drawPixmap(xofs, round(position.y()),
                        self.rightArrowIcon)
                else:
                    painter.drawPixmap(xofs, round(position.y()),
                        self.downArrowIcon)
            #Add Bookmarks and Breakpoint
            elif block.blockNumber() in self._breakpoints:
                linear_gradient = QLinearGradient(
                    xofs, round(position.y()),
                    xofs + self.foldArea, round(position.y()) + self.foldArea)
                linear_gradient.setColorAt(0, QColor(255, 11, 11))
                linear_gradient.setColorAt(1, QColor(147, 9, 9))
                painter.setRenderHints(QPainter.Antialiasing, True)
                painter.setPen(Qt.NoPen)
                painter.setBrush(QBrush(linear_gradient))
                painter.drawEllipse(
                    xofs + 1,
                    round(position.y()) + 6,
                    self.foldArea - 1, self.foldArea - 1)
            elif block.blockNumber() in self._bookmarks:
                linear_gradient = QLinearGradient(
                    xofs, round(position.y()),
                    xofs + self.foldArea, round(position.y()) + self.foldArea)
                linear_gradient.setColorAt(0, QColor(13, 62, 243))
                linear_gradient.setColorAt(1, QColor(5, 27, 106))
                painter.setRenderHints(QPainter.Antialiasing, True)
                painter.setPen(Qt.NoPen)
                painter.setBrush(QBrush(linear_gradient))
                painter.drawRoundedRect(
                    xofs + 1,
                    round(position.y()) + 6,
                    self.foldArea - 2, self.foldArea - 1,
                    3, 3)

            block = block.next()

        painter.end()
        QWidget.paintEvent(self, event)
Beispiel #23
0
    def paintEvent(self, event):
        page_bottom = self.edit.viewport().height()
        font_metrics = QFontMetrics(self.edit.document().defaultFont())
        current_block = self.edit.document().findBlock(
            self.edit.textCursor().position())
        pattern = self.pat if self.edit.lang == "python" else self.patNotPython

        painter = QPainter(self)
        background = resources.CUSTOM_SCHEME.get('sidebar-background',
            resources.COLOR_SCHEME['sidebar-background'])
        foreground = resources.CUSTOM_SCHEME.get('sidebar-foreground',
            resources.COLOR_SCHEME['sidebar-foreground'])
        painter.fillRect(self.rect(), QColor(background))

        block = self.edit.firstVisibleBlock()
        viewport_offset = self.edit.contentOffset()
        line_count = block.blockNumber()
        painter.setFont(self.edit.document().defaultFont())
        while block.isValid():
            line_count += 1
            # The top left position of the block in the document
            position = self.edit.blockBoundingGeometry(block).topLeft() + \
                viewport_offset
            # Check if the position of the block is outside of the visible area
            if position.y() > page_bottom:
                break

            # Set the Painter Pen depending on special lines
            painter.setPen(QColor(foreground))
            error = False
            checkers = sorted(self._neditable.registered_checkers,
                key=lambda x: x[2], reverse=True)
            for items in checkers:
                checker, color, _ = items
                if (line_count - 1) in checker.checks:
                    painter.setPen(QColor(color))
                    font = painter.font()
                    font.setItalic(True)
                    font.setUnderline(True)
                    painter.setFont(font)
                    error = True
                    break

            # We want the line number for the selected line to be bold.
            bold = False
            if block == current_block:
                bold = True
                font = painter.font()
                font.setBold(True)
                painter.setFont(font)

            # Draw the line number right justified at the y position of the
            # line. 3 is a magic padding number. drawText(x, y, text).
            if block.isVisible():
                painter.drawText(self.width() - self.foldArea -
                    font_metrics.width(str(line_count)) - 3,
                    round(position.y()) + font_metrics.ascent() +
                    font_metrics.descent() - 1,
                    str(line_count))

            # Remove the bold style if it was set previously.
            if bold:
                font = painter.font()
                font.setBold(False)
                painter.setFont(font)
            if error:
                font = painter.font()
                font.setItalic(False)
                font.setUnderline(False)
                painter.setFont(font)

            block = block.next()

        self.highest_line = line_count

        #Code Folding
        xofs = self.width() - self.foldArea
        painter.fillRect(xofs, 0, self.foldArea, self.height(),
                QColor(resources.CUSTOM_SCHEME.get('fold-area',
                resources.COLOR_SCHEME['fold-area'])))
        if self.foldArea != self.rightArrowIcon.width():
            polygon = QPolygonF()

            self.rightArrowIcon = QPixmap(self.foldArea, self.foldArea)
            self.rightArrowIcon.fill(Qt.transparent)
            self.downArrowIcon = QPixmap(self.foldArea, self.foldArea)
            self.downArrowIcon.fill(Qt.transparent)

            polygon.append(QPointF(self.foldArea * 0.4, self.foldArea * 0.25))
            polygon.append(QPointF(self.foldArea * 0.4, self.foldArea * 0.75))
            polygon.append(QPointF(self.foldArea * 0.8, self.foldArea * 0.5))
            iconPainter = QPainter(self.rightArrowIcon)
            iconPainter.setRenderHint(QPainter.Antialiasing)
            iconPainter.setPen(Qt.NoPen)
            iconPainter.setBrush(QColor(
                resources.CUSTOM_SCHEME.get('fold-arrow',
                resources.COLOR_SCHEME['fold-arrow'])))
            iconPainter.drawPolygon(polygon)

            polygon.clear()
            polygon.append(QPointF(self.foldArea * 0.25, self.foldArea * 0.4))
            polygon.append(QPointF(self.foldArea * 0.75, self.foldArea * 0.4))
            polygon.append(QPointF(self.foldArea * 0.5, self.foldArea * 0.8))
            iconPainter = QPainter(self.downArrowIcon)
            iconPainter.setRenderHint(QPainter.Antialiasing)
            iconPainter.setPen(Qt.NoPen)
            iconPainter.setBrush(QColor(
                resources.CUSTOM_SCHEME.get('fold-arrow',
                resources.COLOR_SCHEME['fold-arrow'])))
            iconPainter.drawPolygon(polygon)

            self.calculate_docstring_block_fold()

        block = self.edit.firstVisibleBlock()
        while block.isValid():
            position = self.edit.blockBoundingGeometry(
                block).topLeft() + viewport_offset
            #Check if the position of the block is outside of the visible area
            if position.y() > page_bottom:
                break

            if pattern.match(block.text()) and block.isVisible():
                can_fold = True
                if self.patComment.match(block.text()) and \
                   (block.blockNumber() in self._endDocstringBlocks):
                    can_fold = False

                if can_fold:
                    if block.blockNumber() in self.foldedBlocks:
                        painter.drawPixmap(xofs, round(position.y()),
                            self.rightArrowIcon)
                    else:
                        painter.drawPixmap(xofs, round(position.y()),
                            self.downArrowIcon)
            #Add Bookmarks and Breakpoint
            if block.blockNumber() in self.breakpoints:
                linear_gradient = QLinearGradient(
                    xofs, round(position.y()),
                    xofs + self.foldArea, round(position.y()) + self.foldArea)
                linear_gradient.setColorAt(0, QColor(255, 11, 11))
                linear_gradient.setColorAt(1, QColor(147, 9, 9))
                painter.setRenderHints(QPainter.Antialiasing, True)
                painter.setPen(Qt.NoPen)
                painter.setBrush(QBrush(linear_gradient))
                painter.drawEllipse(
                    xofs + 1,
                    round(position.y()) + 6,
                    self.foldArea - 1, self.foldArea - 1)
            elif block.blockNumber() in self.bookmarks:
                linear_gradient = QLinearGradient(
                    xofs, round(position.y()),
                    xofs + self.foldArea, round(position.y()) + self.foldArea)
                linear_gradient.setColorAt(0, QColor(13, 62, 243))
                linear_gradient.setColorAt(1, QColor(5, 27, 106))
                painter.setRenderHints(QPainter.Antialiasing, True)
                painter.setPen(Qt.NoPen)
                painter.setBrush(QBrush(linear_gradient))
                painter.drawRoundedRect(
                    xofs + 1,
                    round(position.y()) + 6,
                    self.foldArea - 2, self.foldArea - 1,
                    3, 3)

            block = block.next()

        painter.end()
        QWidget.paintEvent(self, event)
Beispiel #24
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
        r = 8

        # draw a rounded style
        if self._rolloutStyle == 2:
            # draw the text
            painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop,
                             self.title())

            # draw the triangle
            self.__drawTriangle(painter, x, y)

            # draw the borders
            pen = QPen(self.palette().color(QPalette.Light))
            pen.setWidthF(0.6)
            painter.setPen(pen)

            painter.drawRoundedRect(x + 1, y + 1, w - 1, h - 1, r, r)

            pen.setColor(self.palette().color(QPalette.Shadow))
            painter.setPen(pen)

            painter.drawRoundedRect(x, y, w - 1, h - 1, r, r)

        # draw a square style
        if self._rolloutStyle == 3:
            # draw the text
            painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop,
                             self.title())

            self.__drawTriangle(painter, x, y)

            # draw the borders
            pen = QPen(self.palette().color(QPalette.Light))
            pen.setWidthF(0.6)
            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)

        # draw a Maya style
        if self._rolloutStyle == 4:
            # draw the text
            painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop,
                             self.title())

            painter.setRenderHint(QPainter.Antialiasing, False)

            self.__drawTriangle(painter, x, y)

            # draw the borders - top
            headerHeight = 20

            headerRect = QRect(x + 1, y + 1, w - 1, headerHeight)
            headerRectShadow = QRect(x - 1, y - 1, w + 1, headerHeight + 2)

            # Highlight
            pen = QPen(self.palette().color(QPalette.Light))
            pen.setWidthF(0.4)
            painter.setPen(pen)

            painter.drawRect(headerRect)
            painter.fillRect(headerRect, QColor(255, 255, 255, 18))

            # Shadow
            pen.setColor(self.palette().color(QPalette.Dark))
            painter.setPen(pen)
            painter.drawRect(headerRectShadow)

            if not self.isCollapsed():
                # draw the lover border
                pen = QPen(self.palette().color(QPalette.Dark))
                pen.setWidthF(0.8)
                painter.setPen(pen)

                offSet = headerHeight + 3
                bodyRect = QRect(x, y + offSet, w, h - offSet)
                bodyRectShadow = QRect(x + 1, y + offSet, w + 1,
                                       h - offSet + 1)
                painter.drawRect(bodyRect)

                pen.setColor(self.palette().color(QPalette.Light))
                pen.setWidthF(0.4)
                painter.setPen(pen)

                painter.drawRect(bodyRectShadow)

        # draw a boxed style
        elif self._rolloutStyle == 1:
            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 = '-'

            # draw the borders
            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()

            # draw the lines
            l = rect.left()
            r = rect.right()
            cy = rect.center().y()

            for y in (cy - 3, cy, cy + 3):
                painter.drawLine(l, y, r, y)

        painter.end()
Beispiel #25
0
class Printer(BasePrinter):

    FONT_NAME = 'Courrier'

    def __init__(self, *args, **kwargs):
        BasePrinter.__init__(self, *args, **kwargs)
        self.page_number = 0

        self.printer = QPrinter(QPrinter.HighResolution)
        ## todo: remove-me
        self.printer.setOutputFileName("ufwi_log-page.pdf")
        self.printer.setOutputFormat(QPrinter.NativeFormat)
        #self.printer.setOrientation(QPrinter.Landscape)
        self.printer.setPaperSize(QPrinter.A4)
        self.printer.setResolution(100)

    def _init_painter(self):
        self.painter = QPainter(self.printer)
        self.painter.setRenderHint(QPainter.Antialiasing)
        self.painter.setBackgroundMode(Qt.OpaqueMode)
        self.painter.setBrush(Qt.white)
        self.painter.setFont(QFont(self.FONT_NAME, 9))
        fillrect = QRect(0, 0, self.printer.pageRect().width(), self.printer.pageRect().height())
        self.painter.fillRect(fillrect, self.painter.brush())
        self.page_number = 1

        self._draw_header()
        self._draw_footer()
        self.drawCentralTitle(self.title)
        if self.logo:
            self.painter.drawImage(QPoint(self.width() / 2 - self.logo.width() / 2,
                                          self.height() / 2 + QFontMetrics(self.painter.font()).height() + self.height() / 4 - self.logo.height() / 2),
                                   self.logo)

    def _draw_header(self):
        if not self.header_enabled:
            return

        h = -self.headerHeight()
        self.drawText(QDateTime.currentDateTime().toString('yyyy-MM-dd hh:mm'), h, Qt.AlignLeft)
        h += self.drawText(self.interval_label, h, Qt.AlignRight)
        self.drawText(self.title, h, Qt.AlignLeft)
        self.drawText(self.enterprise, h, Qt.AlignRight)

        self.painter.drawLine(0,
                              self.headerHeight() - 1,
                              self.printer.pageRect().width(),
                              self.headerHeight() - 1)

    def _draw_footer(self):
        if not self.footer_enabled:
            return

        self.painter.drawLine(10,
                              self.printer.pageRect().height() - self.footerHeight(),
                              self.printer.pageRect().width() - 10,
                              self.printer.pageRect().height() - self.footerHeight())
        h = self.height() + 1
        #self.drawText('topleft', h, Qt.AlignLeft)
        h += self.drawText(u'© 2008-2010 EdenWall', h, Qt.AlignRight, size=9)
        self.drawText(unicode(self.page_number), h, Qt.AlignHCenter)
        #self.drawText('bottomright', h, Qt.AlignRight)

    def headerHeight(self):
        if self.header_enabled:
            return 40
        else:
            return 0

    def footerHeight(self):
        if self.footer_enabled:
            return 40
        else:
            return 0

    def height(self):
        return self.printer.pageRect().height() - self.headerHeight() - self.footerHeight()

    def width(self):
        return self.printer.pageRect().width()

    def showDialog(self, parent):
        dialog = QPrintDialog(self.printer, parent)
        if dialog.exec_() != QPrintDialog.Accepted:
            return False

        self._init_painter()
        return True

    def end(self):
        self.painter.end()

    def newPage(self):
        self.printer.newPage()
        self.page_number += 1
        self._draw_header()
        self._draw_footer()

    def drawCentralTitle(self, text):
        self.painter.setBackgroundMode(Qt.TransparentMode)
        f = QFont(self.FONT_NAME, 22)
        f.setWeight(QFont.Bold)
        self.painter.setFont(f)
        height = QFontMetrics(self.painter.font()).height()
        self.painter.drawText(QRect(0,
                                    self.printer.pageRect().height() * 0.5,
                                    self.printer.pageRect().width(),
                                    height),
                              Qt.AlignHCenter | Qt.AlignVCenter,
                              text)
        self.painter.setFont(QFont(self.FONT_NAME, 10))

    def drawHCenteredTitle(self, text, vpos):
        self.painter.setBackgroundMode(Qt.TransparentMode)
        self.painter.setFont(QFont(self.FONT_NAME, 18))
        height = QFontMetrics(self.painter.font()).height()
        self.painter.drawText(QRect(0,
                                    self.headerHeight() + vpos,
                                    self.printer.pageRect().width(),
                                    height),
                              Qt.AlignHCenter | Qt.AlignVCenter,
                              text)
        self.painter.setFont(QFont(self.FONT_NAME, 10))
        return height

    def drawText(self, text, vpos, halign=Qt.AlignLeft, size=10, width=None):
        self.painter.setBackgroundMode(Qt.TransparentMode)
        self.painter.setFont(QFont(self.FONT_NAME, size))
        height = QFontMetrics(self.painter.font()).height()
        if width is None:
            width = self.printer.pageRect().width()
        self.painter.drawText(QRect(0,
                                    self.headerHeight() + vpos,
                                    width,
                                    height),
                              halign | Qt.AlignVCenter,
                              text)

        return height

    def drawFragment(self, frag_widget, vpos, len_frags):

        # Display it on half the page
        scale = 1
        single_frag = False
        if frag_widget.pos == len_frags - 1 and frag_widget.pos % 2 == 0:
            scale = 2
            single_frag = True

        y = self.headerHeight() + vpos
        width = self.printer.pageRect().width() * 0.8 * scale
        height = self.printer.pageRect().height() * 0.5 * 0.8
        x = self.printer.pageRect().width() * 0.1

        if single_frag:
            if frag_widget.view.__class__.__name__ != "TreeFragmentView":
                x = -(width - self.printer.pageRect().width()) / 2.
            else:
                width = width / 2.

        rect = QRect(x, y, width, height)

        # Temporary remove stylesheet to avoid to print background.
        stylesheet_save = frag_widget.styleSheet()
        frag_widget.setStyleSheet('')
        frag_widget.getView().printMe(self.painter, rect)
        frag_widget.setStyleSheet(stylesheet_save)
Beispiel #26
0
    def paintEvent(self, event):

        page_bottom = self.edit.viewport().height()

        font_metrics = QFontMetrics(self.edit.document().defaultFont())
        current_block = self.edit.document().findBlock(self.edit.textCursor().position())

        if self._firstPaintEvent is True:
            self.jumpedUP = False
            self.strings = self.edit.toPlainText().split("\n")
            self._originalTotalLine = len(self.strings)
            self.edit.jump_to_line(len(self.strings) - 2)
        elif self.jumpedUP is False:
            self.edit.jump_to_line(1)
            self.edit.verticalScrollBar().setValue(0)
            self.jumpedUP = True
            return

        pattern = self.pat if self.edit.lang == "python" else self.patNotPython

        painter = QPainter(self)
        background = resources.CUSTOM_SCHEME.get("sidebar-background", resources.COLOR_SCHEME["sidebar-background"])
        foreground = resources.CUSTOM_SCHEME.get("sidebar-foreground", resources.COLOR_SCHEME["sidebar-foreground"])
        pep8color = resources.CUSTOM_SCHEME.get("pep8-underline", resources.COLOR_SCHEME["pep8-underline"])
        errorcolor = resources.CUSTOM_SCHEME.get("error-underline", resources.COLOR_SCHEME["error-underline"])
        migrationcolor = resources.CUSTOM_SCHEME.get(
            "migration-underline", resources.COLOR_SCHEME["migration-underline"]
        )
        painter.fillRect(self.rect(), QColor(background))

        """
        if self._firstPaintEvent is True:
            block = self.edit.document().findBlock(0)
        else:
            block = self.edit.firstVisibleBlock()
        """
        block = self.edit.firstVisibleBlock()
        viewport_offset = self.edit.contentOffset()
        line_count = block.blockNumber()
        painter.setFont(self.edit.document().defaultFont())

        pat = re.compile("\s*#AppObject:")
        patAlexaAppImage = re.compile("\s*#AppImage:")
        patAlexaAppText = re.compile("\s*#AppText:")
        patAlexaLog = re.compile("\s*#Alexa Log")

        while block.isValid():
            line_count += 1
            # The top left position of the block in the document
            position = self.edit.blockBoundingGeometry(block).topLeft() + viewport_offset
            # Check if the position of the block is outside of the visible area
            if position.y() > page_bottom:
                break

            # Set the Painter Pen depending on special lines
            error = False
            if settings.CHECK_STYLE and ((line_count - 1) in self._pep8Lines):
                painter.setPen(QColor(pep8color))
                font = painter.font()
                font.setItalic(True)
                font.setUnderline(True)
                painter.setFont(font)
                error = True
            elif settings.FIND_ERRORS and ((line_count - 1) in self._errorsLines):
                painter.setPen(QColor(errorcolor))
                font = painter.font()
                font.setItalic(True)
                font.setUnderline(True)
                painter.setFont(font)
                error = True
            elif settings.SHOW_MIGRATION_TIPS and ((line_count - 1) in self._migrationLines):
                painter.setPen(QColor(migrationcolor))
                font = painter.font()
                font.setItalic(True)
                font.setUnderline(True)
                painter.setFont(font)
                error = True
            else:
                painter.setPen(QColor(foreground))

            # We want the line number for the selected line to be bold.
            bold = False
            if block == current_block:
                bold = True
                font = painter.font()
                font.setBold(True)
                painter.setFont(font)

            # Draw the line number right justified at the y position of the
            # line. 3 is a magic padding number. drawText(x, y, text).
            if block.isVisible():
                painter.drawText(
                    self.width() - self.foldArea - font_metrics.width(str(line_count)) - 3,
                    round(position.y()) + font_metrics.ascent() + font_metrics.descent() - 1,
                    str(line_count),
                )

            # Remove the bold style if it was set previously.
            if bold:
                font = painter.font()
                font.setBold(False)
                painter.setFont(font)
            if error:
                font = painter.font()
                font.setItalic(False)
                font.setUnderline(False)
                painter.setFont(font)

            block = block.next()

        self.highest_line = line_count

        # Code Folding
        xofs = self.width() - self.foldArea
        painter.fillRect(
            xofs,
            0,
            self.foldArea,
            self.height(),
            QColor(resources.CUSTOM_SCHEME.get("fold-area", resources.COLOR_SCHEME["fold-area"])),
        )
        if self.foldArea != self.rightArrowIcon.width():
            polygon = QPolygonF()

            self.rightArrowIcon = QPixmap(self.foldArea, self.foldArea)
            self.rightArrowIcon.fill(Qt.transparent)
            self.downArrowIcon = QPixmap(self.foldArea, self.foldArea)
            self.downArrowIcon.fill(Qt.transparent)

            polygon.append(QPointF(self.foldArea * 0.4, self.foldArea * 0.25))
            polygon.append(QPointF(self.foldArea * 0.4, self.foldArea * 0.75))
            polygon.append(QPointF(self.foldArea * 0.8, self.foldArea * 0.5))
            iconPainter = QPainter(self.rightArrowIcon)
            iconPainter.setRenderHint(QPainter.Antialiasing)
            iconPainter.setPen(Qt.NoPen)
            iconPainter.setBrush(
                QColor(resources.CUSTOM_SCHEME.get("fold-arrow", resources.COLOR_SCHEME["fold-arrow"]))
            )
            iconPainter.drawPolygon(polygon)

            polygon.clear()
            polygon.append(QPointF(self.foldArea * 0.25, self.foldArea * 0.4))
            polygon.append(QPointF(self.foldArea * 0.75, self.foldArea * 0.4))
            polygon.append(QPointF(self.foldArea * 0.5, self.foldArea * 0.8))
            iconPainter = QPainter(self.downArrowIcon)
            iconPainter.setRenderHint(QPainter.Antialiasing)
            iconPainter.setPen(Qt.NoPen)
            iconPainter.setBrush(
                QColor(resources.CUSTOM_SCHEME.get("fold-arrow", resources.COLOR_SCHEME["fold-arrow"]))
            )
            iconPainter.drawPolygon(polygon)

        if self._firstPaintEvent is True:
            block = self.edit.document().findBlock(0)
        else:
            block = self.edit.firstVisibleBlock()
        # block = self.edit.firstVisibleBlock()
        line_count = block.blockNumber()
        while block.isValid():
            # while line_count < 5000:
            line_count += 1
            position = self.edit.blockBoundingGeometry(block).topLeft() + viewport_offset
            # Check if the position of the block is outside of the visible area
            if position.y() > page_bottom:
                break

            # block.isVisible() and
            if block.isVisible() and pat.match(block.text()) and block not in self._foldedAlexaObject:
                self._fold(line_count)
                self._foldedAlexaObject.append(block)
                self._alexaObjectsPresent = True
            elif block.isVisible() and patAlexaAppImage.match(block.text()) and block not in self._foldedAlexaImage:
                self._fold(line_count)
                self._foldedAlexaImage.append(block)
                self._alexaObjectsPresent = True
            elif block.isVisible() and patAlexaAppText.match(block.text()) and block not in self._foldedAlexaText:
                self._fold(line_count)
                self._foldedAlexaText.append(block)
                self._alexaObjectsPresent = True
            elif block.isVisible() and patAlexaLog.match(block.text()) and block not in self._foldedAlexaLog:
                self._fold(line_count)
                self._foldedAlexaLog.append(block)
                self._alexaObjectsPresent = True
            elif pattern.match(block.text()) and block.isVisible():
                if block.blockNumber() in self._foldedBlocks:
                    painter.drawPixmap(xofs, round(position.y()), self.rightArrowIcon)
                else:
                    # block.setVisible(True)
                    painter.drawPixmap(xofs, round(position.y()), self.downArrowIcon)
            # Add Bookmarks and Breakpoint
            elif block.blockNumber() in self._breakpoints:
                linear_gradient = QLinearGradient(
                    xofs, round(position.y()), xofs + self.foldArea, round(position.y()) + self.foldArea
                )
                linear_gradient.setColorAt(0, QColor(255, 11, 11))
                linear_gradient.setColorAt(1, QColor(147, 9, 9))
                painter.setRenderHints(QPainter.Antialiasing, True)
                painter.setPen(Qt.NoPen)
                painter.setBrush(QBrush(linear_gradient))
                painter.drawEllipse(xofs + 1, round(position.y()) + 6, self.foldArea - 1, self.foldArea - 1)
            elif block.blockNumber() in self._bookmarks:
                linear_gradient = QLinearGradient(
                    xofs, round(position.y()), xofs + self.foldArea, round(position.y()) + self.foldArea
                )
                linear_gradient.setColorAt(0, QColor(13, 62, 243))
                linear_gradient.setColorAt(1, QColor(5, 27, 106))
                painter.setRenderHints(QPainter.Antialiasing, True)
                painter.setPen(Qt.NoPen)
                painter.setBrush(QBrush(linear_gradient))
                painter.drawRoundedRect(xofs + 1, round(position.y()) + 6, self.foldArea - 2, self.foldArea - 1, 3, 3)

            block = block.next()

        block = self.edit.document().findBlock(0)
        line_count = 0
        line_hidden = 0
        while block.isValid():
            line_count += 1
            if not block.isVisible():
                line_hidden += 1
            block = block.next()
        endScrollBar = line_count - line_hidden
        self.edit.verticalScrollBar().setRange(0, endScrollBar)

        if self._firstPaintEvent is True:
            self._firstPaintEvent = False

        # self.updateAlexaAppObjCoords()
        # self.updateAlexaLogCoords()
        painter.end()

        """
        #self.edit.update()
        if self.edit.verticalScrollBar().value() != self._oldVerticalScrollbarPosition and self._alexaObjectsPresent is True:
            self._oldVerticalScrollbarPosition = self.edit.verticalScrollBar().value()
            self.updateAlexaCoords()
            self.edit.update()  # in this way we can refresh alexa icon position

        if self.edit.horizontalScrollBar().value() != self._oldHorizontalScrollbarPosition and self._alexaObjectsPresent is True:
            self._oldHorizontalScrollbarPosition = self.edit.horizontalScrollBar().value()
            self.updateAlexaCoords()
            self.edit.update()  # in this way we can refresh alexa icon position
        """

        self.strings = self.edit.toPlainText().split("\n")
        self._currentTotalLine = len(self.strings)

        if self._currentTotalLine != self._originalTotalLine:
            self._originalTotalLine = self._currentTotalLine
            self.updateAlexaCoords()
            self.edit.update()

        """
        if self._returnPressed is True:
            self._returnPressed = False
            self.updateAlexaAppObjCoords()
            self.updateAlexaLogCoords()
            self.edit.update()

        if self._backspacePressed is True:
            self._backspacePressed = False
            self.strings = self.edit.toPlainText().split('\n')
            self._currentTotalLine = len(self.strings)
            if self._currentTotalLine != self._originalTotalLine:
                self.updateAlexaAppObjCoords()
                self.updateAlexaLogCoords()
                self.edit.update()
        """

        if self.edit._alexaAppObjIconsCoords != self._oldAlexaAppObjIconsCoords:
            self._oldAlexaAppObjIconsCoords = copy.deepcopy(self.edit._alexaAppObjIconsCoords)
            self.edit.update()

        if self.edit._alexaAppImgIconsCoords != self._oldAlexaAppImgIconsCoords:
            self._oldAlexaAppImgIconsCoords = copy.deepcopy(self.edit._alexaAppImgIconsCoords)
            self.edit.update()

        if self.edit._alexaAppTextIconsCoords != self._oldAlexaAppTextIconsCoords:
            self._oldAlexaAppTextIconsCoords = copy.deepcopy(self.edit._alexaAppTextIconsCoords)
            self.edit.update()

        if self.edit._alexaLogIconsCoords != self._oldAlexaLogIconsCoords:
            self._oldAlexaLogIconsCoords = copy.deepcopy(self.edit._alexaLogIconsCoords)
            self.edit.update()

        selectedLine = self.edit.textCursor().selectedText()
        textAtCursorPos = self.edit.textCursor().block().text()

        try:
            # tmp = selectedLine.index("#   AppObject")
            if (
                pat.match(selectedLine)
                or patAlexaLog.match(selectedLine)
                or pat.match(textAtCursorPos)
                or patAlexaLog.match(textAtCursorPos)
                or patAlexaAppImage.match(selectedLine)
                or patAlexaAppImage.match(textAtCursorPos)
                or patAlexaAppText.match(selectedLine)
                or patAlexaAppText.match(textAtCursorPos)
            ) and self._keypress is True:
                self._keypress = False
                self.updateAlexaCoords()
        except:
            pass

        QWidget.paintEvent(self, event)

        """
Beispiel #27
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
        r = 8

        # draw a rounded style
        if self._rolloutStyle == 2:
            # draw the text
            painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title())

            # draw the triangle
            self.__drawTriangle(painter, x, y)

            # draw the borders
            pen = QPen(self.palette().color(QPalette.Light))
            pen.setWidthF(0.6)
            painter.setPen(pen)

            painter.drawRoundedRect(x + 1, y + 1, w - 1, h - 1, r, r)

            pen.setColor(self.palette().color(QPalette.Shadow))
            painter.setPen(pen)

            painter.drawRoundedRect(x, y, w - 1, h - 1, r, r)

        # draw a square style
        if self._rolloutStyle == 3:
            # draw the text
            painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title())

            self.__drawTriangle(painter, x, y)

            # draw the borders
            pen = QPen(self.palette().color(QPalette.Light))
            pen.setWidthF(0.6)
            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)

        # draw a Maya style
        if self._rolloutStyle == 4:
            # draw the text
            painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title())

            painter.setRenderHint(QPainter.Antialiasing, False)

            self.__drawTriangle(painter, x, y)

            # draw the borders - top
            headerHeight = 20

            headerRect = QRect(x + 1, y + 1, w - 1, headerHeight)
            headerRectShadow = QRect(x - 1, y - 1, w + 1, headerHeight + 2)

            # Highlight
            pen = QPen(self.palette().color(QPalette.Light))
            pen.setWidthF(0.4)
            painter.setPen(pen)

            painter.drawRect(headerRect)
            painter.fillRect(headerRect, QColor(255, 255, 255, 18))

            # Shadow
            pen.setColor(self.palette().color(QPalette.Dark))
            painter.setPen(pen)
            painter.drawRect(headerRectShadow)

            if not self.isCollapsed():
                # draw the lover border
                pen = QPen(self.palette().color(QPalette.Dark))
                pen.setWidthF(0.8)
                painter.setPen(pen)

                offSet = headerHeight + 3
                bodyRect = QRect(x, y + offSet, w, h - offSet)
                bodyRectShadow = QRect(x + 1, y + offSet, w + 1, h - offSet + 1)
                painter.drawRect(bodyRect)

                pen.setColor(self.palette().color(QPalette.Light))
                pen.setWidthF(0.4)
                painter.setPen(pen)

                painter.drawRect(bodyRectShadow)

        # draw a boxed style
        elif self._rolloutStyle == 1:
            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 = '-'

            # draw the borders
            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()

            # draw the lines
            l = rect.left()
            r = rect.right()
            cy = rect.center().y()

            for y in (cy - 3, cy, cy + 3):
                painter.drawLine(l, y, r, y)

        painter.end()
    def paintEvent(self, e):
        """ """
        PKWidget.paintEvent(self, e)

        painter = QPainter(self)
        orig_pen = QPen(painter.pen())
        orig_brush = QBrush(painter.brush())
        orig_font = QFont(painter.font())
        metrics = painter.fontMetrics()
        f_height = metrics.ascent()
        text_flags = Qt.AlignHCenter | Qt.AlignVCenter
        
        region = e.region()
        for item in self._shown:
            font_y = item.y + item.height / 2 + f_height / 2

            item_rect = QRect(0, item.y, self.width(), item.height)
            if not region.contains(item_rect):
                continue

            painter.setFont(orig_font)

            # background
            pen = item.color().dark(110)
            pen.setAlpha(100)
            painter.setBrush(QBrush(item.color()))
            painter.setPen(QPen(pen))
            w = self.width() * (item.progress * .01)
            rect = QRect(0, item.y, w, item.height)
            painter.drawRect(rect)

            # queue pos
            pen = pen.dark(140)
            pen.setAlpha(255)
            painter.setPen(QPen(pen))
            queue_rect = QRect(self.padding, item.y + self.padding,
                               item.height - self.padding * 2,
                               item.height - self.padding * 2)
            painter.drawRoundRect(queue_rect, 35, 35)

            # num
            if not item.num is None:
                painter.setPen(orig_pen)
                painter.setBrush(orig_brush)
                painter.drawText(queue_rect, text_flags, str(item.num))

            # text
            painter.setPen(orig_pen)
            painter.setBrush(orig_brush)
            font = QFont('Utopia, Italic', 14, -1, True)
            painter.setFont(font)
            rect = QRect(item_rect)
            rect.setX(item.height + self.padding * 2)
            rect.setWidth(rect.width() - rect.x())
            painter.drawText(rect, Qt.AlignVCenter | Qt.AlignLeft, item.text)

            # state
            if item.state:
                font = QFont('7th Service Expanded Italic, Italic')
                font.setPointSize(18)
                pen = QColor(orig_pen.color())
                pen.setAlpha(50)
                painter.setPen(QPen(pen))
                painter.setFont(font)
                x = item.x
                y = item.y
                w = self.width()
                h = item.height
                rect = QRect(x, y, w, h)
                flags = Qt.AlignVCenter | Qt.AlignRight
                painter.drawText(rect, flags, item.state+'  ')